Skip to content

Commit

Permalink
docs: add documentation for the global transaction id (watson-develop…
Browse files Browse the repository at this point in the history
…er-cloud#1022)

* add code examples showing how to extract the ID
  • Loading branch information
dpopp07 authored Jan 29, 2020
1 parent f2cbb5e commit e21eb98
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 15 deletions.
45 changes: 43 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ The SDK now returns the full HTTP response by default for each method.
Here is an example of how to access the response headers for Watson Assistant:

```js
const assistant = new watson.AssistantV1({
const assistant = new AssistantV1({
/* authenticator, version, url, etc... */
});

Expand All @@ -262,11 +262,52 @@ assistant.message(params).then(
console.log(response.headers);
},
err => {
console.log('error: ', err);
console.log(err);
/*
`err` is an Error object. It will always have a `message` field
and depending on the type of error, it may also have the following fields:
- body
- headers
- name
- code
*/
}
);
```

### Global Transaction ID
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.

#### HTTP Example
```js
const assistant = new AssistantV1({
/* authenticator, version, url, etc... */
});

assistant.message(params).then(
response => {
console.log(response.headers['x-global-transaction-id']);
},
err => {
console.log(err);
}
);
```

#### WebSocket Example
```js
const speechToText = new SpeechToTextV1({
/* authenticator, version, url, etc... */
});
const recognizeStream = recognizeUsingWebSocket(params);

// getTransactionId returns a Promise that resolves to the ID
recognizeStream.getTransactionId().then(
globalTransactionId => console.log(globalTransactionId),
err => console.log(err),
);
```

## Data collection opt-out

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:
Expand Down
4 changes: 1 addition & 3 deletions scripts/report_integration_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ if (process.env.TRAVIS_PULL_REQUEST && process.env.TRAVIS_PULL_REQUEST !== 'fals
// Send the result to the pull request if it is a pull request.
axios
.post(
`https://api.github.com/repos/${process.env.TRAVIS_REPO_SLUG}/issues/${
process.env.TRAVIS_PULL_REQUEST
}/comments`,
`https://api.github.com/repos/${process.env.TRAVIS_REPO_SLUG}/issues/${process.env.TRAVIS_PULL_REQUEST}/comments`,
{
body: body,
},
Expand Down
Binary file modified secrets.tar.enc
Binary file not shown.
4 changes: 2 additions & 2 deletions test/integration/compare-comply.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ describe('compare comply integration', () => {
expect(result.feedback_data).toBeDefined();
done();
});
}, 15000);
}, 25000);

test('getFeedback', done => {
if (!feedbackId) {
Expand All @@ -214,7 +214,7 @@ describe('compare comply integration', () => {
expect(result.feedback_data).toBeDefined();
done();
});
}, 10000);
}, 20000);

test('listFeedback', done => {
compareComply.listFeedback((err, res) => {
Expand Down
13 changes: 5 additions & 8 deletions test/integration/speech-to-text.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,12 @@ describe('speech to text integration', () => {
function waitUntilReady(test) {
return done => {
jest.setTimeout(TWO_MINUTES);
speechToText.whenCustomizationReady(
{ customizationId, interval: 250, times: 400 },
err => {
if (err && err.code !== SpeechToTextV1.ERR_NO_CORPORA) {
return done(err);
}
test(done);
speechToText.whenCustomizationReady({ customizationId, interval: 250, times: 400 }, err => {
if (err && err.code !== SpeechToTextV1.ERR_NO_CORPORA) {
return done(err);
}
);
test(done);
});
};
}

Expand Down

0 comments on commit e21eb98

Please sign in to comment.