@aws/durable-execution-sdk-js-otel 0.1.1 → 1.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.
Files changed (53) hide show
  1. package/README.md +523 -175
  2. package/dist/execution-plugin.mjs +539 -0
  3. package/dist/execution-plugin.mjs.map +1 -0
  4. package/dist/global-id-generator.mjs +648 -0
  5. package/dist/global-id-generator.mjs.map +1 -0
  6. package/dist/index.mjs +8 -537
  7. package/dist/index.mjs.map +1 -1
  8. package/dist/invocation-plugin.mjs +661 -0
  9. package/dist/invocation-plugin.mjs.map +1 -0
  10. package/dist/otel-execution.mjs +15 -0
  11. package/dist/otel-execution.mjs.map +1 -0
  12. package/dist/otel-invocation.mjs +16 -0
  13. package/dist/otel-invocation.mjs.map +1 -0
  14. package/dist-cjs/execution-plugin.js +541 -0
  15. package/dist-cjs/execution-plugin.js.map +1 -0
  16. package/dist-cjs/global-id-generator.js +664 -0
  17. package/dist-cjs/global-id-generator.js.map +1 -0
  18. package/dist-cjs/index.js +19 -540
  19. package/dist-cjs/index.js.map +1 -1
  20. package/dist-cjs/invocation-plugin.js +663 -0
  21. package/dist-cjs/invocation-plugin.js.map +1 -0
  22. package/dist-cjs/otel-execution.js +17 -0
  23. package/dist-cjs/otel-execution.js.map +1 -0
  24. package/dist-cjs/otel-invocation.js +18 -0
  25. package/dist-cjs/otel-invocation.js.map +1 -0
  26. package/dist-types/context-extractors.d.ts +70 -2
  27. package/dist-types/context-extractors.d.ts.map +1 -1
  28. package/dist-types/deterministic-id-generator.d.ts +56 -31
  29. package/dist-types/deterministic-id-generator.d.ts.map +1 -1
  30. package/dist-types/execution-plugin-provider.d.ts +7 -0
  31. package/dist-types/execution-plugin-provider.d.ts.map +1 -0
  32. package/dist-types/execution-plugin.d.ts +78 -0
  33. package/dist-types/execution-plugin.d.ts.map +1 -0
  34. package/dist-types/execution-trace-context.d.ts +131 -0
  35. package/dist-types/execution-trace-context.d.ts.map +1 -0
  36. package/dist-types/global-id-generator.d.ts +12 -0
  37. package/dist-types/global-id-generator.d.ts.map +1 -0
  38. package/dist-types/global-sampler.d.ts +25 -0
  39. package/dist-types/global-sampler.d.ts.map +1 -0
  40. package/dist-types/index.d.ts +6 -3
  41. package/dist-types/index.d.ts.map +1 -1
  42. package/dist-types/invocation-plugin-provider.d.ts +7 -0
  43. package/dist-types/invocation-plugin-provider.d.ts.map +1 -0
  44. package/dist-types/invocation-plugin.d.ts +89 -0
  45. package/dist-types/invocation-plugin.d.ts.map +1 -0
  46. package/dist-types/otel-plugin-config.d.ts +66 -0
  47. package/dist-types/otel-plugin-config.d.ts.map +1 -0
  48. package/dist-types/otel-plugin-provider.d.ts +21 -0
  49. package/dist-types/otel-plugin-provider.d.ts.map +1 -0
  50. package/package.json +26 -15
  51. package/dist-types/plugin.d.ts +0 -46
  52. package/dist-types/plugin.d.ts.map +0 -1
  53. package/dist-types/tsconfig.build.tsbuildinfo +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invocation-plugin.js","sources":["../src/invocation-plugin.ts"],"names":["SamplingDecision","DeterministicIdGenerator","xRayContextExtractor","createTracerProvider","tryInstallDurableSampler","tryInstallGlobalIdGenerator","canonicalTraceId","resolveExecutionTraceContext","rootSamplingDecision","deriveWorkflowSpanId","trace","SpanKind","hrTime","context","SpanStatusCode","ROOT_CONTEXT","isSpanContextValid","TraceFlags","deriveSpanIdFromOperationId"],"mappings":";;;;;;;AA8CA,MAAM,4BAA4B,GAAG,8BAA8B;AAEnE;;;;;;AAMG;MACU,oBAAoB,CAAA;AACvB,IAAA,cAAc;AACd,IAAA,MAAM;AACN,IAAA,WAAW;AACF,IAAA,gBAAgB;AAChB,IAAA,mBAAmB;AACnB,IAAA,kBAAkB;AAC3B,IAAA,0BAA0B;AAC1B,IAAA,cAAc;IACd,cAAc,GAAG,KAAK;AACb,IAAA,gBAAgB;AAChB,IAAA,YAAY;;AAGrB,IAAA,OAAO,GAAsB,IAAI,GAAG,EAAE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');
