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
+66
Original file line number
Diff line number
Diff line change
@@ -42,6 +42,72 @@ The `Tracer` utility must always be instantiated outside of the Lambda handler.
42
42
--8<-- "examples/snippets/tracer/basicUsage.ts"
43
43
```
44
44
45
+
#### Using with ESM?
46
+
47
+
Tracer relies on the AWS X-Ray SDK for Node.js, which is distributed as a CommonJS module and uses `require`.
48
+
49
+
To use it in an ESM project, you can instruct your bundler to use the `require` syntax for specific dependencies while using ESM for everything else. This is commonly known as [polyfill](https://developer.mozilla.org/en-US/docs/Glossary/Polyfill){target="_blank"}.
50
+
51
+
??? note "Code snippets for AWS CDK and AWS SAM CLI with `esbuild`"
52
+
53
+
=== "With AWS CDK"
54
+
55
+
```typescript hl_lines="15 20-21"
56
+
import { Stack, type StackProps } from 'aws-cdk-lib';
57
+
import { Construct } from 'constructs';
58
+
import { NodejsFunction, OutputFormat } from 'aws-cdk-lib/aws-lambda-nodejs';
59
+
import { Runtime } from 'aws-cdk-lib/aws-lambda';
60
+
61
+
export class MyStack extends Stack {
62
+
public constructor(scope: Construct, id: string, props?: StackProps) {
63
+
super(scope, id, props);
64
+
65
+
const handler = new NodejsFunction(this, 'helloWorldFunction', {
0 commit comments