@aws/durable-execution-sdk-js-otel 1.0.0 → 1.2.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.
Files changed (59) hide show
  1. package/README.md +233 -2
  2. package/dist/execution-plugin.mjs +100 -21
  3. package/dist/execution-plugin.mjs.map +1 -1
  4. package/dist/index.mjs +1 -1
  5. package/dist/invocation-plugin.mjs +130 -55
  6. package/dist/invocation-plugin.mjs.map +1 -1
  7. package/dist/otel-execution.mjs +1 -1
  8. package/dist/otel-execution.mjs.map +1 -1
  9. package/dist/otel-invocation.mjs +1 -1
  10. package/dist/otel-invocation.mjs.map +1 -1
  11. package/dist/{global-id-generator.mjs → plugin-registration.mjs} +109 -7
  12. package/dist/plugin-registration.mjs.map +1 -0
  13. package/dist-cjs/execution-plugin.js +113 -34
  14. package/dist-cjs/execution-plugin.js.map +1 -1
  15. package/dist-cjs/index.js +10 -9
  16. package/dist-cjs/index.js.map +1 -1
  17. package/dist-cjs/invocation-plugin.js +142 -67
  18. package/dist-cjs/invocation-plugin.js.map +1 -1
  19. package/dist-cjs/otel-execution.js +1 -1
  20. package/dist-cjs/otel-execution.js.map +1 -1
  21. package/dist-cjs/otel-invocation.js +1 -1
  22. package/dist-cjs/otel-invocation.js.map +1 -1
  23. package/dist-cjs/{global-id-generator.js → plugin-registration.js} +113 -6
  24. package/dist-cjs/plugin-registration.js.map +1 -0
  25. package/dist-types/context-extractors.d.ts +111 -0
  26. package/dist-types/context-extractors.d.ts.map +1 -0
  27. package/dist-types/deterministic-id-generator.d.ts +95 -0
  28. package/dist-types/deterministic-id-generator.d.ts.map +1 -0
  29. package/dist-types/execution-plugin-provider.d.ts +7 -0
  30. package/dist-types/execution-plugin-provider.d.ts.map +1 -0
  31. package/dist-types/execution-plugin.d.ts +88 -0
  32. package/dist-types/execution-plugin.d.ts.map +1 -0
  33. package/dist-types/execution-trace-context.d.ts +133 -0
  34. package/dist-types/execution-trace-context.d.ts.map +1 -0
  35. package/dist-types/external-completions.d.ts +11 -0
  36. package/dist-types/external-completions.d.ts.map +1 -0
  37. package/dist-types/global-id-generator.d.ts +12 -0
  38. package/dist-types/global-id-generator.d.ts.map +1 -0
  39. package/dist-types/global-sampler.d.ts +27 -0
  40. package/dist-types/global-sampler.d.ts.map +1 -0
  41. package/dist-types/index.d.ts +9 -0
  42. package/dist-types/index.d.ts.map +1 -0
  43. package/dist-types/invocation-clock.d.ts +9 -0
  44. package/dist-types/invocation-clock.d.ts.map +1 -0
  45. package/dist-types/invocation-plugin-provider.d.ts +7 -0
  46. package/dist-types/invocation-plugin-provider.d.ts.map +1 -0
  47. package/dist-types/invocation-plugin.d.ts +99 -0
  48. package/dist-types/invocation-plugin.d.ts.map +1 -0
  49. package/dist-types/otel-plugin-config.d.ts +66 -0
  50. package/dist-types/otel-plugin-config.d.ts.map +1 -0
  51. package/dist-types/otel-plugin-provider.d.ts +21 -0
  52. package/dist-types/otel-plugin-provider.d.ts.map +1 -0
  53. package/dist-types/plugin-registration.d.ts +2 -0
  54. package/dist-types/plugin-registration.d.ts.map +1 -0
  55. package/dist-types/propagation-metadata.d.ts +12 -0
  56. package/dist-types/propagation-metadata.d.ts.map +1 -0
  57. package/package.json +13 -9
  58. package/dist/global-id-generator.mjs.map +0 -1
  59. package/dist-cjs/global-id-generator.js.map +0 -1
@@ -227,7 +227,8 @@ function hasValidTraceId(extracted) {
227
227
  return extracted != null && isValidTraceId(extracted.traceId);
228
228
  }