4
+ require('@opentelemetry/api');
5
+ require('./global-id-generator.js');
6
+ require('@opentelemetry/sdk-trace-node');
7
+ require('node:async_hooks');
8
+ require('node:crypto');
9
+
10
+ const durableExecutionPluginProvider = {
11
+ pluginApiVersion: 1,
12
+ pluginType: executionPlugin.ExecutionOtelPlugin,
13
+ createPlugin: () => new executionPlugin.ExecutionOtelPlugin(),
14
+ };
15
+
16
+ exports.durableExecutionPluginProvider = durableExecutionPluginProvider;
17
+ //# sourceMappingURL=otel-execution.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"otel-execution.js","sources":["../src/execution-plugin-provider.ts"],"names":["ExecutionOtelPlugin"],"mappings":";;;;;;;;;AAGO,MAAM,8BAA8B,GAAG;AAC5C,IAAA,gBAAgB,EAAE,CAAC;AACnB,IAAA,UAAU,EAAEA,mCAAmB;AAC/B,IAAA,YAAY,EAAE,MAAM,IAAIA,mCAAmB,EAAE;;;;;"}
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ var invocationPlugin = require('./invocation-plugin.js');
4
+ require('@opentelemetry/api');
5
+ require('@opentelemetry/core');
6
+ require('@opentelemetry/sdk-trace-node');
7
+ require('./global-id-generator.js');
8
+ require('node:async_hooks');
9
+ require('node:crypto');
10
+
11
+ const durableExecutionPluginProvider = {
12
+ pluginApiVersion: 1,
13
+ pluginType: invocationPlugin.InvocationOtelPlugin,
14
+ createPlugin: () => new invocationPlugin.InvocationOtelPlugin(),
15
+ };
16
+
17
+ exports.durableExecutionPluginProvider = durableExecutionPluginProvider;
18
+ //# sourceMappingURL=otel-invocation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"otel-invocation.js","sources":["../src/invocation-plugin-provider.ts"],"names":["InvocationOtelPlugin"],"mappings":";;;;;;;;;;AAGO,MAAM,8BAA8B,GAAG;AAC5C,IAAA,gBAAgB,EAAE,CAAC;AACnB,IAAA,UAAU,EAAEA,qCAAoB;AAChC,IAAA,YAAY,EAAE,MAAM,IAAIA,qCAAoB,EAAE;;;;;"}
@@ -1,18 +1,76 @@
1
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";
2
12
  /**
3
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.
4
24
  */
