Skip to content

Commit f46567a

Browse files
committed
doc(transaction-id): Add doc for getting transaction id
1 parent e0e5f83 commit f46567a

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Python client library to quickly get started with the various [Watson APIs][wdc]
3131
* [Setting the service url](#setting-the-service-url)
3232
* [Sending request headers](#sending-request-headers)
3333
* [Parsing HTTP response information](#parsing-http-response-information)
34+
* [Getting the transaction ID](#getting-the-transaction-id)
3435
* [Using Websockets](#using-websockets)
3536
* [Cloud Pak for Data(CP4D)](#cloud-pak-for-data)
3637
* [Logging](#logging)
@@ -362,6 +363,30 @@ This would give an output of `DetailedResponse` having the structure:
362363
```
363364
You can use the `get_result()`, `get_headers()` and get_status_code() to return the result, headers and status code respectively.
364365

366+
## Getting the transaction ID
367+
Every response from the SDK will contain a transaction ID. This transaction ID is useful for troubleshooting and accessing relevant logs from your service instance.
368+
### Suceess
369+
```python
370+
from ibm_watson import MyService
371+
372+
service = MyService(authenticator=my_authenticator)
373+
response_headers = service.my_service_call().get_headers()
374+
print(response_headers.get('x-global-transaction-id'))
375+
```
376+
377+
### Failure
378+
```python
379+
from ibm_watson import MyService, ApiException
380+
381+
try:
382+
service = MyService(authenticator=my_authenticators)
383+
service.my_service_call()
384+
except ApiException as e:
385+
print(e.global_transaction_id)
386+
# OR
387+
print(e.http_response.headers.get('x-global-transaction-id'))
388+
```
389+
365390
## Using Websockets
366391
The Text to Speech service supports synthesizing text to spoken audio using web sockets with the `synthesize_using_websocket`. The Speech to Text service supports recognizing speech to text using web sockets with the `recognize_using_websocket`. These methods need a custom callback class to listen to events. Below is an example of `synthesize_using_websocket`. Note: The service accepts one request per connection.
367392

0 commit comments

Comments
 (0)