You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/core/tracer.md
+32
Original file line number
Diff line number
Diff line change
@@ -484,6 +484,38 @@ Use **`POWERTOOLS_TRACER_CAPTURE_ERROR=false`** environment variable to instruct
484
484
485
485
1. You might **return sensitive** information from errors, stack traces you might not control
486
486
487
+
### Access AWS X-Ray Root Trace ID
488
+
489
+
Tracer exposes a `getRootXrayTraceId()` method that allows you to retrieve the [AWS X-Ray Root Trace ID](https://docs.aws.amazon.com/xray/latest/devguide/xray-concepts.html#xray-concepts-traces) corresponds to the current function execution.
490
+
491
+
!!! info "This is commonly useful in two scenarios"
492
+
493
+
1. By including the root trace id in your response, consumers can use it to correlate requests
494
+
2. You might want to surface the root trace id to your end users so that they can reference it while contacting customer service
495
+
496
+
=== "index.ts"
497
+
498
+
```typescript hl_lines="9"
499
+
import { Tracer } from '@aws-lambda-powertools/tracer';
500
+
501
+
const tracer = new Tracer({ serviceName: 'serverlessAirline' });
body: `Internal Error - Please contact support and quote the following id: ${rootTraceId}`,
513
+
headers: { "_X_AMZN_TRACE_ID": rootTraceId },
514
+
};
515
+
}
516
+
};
517
+
```
518
+
487
519
### Escape hatch mechanism
488
520
489
521
You can use `tracer.provider` attribute to access all methods provided by the [AWS X-Ray SDK](https://docs.aws.amazon.com/xray-sdk-for-nodejs/latest/reference/AWSXRay.html).
0 commit comments