5
25
  export type ContextExtractorResult = {
6
26
  traceId: string;
7
27
  parentSpanId?: string;
8
28
  traceFlags?: number;
29
+ sampling?: Sampling;
9
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>;
10
67
  /**
11
68
  * A function that extracts upstream trace context from the invocation environment.
12
69
  */
13
70
  export type ContextExtractor = (info: InvocationInfo) => ContextExtractorResult;
14
71
  /**
15
- * Reads the X-Ray trace header from the `_X_AMZN_TRACE_ID` environment variable.
72
+ * Parses an X-Ray trace header into the context used by the execution trace
73
+ * resolver.
16
74
  *
17
75
  * The durable execution backend propagates the same Root trace ID to every
18
76
  * invocation, so all invocations of the same execution share one traceId.
@@ -22,8 +80,18 @@ export type ContextExtractor = (info: InvocationInfo) => ContextExtractorResult;
22
80
  *
23
81
  * - Extract Root value, strip "1-" prefix and all "-" to get 32-char hex traceId
24
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).
25
89
  *
26
- * Returns undefined when _X_AMZN_TRACE_ID is missing or malformed.
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.
27
95
  */
28
96
  export declare function xRayContextExtractor(_info: InvocationInfo): ContextExtractorResult;
29
97
  /**
@@ -1 +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"}
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"}
@@ -1,39 +1,30 @@
1
- import type { IdGenerator } from "@opentelemetry/sdk-trace-node";
1
+ import { type IdGenerator } from "@opentelemetry/sdk-trace-node";
2
+ export interface IdOverride {
3
+ traceId?: string;
4
+ spanId?: string;
5
+ }
2
6
  /**
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.
7
+ * An OpenTelemetry IdGenerator with execution-scoped deterministic overrides.
6
8
  *
7
- * This ensures that spans from different Lambda invocations of the same durable
8
- * execution are stitched into a single coherent trace.
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.
9
13
  */
10
14
  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;
15
+ private readonly fallbackIdGenerator;
16
+ private static readonly idOverrides;
17
+ constructor(fallbackIdGenerator?: IdGenerator);
24
18
  /**
25
- * Generate a 32-char lowercase hex trace ID.
19
+ * Runs a synchronous span-creation callback with deterministic IDs.
26
20
  *
27
- * If setTraceId has been called, returns that value persistently.
28
- * Otherwise returns a random 32-char hex string as fallback.
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.
29
23
  */
24
+ withIds<T>(ids: IdOverride, fn: () => T): T;
25
+ /** Generate a 32-char lowercase hex trace ID. */
30
26
  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
- */
27
+ /** Generate a 16-char lowercase hex span ID. */
37
28
  generateSpanId(): string;
38
29
  }
39
30
  /**
@@ -46,13 +37,18 @@ export declare class DeterministicIdGenerator implements IdGenerator {
46
37
  */
47
38
  export declare function deriveTraceIdFromXRayRoot(xRayRoot: string): string | undefined;
48
39
  /**
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.
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.
51
46
  *
52
47
  * @param executionArn - The execution ARN string
48
+ * @param executionStartTimestamp - Stable start time of the durable execution
53
49
  * @returns A 32-char lowercase hex string
54
50
  */
55
- export declare function deriveTraceIdFromArn(executionArn: string): string;
51
+ export declare function deriveTraceIdFromArn(executionArn: string, executionStartTimestamp?: Date): string;
56
52
  /**
57
53
  * Derive a deterministic span ID from an operation ID scoped to a specific execution.
58
54
  * Hashes `executionArn + ":" + operationId` with SHA-256 and truncates to the first
@@ -67,4 +63,33 @@ export declare function deriveTraceIdFromArn(executionArn: string): string;
67
63
  * @returns A 16-char lowercase hex string
68
64
  */
69
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;
70
95
  //# sourceMappingURL=deterministic-id-generator.d.ts.map
