@aws/durable-execution-sdk-js-otel 0.0.1 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # AWS Durable Execution SDK - OpenTelemetry Plugin
2
2
 
3
+ > **⚠️ Experimental Beta:** This plugin is currently in experimental beta. Functionality may change without notice between releases. It is not recommended for production workloads at this time.
4
+
3
5
  OpenTelemetry instrumentation plugin for AWS Durable Execution SDK. Emits distributed traces that correlate across multiple Lambda invocations of a single durable execution, producing deterministic span and trace IDs so that spans from different invocations are stitched into a single coherent trace.
4
6
 
5
7
  ## Features
@@ -11,19 +13,100 @@ OpenTelemetry instrumentation plugin for AWS Durable Execution SDK. Emits distri
11
13
  - **Configurable Sampling**: Control trace volume via environment variable or plugin options
12
14
  - **Self-Contained Setup**: No manual TracerProvider configuration required
13
15
 
14
- ## Prerequisites
16
+ ## Installation
17
+
18
+ ```bash
19
+ npm install @aws/durable-execution-sdk-js-otel
20
+ ```
21
+
22
+ ## Quick Start using Xray/CloudWatch Tracing
23
+
24
+ 1. Add the ADOT Lambda Layer to your function and set `AWS_LAMBDA_EXEC_WRAPPER=/opt/otel-instrument`
25
+ 2. Enable X-Ray Active Tracing on the function
26
+ 3. Pass `OtelPlugin` to your handler's `plugins` array
27
+ 4. Add Xray Write Permissions
15
28
 
16
- ### ADOT Lambda Layer
29
+ ### 1. ADOT Lambda Layer
17
30
 
