@aws/durable-execution-sdk-js-otel 0.0.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 ADDED
@@ -0,0 +1,248 @@
1
+ # AWS Durable Execution SDK - OpenTelemetry Plugin
2
+
3
+ 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
+
5
+ ## Features
6
+
7
+ - **Deterministic Trace IDs**: All invocations of the same durable execution share a single trace, derived from the X-Ray trace header or execution ARN
8
+ - **Span-per-Operation**: Each durable operation (step, wait, invoke) gets its own span with accurate timing
9
+ - **Continuation Spans**: Operations completing in a different invocation are linked back to the original span
10
+ - **Log Correlation**: Enrich application logs with trace ID and span ID for end-to-end observability
11
+ - **Configurable Sampling**: Control trace volume via environment variable or plugin options
12
+ - **Self-Contained Setup**: No manual TracerProvider configuration required
13
+
14
+ ## Prerequisites
15
+
16
+ ### ADOT Lambda Layer
17
+
18
+ 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
+
20
+ To find the latest ADOT layer ARN for your region:
21
+
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
25
+
26
+ ### AWS X-Ray Active Tracing
27
+
28
+ 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
+
30
+ **AWS Console:** Lambda → Configuration → Monitoring and operations tools → Active tracing → Enable
31
+
32
+ **AWS CLI:**
33
+
34
+ ```bash
35
+ aws lambda update-function-configuration \
36
+ --function-name your-function-name \
37
+ --tracing-config Mode=Active
38
+ ```
39
+
40
+ **CloudFormation / SAM:**
41
+
42
+ ```yaml
43
+ MyFunction:
44
+ Type: AWS::Lambda::Function
45
+ Properties:
46
+ TracingConfig:
47
+ Mode: Active
48
+ ```
49
+
50
+ **CDK:**
51
+
52
+ ```typescript
53
+ new lambda.Function(this, "MyFunction", {
54
+ tracing: lambda.Tracing.ACTIVE,
55
+ });
56
+ ```
57
+
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
77
+
78
+ ```typescript
79
+ import { withDurableExecution } from "@aws/durable-execution-sdk-js";
80
+ import { DurableExecutionOtelPlugin } from "@aws/durable-execution-sdk-js-otel";
81
+
82
+ export const handler = withDurableExecution(
83
+ async (event, context) => {
84
+ const result = await context.step("fetch-data", async () => {
85
+ return fetchData(event.id);
86
+ });
87
+
88
+ await context.wait({ seconds: 5 });
89
+
90
+ await context.step("process", async () => {
91
+ return process(result);
92
+ });
93
+
94
+ return result;
95
+ },
96
+ { plugins: [new DurableExecutionOtelPlugin()] },
97
+ );
98
+ ```
99
+
100
+ That's it. The plugin handles TracerProvider setup, deterministic ID generation, and span lifecycle internally.
101
+
102
+ ## Configuration
103
+
104
+ ### Plugin Options
105
+
106
+ ```typescript
107
+ import { DurableExecutionOtelPlugin } from "@aws/durable-execution-sdk-js-otel";
108
+
109
+ const plugin = new DurableExecutionOtelPlugin({
110
+ // Use a custom context extractor (default: xRayContextExtractor)
111
+ contextExtractor: xRayContextExtractor,
112
+
113
+ // Provide your own TracerProvider if you already have one configured
114
+ tracerProvider: myTracerProvider,
115
+
116
+ // Custom instrumentation scope name (default: "aws-durable-execution-sdk-js")
117
+ instrumentationName: "my-service",
118
+ });
119
+ ```
120
+
121
+ ### Context Extractors
122
+
123
+ The plugin supports multiple strategies for extracting upstream trace context:
124
+
125
+ ```typescript
126
+ import {
127
+ DurableExecutionOtelPlugin,
128
+ xRayContextExtractor,
129
+ w3cClientContextExtractor,
130
+ } from "@aws/durable-execution-sdk-js-otel";
131
+
132
+ // Default: X-Ray trace header (recommended for most Lambda deployments)
133
+ new DurableExecutionOtelPlugin({ contextExtractor: xRayContextExtractor });
134
+
135
+ // W3C Trace Context via clientContext (requires backend propagation support (TODO))
136
+ new DurableExecutionOtelPlugin({ contextExtractor: w3cClientContextExtractor });
137
+ ```
138
+
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
+ ## Verification
195
+
196
+ After deploying your function with the plugin configured:
197
+
198
+ 1. **Invoke your durable function** — trigger at least one execution that includes multiple steps or a wait/resume cycle.
199
+
200
+ 2. **Check Cloudwatch console** — Navigate to Cloudwatch → Traces in the AWS Console. You should see a trace with:
201
+ - An "invocation" span per invocation
202
+ - Child spans for each durable operation (named after your step names)
203
+ - All invocations of the same execution grouped under one trace ID
204
+
205
+ 3. **Check log correlation** — If you use `enrichLogContext()`, verify that your logs include `traceId` and `spanId` fields matching the spans in X-Ray.
206
+
207
+ 4. **Confirm sampling** — If you set `OTEL_TRACES_SAMPLER=traceidratio` and `OTEL_TRACES_SAMPLER_ARG` to a value less than 1.0, verify that only the expected proportion of traces appear.
208
+
209
+ 5. **span links** — For operations that span multiple invocations (e.g., after a wait resumes), though span links are set, they are not visualized within CloudWatch console.
210
+
211
+ ### Troubleshooting
212
+
213
+ | Symptom | Likely Cause |
214
+ | --------------------------------- | --------------------------------------------------------------- |
215
+ | No traces appear | ADOT layer not configured, or `AWS_LAMBDA_EXEC_WRAPPER` not set |
216
+ | Traces appear but are fragmented | X-Ray active tracing not enabled on the Lambda function |
217
+ | Missing spans for some operations | `OTEL_TRACES_SAMPLER_ARG` set below 1.0 |
218
+ | `_X_AMZN_TRACE_ID` not populated | X-Ray active tracing not enabled |
219
+
220
+ ## API Reference
221
+
222
+ ### `DurableExecutionOtelPlugin`
223
+
224
+ The main plugin class. Implements `DurableInstrumentationPlugin` from `@aws/durable-execution-sdk-js`.
225
+
226
+ ```typescript
227
+ new DurableExecutionOtelPlugin(config?: DurableExecutionOtelPluginConfig)
228
+ ```
229
+
230
+ ### `DeterministicIdGenerator`
231
+
232
+ A custom OpenTelemetry `IdGenerator` that produces reproducible trace and span IDs from execution metadata. Exported for advanced use cases.
233
+
234
+ ### `xRayContextExtractor`
235
+
236
+ Default context extractor. Reads the `_X_AMZN_TRACE_ID` environment variable to derive trace context.
237
+
238
+ ### `w3cClientContextExtractor`
239
+
240
+ Alternative context extractor. Reads `traceparent` from `context.clientContext.custom.traceparent` (W3C Trace Context format).
241
+
242
+ ### `ContextExtractor`
243
+
244
+ Type definition for custom context extractor functions.
245
+
246
+ ## License
247
+
248
+ Apache-2.0
package/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ // Placeholder – real implementation coming soon.
2
+ export {};
package/index.js ADDED
@@ -0,0 +1 @@
1
+ // Placeholder – real implementation coming soon.
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@aws/durable-execution-sdk-js-otel",
3
+ "description": "OpenTelemetry instrumentation plugin for AWS Durable Execution SDK (placeholder)",
4
+ "version": "0.0.1",
5
+ "license": "Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+ssh://git@github.com/aws/aws-durable-execution-sdk-js.git",
9
+ "directory": "packages/aws-durable-execution-sdk-js-otel"
10
+ },
11
+ "homepage": "https://github.com/aws/aws-durable-execution-sdk-js/tree/main/packages/aws-durable-execution-sdk-js-otel",
12
+ "main": "./index.js",
13
+ "types": "./index.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./index.d.ts",
17
+ "import": "./index.js",
18
+ "require": "./index.js"
19
+ }
20
+ },
21
+ "files": [
22
+ "index.js",
23
+ "index.d.ts"
24
+ ],
25
+ "scripts": {
26
+ "prepublishOnly": "echo 'dummy publish'"
27
+ }
28
+ }