Skip to content

Commit e21eb98

Browse files
authored
docs: add documentation for the global transaction id (#1022)
* add code examples showing how to extract the ID
1 parent f2cbb5e commit e21eb98

5 files changed

Lines changed: 51 additions & 15 deletions

File tree

README.md

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ The SDK now returns the full HTTP response by default for each method.
253253
Here is an example of how to access the response headers for Watson Assistant:
254254

255255
```js
256-
const assistant = new watson.AssistantV1({
256+
const assistant = new AssistantV1({
257257
/* authenticator, version, url, etc... */
258258
});
259259

@@ -262,11 +262,52 @@ assistant.message(params).then(
262262
console.log(response.headers);
263263
},
264264
err => {
265-
console.log('error: ', err);
265+
console.log(err);
266+
/*
267+
`err` is an Error object. It will always have a `message` field
268+
and depending on the type of error, it may also have the following fields:
269+
- body
270+
- headers
271+
- name
272+
- code
273+
*/
266274
}
267275
);
268276
```
269277

278+
### Global Transaction ID
279+
Every SDK call returns a response with a transaction ID in the x-global-transaction-id header. This transaction ID is useful for troubleshooting and accessing relevant logs from your service instance.
280+
281+
#### HTTP Example
282+
```js
283+
const assistant = new AssistantV1({
284+
/* authenticator, version, url, etc... */
285+
});
286+
287+
assistant.message(params).then(
288+
response => {
289+
console.log(response.headers['x-global-transaction-id']);
290+
},
291+
err => {
292+
console.log(err);
293+
}
294+
);
295+
```
296+
297+
#### WebSocket Example
298+
```js
299+
const speechToText = new SpeechToTextV1({
300+
/* authenticator, version, url, etc... */
301+
});
302+
const recognizeStream = recognizeUsingWebSocket(params);
303+
304+
// getTransactionId returns a Promise that resolves to the ID
305+
recognizeStream.getTransactionId().then(
306+
globalTransactionId => console.log(globalTransactionId),
307+
err => console.log(err),
308+
);
309+
```
310+
270311
## Data collection opt-out
271312

272313
By default, [all requests are logged](https://cloud.ibm.com/docs/services/watson/getting-started-logging.html). This can be disabled of by setting the `X-Watson-Learning-Opt-Out` header when creating the service instance:

scripts/report_integration_test.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ if (process.env.TRAVIS_PULL_REQUEST && process.env.TRAVIS_PULL_REQUEST !== 'fals
5050
// Send the result to the pull request if it is a pull request.
5151
axios
5252
.post(
53-
`https://api.github.com/repos/${process.env.TRAVIS_REPO_SLUG}/issues/${
54-
process.env.TRAVIS_PULL_REQUEST
55-
}/comments`,
53+
`https://api.github.com/repos/${process.env.TRAVIS_REPO_SLUG}/issues/${process.env.TRAVIS_PULL_REQUEST}/comments`,
5654
{
5755
body: body,
5856
},

secrets.tar.enc

0 Bytes
Binary file not shown.

test/integration/compare-comply.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ describe('compare comply integration', () => {
189189
expect(result.feedback_data).toBeDefined();
190190
done();
191191
});
192-
}, 15000);
192+
}, 25000);
193193

194194
test('getFeedback', done => {
195195
if (!feedbackId) {
@@ -214,7 +214,7 @@ describe('compare comply integration', () => {
214214
expect(result.feedback_data).toBeDefined();
215215
done();
216216
});
217-
}, 10000);
217+
}, 20000);
218218

219219
test('listFeedback', done => {
220220
compareComply.listFeedback((err, res) => {

test/integration/speech-to-text.test.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,12 @@ describe('speech to text integration', () => {
105105
function waitUntilReady(test) {
106106
return done => {
107107
jest.setTimeout(TWO_MINUTES);
108-
speechToText.whenCustomizationReady(
109-
{ customizationId, interval: 250, times: 400 },
110-
err => {
111-
if (err && err.code !== SpeechToTextV1.ERR_NO_CORPORA) {
112-
return done(err);
113-
}
114-
test(done);
108+
speechToText.whenCustomizationReady({ customizationId, interval: 250, times: 400 }, err => {
109+
if (err && err.code !== SpeechToTextV1.ERR_NO_CORPORA) {
110+
return done(err);
115111
}
116-
);
112+
test(done);
113+
});
117114
};
118115
}
119116

0 commit comments

Comments
 (0)