229
229
  /**
230
- * Reads the X-Ray trace header from the `_X_AMZN_TRACE_ID` environment variable.
230
+ * Parses an X-Ray trace header into the context used by the execution trace
231
+ * resolver.
231
232
  *
232
233
  * The durable execution backend propagates the same Root trace ID to every
233
234
  * invocation, so all invocations of the same execution share one traceId.
@@ -244,10 +245,9 @@ function hasValidTraceId(extracted) {
244
245
  * as invalid (it is well-formed hex but not a usable ID). A valid Root with no
245
246
  * usable Parent is still returned (the trace ID is usable on its own).
246
247
  *
247
- * Returns undefined when _X_AMZN_TRACE_ID is missing or has no valid Root.
248
+ * Returns undefined when the header is missing or has no valid Root.
248
249
  */
249
- function xRayContextExtractor(_info) {
250
- const header = process.env._X_AMZN_TRACE_ID;
250
+ function parseXRayTraceHeader(header) {
251
251
  if (!header) {
252
252
  return undefined;
253
253
  }
@@ -289,6 +289,12 @@ function xRayContextExtractor(_info) {
289
289
  : "UNDECIDED";
290
290
  return { traceId, parentSpanId, sampling };
291
291
  }
292
+ /**
293
+ * Reads the X-Ray trace header from the `_X_AMZN_TRACE_ID` environment variable.
294
+ */
295
+ function xRayContextExtractor(_info) {
296
+ return parseXRayTraceHeader(process.env._X_AMZN_TRACE_ID);
297
+ }
292
298
  /**
293
299
  * Reads W3C traceparent from `context.clientContext.custom.traceparent`.
294
300
  *
@@ -409,6 +415,17 @@ function tryInstallDurableSampler(tracer) {
409
415
  return undefined;
410
416
  }
411
417
  }
418
+ /** Whether this tracer still uses the bridge that controls SDK span decisions. */
419
+ function isDurableSamplerInstalled(tracer, sampler) {
420
+ if (!sampler)
421
+ return false;
422
+ try {
423
+ return Reflect.get(tracer, SAMPLER_FIELD) === sampler;
424
+ }
425
+ catch {
426
+ return false;
427
+ }
428
+ }
412
429
  function getConfiguredSampler(tracer) {
413
430
  try {
414
431
  const sampler = Reflect.get(tracer, SAMPLER_FIELD);
@@ -443,6 +460,26 @@ function canonicalTraceId(extracted, executionArn, executionStartTimestamp) {
443
460
  }
444
461
  return deriveTraceIdFromArn(executionArn, executionStartTimestamp);
445
462
  }
463
+ /**
464
+ * Derives the trace ID used by the OpenTelemetry plugins for a durable
465
+ * execution with the default X-Ray context extractor.
466
+ *
467
+ * A valid `Root` from `_X_AMZN_TRACE_ID` takes precedence. When the header is
468
+ * missing or malformed, the trace ID is derived from the execution ARN and
469
+ * stable execution start timestamp using the same resolver as the plugins.
470
+ *
471
+ * Pass the same execution start timestamp supplied to the plugin when no valid
472
+ * X-Ray Root is available. If the timestamp is unavailable to both callers,
473
+ * omit it to use the deterministic ARN-only fallback.
474
+ *
475
+ * @param environment - Environment containing the optional X-Ray trace header
476
+ * @param executionArn - The durable execution ARN
477
+ * @param executionStartTimestamp - Stable start time of the durable execution
478
+ * @returns The 32-character lowercase hexadecimal execution trace ID
479
+ */
480
+ function deriveExecutionTraceId(environment, executionArn, executionStartTimestamp) {
481
+ return canonicalTraceId(parseXRayTraceHeader(environment._X_AMZN_TRACE_ID), executionArn, executionStartTimestamp);
482
+ }
446
483
  /**
447
484
  * Flags for an explicit upstream decision, or the sampler's decision
448
485
  * (`whenUndecided`) when the upstream did not decide. The supplier is consulted
@@ -508,9 +545,15 @@ function resolveExecutionTraceContext(extracted, canonical, executionArn, rootSa
508
545
  const samplingContext = hasValidTraceId(extracted) ? extracted : undefined;
509
546
  const decision = explicitDecision(samplingContext, rootSamplingDecision);
510
547
  const flags = traceFlagsFromDecision(decision);
548
+ // This synthetic root is created and exported by one durable execution,
549
+ // so its span identity must remain owned by that execution. Multiple
550
+ // executions may legitimately share a propagated trace ID, but reusing one
551
+ // span ID across independently timed/resource-scoped roots would create
552
+ // conflicting OpenTelemetry span identities.
553
+ const syntheticRootSpanId = deriveExecutionRootSpanId(executionArn);
511
554
  const syntheticRoot = {
512
555
  traceId: canonical,
513
- spanId: deriveExecutionRootSpanId(executionArn),
556
+ spanId: syntheticRootSpanId,
514
557
  traceFlags: flags,
515
558
  isRemote: false,
516
559
  };
@@ -620,18 +663,82 @@ function tryInstallGlobalIdGenerator(tracer) {
620
663
  }
621
664
  }
622
665
 
666
+ function isExternalOperation(info) {
667
+ return (info.type === "WAIT" ||
668
+ info.type === "INVOKE" ||
669
+ info.type === "CHAINED_INVOKE" ||
670
+ info.type === "CALLBACK");
671
+ }
672
+ /** Invocation-local bookkeeping; no export acknowledgement is persisted. */
673
+ class ExternalCompletions {
674
+ pending = new Map();
675
+ exported = new Set();
676
+ observe(operations = {}) {
677
+ for (const info of Object.values(operations)) {
678
+ if (info.id &&
679
+ isExternalOperation(info) &&
680
+ (info.status === "SUCCEEDED" ||
681
+ info.status === "FAILED" ||
682
+ info.status === "TIMED_OUT" ||
683
+ info.status === "STOPPED" ||
684
+ info.status === "CANCELLED") &&
685
+ !this.exported.has(info.id)) {
686
+ this.pending.set(info.id, info);
687
+ }
688
+ }
689
+ }
690
+ shouldSkip(info) {
691
+ // Replay describes the SDK's initial state, not whether a completion that
692
+ // arrived later in a checkpoint response has already been exported.
693
+ return (isExternalOperation(info) &&
694
+ (this.exported.has(info.id) ||
695
+ (info.isReplay && !this.pending.has(info.id))));
696
+ }
697
+ markExported(info) {
698
+ if (isExternalOperation(info)) {
699
+ this.exported.add(info.id);
700
+ this.pending.delete(info.id);
701
+ }
702
+ }
703
+ clear() {
704
+ this.pending.clear();
705
+ this.exported.clear();
706
+ }
707
+ }
708
+
709
+ /** Encodes the already resolved execution state without creating a span. */
710
+ function createPropagationMetadata(input, executionArn, traceId, traceFlags) {
711
+ if (input.executionArn !== executionArn || !isValidTraceId(traceId))
712
+ return undefined;
713
+ const spanId = deriveSpanIdFromOperationId(input.operationId, executionArn);
714
+ if (!isValidSpanId(spanId))
715
+ return undefined;
716
+ return Object.freeze({
717
+ xAmznTraceId: `Root=1-${traceId.slice(0, 8)}-${traceId.slice(8)};Parent=${spanId};Sampled=${traceFlags & 1 ? "1" : "0"}`,
718
+ });
719
+ }
720
+
721
+ // Match the SDK-owned opt-in protocol without a runtime import of the core SDK.
722
+ // A local symbol declaration also keeps old-core TypeScript consumers compatible.
723
+ const PLUGIN_REGISTRATION = Symbol.for("aws.lambda.durable.instrumentation.plugin-registration");
724
+
623
725
  exports.DeterministicIdGenerator = DeterministicIdGenerator;
726
+ exports.ExternalCompletions = ExternalCompletions;
727
+ exports.PLUGIN_REGISTRATION = PLUGIN_REGISTRATION;
624
728
  exports.canonicalTraceId = canonicalTraceId;
729
+ exports.createPropagationMetadata = createPropagationMetadata;
625
730
  exports.createTracerProvider = createTracerProvider;
626
731
  exports.deriveExecutionRootSpanId = deriveExecutionRootSpanId;
732
+ exports.deriveExecutionTraceId = deriveExecutionTraceId;
627
733
  exports.deriveSpanIdFromOperationId = deriveSpanIdFromOperationId;
628
734
  exports.deriveTraceIdFromArn = deriveTraceIdFromArn;
629
735
  exports.deriveTraceIdFromXRayRoot = deriveTraceIdFromXRayRoot;
630
736
  exports.deriveWorkflowSpanId = deriveWorkflowSpanId;
737
+ exports.isDurableSamplerInstalled = isDurableSamplerInstalled;
631
738
  exports.resolveExecutionTraceContext = resolveExecutionTraceContext;
632
739
  exports.rootSamplingDecision = rootSamplingDecision;
633
740
  exports.tryInstallDurableSampler = tryInstallDurableSampler;
634
741
  exports.tryInstallGlobalIdGenerator = tryInstallGlobalIdGenerator;
635
742
  exports.w3cClientContextExtractor = w3cClientContextExtractor;
636
743
  exports.xRayContextExtractor = xRayContextExtractor;
637
- //# sourceMappingURL=global-id-generator.js.map
744
+ //# sourceMappingURL=plugin-registration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-registration.js","sources":["../src/deterministic-id-generator.ts","../src/context-extractors.ts","../src/global-sampler.ts","../src/execution-trace-context.ts","../src/otel-plugin-provider.ts","../src/global-id-generator.ts","../src/external-completions.ts","../src/propagation-metadata.ts","../src/plugin-registration.ts"],"names":["AsyncLocalStorage","RandomIdGenerator","createHash","SamplingDecision","TraceFlags","ROOT_CONTEXT","SpanKind","trace"],"mappings":";;;;;;;AAYA;;;;;;;AAOG;MACU,wBAAwB,CAAA;AAIhB,IAAA,mBAAA;AAHX,IAAA,OAAgB,WAAW,GAAG,IAAIA,kCAAiB,EAAc;IAEzE,WAAA,CACmB,mBAAA,GAAmC,IAAIC,8BAAiB,EAAE,EAAA;QAA1D,IAAA,CAAA,mBAAmB,GAAnB,mBAAmB;IACnC;AAEH;;;;;AAKG;IACH,OAAO,CAAI,GAAe,EAAE,EAAW,EAAA;AACrC,QAAA,OAAO,wBAAwB,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,GAAG,GAAG,EAAE,EAAE,EAAE,CAAC;IAC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AC,CAAA,CAAA,EAAI,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA,QAAA,EAAW,MAAM,CAAA,SAAA,EAAY,UAAU,GAAG,CAAC,GAAG,GAAG,GAAG,GAAG,CAAA,CAAE;AACzH,KAAA,CAAC;AACJ;;AChCA;AACA;AACO,MAAM,mBAAmB,GAAG,MAAM,CAAC,GAAG,CAC3C,wDAAwD;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,111 @@
1
+ import type { InvocationInfo } from "@aws/durable-execution-sdk-js";
2
+ /**
3
+ * The upstream sampling decision carried by a propagated context.
4
+ *
5
+ * Tri-state so that "no usable decision" is distinct from an explicit
6
+ * "do not sample". Extractors use `SAMPLED` / `NOT_SAMPLED` only for explicit
7
+ * upstream values (for example X-Ray `Sampled=1` / `Sampled=0`, or a W3C
8
+ * `traceparent` sampled bit); anything absent or unusable is `UNDECIDED`, which
9
+ * lets the configured sampler decide.
10
+ */
11
+ export type Sampling = "SAMPLED" | "NOT_SAMPLED" | "UNDECIDED";
12
+ /**
13
+ * Result type returned by context extractors.
14
+ *
15
+ * `sampling` is the tri-state upstream decision. `traceFlags` is retained for
16
+ * backward compatibility with custom extractors: when `sampling` is omitted it
17
+ * is derived from `traceFlags` (sampled bit set -> `SAMPLED`, clear ->
18
+ * `NOT_SAMPLED`), and when neither is provided the decision is `UNDECIDED`.
19
+ *
20
+ * The resolver adopts the trace ID and parent span ID only when they are valid
21
+ * (well-formed, non-zero); an extractor that cannot supply a usable value
22
+ * returns `undefined` for it so the resolver falls back to a deterministic
23
+ * ARN-derived trace and synthetic root.
24
+ */
25
+ export type ContextExtractorResult = {
26
+ traceId: string;
27
+ parentSpanId?: string;
28
+ traceFlags?: number;
29
+ sampling?: Sampling;
30
+ } | undefined;
31
+ /**
32
+ * True when `traceId` is a well-formed, non-zero 32-char hex OTel trace ID.
33
+ *
34
+ * Validity is stricter than a format match: an all-zero ID is well-formed hex
35
+ * but invalid, and anchoring an execution on it would split the trace.
36
+ */
37
+ export declare function isValidTraceId(traceId: string | undefined): traceId is string;
38
+ /**
39
+ * True when `spanId` is a well-formed, non-zero 16-char hex OTel span ID.
40
+ */
41
+ export declare function isValidSpanId(spanId: string | undefined): spanId is string;
42
+ /**
43
+ * Resolves the tri-state sampling decision for an extracted context.
44
+ *
45
+ * Prefers an explicit `sampling` value; otherwise derives from `traceFlags`
46
+ * when present; otherwise `UNDECIDED`.
47
+ */
48
+ export declare function resolveSampling(extracted: {
49
+ traceFlags?: number;
50
+ sampling?: Sampling;
51
+ }): Sampling;
52
+ /**
53
+ * True when the extracted context carries a complete remote parent: a valid
54
+ * trace ID and a valid parent span ID, so it can serve as a remote parent.
55
+ */
56
+ export declare function hasCompleteRemoteParent(extracted: ContextExtractorResult): extracted is {
57
+ traceId: string;
58
+ parentSpanId: string;
59
+ } & NonNullable<ContextExtractorResult>;
60
+ /**
61
+ * True when the extracted context carries a valid (well-formed, non-zero) trace
62
+ * ID that the resolver can anchor the durable execution trace on.
63
+ */
64
+ export declare function hasValidTraceId(extracted: ContextExtractorResult): extracted is {
65
+ traceId: string;
66
+ } & NonNullable<ContextExtractorResult>;
67
+ /**
68
+ * A function that extracts upstream trace context from the invocation environment.
69
+ */
70
+ export type ContextExtractor = (info: InvocationInfo) => ContextExtractorResult;
71
+ /**
72
+ * Parses an X-Ray trace header into the context used by the execution trace
73
+ * resolver.
74
+ *
75
+ * The durable execution backend propagates the same Root trace ID to every
76
+ * invocation, so all invocations of the same execution share one traceId.
77
+ *
78
+ * X-Ray Header format:
79
+ * Root=1-5759e988-bd862e3fe1be46a994272793;Parent=53995c3f42cd8ad8;Sampled=1
80
+ *
81
+ * - Extract Root value, strip "1-" prefix and all "-" to get 32-char hex traceId
82
+ * - Extract Parent value for parentSpanId (16-char hex)
83
+ * - Extract Sampled: `1` -> SAMPLED, `0` -> NOT_SAMPLED, anything else undecided
84
+ *
85
+ * `Root`, `Parent`, and `Sampled` are parsed independently: only `Sampled=1`
86
+ * and `Sampled=0` are authoritative, and an all-zero Root or Parent is rejected
87
+ * as invalid (it is well-formed hex but not a usable ID). A valid Root with no
88
+ * usable Parent is still returned (the trace ID is usable on its own).
89
+ *
90
+ * Returns undefined when the header is missing or has no valid Root.
91
+ */
92
+ export declare function parseXRayTraceHeader(header: string | undefined): ContextExtractorResult;
93
+ /**
94
+ * Reads the X-Ray trace header from the `_X_AMZN_TRACE_ID` environment variable.
95
+ */
96
+ export declare function xRayContextExtractor(_info: InvocationInfo): ContextExtractorResult;
97
+ /**
98
+ * Reads W3C traceparent from `context.clientContext.custom.traceparent`.
99
+ *
100
+ * W3C traceparent format:
101
+ * 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01
102
+ * Format: version-traceId-parentId-traceFlags
103
+ *
104
+ * - traceId is 32 hex chars
105
+ * - parentId is 16 hex chars
106
+ * - flags is 2 hex chars (parsed to number)
107
+ *
108
+ * Returns undefined when clientContext or traceparent is missing or malformed.
109
+ */
110
+ export declare function w3cClientContextExtractor(info: InvocationInfo): ContextExtractorResult;
111
+ //# 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;;;;;;;;GAQG;AACH,MAAM,MAAM,QAAQ,GAAG,SAAS,GAAG,aAAa,GAAG,WAAW,CAAC;AAE/D;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,sBAAsB,GAC9B;IACE,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB,GACD,SAAS,CAAC;AAOd;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,IAAI,MAAM,CAM7E;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,IAAI,MAAM,CAM1E;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE;IACzC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB,GAAG,QAAQ,CAQX;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,sBAAsB,GAChC,SAAS,IAAI;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;CACtB,GAAG,WAAW,CAAC,sBAAsB,CAAC,CAMtC;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,SAAS,EAAE,sBAAsB,GAChC,SAAS,IAAI;IACd,OAAO,EAAE,MAAM,CAAC;CACjB,GAAG,WAAW,CAAC,sBAAsB,CAAC,CAEtC;AAED;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,IAAI,EAAE,cAAc,KAAK,sBAAsB,CAAC;AAEhF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,MAAM,GAAG,SAAS,GACzB,sBAAsB,CAiDxB;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,cAAc,GACpB,sBAAsB,CAExB;AAeD;;;;;;;;;;;;GAYG;AACH,wBAAgB,yBAAyB,CACvC,IAAI,EAAE,cAAc,GACnB,sBAAsB,CASxB"}
@@ -0,0 +1,95 @@
1
+ import { type IdGenerator } from "@opentelemetry/sdk-trace-node";
2
+ export interface IdOverride {
3
+ traceId?: string;
4
+ spanId?: string;
5
+ }
6
+ /**
7
+ * An OpenTelemetry IdGenerator with execution-scoped deterministic overrides.
8
+ *
9
+ * Overrides are active only while {@link withIds} runs. All other ID generation
10
+ * is delegated to the fallback generator. AsyncLocalStorage makes the override
11
+ * visible to the provider-owned generator without leaking it to unrelated spans
12
+ * or concurrent durable executions.
13
+ */
14
+ export declare class DeterministicIdGenerator implements IdGenerator {
15
+ private readonly fallbackIdGenerator;
16
+ private static readonly idOverrides;
17
+ constructor(fallbackIdGenerator?: IdGenerator);
18
+ /**
19
+ * Runs a synchronous span-creation callback with deterministic IDs.
20
+ *
21
+ * The span ID is consumed on its first use so re-entrant ID generation cannot
22
+ * accidentally assign the same ID to more than one span.
23
+ */
24
+ withIds<T>(ids: IdOverride, fn: () => T): T;
25
+ /** Generate a 32-char lowercase hex trace ID. */
26
+ generateTraceId(): string;
27
+ /** Generate a 16-char lowercase hex span ID. */
28
+ generateSpanId(): string;
29
+ }
30
+ /**
31
+ * Derive a deterministic trace ID from an X-Ray Root field.
32
+ * Strips the `Root=1-` prefix and all `-` separators to produce
33
+ * a valid 32-character lowercase hex OpenTelemetry trace ID.
34
+ *
35
+ * @param xRayRoot - The Root field value, e.g. "1-5759e988-bd862e3fe1be46a994272793"
36
+ * @returns A 32-char lowercase hex string, or undefined if the input is invalid
37
+ */
38
+ export declare function deriveTraceIdFromXRayRoot(xRayRoot: string): string | undefined;
39
+ /**
40
+ * Derive a deterministic trace ID from an execution ARN and its durable start
41
+ * timestamp by hashing them with SHA-256 and truncating to the first 32
42
+ * lowercase hex characters.
43
+ *
44
+ * The timestamp is optional for callers that do not have it. When omitted, the
45
+ * ARN-only derivation is retained as a deterministic fallback.
46
+ *
47
+ * @param executionArn - The execution ARN string
48
+ * @param executionStartTimestamp - Stable start time of the durable execution
49
+ * @returns A 32-char lowercase hex string
50
+ */
51
+ export declare function deriveTraceIdFromArn(executionArn: string, executionStartTimestamp?: Date): string;
52
+ /**
53
+ * Derive a deterministic span ID from an operation ID scoped to a specific execution.
54
+ * Hashes `executionArn + ":" + operationId` with SHA-256 and truncates to the first
55
+ * 16 lowercase hex characters.
56
+ *
57
+ * The executionArn is included in the hash input to avoid span ID collisions when
58
+ * different executions (e.g., a parent and child workflow) share the same trace and
59
+ * have operations at the same positional ID.
60
+ *
61
+ * @param operationId - The operation ID string (positional identifier within an execution)
62
+ * @param executionArn - The execution ARN, used to scope span IDs per execution
63
+ * @returns A 16-char lowercase hex string
64
+ */
65
+ export declare function deriveSpanIdFromOperationId(operationId: string, executionArn: string): string;
66
+ /**
67
+ * Derive a deterministic span ID for a Workflow_Span from an execution ARN.
68
+ * Hashes `"workflow:" + executionArn` with SHA-256 and truncates to the first
69
+ * 16 lowercase hex characters.
70
+ *
71
+ * The "workflow:" prefix acts as a salt to ensure the resulting span ID is
72
+ * distinct from IDs produced by `deriveSpanIdFromOperationId` for the same ARN.
73
+ *
74
+ * @param executionArn - The execution ARN string (must be non-empty)
75
+ * @returns A 16-char lowercase hex string, never equal to "0000000000000000"
76
+ * @throws Error if the execution ARN is an empty string
77
+ */
78
+ export declare function deriveWorkflowSpanId(executionArn: string): string;
79
+ /**
80
+ * Derive a deterministic span ID for the synthetic execution root from an
81
+ * execution ARN. Hashes `"execution-root:" + executionArn` with SHA-256 and
82
+ * truncates to the first 16 lowercase hex characters.
83
+ *
84
+ * The `"execution-root:"` prefix is a distinct namespace from
85
+ * `deriveWorkflowSpanId` (`"workflow:"`) and `deriveSpanIdFromOperationId`
86
+ * (`"<arn>:<opId>"`), so the synthetic root never collides with the Workflow or
87
+ * operation spans that share the execution trace. Stable across reinvocations
88
+ * so the same synthetic root is the common ancestor every invocation.
89
+ *
90
+ * @param executionArn - The execution ARN string (must be non-empty)
91
+ * @returns A 16-char lowercase hex string, never equal to "0000000000000000"
92
+ * @throws Error if the execution ARN is an empty string
93
+ */
94
+ export declare function deriveExecutionRootSpanId(executionArn: string): string;
95
+ //# 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":"AAEA,OAAO,EAEL,KAAK,WAAW,EACjB,MAAM,+BAA+B,CAAC;AAEvC,MAAM,WAAW,UAAU;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;GAOG;AACH,qBAAa,wBAAyB,YAAW,WAAW;IAIxD,OAAO,CAAC,QAAQ,CAAC,mBAAmB;IAHtC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAuC;gBAGvD,mBAAmB,GAAE,WAAqC;IAG7E;;;;;OAKG;IACH,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC;IAI3C,iDAAiD;IACjD,eAAe,IAAI,MAAM;IAQzB,gDAAgD;IAChD,cAAc,IAAI,MAAM;CASzB;AAED;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,MAAM,GACf,MAAM,GAAG,SAAS,CAuBpB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAClC,YAAY,EAAE,MAAM,EACpB,uBAAuB,CAAC,EAAE,IAAI,GAC7B,MAAM,CAQR;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,2BAA2B,CACzC,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,GACnB,MAAM,CAKR;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAiBjE;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,yBAAyB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAetE"}
@@ -0,0 +1,7 @@
1
+ import { ExecutionOtelPlugin } from "./execution-plugin";
2
+ export declare const durableExecutionPluginProvider: {
3
+ pluginApiVersion: 1;
4
+ pluginType: typeof ExecutionOtelPlugin;
5
+ createPlugin: () => ExecutionOtelPlugin;
6
+ };
7
+ //# sourceMappingURL=execution-plugin-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execution-plugin-provider.d.ts","sourceRoot":"","sources":["../src/execution-plugin-provider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD,eAAO,MAAM,8BAA8B;;;;CAI0B,CAAC"}
@@ -0,0 +1,88 @@
1
+ import type { DurableInstrumentationPlugin, InvocationInfo, InvocationEndInfo, OperationInfo, OperationEndInfo, AttemptInfo, AttemptEndInfo, OperationChangeInfo } from "@aws/durable-execution-sdk-js";
2
+ import type { DurableExecutionInvocationOutput } from "@aws/durable-execution-sdk-js";
3
+ import type { OtelPluginConfig } from "./otel-plugin-config";
4
+ import type { PropagationInput, PropagationMetadata } from "./propagation-metadata";
5
+ import { PLUGIN_REGISTRATION } from "./plugin-registration";
6
+ /**
7
+ * OpenTelemetry instrumentation plugin for durable executions.
8
+ *
9
+ * Implements the DurableInstrumentationPlugin interface. The Workflow span joins
10
+ * the execution trace by parenting onto the resolved execution ancestor (a
11
+ * propagated remote parent or a synthetic execution root), so the whole
12
+ * execution shares one trace. Operation spans parent onto the Workflow span and
13
+ * the per-invocation Invocation span is a correlation sibling (linked from, not
14
+ * a parent of, the operation spans). Both the Workflow span and each operation
15
+ * span are deferred: their identity is carried as a non-recording context and
16
+ * the single recording span is created and ended together at terminal /
17
+ * onOperationEnd, so nothing is left un-ended across invocations (issue #831).
18
+ */
19
+ export declare class ExecutionOtelPlugin implements DurableInstrumentationPlugin {
20
+ private static readonly [PLUGIN_REGISTRATION];
21
+ private idGenerator;
22
+ private readonly contextExtractor;
23
+ private tracerProvider;
24
+ private tracer;
25
+ private readonly instrumentationName;
26
+ private workflowSpan;
27
+ private invocationSpan;
28
+ private spanMap;
29
+ private operationContexts;
30
+ private operationStarts;
31
+ private executionArn;
32
+ private executionTraceId;
33
+ private executionTraceFlags;
34
+ private executionSamplingDecision;
35
+ private executionAncestor;
36
+ private executionStartTimestamp;
37
+ private syntheticRootAnchorTimestamp;
38
+ private syntheticRootMaterialized;
39
+ private readonly usesGlobalProvider;
40
+ private globalIdGeneratorInstalled;
41
+ private durableSampler;
42
+ private tracingEnabled;
43
+ private readonly externalCompletions;
44
+ private readonly workflowSpanName;
45
+ private readonly enrichLogger;
46
+ constructor(config?: OtelPluginConfig);
47
+ onInvocationStart(info: InvocationInfo): Promise<void>;
48
+ providePropagationMetadata(input: PropagationInput): PropagationMetadata | undefined;
49
+ wrapInvocation(_info: InvocationInfo, fn: () => Promise<DurableExecutionInvocationOutput>): Promise<DurableExecutionInvocationOutput>;
50
+ onInvocationEnd(info: InvocationEndInfo): Promise<void>;
51
+ /** Creates at most one SDK-owned root per invocation; the caller ends it. */
52
+ private createSyntheticRoot;
53
+ private ensureGlobalIdGeneratorInstalled;
54
+ private resetInvocationState;
55
+ private startSpan;
56
+ /**
57
+ * The parent context for the Invocation span: the active ambient span when it
58
+ * is already on the execution trace, otherwise the execution ancestor so the
59
+ * Invocation span stays within the same trace.
60
+ */
61
+ private invocationParentContext;
62
+ /**
63
+ * Builds span links to the invocation span for child spans.
64
+ *
65
+ * Always links to the plugin-created Invocation_Span (this.invocationSpan),
66
+ * which is created in both default-provider and non-default modes.
67
+ */
68
+ private buildInvocationLinks;
69
+ onOperationStart(info: OperationInfo): Promise<void>;
70
+ wrapChildContextFn(info: OperationInfo, fn: () => unknown): unknown;
71
+ onOperationEnd(info: OperationEndInfo): Promise<void>;
72
+ /**
73
+ * The parent context for an operation or attempt span: the parent operation's
74
+ * deterministic identity, or the Workflow identity for a top-level operation.
75
+ * A completion notification can arrive without traversing its parent in this
76
+ * invocation (for example, a completed child context skipped during replay).
77
+ */
78
+ private resolveOperationParentContext;
79
+ /** The earlier of two timestamps, ignoring undefined; undefined only when both are. */
80
+ private earliestStart;
81
+ private getAttemptKey;
82
+ onOperationAttemptStart(info: AttemptInfo): Promise<void>;
83
+ wrapOperationAttemptFn(info: AttemptInfo, fn: () => unknown): unknown;
84
+ onOperationAttemptEnd(info: AttemptEndInfo): Promise<void>;
85
+ onOperationChange(info: OperationChangeInfo): Promise<void>;
86
+ enrichLogContext(): Record<string, string | number | boolean> | undefined;
87
+ }
88
+ //# sourceMappingURL=execution-plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execution-plugin.d.ts","sourceRoot":"","sources":["../src/execution-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,4BAA4B,EAC5B,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,gBAAgB,EAChB,WAAW,EACX,cAAc,EACd,mBAAmB,EACpB,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,+BAA+B,CAAC;AA+BtF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAW7D,OAAO,KAAK,EACV,gBAAgB,EAChB,mBAAmB,EACpB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAI5D;;;;;;;;;;;;GAYG;AACH,qBAAa,mBAAoB,YAAW,4BAA4B;IACtE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,mBAAmB,CAAC,CAElC;IAGX,OAAO,CAAC,WAAW,CAA2B;IAC9C,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAmB;IAGpD,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAS;IAI7C,OAAO,CAAC,YAAY,CAAmB;IACvC,OAAO,CAAC,cAAc,CAAmB;IAGzC,OAAO,CAAC,OAAO,CAAoB;IAGnC,OAAO,CAAC,iBAAiB,CAA2B;IAEpD,OAAO,CAAC,eAAe,CAGrB;IACF,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,gBAAgB,CAAS;IACjC,OAAO,CAAC,mBAAmB,CAAa;IACxC,OAAO,CAAC,yBAAyB,CAAmB;IAIpD,OAAO,CAAC,iBAAiB,CAA0B;IACnD,OAAO,CA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