@@ -1 +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;;;;;;;;;;;;GAYG;AACH,wBAAgB,2BAA2B,CACzC,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,GACnB,MAAM,CAKR"}
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,78 @@
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
+ /**
5
+ * OpenTelemetry instrumentation plugin for durable executions.
6
+ *
7
+ * Implements the DurableInstrumentationPlugin interface. The Workflow span joins
8
+ * the execution trace by parenting onto the resolved execution ancestor (a
9
+ * propagated remote parent or a synthetic execution root), so the whole
10
+ * execution shares one trace. Operation spans parent onto the Workflow span and
11
+ * the per-invocation Invocation span is a correlation sibling (linked from, not
12
+ * a parent of, the operation spans). Both the Workflow span and each operation
13
+ * span are deferred: their identity is carried as a non-recording context and
14
+ * the single recording span is created and ended together at terminal /
15
+ * onOperationEnd, so nothing is left un-ended across invocations (issue #831).
16
+ */
17
+ export declare class ExecutionOtelPlugin implements DurableInstrumentationPlugin {
18
+ private idGenerator;
19
+ private readonly contextExtractor;
20
+ private tracerProvider;
21
+ private tracer;
22
+ private readonly instrumentationName;
23
+ private workflowSpan;
24
+ private invocationSpan;
25
+ private spanMap;
26
+ private operationContexts;
27
+ private operationStarts;
28
+ private executionArn;
29
+ private executionTraceId;
30
+ private executionTraceFlags;
31
+ private executionSamplingDecision;
32
+ private executionAncestor;
33
+ private executionStartTimestamp;
34
+ private readonly usesGlobalProvider;
35
+ private globalIdGeneratorInstalled;
36
+ private durableSampler;
37
+ private tracingEnabled;
38
+ private readonly workflowSpanName;
39
+ private readonly enrichLogger;
40
+ constructor(config?: OtelPluginConfig);
41
+ onInvocationStart(info: InvocationInfo): Promise<void>;
42
+ wrapInvocation(_info: InvocationInfo, fn: () => Promise<DurableExecutionInvocationOutput>): Promise<DurableExecutionInvocationOutput>;
43
+ onInvocationEnd(info: InvocationEndInfo): Promise<void>;
44
+ private ensureGlobalIdGeneratorInstalled;
45
+ private resetInvocationState;
46
+ private startSpan;
47
+ /**
48
+ * The parent context for the Invocation span: the active ambient span when it
49
+ * is already on the execution trace, otherwise the execution ancestor so the
50
+ * Invocation span stays within the same trace.
51
+ */
52
+ private invocationParentContext;
53
+ /**
54
+ * Builds span links to the invocation span for child spans.
55
+ *
56
+ * Always links to the plugin-created Invocation_Span (this.invocationSpan),
57
+ * which is created in both default-provider and non-default modes.
58
+ */
59
+ private buildInvocationLinks;
60
+ onOperationStart(info: OperationInfo): Promise<void>;
61
+ wrapChildContextFn(info: OperationInfo, fn: () => unknown): unknown;
62
+ onOperationEnd(info: OperationEndInfo): Promise<void>;
63
+ /**
64
+ * The parent context for an operation or attempt span: the parent operation's
65
+ * deterministic placeholder context when known, otherwise the deferred
66
+ * Workflow span's context so the span still hangs off the execution trace.
67
+ */
68
+ private resolveOperationParentContext;
69
+ /** The earlier of two timestamps, ignoring undefined; undefined only when both are. */
70
+ private earliestStart;
71
+ private getAttemptKey;
72
+ onOperationAttemptStart(info: AttemptInfo): Promise<void>;
73
+ wrapOperationAttemptFn(info: AttemptInfo, fn: () => unknown): unknown;
74
+ onOperationAttemptEnd(info: AttemptEndInfo): Promise<void>;
75
+ onOperationChange(_info: OperationChangeInfo): Promise<void>;
76
+ enrichLogContext(): Record<string, string | number | boolean> | undefined;
77
+ }
78
+ //# 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,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IAOtC,eAAe,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IA0G7D,OAAO,CAAC,gCAAgC;IAyBxC,OAAO,CAAC,oBAAoB;IAe5B,OAAO,CAAC,SAAS;IAWjB;;;;OAIG;IACH,OAAO,CAAC,uBAAuB;IAyB/B;;;;;OAKG;IACH,OAAO,CAAC,oBAAoB;IAOtB,gBAAgB,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAkC1D,kBAAkB,CAAC,IAAI,EAAE,aAAa,EAAE,EAAE,EAAE,MAAM,OAAO,GAAG,OAAO;IAgB7D,cAAc,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAmF3D;;;;OAIG;IACH,OAAO,CAAC,6BAA6B;IAcrC,uFAAuF;IACvF,OAAO,CAAC,aAAa;IAarB,OAAO,CAAC,aAAa;IAIf,uBAAuB,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAuC/D,sBAAsB,CAAC,IAAI,EAAE,WAAW,EAAE,EAAE,EAAE,MAAM,OAAO,GAAG,OAAO;IAc/D,qBAAqB,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IA0B1D,iBAAiB,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlE,gBAAgB,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,GAAG,SAAS;CAe1E"}
@@ -0,0 +1,131 @@
1
+ import type { SpanContext, Tracer } from "@opentelemetry/api";
2
+ import { SamplingDecision } from "@opentelemetry/sdk-trace-node";
3
+ import type { ContextExtractorResult } from "./context-extractors";
4
+ /**
5
+ * Environment values used to resolve the default X-Ray execution trace ID.
6
+ *
7
+ * `process.env` and plain objects containing `_X_AMZN_TRACE_ID` both satisfy
8
+ * this interface, which keeps {@link deriveExecutionTraceId} pure and easy to
9
+ * test.
10
+ */
11
+ export interface ExecutionTraceEnvironment {
12
+ readonly _X_AMZN_TRACE_ID?: string;
13
+ }
14
+ /**
15
+ * The per-execution trace context resolved once at invocation start, shared by
16
+ * both plugins.
17
+ *
18
+ * It selects the common execution ancestor that the Workflow and Invocation
19
+ * spans parent onto, so they share one trace. The ancestor is chosen by
20
+ * precedence:
21
+ *
22
+ * 1. a complete remote backend context (valid trace ID + valid parent span ID)
23
+ * is the authoritative ancestor, used directly whether or not the upstream
24
+ * carries an explicit sampling decision;
25
+ * 2. otherwise a synthetic execution root anchors the execution, with a
26
+ * deterministic span ID in its own namespace, on the canonical trace.
27
+ *
28
+ * A live ambient span is deliberately never used as the ancestor: its trace ID
29
+ * is not guaranteed stable across Lambda reinvocations, so anchoring the
30
+ * multi-invocation execution on it could change the execution trace on replay
31
+ * and break the cross-invocation continuation/replay links.
32
+ *
33
+ * The canonical trace ID follows the same precedence: the remote trace ID when
34
+ * valid, else one derived from the ARN and start time.
35
+ *
36
+ * Sampling: an explicit upstream decision is preserved only when it belongs to
37
+ * a valid extracted trace; when it is absent, the configured root decision
38
+ * (`whenUndecided`) is applied to both a remote parent and a synthetic root.
39
+ * Trace flags carry a single sampled bit with no "unset" state, so a
40
+ * remote parent left unsampled would make a parent-based sampler drop every
41
+ * child span.
42
+ *
43
+ * The ancestor is a non-recording context: it is either the external backend
44
+ * server span or a synthetic root the SDK does not export.
45
+ */
46
+ export interface ExecutionTraceContext {
47
+ /** The common parent context for the Workflow and Invocation spans. */
48
+ executionAncestor: SpanContext;
49
+ /** The trace ID of the execution trace (equals `executionAncestor.traceId`). */
50
+ traceId: string;
51
+ /** The trace flags of the execution trace. */
52
+ traceFlags: number;
53
+ /** The sampling decision enforced for SDK-created spans in this execution. */
54
+ samplingDecision: SamplingDecision;
55
+ }
56
+ /**
57
+ * The canonical trace ID: the propagated remote trace ID when valid, else one
58
+ * derived from the ARN and start time.
59
+ *
60
+ * Only these two anchors are used, and both are stable across Lambda
61
+ * reinvocations: the propagated `Root` is kept identical for every invocation by
62
+ * the durable backend, and the ARN-derived ID is a pure hash of the ARN. A live
63
+ * ambient span's trace ID is deliberately NOT used — it is not guaranteed stable
64
+ * across invocations, so anchoring on one could change the execution trace on
65
+ * replay and break the continuation/replay links (which target
66
+ * `deriveSpanIdFromOperationId` on the canonical trace).
67
+ *
68
+ * An all-zero or malformed remote trace ID is not usable, so it falls through to
69
+ * the ARN-derived ID rather than anchoring the execution on an unstable trace.
70
+ */
71
+ export declare function canonicalTraceId(extracted: ContextExtractorResult, executionArn: string, executionStartTimestamp: Date | undefined): string;
72
+ /**
73
+ * Derives the trace ID used by the OpenTelemetry plugins for a durable
74
+ * execution with the default X-Ray context extractor.
75
+ *
76
+ * A valid `Root` from `_X_AMZN_TRACE_ID` takes precedence. When the header is
77
+ * missing or malformed, the trace ID is derived from the execution ARN and
78
+ * stable execution start timestamp using the same resolver as the plugins.
79
+ *
80
+ * Pass the same execution start timestamp supplied to the plugin when no valid
81
+ * X-Ray Root is available. If the timestamp is unavailable to both callers,
82
+ * omit it to use the deterministic ARN-only fallback.
83
+ *
84
+ * @param environment - Environment containing the optional X-Ray trace header
85
+ * @param executionArn - The durable execution ARN
86
+ * @param executionStartTimestamp - Stable start time of the durable execution
87
+ * @returns The 32-character lowercase hexadecimal execution trace ID
88
+ */
89
+ export declare function deriveExecutionTraceId(environment: ExecutionTraceEnvironment, executionArn: string, executionStartTimestamp?: Date): string;
90
+ /**
91
+ * Resolves the execution ancestor: a complete propagated remote parent when
92
+ * present, otherwise a synthetic execution root on the canonical trace.
93
+ *
94
+ * A live ambient span is never used as the ancestor. Its trace ID is not
95
+ * guaranteed stable across Lambda reinvocations, so anchoring the multi-
96
+ * invocation execution on it could change the execution trace on replay and
97
+ * break cross-invocation links. The two anchors used here are both stable: a
98
+ * propagated remote parent (the backend keeps `Root` identical every invocation)
99
+ * and the ARN-derived synthetic root (a pure hash of the ARN).
100
+ *
101
+ * @param extracted the context parsed from the backend header, or undefined
102
+ * @param canonical the trace ID the ancestor is anchored on
103
+ * @param executionArn the durable execution ARN
104
+ * @param rootSamplingDecision the configured root decision for this trace, applied
105
+ * to a remote parent or synthetic root when the header carries no explicit
106
+ * Sampled value
107
+ */
108
+ export declare function resolveExecutionTraceContext(extracted: ContextExtractorResult, canonical: string, executionArn: string, rootSamplingDecision: () => SamplingDecision): ExecutionTraceContext;
109
+ /**
110
+ * Decides how a root span on the given trace should be sampled, used only
111
+ * when the propagated context carries no explicit decision.
112
+ *
113
+ * Sampling precedence, highest first:
114
+ *
115
+ * 1. the backend's explicit `Sampled` on the propagated header — handled by the
116
+ * caller before reaching here;
117
+ * 2. the configured sampler is evaluated at its root policy (`ROOT_CONTEXT`, no
118
+ * parent) with the real trace ID. This honors custom samplers and avoids
119
+ * inheriting an unrelated ambient span's decision.
120
+ *
121
+ * The resolved decision is then enforced through DurableSampler for every
122
+ * SDK-created span, so direct samplers that ignore parent flags cannot override
123
+ * an explicit backend decision or the configured root decision.
124
+ *
125
+ * @param tracer the resolved SDK tracer
126
+ * @param traceId the canonical trace ID to evaluate
127
+ * @param spanName the span name passed to the sampler
128
+ * @param attributes the attributes the span is started with
129
+ */
130
+ export declare function rootSamplingDecision(tracer: Tracer, traceId: string, spanName: string, attributes: Record<string, string | number | boolean>): SamplingDecision;
131
+ //# sourceMappingURL=execution-trace-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execution-trace-context.d.ts","sourceRoot":"","sources":["../src/execution-trace-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAWjE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAGnE;;;;;;GAMG;AACH,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;CACpC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,WAAW,qBAAqB;IACpC,uEAAuE;IACvE,iBAAiB,EAAE,WAAW,CAAC;IAC/B,gFAAgF;IAChF,OAAO,EAAE,MAAM,CAAC;IAChB,8CAA8C;IAC9C,UAAU,EAAE,MAAM,CAAC;IACnB,8EAA8E;IAC9E,gBAAgB,EAAE,gBAAgB,CAAC;CACpC;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,sBAAsB,EACjC,YAAY,EAAE,MAAM,EACpB,uBAAuB,EAAE,IAAI,GAAG,SAAS,GACxC,MAAM,CAKR;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,sBAAsB,CACpC,WAAW,EAAE,yBAAyB,EACtC,YAAY,EAAE,MAAM,EACpB,uBAAuB,CAAC,EAAE,IAAI,GAC7B,MAAM,CAMR;AA8BD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,4BAA4B,CAC1C,SAAS,EAAE,sBAAsB,EACjC,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,EACpB,oBAAoB,EAAE,MAAM,gBAAgB,GAC3C,qBAAqB,CAqCvB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,GACpD,gBAAgB,CAuBlB"}
@@ -0,0 +1,12 @@
1
+ import type { Tracer } from "@opentelemetry/api";
2
+ import { DeterministicIdGenerator } from "./deterministic-id-generator";
3
+ /**
4
+ * Installs deterministic durable IDs on an OpenTelemetry SDK tracer while
5
+ * preserving its configured generator for all unscoped ID generation.
6
+ *
7
+ * OpenTelemetry JavaScript does not expose this generator through its public
8
+ * API. SDK tracers have historically stored it in the TypeScript-private
9
+ * `_idGenerator` field, which remains writable at runtime.
10
+ */
11
+ export declare function tryInstallGlobalIdGenerator(tracer: Tracer): DeterministicIdGenerator | undefined;
12
+ //# sourceMappingURL=global-id-generator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"global-id-generator.d.ts","sourceRoot":"","sources":["../src/global-id-generator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAEjD,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAexE;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,MAAM,GACb,wBAAwB,GAAG,SAAS,CAuBtC"}
@@ -0,0 +1,25 @@
1
+ import type { Context, Attributes, Link, SpanKind, Tracer } from "@opentelemetry/api";
2
+ import { SamplingDecision } from "@opentelemetry/sdk-trace-node";
3
+ import type { Sampler, SamplingResult } from "@opentelemetry/sdk-trace-node";
4
+ /**
5
+ * Sampler wrapper that preserves the application's sampler except while the
6
+ * durable plugin is creating its own spans with a resolved execution decision.
7
+ */
8
+ export declare class DurableSampler implements Sampler {
9
+ private readonly delegate;
10
+ private static readonly decisions;
11
+ constructor(delegate: Sampler);
12
+ withDecision<T>(decision: SamplingDecision, fn: () => T): T;
13
+ shouldSample(context: Context, traceId: string, spanName: string, spanKind: SpanKind, attributes: Attributes, links: Link[]): SamplingResult;
14
+ toString(): string;
15
+ }
16
+ /**
17
+ * Installs a durable-aware sampler on an OpenTelemetry SDK tracer.
18
+ *
19
+ * OpenTelemetry JavaScript does not expose the sampler through its public API.
20
+ * SDK tracers have historically stored it in the TypeScript-private `_sampler`
21
+ * field, which remains writable at runtime.
22
+ */
23
+ export declare function tryInstallDurableSampler(tracer: Tracer): DurableSampler | undefined;
24
+ export declare function getConfiguredSampler(tracer: Tracer): Sampler | undefined;
25
+ //# sourceMappingURL=global-sampler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"global-sampler.d.ts","sourceRoot":"","sources":["../src/global-sampler.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,OAAO,EACP,UAAU,EACV,IAAI,EACJ,QAAQ,EACR,MAAM,EACP,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAa7E;;;GAGG;AACH,qBAAa,cAAe,YAAW,OAAO;IAGhC,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAFrC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAA6C;gBAEjD,QAAQ,EAAE,OAAO;IAE9C,YAAY,CAAC,CAAC,EAAE,QAAQ,EAAE,gBAAgB,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC;IAI3D,YAAY,CACV,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,QAAQ,EAClB,UAAU,EAAE,UAAU,EACtB,KAAK,EAAE,IAAI,EAAE,GACZ,cAAc;IAejB,QAAQ,IAAI,MAAM;CAGnB;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,MAAM,GACb,cAAc,GAAG,SAAS,CAqB5B;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAUxE"}
@@ -1,6 +1,9 @@
1
- export { OtelPlugin } from "./plugin";
2
- export type { OtelPluginConfig } from "./plugin";
3
- export { DeterministicIdGenerator, deriveTraceIdFromXRayRoot, deriveTraceIdFromArn, deriveSpanIdFromOperationId, } from "./deterministic-id-generator";
1
+ export { ExecutionOtelPlugin } from "./execution-plugin";
2
+ export type { IdGeneratorFactory, OtelPluginConfig, TracerProviderFactory, } from "./otel-plugin-config";
3
+ export { InvocationOtelPlugin } from "./invocation-plugin";
4
+ export { DeterministicIdGenerator, deriveTraceIdFromXRayRoot, deriveTraceIdFromArn, deriveSpanIdFromOperationId, deriveWorkflowSpanId, deriveExecutionRootSpanId, } from "./deterministic-id-generator";
4
5
  export { xRayContextExtractor, w3cClientContextExtractor, } from "./context-extractors";
5
6
  export type { ContextExtractor, ContextExtractorResult, } from "./context-extractors";
7
+ export { deriveExecutionTraceId } from "./execution-trace-context";
8
+ export type { ExecutionTraceEnvironment } from "./execution-trace-context";
6
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,YAAY,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAGjD,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"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAGzD,YAAY,EACV,kBAAkB,EAClB,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAG3D,OAAO,EACL,wBAAwB,EACxB,yBAAyB,EACzB,oBAAoB,EACpB,2BAA2B,EAC3B,oBAAoB,EACpB,yBAAyB,GAC1B,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EACL,oBAAoB,EACpB,yBAAyB,GAC1B,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EACV,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACnE,YAAY,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { InvocationOtelPlugin } from "./invocation-plugin";
2
+ export declare const durableExecutionPluginProvider: {
3
+ pluginApiVersion: 1;
4
+ pluginType: typeof InvocationOtelPlugin;
5
+ createPlugin: () => InvocationOtelPlugin;
6
+ };
7
+ //# sourceMappingURL=invocation-plugin-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invocation-plugin-provider.d.ts","sourceRoot":"","sources":["../src/invocation-plugin-provider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAE3D,eAAO,MAAM,8BAA8B;;;;CAI2B,CAAC"}