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

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.
@@ -0,0 +1,525 @@
1
+ 'use strict';
2
+
3
+ var api = require('@opentelemetry/api');
4
+ var instrumentationAwsSdk = require('@opentelemetry/instrumentation-aws-sdk');
5
+ var instrumentation = require('@opentelemetry/instrumentation');
6
+ var node_crypto = require('node:crypto');
7
+
8
+ /**
9
+ * A custom OpenTelemetry IdGenerator that produces deterministic trace and span IDs
10
+ * derived from execution metadata (X-Ray headers, execution ARNs, operation IDs)
11
+ * rather than random values.
12
+ *
13
+ * This ensures that spans from different Lambda invocations of the same durable
14
+ * execution are stitched into a single coherent trace.
15
+ */
16
+ class DeterministicIdGenerator {
17
+ traceId;
18
+ nextSpanId;
19
+ /**
20
+ * Set the trace ID for all subsequent generateTraceId() calls.
21
+ * This is persistent until setTraceId is called again.
22
+ */
23
+ setTraceId(traceId) {
24
+ this.traceId = traceId;
25
+ }
26
+ /**
27
+ * Set the span ID to return on the next single generateSpanId() call.
28
+ * This is a one-shot override: it is consumed on the next call and then
29
+ * reverts to default behavior.
30
+ */
31
+ setNextSpanId(spanId) {
32
+ this.nextSpanId = spanId;
33
+ }
34
+ /**
35
+ * Generate a 32-char lowercase hex trace ID.
36
+ *
37
+ * If setTraceId has been called, returns that value persistently.
38
+ * Otherwise returns a random 32-char hex string as fallback.
39
+ */
40
+ generateTraceId() {
41
+ if (this.traceId) {
42
+ return this.traceId;
43
+ }
44
+ // Fallback: generate a random trace ID
45
+ return node_crypto.createHash("sha256")
46
+ .update(Math.random().toString())
47
+ .digest("hex")
48
+ .slice(0, 32);
49
+ }
50
+ /**
51
+ * Generate a 16-char lowercase hex span ID.
52
+ *
53
+ * If setNextSpanId has been called, returns that value once (one-shot)
54
+ * and then clears it. Otherwise returns a random 16-char hex string.
55
+ */
56
+ generateSpanId() {
57
+ if (this.nextSpanId) {
58
+ const spanId = this.nextSpanId;
59
+ this.nextSpanId = undefined;
60
+ return spanId;
61
+ }
62
+ // Fallback: generate a random span ID
63
+ return node_crypto.createHash("sha256")
64
+ .update(Math.random().toString())
65
+ .digest("hex")
66
+ .slice(0, 16);
67
+ }
68
+ }
69
+ /**
70
+ * Derive a deterministic trace ID from an X-Ray Root field.
71
+ * Strips the `Root=1-` prefix and all `-` separators to produce
72
+ * a valid 32-character lowercase hex OpenTelemetry trace ID.
73
+ *
74
+ * @param xRayRoot - The Root field value, e.g. "1-5759e988-bd862e3fe1be46a994272793"
75
+ * @returns A 32-char lowercase hex string, or undefined if the input is invalid
76
+ */
77
+ function deriveTraceIdFromXRayRoot(xRayRoot) {
78
+ // Strip "Root=" prefix if present
79
+ let root = xRayRoot;
80
+ if (root.startsWith("Root=")) {
81
+ root = root.slice(5);
82
+ }
83
+ // Strip the version prefix "1-"
84
+ if (root.startsWith("1-")) {
85
+ root = root.slice(2);
86
+ }
87
+ else {
88
+ return undefined;
89
+ }
90
+ // Remove all dashes
91
+ const hex = root.replace(/-/g, "");
92
+ // Validate: must be exactly 32 lowercase hex characters
93
+ if (hex.length !== 32 || !/^[0-9a-f]{32}$/.test(hex)) {
94
+ return undefined;
95
+ }
96
+ return hex;
97
+ }
98
+ /**
99
+ * Derive a deterministic trace ID from an execution ARN by hashing it
100
+ * with SHA-256 and truncating to the first 32 lowercase hex characters.
101
+ *
102
+ * @param executionArn - The execution ARN string
103
+ * @returns A 32-char lowercase hex string
104
+ */
105
+ function deriveTraceIdFromArn(executionArn) {
106
+ return node_crypto.createHash("sha256").update(executionArn).digest("hex").slice(0, 32);
107
+ }
108
+ /**
109
+ * Derive a deterministic span ID from an operation ID by hashing it
110
+ * with SHA-256 and truncating to the first 16 lowercase hex characters.
111
+ *
112
+ * @param operationId - The operation ID string
113
+ * @returns A 16-char lowercase hex string
114
+ */
115
+ function deriveSpanIdFromOperationId(operationId) {
116
+ return node_crypto.createHash("sha256").update(operationId).digest("hex").slice(0, 16);
117
+ }
118
+
119
+ /**
120
+ * Reads the X-Ray trace header from the `_X_AMZN_TRACE_ID` environment variable.
121
+ *
122
+ * The durable execution backend propagates the same Root trace ID to every
123
+ * invocation, so all invocations of the same execution share one traceId.
124
+ *
125
+ * X-Ray Header format:
126
+ * Root=1-5759e988-bd862e3fe1be46a994272793;Parent=53995c3f42cd8ad8;Sampled=1
127
+ *
128
+ * - Extract Root value, strip "1-" prefix and all "-" to get 32-char hex traceId
129
+ * - Extract Parent value for parentSpanId (16-char hex)
130
+ *
131
+ * Returns undefined when _X_AMZN_TRACE_ID is missing or malformed.
132
+ */
133
+ function xRayContextExtractor(_info) {
134
+ const header = process.env._X_AMZN_TRACE_ID;
135
+ if (!header) {
136
+ return undefined;
137
+ }
138
+ // Parse the header into key-value pairs separated by semicolons
139
+ const fields = new Map();
140
+ for (const part of header.split(";")) {
141
+ const eqIdx = part.indexOf("=");
142
+ if (eqIdx > 0) {
143
+ const key = part.slice(0, eqIdx).trim();
144
+ const value = part.slice(eqIdx + 1).trim();
145
+ fields.set(key, value);
146
+ }
147
+ }
148
+ const root = fields.get("Root");
149
+ if (!root) {
150
+ return undefined;
151
+ }
152
+ // Root format: 1-5759e988-bd862e3fe1be46a994272793
153
+ // Strip the "1-" prefix and remove all dashes to get 32-char hex
154
+ const rootValue = root.startsWith("1-") ? root.slice(2) : root;
155
+ const traceId = rootValue.replace(/-/g, "").toLowerCase();
156
+ // Validate: must be exactly 32 hex characters
157
+ if (!/^[0-9a-f]{32}$/.test(traceId)) {
158
+ return undefined;
159
+ }
160
+ const parent = fields.get("Parent");
161
+ let parentSpanId;
162
+ if (parent && /^[0-9a-f]{16}$/.test(parent.toLowerCase())) {
163
+ parentSpanId = parent.toLowerCase();
164
+ }
165
+ return { traceId, parentSpanId };
166
+ }
167
+ /**
168
+ * Reads W3C traceparent from `context.clientContext.custom.traceparent`.
169
+ *
170
+ * W3C traceparent format:
171
+ * 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01
172
+ * Format: version-traceId-parentId-traceFlags
173
+ *
174
+ * - traceId is 32 hex chars
175
+ * - parentId is 16 hex chars
176
+ * - flags is 2 hex chars (parsed to number)
177
+ *
178
+ * Returns undefined when clientContext or traceparent is missing or malformed.
179
+ */
180
+ function w3cClientContextExtractor(info) {
181
+ const extendedInfo = info;
182
+ const traceparent = extendedInfo.context?.clientContext?.custom?.traceparent;
183
+ if (!traceparent) {
184
+ return undefined;
185
+ }
186
+ return parseW3CTraceparent(traceparent);
187
+ }
188
+ /**
189
+ * Parses a W3C traceparent header value.
190
+ *
191
+ * Format: version-traceId-parentId-flags
192
+ * Example: 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01
193
+ */
194
+ function parseW3CTraceparent(traceparent) {
195
+ const parts = traceparent.split("-");
196
+ // Must have exactly 4 parts: version, traceId, parentId, flags
197
+ if (parts.length !== 4) {
198
+ return undefined;
199
+ }
200
+ const [version, traceId, parentId, flags] = parts;
201
+ // Version must be 2 hex chars
202
+ if (!/^[0-9a-f]{2}$/.test(version)) {
203
+ return undefined;
204
+ }
205
+ // TraceId must be 32 hex chars
206
+ if (!/^[0-9a-f]{32}$/.test(traceId)) {
207
+ return undefined;
208
+ }
209
+ // ParentId must be 16 hex chars
210
+ if (!/^[0-9a-f]{16}$/.test(parentId)) {
211
+ return undefined;
212
+ }
213
+ // Flags must be 2 hex chars
214
+ if (!/^[0-9a-f]{2}$/.test(flags)) {
215
+ return undefined;
216
+ }
217
+ const traceFlags = parseInt(flags, 16);
218
+ return {
219
+ traceId,
220
+ parentSpanId: parentId,
221
+ traceFlags,
222
+ };
223
+ }
224
+
225
+ const DEFAULT_INSTRUMENTATION_NAME = "aws-durable-execution-sdk-js";
226
+ /**
227
+ * OpenTelemetry instrumentation plugin for durable executions.
228
+ *
229
+ * Implements the DurableInstrumentationPlugin interface to emit distributed
230
+ * traces that correlate across multiple Lambda invocations of a single
231
+ * durable execution.
232
+ */
233
+ class DurableExecutionOtelPlugin {
234
+ tracerProvider;
235
+ tracer;
236
+ idGenerator;
237
+ contextExtractor;
238
+ // Per-invocation state
239
+ spanMap = new Map();
240
+ spanStack = [];
241
+ invocationSpan;
242
+ executionArn = "";
243
+ attemptSpan;
244
+ constructor(config) {
245
+ const instrumentationName = config?.instrumentationName ?? DEFAULT_INSTRUMENTATION_NAME;
246
+ this.idGenerator = new DeterministicIdGenerator();
247
+ this.contextExtractor = config?.contextExtractor ?? xRayContextExtractor;
248
+ if (config?.tracerProvider) {
249
+ this.tracerProvider = config.tracerProvider;
250
+ }
251
+ else {
252
+ this.tracerProvider = api.trace.getTracerProvider();
253
+ instrumentation.registerInstrumentations({
254
+ tracerProvider: this.tracerProvider,
255
+ instrumentations: [
256
+ new instrumentationAwsSdk.AwsInstrumentation({
257
+ suppressInternalInstrumentation: true,
258
+ sqsExtractContextPropagationFromPayload: true,
259
+ }),
260
+ ],
261
+ });
262
+ }
263
+ this.tracer = this.tracerProvider.getTracer(instrumentationName);
264
+ // Monkey-patch the tracer's ID generator so spans use deterministic IDs.
265
+ // The _idGenerator field is internal to @opentelemetry/sdk-trace-base's Tracer class.
266
+ this.tracer._idGenerator = this.idGenerator;
267
+ }
268
+ async onInvocationStart(info) {
269
+ // 1. Store the execution ARN
270
+ this.executionArn = info.executionArn;
271
+ // 2. Invoke the context extractor
272
+ const extractedContext = this.contextExtractor(info);
273
+ // 3. Set the trace ID on the ID generator
274
+ if (extractedContext?.traceId) {
275
+ this.idGenerator.setTraceId(extractedContext.traceId);
276
+ }
277
+ else {
278
+ // Fallback: derive trace ID from ARN
279
+ const derivedId = deriveTraceIdFromArn(info.executionArn);
280
+ this.idGenerator.setTraceId(derivedId);
281
+ }
282
+ // 4. Create the invocation span
283
+ this.invocationSpan = this.tracer.startSpan("invocation", {
284
+ attributes: {
285
+ "durable.execution.arn": info.executionArn,
286
+ },
287
+ });
288
+ }
289
+ wrapInvocation(_info, fn) {
290
+ if (!this.invocationSpan) {
291
+ return fn();
292
+ }
293
+ return api.context.with(api.trace.setSpan(api.context.active(), this.invocationSpan), fn);
294
+ }
295
+ async onInvocationEnd(_info) {
296
+ // 1. End all spans in the stack in reverse order
297
+ while (this.spanStack.length > 0) {
298
+ const span = this.spanStack.pop();
299
+ span.end();
300
+ }
301
+ // 2. End the invocation span if it exists
302
+ if (this.invocationSpan) {
303
+ this.invocationSpan.end();
304
+ }
305
+ // 3. Force flush the tracer provider
306
+ if ("forceFlush" in this.tracerProvider) {
307
+ try {
308
+ await this.tracerProvider.forceFlush();
309
+ }
310
+ catch {
311
+ // Gracefully handle flush errors
312
+ }
313
+ }
314
+ // 4. Clear all per-invocation state
315
+ this.spanMap.clear();
316
+ this.spanStack = [];
317
+ this.invocationSpan = undefined;
318
+ this.executionArn = "";
319
+ this.attemptSpan = undefined;
320
+ }
321
+ async onOperationStart(info) {
322
+ const deterministicSpanId = deriveSpanIdFromOperationId(info.id);
323
+ const spanName = info.name ?? info.type;
324
+ // Resolve parent span: use parentId from map, or fall back to invocation span
325
+ let parentSpan;
326
+ if (info.parentId && this.spanMap.has(info.parentId)) {
327
+ parentSpan = this.spanMap.get(info.parentId);
328
+ }
329
+ else {
330
+ parentSpan = this.invocationSpan;
331
+ }
332
+ const parentContext = parentSpan
333
+ ? api.trace.setSpan(api.context.active(), parentSpan)
334
+ : api.context.active();
335
+ const attributes = {
336
+ "durable.execution.arn": this.executionArn,
337
+ "durable.operation.id": info.id,
338
+ "durable.operation.type": info.type,
339
+ };
340
+ if (info.name) {
341
+ attributes["durable.operation.name"] = info.name;
342
+ }
343
+ let span;
344
+ if (!info.isReplay) {
345
+ // Non-replay: use deterministic span ID
346
+ this.idGenerator.setNextSpanId(deterministicSpanId);
347
+ span = this.tracer.startSpan(spanName, {
348
+ attributes,
349
+ startTime: info.startTimestamp,
350
+ }, parentContext);
351
+ }
352
+ else if (info.type === "CONTEXT" || info.type === "STEP") {
353
+ // Replay: use random span ID, add Link to deterministic span
354
+ const traceId = this.invocationSpan?.spanContext().traceId ??
355
+ this.idGenerator.generateTraceId();
356
+ span = this.tracer.startSpan(spanName, {
357
+ attributes,
358
+ startTime: info.startTimestamp,
359
+ links: [
360
+ {
361
+ context: { traceId, spanId: deterministicSpanId, traceFlags: 1 },
362
+ },
363
+ ],
364
+ }, parentContext);
365
+ }
366
+ // Push to map and stack
367
+ if (span != undefined) {
368
+ this.spanMap.set(info.id, span);
369
+ this.spanStack.push(span);
370
+ }
371
+ }
372
+ wrapChildContextFn(info, fn) {
373
+ const span = this.spanMap.get(info.id);
374
+ if (!span) {
375
+ return fn();
376
+ }
377
+ return api.context.with(api.trace.setSpan(api.context.active(), span), fn);
378
+ }
379
+ async onOperationEnd(info) {
380
+ // Skip span creation for WAIT, INVOKE, CHAINED_INVOKE, and CALLBACK operations on replay
381
+ if (info.isReplay &&
382
+ (info.type === "WAIT" ||
383
+ info.type === "INVOKE" ||
384
+ info.type === "CHAINED_INVOKE" ||
385
+ info.type === "CALLBACK")) {
386
+ return;
387
+ }
388
+ const deterministicSpanId = deriveSpanIdFromOperationId(info.id);
389
+ if (this.spanMap.has(info.id)) {
390
+ // Operation was started in this invocation
391
+ const span = this.spanMap.get(info.id);
392
+ // Record error if present
393
+ if (info.error) {
394
+ span.setStatus({
395
+ code: api.SpanStatusCode.ERROR,
396
+ message: info.error.message,
397
+ });
398
+ span.recordException(info.error);
399
+ }
400
+ // End the span
401
+ span.end(info.endTimestamp);
402
+ // Remove from map
403
+ this.spanMap.delete(info.id);
404
+ // Remove from stack (find by reference)
405
+ const stackIndex = this.spanStack.indexOf(span);
406
+ if (stackIndex !== -1) {
407
+ this.spanStack.splice(stackIndex, 1);
408
+ }
409
+ }
410
+ else if (!info.isReplay) {
411
+ // Operation was started in a prior invocation — create Continuation_Span
412
+ const spanName = info.name ?? info.type;
413
+ const traceId = this.invocationSpan?.spanContext().traceId ??
414
+ this.idGenerator.generateTraceId();
415
+ const parentContext = this.invocationSpan
416
+ ? api.trace.setSpan(api.context.active(), this.invocationSpan)
417
+ : api.context.active();
418
+ const attributes = {
419
+ "durable.execution.arn": this.executionArn,
420
+ "durable.operation.id": info.id,
421
+ "durable.operation.type": info.type,
422
+ };
423
+ if (info.name) {
424
+ attributes["durable.operation.name"] = info.name;
425
+ }
426
+ const continuationSpan = this.tracer.startSpan(spanName, {
427
+ attributes,
428
+ startTime: info.startTimestamp,
429
+ links: [
430
+ {
431
+ context: { traceId, spanId: deterministicSpanId, traceFlags: 1 },
432
+ },
433
+ ],
434
+ }, parentContext);
435
+ // Record error if present
436
+ if (info.error) {
437
+ continuationSpan.setStatus({
438
+ code: api.SpanStatusCode.ERROR,
439
+ message: info.error.message,
440
+ });
441
+ continuationSpan.recordException(info.error);
442
+ }
443
+ // Immediately end
444
+ continuationSpan.end(info.endTimestamp);
445
+ }
446
+ }
447
+ async onOperationAttemptStart(info) {
448
+ const deterministicSpanId = deriveSpanIdFromOperationId(info.id);
449
+ const spanName = info.name ?? info.type;
450
+ // Find the parent Operation_Span for this operation
451
+ const parentSpan = this.spanMap.get(info.id);
452
+ const parentContext = parentSpan
453
+ ? api.trace.setSpan(api.context.active(), parentSpan)
454
+ : api.context.active();
455
+ // Get current trace ID for the link
456
+ const currentTraceId = this.invocationSpan?.spanContext().traceId ??
457
+ this.idGenerator.generateTraceId();
458
+ const attributes = {
459
+ "durable.execution.arn": this.executionArn,
460
+ "durable.operation.id": info.id,
461
+ "durable.operation.type": info.type,
462
+ "durable.operation.attempt": info.attempt,
463
+ };
464
+ if (info.name) {
465
+ attributes["durable.operation.name"] = info.name;
466
+ }
467
+ // Create Attempt_Span as child of Operation_Span with Link to deterministic span
468
+ const attemptSpan = this.tracer.startSpan(spanName, {
469
+ attributes,
470
+ startTime: info.startTimestamp,
471
+ links: [
472
+ {
473
+ context: {
474
+ traceId: currentTraceId,
475
+ spanId: deterministicSpanId,
476
+ traceFlags: 1,
477
+ },
478
+ },
479
+ ],
480
+ }, parentContext);
481
+ this.attemptSpan = attemptSpan;
482
+ }
483
+ wrapOperationAttemptFn(_info, fn) {
484
+ if (!this.attemptSpan) {
485
+ return fn();
486
+ }
487
+ return api.context.with(api.trace.setSpan(api.context.active(), this.attemptSpan), fn);
488
+ }
489
+ async onOperationAttemptEnd(info) {
490
+ if (this.attemptSpan) {
491
+ if (info.error) {
492
+ this.attemptSpan.setStatus({
493
+ code: api.SpanStatusCode.ERROR,
494
+ message: info.error.message,
495
+ });
496
+ this.attemptSpan.recordException(info.error);
497
+ }
498
+ this.attemptSpan.end(info.endTimestamp);
499
+ this.attemptSpan = undefined;
500
+ }
501
+ }
502
+ async onOperationChange(_info) {
503
+ // No-op for this plugin
504
+ }
505
+ enrichLogContext() {
506
+ const span = api.trace.getSpan(api.context.active());
507
+ if (!span) {
508
+ return undefined;
509
+ }
510
+ const spanContext = span.spanContext();
511
+ return {
512
+ traceId: spanContext.traceId,
513
+ spanId: spanContext.spanId,
514
+ };
515
+ }
516
+ }
517
+
518
+ exports.DeterministicIdGenerator = DeterministicIdGenerator;
519
+ exports.DurableExecutionOtelPlugin = DurableExecutionOtelPlugin;
520
+ exports.deriveSpanIdFromOperationId = deriveSpanIdFromOperationId;
521
+ exports.deriveTraceIdFromArn = deriveTraceIdFromArn;
522
+ exports.deriveTraceIdFromXRayRoot = deriveTraceIdFromXRayRoot;
523
+ exports.w3cClientContextExtractor = w3cClientContextExtractor;
524
+ exports.xRayContextExtractor = xRayContextExtractor;
525
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/deterministic-id-generator.ts","../src/context-extractors.ts","../src/plugin.ts"],"names":["createHash","trace","registerInstrumentations","AwsInstrumentation","context","SpanStatusCode"],"mappings":";;;;;;;AAGA;;;;;;;AAOG;MACU,wBAAwB,CAAA;AAC3B,IAAA,OAAO;AACP,IAAA,UAAU;AAElB;;;AAGG;AACH,IAAA,UAAU,CAAC,OAAe,EAAA;AACxB,QAAA,IAAI,CAAC,OAAO,GAAG,OAAO;IACxB;AAEA;;;;AAIG;AACH,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AA,OAAO,SAAS;QAClB;AACA,QAAA,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,EAAE;QACtC,OAAO;YACL,OAAO,EAAE,WAAW,CAAC,OAAO;YAC5B,MAAM,EAAE,WAAW,CAAC,MAAM;SAC3B;IACH;AACD;;;;;;;;;;"}
@@ -0,0 +1,43 @@
1
+ import type { InvocationInfo } from "@aws/durable-execution-sdk-js";
2
+ /**
3
+ * Result type returned by context extractors.
4
+ */
5
+ export type ContextExtractorResult = {
6
+ traceId: string;
7
+ parentSpanId?: string;
8
+ traceFlags?: number;
9
+ } | undefined;
10
+ /**
11
+ * A function that extracts upstream trace context from the invocation environment.
12
+ */
13
+ export type ContextExtractor = (info: InvocationInfo) => ContextExtractorResult;
14
+ /**
15
+ * Reads the X-Ray trace header from the `_X_AMZN_TRACE_ID` environment variable.
16
+ *
17
+ * The durable execution backend propagates the same Root trace ID to every
18
+ * invocation, so all invocations of the same execution share one traceId.
19
+ *
20
+ * X-Ray Header format:
21
+ * Root=1-5759e988-bd862e3fe1be46a994272793;Parent=53995c3f42cd8ad8;Sampled=1
22
+ *
23
+ * - Extract Root value, strip "1-" prefix and all "-" to get 32-char hex traceId
24
+ * - Extract Parent value for parentSpanId (16-char hex)
25
+ *
26
+ * Returns undefined when _X_AMZN_TRACE_ID is missing or malformed.
27
+ */
28
+ export declare function xRayContextExtractor(_info: InvocationInfo): ContextExtractorResult;
29
+ /**
30
+ * Reads W3C traceparent from `context.clientContext.custom.traceparent`.
31
+ *
32
+ * W3C traceparent format:
33
+ * 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01
34
+ * Format: version-traceId-parentId-traceFlags
35
+ *
36
+ * - traceId is 32 hex chars
37
+ * - parentId is 16 hex chars
38
+ * - flags is 2 hex chars (parsed to number)
39
+ *
40
+ * Returns undefined when clientContext or traceparent is missing or malformed.
41
+ */
42
+ export declare function w3cClientContextExtractor(info: InvocationInfo): ContextExtractorResult;
43
+ //# sourceMappingURL=context-extractors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-extractors.d.ts","sourceRoot":"","sources":["../src/context-extractors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAEpE;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAC9B;IACE,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,GACD,SAAS,CAAC;AAEd;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,IAAI,EAAE,cAAc,KAAK,sBAAsB,CAAC;AAEhF;;;;;;;;;;;;;GAaG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,cAAc,GACpB,sBAAsB,CAuCxB;AAeD;;;;;;;;;;;;GAYG;AACH,wBAAgB,yBAAyB,CACvC,IAAI,EAAE,cAAc,GACnB,sBAAsB,CASxB"}
@@ -0,0 +1,64 @@
1
+ import type { IdGenerator } from "@opentelemetry/sdk-trace-node";
2
+ /**
3
+ * A custom OpenTelemetry IdGenerator that produces deterministic trace and span IDs
4
+ * derived from execution metadata (X-Ray headers, execution ARNs, operation IDs)
5
+ * rather than random values.
6
+ *
7
+ * This ensures that spans from different Lambda invocations of the same durable
8
+ * execution are stitched into a single coherent trace.
9
+ */
10
+ export declare class DeterministicIdGenerator implements IdGenerator {
11
+ private traceId;
12
+ private nextSpanId;
13
+ /**
14
+ * Set the trace ID for all subsequent generateTraceId() calls.
15
+ * This is persistent until setTraceId is called again.
16
+ */
17
+ setTraceId(traceId: string): void;
18
+ /**
19
+ * Set the span ID to return on the next single generateSpanId() call.
20
+ * This is a one-shot override: it is consumed on the next call and then
21
+ * reverts to default behavior.
22
+ */
23
+ setNextSpanId(spanId: string): void;
24
+ /**
25
+ * Generate a 32-char lowercase hex trace ID.
26
+ *
27
+ * If setTraceId has been called, returns that value persistently.
28
+ * Otherwise returns a random 32-char hex string as fallback.
29
+ */
30
+ generateTraceId(): string;
31
+ /**
32
+ * Generate a 16-char lowercase hex span ID.
33
+ *
34
+ * If setNextSpanId has been called, returns that value once (one-shot)
35
+ * and then clears it. Otherwise returns a random 16-char hex string.
36
+ */
37
+ generateSpanId(): string;
38
+ }
39
+ /**
40
+ * Derive a deterministic trace ID from an X-Ray Root field.
41
+ * Strips the `Root=1-` prefix and all `-` separators to produce
42
+ * a valid 32-character lowercase hex OpenTelemetry trace ID.
43
+ *
44
+ * @param xRayRoot - The Root field value, e.g. "1-5759e988-bd862e3fe1be46a994272793"
45
+ * @returns A 32-char lowercase hex string, or undefined if the input is invalid
46
+ */
47
+ export declare function deriveTraceIdFromXRayRoot(xRayRoot: string): string | undefined;
48
+ /**
49
+ * Derive a deterministic trace ID from an execution ARN by hashing it
50
+ * with SHA-256 and truncating to the first 32 lowercase hex characters.
51
+ *
52
+ * @param executionArn - The execution ARN string
53
+ * @returns A 32-char lowercase hex string
54
+ */
55
+ export declare function deriveTraceIdFromArn(executionArn: string): string;
56
+ /**
57
+ * Derive a deterministic span ID from an operation ID by hashing it
58
+ * with SHA-256 and truncating to the first 16 lowercase hex characters.
59
+ *
60
+ * @param operationId - The operation ID string
61
+ * @returns A 16-char lowercase hex string
62
+ */
63
+ export declare function deriveSpanIdFromOperationId(operationId: string): string;
64
+ //# sourceMappingURL=deterministic-id-generator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deterministic-id-generator.d.ts","sourceRoot":"","sources":["../src/deterministic-id-generator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAEjE;;;;;;;GAOG;AACH,qBAAa,wBAAyB,YAAW,WAAW;IAC1D,OAAO,CAAC,OAAO,CAAqB;IACpC,OAAO,CAAC,UAAU,CAAqB;IAEvC;;;OAGG;IACH,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAIjC;;;;OAIG;IACH,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAInC;;;;;OAKG;IACH,eAAe,IAAI,MAAM;IAWzB;;;;;OAKG;IACH,cAAc,IAAI,MAAM;CAYzB;AAED;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,MAAM,GACf,MAAM,GAAG,SAAS,CAuBpB;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAEjE;AAED;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAEvE"}
@@ -0,0 +1,6 @@
1
+ export { DurableExecutionOtelPlugin } from "./plugin";
2
+ export type { DurableExecutionOtelPluginConfig } from "./plugin";
3
+ export { DeterministicIdGenerator, deriveTraceIdFromXRayRoot, deriveTraceIdFromArn, deriveSpanIdFromOperationId, } from "./deterministic-id-generator";
4
+ export { xRayContextExtractor, w3cClientContextExtractor, } from "./context-extractors";
5
+ export type { ContextExtractor, ContextExtractorResult, } from "./context-extractors";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAC;AACtD,YAAY,EAAE,gCAAgC,EAAE,MAAM,UAAU,CAAC;AAGjE,OAAO,EACL,wBAAwB,EACxB,yBAAyB,EACzB,oBAAoB,EACpB,2BAA2B,GAC5B,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EACL,oBAAoB,EACpB,yBAAyB,GAC1B,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EACV,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,sBAAsB,CAAC"}