18
31
  This plugin requires the [AWS Distro for OpenTelemetry (ADOT) Lambda layer](https://aws-otel.github.io/docs/getting-started/lambda) to export traces from your Lambda function.
19
32
 
20
- To find the latest ADOT layer ARN for your region:
33
+ The layer ARN follows the format:
34
+
35
+ ```
36
+ arn:aws:lambda:<region>:<awsAccountId>:layer:AWSOpenTelemetryDistroJs:<version>
37
+ ```
38
+
39
+ Refer to the [ADOT Lambda Layer ARNs](https://aws-otel.github.io/docs/getting-started/lambda#aws-lambda-layer-for-opentelemetry-arns) page for the latest version number and supported regions.
40
+
41
+ **AWS CLI:**
42
+
43
+ ```bash
44
+ aws lambda update-function-configuration \
45
+ --function-name your-function-name \
46
+ --layers "arn:aws:lambda:<region>:<<awsAccountId>>:layer:AWSOpenTelemetryDistroJs:<version>"
47
+ ```
48
+
49
+ You must also set the `AWS_LAMBDA_EXEC_WRAPPER` environment variable:
50
+
51
+ ```bash
52
+ aws lambda update-function-configuration \
53
+ --function-name your-function-name \
54
+ --environment "Variables={AWS_LAMBDA_EXEC_WRAPPER=/opt/otel-instrument}"
55
+ ```
56
+
57
+ > **Note:** Replace `<region>`, `<awsAccountId>` `<version>` with the latest layer information from the ADOT docs.
58
+
59
+ **CloudFormation / SAM:**
60
+
61
+ ```yaml
62
+ MyFunction:
63
+ Type: AWS::Serverless::Function
64
+ Properties:
65
+ Layers:
66
+ - !Sub arn:aws:lambda:${AWS::Region}:<awsAccountId>:layer:AWSOpenTelemetryDistroJs:<version>
67
+ Environment:
68
+ Variables:
69
+ AWS_LAMBDA_EXEC_WRAPPER: /opt/otel-instrument
70
+ ```
71
+
72
+ For raw CloudFormation (`AWS::Lambda::Function`):
73
+
74
+ ```yaml
75
+ MyFunction:
76
+ Type: AWS::Lambda::Function
77
+ Properties:
78
+ Layers:
79
+ - !Sub arn:aws:lambda:${AWS::Region}:<awsAccountId>:layer:AWSOpenTelemetryDistroJs:<version>
80
+ Environment:
81
+ Variables:
82
+ AWS_LAMBDA_EXEC_WRAPPER: /opt/otel-instrument
83
+ ```
84
+
85
+ **CDK:**
86
+
87
+ ```typescript
88
+ import * as lambda from "aws-cdk-lib/aws-lambda";
89
+
90
+ const adotLayer = lambda.LayerVersion.fromLayerVersionArn(
91
+ this,
92
+ "AdotLayer",
93
+ `arn:aws:lambda:${this.region}:<awsAccountId>:layer:AWSOpenTelemetryDistroJs:<version>`,
94
+ );
95
+
96
+ const fn = new lambda.Function(this, "MyFunction", {
97
+ runtime: lambda.Runtime.NODEJS_22_X,
98
+ handler: "index.handler",
99
+ code: lambda.Code.fromAsset("lambda"),
100
+ layers: [adotLayer],
101
+ environment: {
102
+ AWS_LAMBDA_EXEC_WRAPPER: "/opt/otel-instrument",
103
+ },
104
+ });
105
+ ```
21
106
 
22
- 1. Visit the [ADOT Lambda Layer ARNs](https://aws-otel.github.io/docs/getting-started/lambda#aws-lambda-layer-for-opentelemetry-arns) for the list of supported regions and layer ARNs
23
- 2. The Node.js layer name follows the format: `AWSOpenTelemetryDistroJs`
24
- 3. Add the layer ARN to your Lambda function configuration
107
+ > **Tip:** Pin the layer version to a specific number in production deployments to avoid unexpected behavior from automatic version changes.
25
108
 
26
- ### AWS X-Ray Active Tracing
109
+ ### 2. AWS X-Ray Active Tracing
27
110
 
28
111
  Enable active tracing on your Lambda function so the `_X_AMZN_TRACE_ID` environment variable is populated at invocation time. The plugin uses this header to derive deterministic trace IDs that remain consistent across all invocations of the same durable execution.
29
112
 
@@ -55,29 +138,11 @@ new lambda.Function(this, "MyFunction", {
55
138
  });
56
139
  ```
57
140
 
58
- ## Installation
59
-
60
- ```bash
61
- npm install @aws/durable-execution-sdk-js-otel
62
- ```
63
-
64
- ### Peer Dependencies
65
-
66
- This package requires the following peer dependencies:
67
-
68
- | Package | Version |
69
- | ---------------------------------------- | ---------- |
70
- | `@aws/durable-execution-sdk-js` | `*` |
71
- | `@opentelemetry/api` | `^1.0.0` |
72
- | `@opentelemetry/instrumentation` | `^0.219.0` |
73
- | `@opentelemetry/instrumentation-aws-sdk` | `^0.74.0` |
74
- | `@opentelemetry/sdk-trace-node` | `^2.6.1` |
75
-
76
- ## Quick Start
141
+ ### 3. In your Lambda handler (index.js)
77
142
 
78
143
  ```typescript
79
144
  import { withDurableExecution } from "@aws/durable-execution-sdk-js";
80
- import { DurableExecutionOtelPlugin } from "@aws/durable-execution-sdk-js-otel";
145
+ import { OtelPlugin } from "@aws/durable-execution-sdk-js-otel";
81
146
 
82
147
  export const handler = withDurableExecution(
83
148
  async (event, context) => {
@@ -93,28 +158,47 @@ export const handler = withDurableExecution(
93
158
 
94
159
  return result;
95
160
  },
96
- { plugins: [new DurableExecutionOtelPlugin()] },
161
+ { plugins: [new OtelPlugin()] },
97
162
  );
98
163
  ```
99
164
 
100
165
  That's it. The plugin handles TracerProvider setup, deterministic ID generation, and span lifecycle internally.
101
166
 
167
+ ### 4. Grant Permissions
168
+
169
+ The function's execution role needs the `AWSXRayDaemonWriteAccess` managed policy (or equivalent permissions) if using X-Ray as the tracing backend.
170
+
171
+ ### AWS Console
172
+
173
+ See https://aws-otel.github.io/docs/getting-started/lambda#use-the-lambda-console.
174
+
175
+ ### Environment Variables for ADOT layer
176
+
177
+ | Variable | Description | Default |
178
+ | ----------------------------- | --------------------------------------------------------------------------------------------- | ----------------- |
179
+ | `OTEL_EXPORTER_OTLP_ENDPOINT` | Endpoint for the OTLP exporter (e.g., `http://localhost:4318` for the ADOT collector sidecar) | Set by ADOT layer |
180
+ | `AWS_LAMBDA_EXEC_WRAPPER` | Set to `/opt/otel-instrument` for the ADOT layer to instrument your function | — |
181
+ | `OTEL_TRACES_SAMPLER` | Sampler to use (e.g., `traceidratio` for ratio-based sampling) | `always_on` |
182
+ | `OTEL_TRACES_SAMPLER_ARG` | Argument for the sampler (e.g., `0.3` to sample 30% of traces) | — |
183
+
184
+ See the [ADOT sampling configuration](https://aws-otel.github.io/docs/getting-started/lambda#sampling-configuration) for more details.
185
+
102
186
  ## Configuration
103
187
 
104
188
  ### Plugin Options
105
189
 
106
190
  ```typescript
107
- import { DurableExecutionOtelPlugin } from "@aws/durable-execution-sdk-js-otel";
191
+ import { OtelPlugin } from "@aws/durable-execution-sdk-js-otel";
108
192
 
109
- const plugin = new DurableExecutionOtelPlugin({
193
+ const plugin = new OtelPlugin({
110
194
  // Use a custom context extractor (default: xRayContextExtractor)
111
- contextExtractor: xRayContextExtractor,
195
+ contextExtractor?: xRayContextExtractor,
112
196
 
113
197
  // Provide your own TracerProvider if you already have one configured
114
- tracerProvider: myTracerProvider,
198
+ tracerProvider?: myTracerProvider,
115
199
 
116
200
  // Custom instrumentation scope name (default: "aws-durable-execution-sdk-js")
117
- instrumentationName: "my-service",
201
+ instrumentationName?: "my-service",
118
202
  });
119
203
  ```
120
204
 
@@ -124,73 +208,18 @@ The plugin supports multiple strategies for extracting upstream trace context:
124
208
 
125
209
  ```typescript
126
210
  import {
127
- DurableExecutionOtelPlugin,
211
+ OtelPlugin,
128
212
  xRayContextExtractor,
129
213
  w3cClientContextExtractor,
130
214
  } from "@aws/durable-execution-sdk-js-otel";
131
215
 
132
216
  // Default: X-Ray trace header (recommended for most Lambda deployments)
133
- new DurableExecutionOtelPlugin({ contextExtractor: xRayContextExtractor });
217
+ new OtelPlugin({ contextExtractor: xRayContextExtractor });
134
218
 
135
219
  // W3C Trace Context via clientContext (requires backend propagation support (TODO))
136
- new DurableExecutionOtelPlugin({ contextExtractor: w3cClientContextExtractor });
220
+ new OtelPlugin({ contextExtractor: w3cClientContextExtractor });
137
221
  ```
138
222
 
139
- ## Lambda Setup
140
-
141
- ### SAM template setup
142
-
143
- #### 1. Add the ADOT Layer
144
-
145
- Add the ADOT Lambda layer to your function. The layer provides the OpenTelemetry collector that exports traces to your configured backend.
146
-
147
- ```yaml
148
- # SAM template example
149
- MyFunction:
150
- Type: AWS::Serverless::Function
151
- Properties:
152
- Layers:
153
- - !Sub arn:aws:lambda:${AWS::Region}:615299751070:layer:AWSOpenTelemetryDistroJs:<version>
154
- ```
155
-
156
- > **Note:** The layer ARN varies by region, account, and version. Refer to the [ADOT Lambda Layer ARNs](https://aws-otel.github.io/docs/getting-started/lambda#aws-lambda-layer-for-opentelemetry-arns) for the latest ARN in your region.
157
-
158
- #### 2. Set Environment Variables
159
-
160
- ```yaml
161
- Environment:
162
- Variables:
163
- AWS_LAMBDA_EXEC_WRAPPER: /opt/otel-instrument
164
- ```
165
-
166
- #### 3. Enable X-Ray Active Tracing
167
-
168
- ```yaml
169
- TracingConfig:
170
- Mode: Active
171
- ```
172
-
173
- This ensures the `_X_AMZN_TRACE_ID` environment variable is set on every invocation. The durable execution backend propagates the same Root trace ID to every invocation, so all invocations of the same execution share one trace.
174
-
175
- #### 4. Grant Permissions
176
-
177
- The function's execution role needs the `AWSXRayDaemonWriteAccess` managed policy (or equivalent permissions) if using X-Ray as the tracing backend.
178
-
179
- ### AWS Console
180
-
181
- See https://aws-otel.github.io/docs/getting-started/lambda#use-the-lambda-console.
182
-
183
- ### Environment Variables for ADOT layer
184
-
185
- | Variable | Description | Default |
186
- | ----------------------------- | --------------------------------------------------------------------------------------------- | ----------------- |
187
- | `OTEL_EXPORTER_OTLP_ENDPOINT` | Endpoint for the OTLP exporter (e.g., `http://localhost:4318` for the ADOT collector sidecar) | Set by ADOT layer |
188
- | `AWS_LAMBDA_EXEC_WRAPPER` | Set to `/opt/otel-instrument` for the ADOT layer to instrument your function | — |
189
- | `OTEL_TRACES_SAMPLER` | Sampler to use (e.g., `traceidratio` for ratio-based sampling) | `always_on` |
190
- | `OTEL_TRACES_SAMPLER_ARG` | Argument for the sampler (e.g., `0.3` to sample 30% of traces) | — |
191
-
192
- See the [ADOT sampling configuration](https://aws-otel.github.io/docs/getting-started/lambda#sampling-configuration) for more details.
193
-
194
223
  ## Verification
195
224
 
196
225
  After deploying your function with the plugin configured:
@@ -219,12 +248,12 @@ After deploying your function with the plugin configured:
219
248
 
220
249
  ## API Reference
221
250
 
222
- ### `DurableExecutionOtelPlugin`
251
+ ### `OtelPlugin`
223
252
 
224
253
  The main plugin class. Implements `DurableInstrumentationPlugin` from `@aws/durable-execution-sdk-js`.
225
254
 
226
255
  ```typescript
227
- new DurableExecutionOtelPlugin(config?: DurableExecutionOtelPluginConfig)
256
+ new OtelPlugin(config?: OtelPluginConfig)
228
257
  ```
229
258
 
230
259
  ### `DeterministicIdGenerator`