@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,664 @@
1
+ 'use strict';
2
+
3
+ var api = require('@opentelemetry/api');
4
+ var sdkTraceNode = require('@opentelemetry/sdk-trace-node');
5
+ var node_async_hooks = require('node:async_hooks');
6
+ var node_crypto = require('node:crypto');
7
+
8
+ /**
9
+ * An OpenTelemetry IdGenerator with execution-scoped deterministic overrides.
10
+ *
11
+ * Overrides are active only while {@link withIds} runs. All other ID generation
12
+ * is delegated to the fallback generator. AsyncLocalStorage makes the override
13
+ * visible to the provider-owned generator without leaking it to unrelated spans
14
+ * or concurrent durable executions.
15
+ */
16
+ class DeterministicIdGenerator {
17
+ fallbackIdGenerator;
18
+ static idOverrides = new node_async_hooks.AsyncLocalStorage();
19
+ constructor(fallbackIdGenerator = new sdkTraceNode.RandomIdGenerator()) {
20
+ this.fallbackIdGenerator = fallbackIdGenerator;
21
+ }
22
+ /**
23
+ * Runs a synchronous span-creation callback with deterministic IDs.
24
+ *
25
+ * The span ID is consumed on its first use so re-entrant ID generation cannot
26
+ * accidentally assign the same ID to more than one span.
27
+ */
28
+ withIds(ids, fn) {
29
+ return DeterministicIdGenerator.idOverrides.run({ ...ids }, fn);
30
+ }
31
+ /** Generate a 32-char lowercase hex trace ID. */
32
+ generateTraceId() {
33
+ const traceId = DeterministicIdGenerator.idOverrides.getStore()?.traceId;
34
+ if (traceId) {
35
+ return traceId;
36
+ }
37
+ return this.fallbackIdGenerator.generateTraceId();
38
+ }
39
+ /** Generate a 16-char lowercase hex span ID. */
40
+ generateSpanId() {
41
+ const override = DeterministicIdGenerator.idOverrides.getStore();
42
+ if (override?.spanId) {
43
+ const spanId = override.spanId;
44
+ override.spanId = undefined;
45
+ return spanId;
46
+ }
47
+ return this.fallbackIdGenerator.generateSpanId();
48
+ }
49
+ }
50
+ /**
51
+ * Derive a deterministic trace ID from an X-Ray Root field.
52
+ * Strips the `Root=1-` prefix and all `-` separators to produce
53
+ * a valid 32-character lowercase hex OpenTelemetry trace ID.
54
+ *
55
+ * @param xRayRoot - The Root field value, e.g. "1-5759e988-bd862e3fe1be46a994272793"
56
+ * @returns A 32-char lowercase hex string, or undefined if the input is invalid
57
+ */
58
+ function deriveTraceIdFromXRayRoot(xRayRoot) {
59
+ // Strip "Root=" prefix if present
60
+ let root = xRayRoot;
61
+ if (root.startsWith("Root=")) {
62
+ root = root.slice(5);
63
+ }
64
+ // Strip the version prefix "1-"
65
+ if (root.startsWith("1-")) {
66
+ root = root.slice(2);
67
+ }
68
+ else {
69
+ return undefined;
70
+ }
71
+ // Remove all dashes
72
+ const hex = root.replace(/-/g, "");
73
+ // Validate: must be exactly 32 lowercase hex characters
74
+ if (hex.length !== 32 || !/^[0-9a-f]{32}$/.test(hex)) {
75
+ return undefined;
76
+ }
77
+ return hex;
78
+ }
79
+ /**
80
+ * Derive a deterministic trace ID from an execution ARN and its durable start
81
+ * timestamp by hashing them with SHA-256 and truncating to the first 32
82
+ * lowercase hex characters.
83
+ *
84
+ * The timestamp is optional for callers that do not have it. When omitted, the
85
+ * ARN-only derivation is retained as a deterministic fallback.
86
+ *
87
+ * @param executionArn - The execution ARN string
88
+ * @param executionStartTimestamp - Stable start time of the durable execution
89
+ * @returns A 32-char lowercase hex string
90
+ */
91
+ function deriveTraceIdFromArn(executionArn, executionStartTimestamp) {
92
+ const executionIdentity = executionStartTimestamp
93
+ ? `${executionArn}:${executionStartTimestamp.toISOString()}`
94
+ : executionArn;
95
+ return node_crypto.createHash("sha256")
96
+ .update(executionIdentity)
97
+ .digest("hex")
98
+ .slice(0, 32);
99
+ }
100
+ /**
101
+ * Derive a deterministic span ID from an operation ID scoped to a specific execution.
102
+ * Hashes `executionArn + ":" + operationId` with SHA-256 and truncates to the first
103
+ * 16 lowercase hex characters.
104
+ *
105
+ * The executionArn is included in the hash input to avoid span ID collisions when
106
+ * different executions (e.g., a parent and child workflow) share the same trace and
107
+ * have operations at the same positional ID.
108
+ *
109
+ * @param operationId - The operation ID string (positional identifier within an execution)
110
+ * @param executionArn - The execution ARN, used to scope span IDs per execution
111
+ * @returns A 16-char lowercase hex string
112
+ */
113
+ function deriveSpanIdFromOperationId(operationId, executionArn) {
114
+ return node_crypto.createHash("sha256")
115
+ .update(executionArn + ":" + operationId)
116
+ .digest("hex")
117
+ .slice(0, 16);
118
+ }
119
+ /**
120
+ * Derive a deterministic span ID for a Workflow_Span from an execution ARN.
121
+ * Hashes `"workflow:" + executionArn` with SHA-256 and truncates to the first
122
+ * 16 lowercase hex characters.
123
+ *
124
+ * The "workflow:" prefix acts as a salt to ensure the resulting span ID is
125
+ * distinct from IDs produced by `deriveSpanIdFromOperationId` for the same ARN.
126
+ *
127
+ * @param executionArn - The execution ARN string (must be non-empty)
128
+ * @returns A 16-char lowercase hex string, never equal to "0000000000000000"
129
+ * @throws Error if the execution ARN is an empty string
130
+ */
131
+ function deriveWorkflowSpanId(executionArn) {
132
+ if (executionArn === "") {
133
+ throw new Error("Execution ARN must be non-empty");
134
+ }
135
+ const spanId = node_crypto.createHash("sha256")
136
+ .update("workflow:" + executionArn)
137
+ .digest("hex")
138
+ .slice(0, 16);
139
+ // Ensure the result is never all-zeros (astronomically unlikely with SHA-256,
140
+ // but guaranteed by contract)
141
+ if (spanId === "0000000000000000") {
142
+ return "0000000000000001";
143
+ }
144
+ return spanId;
145
+ }
146
+ /**
147
+ * Derive a deterministic span ID for the synthetic execution root from an
148
+ * execution ARN. Hashes `"execution-root:" + executionArn` with SHA-256 and
149
+ * truncates to the first 16 lowercase hex characters.
150
+ *
151
+ * The `"execution-root:"` prefix is a distinct namespace from
152
+ * `deriveWorkflowSpanId` (`"workflow:"`) and `deriveSpanIdFromOperationId`
153
+ * (`"<arn>:<opId>"`), so the synthetic root never collides with the Workflow or
154
+ * operation spans that share the execution trace. Stable across reinvocations
155
+ * so the same synthetic root is the common ancestor every invocation.
156
+ *
157
+ * @param executionArn - The execution ARN string (must be non-empty)
158
+ * @returns A 16-char lowercase hex string, never equal to "0000000000000000"
159
+ * @throws Error if the execution ARN is an empty string
160
+ */
161
+ function deriveExecutionRootSpanId(executionArn) {
162
+ if (executionArn === "") {
163
+ throw new Error("Execution ARN must be non-empty");
164
+ }
165
+ const spanId = node_crypto.createHash("sha256")
166
+ .update("execution-root:" + executionArn)
167
+ .digest("hex")
168
+ .slice(0, 16);
169
+ if (spanId === "0000000000000000") {
170
+ return "0000000000000001";
171
+ }
172
+ return spanId;
173
+ }
174
+
175
+ const OTEL_TRACE_ID_PATTERN = /^[0-9a-f]{32}$/;
176
+ const OTEL_SPAN_ID_PATTERN = /^[0-9a-f]{16}$/;
177
+ const ALL_ZERO_TRACE_ID = "0".repeat(32);
178
+ const ALL_ZERO_SPAN_ID = "0".repeat(16);
179
+ /**
180
+ * True when `traceId` is a well-formed, non-zero 32-char hex OTel trace ID.
181
+ *
182
+ * Validity is stricter than a format match: an all-zero ID is well-formed hex
183
+ * but invalid, and anchoring an execution on it would split the trace.
184
+ */
185
+ function isValidTraceId(traceId) {
186
+ return (traceId != null &&
187
+ OTEL_TRACE_ID_PATTERN.test(traceId) &&
188
+ traceId !== ALL_ZERO_TRACE_ID);
189
+ }
190
+ /**
191
+ * True when `spanId` is a well-formed, non-zero 16-char hex OTel span ID.
192
+ */
193
+ function isValidSpanId(spanId) {
194
+ return (spanId != null &&
195
+ OTEL_SPAN_ID_PATTERN.test(spanId) &&
196
+ spanId !== ALL_ZERO_SPAN_ID);
197
+ }
198
+ /**
199
+ * Resolves the tri-state sampling decision for an extracted context.
200
+ *
201
+ * Prefers an explicit `sampling` value; otherwise derives from `traceFlags`
202
+ * when present; otherwise `UNDECIDED`.
203
+ */
204
+ function resolveSampling(extracted) {
205
+ if (extracted.sampling) {
206
+ return extracted.sampling;
207
+ }
208
+ if (extracted.traceFlags != null) {
209
+ return (extracted.traceFlags & 1) !== 0 ? "SAMPLED" : "NOT_SAMPLED";
210
+ }
211
+ return "UNDECIDED";
212
+ }
213
+ /**
214
+ * True when the extracted context carries a complete remote parent: a valid
215
+ * trace ID and a valid parent span ID, so it can serve as a remote parent.
216
+ */
217
+ function hasCompleteRemoteParent(extracted) {
218
+ return (extracted != null &&
219
+ isValidTraceId(extracted.traceId) &&
220
+ isValidSpanId(extracted.parentSpanId));
221
+ }
222
+ /**
223
+ * True when the extracted context carries a valid (well-formed, non-zero) trace
224
+ * ID that the resolver can anchor the durable execution trace on.
225
+ */
226
+ function hasValidTraceId(extracted) {
227
+ return extracted != null && isValidTraceId(extracted.traceId);
228
+ }
229
+ /**
230
+ * Parses an X-Ray trace header into the context used by the execution trace
231
+ * resolver.
232
+ *
233
+ * The durable execution backend propagates the same Root trace ID to every
234
+ * invocation, so all invocations of the same execution share one traceId.
235
+ *
236
+ * X-Ray Header format:
237
+ * Root=1-5759e988-bd862e3fe1be46a994272793;Parent=53995c3f42cd8ad8;Sampled=1
238
+ *
239
+ * - Extract Root value, strip "1-" prefix and all "-" to get 32-char hex traceId
240
+ * - Extract Parent value for parentSpanId (16-char hex)
241
+ * - Extract Sampled: `1` -> SAMPLED, `0` -> NOT_SAMPLED, anything else undecided
242
+ *
243
+ * `Root`, `Parent`, and `Sampled` are parsed independently: only `Sampled=1`
244
+ * and `Sampled=0` are authoritative, and an all-zero Root or Parent is rejected
245
+ * as invalid (it is well-formed hex but not a usable ID). A valid Root with no
246
+ * usable Parent is still returned (the trace ID is usable on its own).
247
+ *
248
+ * Returns undefined when the header is missing or has no valid Root.
249
+ */
250
+ function parseXRayTraceHeader(header) {
251
+ if (!header) {
252
+ return undefined;
253
+ }
254
+ // Parse the header into key-value pairs separated by semicolons
255
+ const fields = new Map();
256
+ for (const part of header.split(";")) {
257
+ const eqIdx = part.indexOf("=");
258
+ if (eqIdx > 0) {
259
+ const key = part.slice(0, eqIdx).trim();
260
+ const value = part.slice(eqIdx + 1).trim();
261
+ fields.set(key, value);
262
+ }
263
+ }
264
+ const root = fields.get("Root");
265
+ if (!root) {
266
+ return undefined;
267
+ }
268
+ // Root format: 1-5759e988-bd862e3fe1be46a994272793
269
+ // Strip the "1-" prefix and remove all dashes to get 32-char hex
270
+ const rootValue = root.startsWith("1-") ? root.slice(2) : root;
271
+ const traceId = rootValue.replace(/-/g, "").toLowerCase();
272
+ // Reject a missing, malformed, or all-zero Root: it is not a usable trace ID.
273
+ if (!isValidTraceId(traceId)) {
274
+ return undefined;
275
+ }
276
+ // Parent is a 16-char hex span ID; reject an all-zero Parent the same way,
277
+ // and treat an unusable Parent as absent while keeping the valid Root.
278
+ const parent = fields.get("Parent");
279
+ let parentSpanId;
280
+ if (parent && isValidSpanId(parent.toLowerCase())) {
281
+ parentSpanId = parent.toLowerCase();
282
+ }
283
+ // Only Sampled=1 and Sampled=0 are authoritative; anything else is undecided.
284
+ const sampledField = fields.get("Sampled");
285
+ const sampling = sampledField === "1"
286
+ ? "SAMPLED"
287
+ : sampledField === "0"
288
+ ? "NOT_SAMPLED"
289
+ : "UNDECIDED";
290
+ return { traceId, parentSpanId, sampling };
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
+ }
298
+ /**
299
+ * Reads W3C traceparent from `context.clientContext.custom.traceparent`.
300
+ *
301
+ * W3C traceparent format:
302
+ * 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01
303
+ * Format: version-traceId-parentId-traceFlags
304
+ *
305
+ * - traceId is 32 hex chars
306
+ * - parentId is 16 hex chars
307
+ * - flags is 2 hex chars (parsed to number)
308
+ *
309
+ * Returns undefined when clientContext or traceparent is missing or malformed.
310
+ */
311
+ function w3cClientContextExtractor(info) {
312
+ const extendedInfo = info;
313
+ const traceparent = extendedInfo.context?.clientContext?.custom?.traceparent;
314
+ if (!traceparent) {
315
+ return undefined;
316
+ }
317
+ return parseW3CTraceparent(traceparent);
318
+ }
319
+ /**
320
+ * Parses a W3C traceparent header value.
321
+ *
322
+ * Format: version-traceId-parentId-flags
323
+ * Example: 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01
324
+ */
325
+ function parseW3CTraceparent(traceparent) {
326
+ const parts = traceparent.split("-");
327
+ // Must have exactly 4 parts: version, traceId, parentId, flags
328
+ if (parts.length !== 4) {
329
+ return undefined;
330
+ }
331
+ const [version, traceId, parentId, flags] = parts;
332
+ // Version must be 2 hex chars
333
+ if (!/^[0-9a-f]{2}$/.test(version)) {
334
+ return undefined;
335
+ }
336
+ // TraceId and ParentId must be well-formed AND non-zero. An all-zero trace or
337
+ // parent ID is syntactically 32/16 hex chars but invalid per the W3C spec;
338
+ // accepting it would let a malformed traceparent's sampled bit force or
339
+ // suppress sampling even though the resolver rejects the trace ID and falls
340
+ // back to the ARN-derived trace.
341
+ if (!isValidTraceId(traceId) || !isValidSpanId(parentId)) {
342
+ return undefined;
343
+ }
344
+ // Flags must be 2 hex chars
345
+ if (!/^[0-9a-f]{2}$/.test(flags)) {
346
+ return undefined;
347
+ }
348
+ const traceFlags = parseInt(flags, 16);
349
+ // W3C traceparent carries an explicit sampled bit, so the decision is never
350
+ // UNDECIDED.
351
+ const sampling = (traceFlags & 1) !== 0 ? "SAMPLED" : "NOT_SAMPLED";
352
+ return {
353
+ traceId,
354
+ parentSpanId: parentId,
355
+ traceFlags,
356
+ sampling,
357
+ };
358
+ }
359
+
360
+ const SAMPLER_FIELD = "_sampler";
361
+ function isSampler(value) {
362
+ return (typeof value === "object" &&
363
+ value !== null &&
364
+ "shouldSample" in value &&
365
+ typeof value.shouldSample === "function");
366
+ }
367
+ /**
368
+ * Sampler wrapper that preserves the application's sampler except while the
369
+ * durable plugin is creating its own spans with a resolved execution decision.
370
+ */
371
+ class DurableSampler {
372
+ delegate;
373
+ static decisions = new node_async_hooks.AsyncLocalStorage();
374
+ constructor(delegate) {
375
+ this.delegate = delegate;
376
+ }
377
+ withDecision(decision, fn) {
378
+ return DurableSampler.decisions.run(decision, fn);
379
+ }
380
+ shouldSample(context, traceId, spanName, spanKind, attributes, links) {
381
+ const decision = DurableSampler.decisions.getStore();
382
+ if (decision !== undefined) {
383
+ return { decision };
384
+ }
385
+ return this.delegate.shouldSample(context, traceId, spanName, spanKind, attributes, links);
386
+ }
387
+ toString() {
388
+ return `DurableSampler{${this.delegate.toString()}}`;
389
+ }
390
+ }
391
+ /**
392
+ * Installs a durable-aware sampler on an OpenTelemetry SDK tracer.
393
+ *
394
+ * OpenTelemetry JavaScript does not expose the sampler through its public API.
395
+ * SDK tracers have historically stored it in the TypeScript-private `_sampler`
396
+ * field, which remains writable at runtime.
397
+ */
398
+ function tryInstallDurableSampler(tracer) {
399
+ try {
400
+ const existingSampler = Reflect.get(tracer, SAMPLER_FIELD);
401
+ if (!isSampler(existingSampler)) {
402
+ return undefined;
403
+ }
404
+ if (existingSampler instanceof DurableSampler) {
405
+ return existingSampler;
406
+ }
407
+ const durableSampler = new DurableSampler(existingSampler);
408
+ if (!Reflect.set(tracer, SAMPLER_FIELD, durableSampler) ||
409
+ Reflect.get(tracer, SAMPLER_FIELD) !== durableSampler) {
410
+ return undefined;
411
+ }
412
+ return durableSampler;
413
+ }
414
+ catch {
415
+ return undefined;
416
+ }
417
+ }
418
+ function getConfiguredSampler(tracer) {
419
+ try {
420
+ const sampler = Reflect.get(tracer, SAMPLER_FIELD);
421
+ if (sampler instanceof DurableSampler) {
422
+ return Reflect.get(sampler, "delegate");
423
+ }
424
+ return isSampler(sampler) ? sampler : undefined;
425
+ }
426
+ catch {
427
+ return undefined;
428
+ }
429
+ }
430
+
431
+ /**
432
+ * The canonical trace ID: the propagated remote trace ID when valid, else one
433
+ * derived from the ARN and start time.
434
+ *
435
+ * Only these two anchors are used, and both are stable across Lambda
436
+ * reinvocations: the propagated `Root` is kept identical for every invocation by
437
+ * the durable backend, and the ARN-derived ID is a pure hash of the ARN. A live
438
+ * ambient span's trace ID is deliberately NOT used — it is not guaranteed stable
439
+ * across invocations, so anchoring on one could change the execution trace on
440
+ * replay and break the continuation/replay links (which target
441
+ * `deriveSpanIdFromOperationId` on the canonical trace).
442
+ *
443
+ * An all-zero or malformed remote trace ID is not usable, so it falls through to
444
+ * the ARN-derived ID rather than anchoring the execution on an unstable trace.
445
+ */
446
+ function canonicalTraceId(extracted, executionArn, executionStartTimestamp) {
447
+ if (hasValidTraceId(extracted)) {
448
+ return extracted.traceId;
449
+ }
450
+ return deriveTraceIdFromArn(executionArn, executionStartTimestamp);
451
+ }
452
+ /**
453
+ * Derives the trace ID used by the OpenTelemetry plugins for a durable
454
+ * execution with the default X-Ray context extractor.
455
+ *
456
+ * A valid `Root` from `_X_AMZN_TRACE_ID` takes precedence. When the header is
457
+ * missing or malformed, the trace ID is derived from the execution ARN and
458
+ * stable execution start timestamp using the same resolver as the plugins.
459
+ *
460
+ * Pass the same execution start timestamp supplied to the plugin when no valid
461
+ * X-Ray Root is available. If the timestamp is unavailable to both callers,
462
+ * omit it to use the deterministic ARN-only fallback.
463
+ *
464
+ * @param environment - Environment containing the optional X-Ray trace header
465
+ * @param executionArn - The durable execution ARN
466
+ * @param executionStartTimestamp - Stable start time of the durable execution
467
+ * @returns The 32-character lowercase hexadecimal execution trace ID
468
+ */
469
+ function deriveExecutionTraceId(environment, executionArn, executionStartTimestamp) {
470
+ return canonicalTraceId(parseXRayTraceHeader(environment._X_AMZN_TRACE_ID), executionArn, executionStartTimestamp);
471
+ }
472
+ /**
473
+ * Flags for an explicit upstream decision, or the sampler's decision
474
+ * (`whenUndecided`) when the upstream did not decide. The supplier is consulted
475
+ * lazily, only for the `UNDECIDED` case, so an explicit decision never triggers
476
+ * a (discarded) sampler query.
477
+ */
478
+ function explicitDecision(extracted, whenUndecided) {
479
+ const sampling = extracted ? resolveSampling(extracted) : "UNDECIDED";
480
+ switch (sampling) {
481
+ case "SAMPLED":
482
+ return sdkTraceNode.SamplingDecision.RECORD_AND_SAMPLED;
483
+ case "NOT_SAMPLED":
484
+ return sdkTraceNode.SamplingDecision.NOT_RECORD;
485
+ case "UNDECIDED":
486
+ default:
487
+ return whenUndecided();
488
+ }
489
+ }
490
+ function traceFlagsFromDecision(decision) {
491
+ return decision === sdkTraceNode.SamplingDecision.RECORD_AND_SAMPLED
492
+ ? api.TraceFlags.SAMPLED
493
+ : api.TraceFlags.NONE;
494
+ }
495
+ /**
496
+ * Resolves the execution ancestor: a complete propagated remote parent when
497
+ * present, otherwise a synthetic execution root on the canonical trace.
498
+ *
499
+ * A live ambient span is never used as the ancestor. Its trace ID is not
500
+ * guaranteed stable across Lambda reinvocations, so anchoring the multi-
501
+ * invocation execution on it could change the execution trace on replay and
502
+ * break cross-invocation links. The two anchors used here are both stable: a
503
+ * propagated remote parent (the backend keeps `Root` identical every invocation)
504
+ * and the ARN-derived synthetic root (a pure hash of the ARN).
505
+ *
506
+ * @param extracted the context parsed from the backend header, or undefined
507
+ * @param canonical the trace ID the ancestor is anchored on
508
+ * @param executionArn the durable execution ARN
509
+ * @param rootSamplingDecision the configured root decision for this trace, applied
510
+ * to a remote parent or synthetic root when the header carries no explicit
511
+ * Sampled value
512
+ */
513
+ function resolveExecutionTraceContext(extracted, canonical, executionArn, rootSamplingDecision) {
514
+ // A valid remote backend parent is the authoritative ancestor, regardless of
515
+ // whether Sampled is present.
516
+ if (hasCompleteRemoteParent(extracted)) {
517
+ const decision = explicitDecision(extracted, rootSamplingDecision);
518
+ const flags = traceFlagsFromDecision(decision);
519
+ const remoteParent = {
520
+ traceId: extracted.traceId,
521
+ spanId: extracted.parentSpanId,
522
+ traceFlags: flags,
523
+ isRemote: true,
524
+ };
525
+ return {
526
+ executionAncestor: remoteParent,
527
+ traceId: remoteParent.traceId,
528
+ traceFlags: flags,
529
+ samplingDecision: decision,
530
+ };
531
+ }
532
+ // No complete remote parent: synthesize an execution root on the canonical
533
+ // trace (the stable remote Root if one was provided, else the ARN-derived ID).
534
+ const samplingContext = hasValidTraceId(extracted) ? extracted : undefined;
535
+ const decision = explicitDecision(samplingContext, rootSamplingDecision);
536
+ const flags = traceFlagsFromDecision(decision);
537
+ const syntheticRoot = {
538
+ traceId: canonical,
539
+ spanId: deriveExecutionRootSpanId(executionArn),
540
+ traceFlags: flags,
541
+ isRemote: false,
542
+ };
543
+ return {
544
+ executionAncestor: syntheticRoot,
545
+ traceId: canonical,
546
+ traceFlags: flags,
547
+ samplingDecision: decision,
548
+ };
549
+ }
550
+ /**
551
+ * Decides how a root span on the given trace should be sampled, used only
552
+ * when the propagated context carries no explicit decision.
553
+ *
554
+ * Sampling precedence, highest first:
555
+ *
556
+ * 1. the backend's explicit `Sampled` on the propagated header — handled by the
557
+ * caller before reaching here;
558
+ * 2. the configured sampler is evaluated at its root policy (`ROOT_CONTEXT`, no
559
+ * parent) with the real trace ID. This honors custom samplers and avoids
560
+ * inheriting an unrelated ambient span's decision.
561
+ *
562
+ * The resolved decision is then enforced through DurableSampler for every
563
+ * SDK-created span, so direct samplers that ignore parent flags cannot override
564
+ * an explicit backend decision or the configured root decision.
565
+ *
566
+ * @param tracer the resolved SDK tracer
567
+ * @param traceId the canonical trace ID to evaluate
568
+ * @param spanName the span name passed to the sampler
569
+ * @param attributes the attributes the span is started with
570
+ */
571
+ function rootSamplingDecision(tracer, traceId, spanName, attributes) {
572
+ const sampler = getConfiguredSampler(tracer);
573
+ if (!sampler) {
574
+ return sdkTraceNode.SamplingDecision.RECORD_AND_SAMPLED;
575
+ }
576
+ try {
577
+ // Evaluate with ROOT_CONTEXT (no parent), not the active context: a
578
+ // ParentBasedSampler must decide the execution root on its own root policy,
579
+ // not inherit the sampled bit of an unrelated ambient span that the resolver
580
+ // already rejected. Otherwise an unrelated unsampled ambient span could drop
581
+ // an execution whose root policy would sample it.
582
+ const result = sampler.shouldSample(api.ROOT_CONTEXT, traceId, spanName, api.SpanKind.INTERNAL, attributes, []);
583
+ return result.decision;
584
+ }
585
+ catch {
586
+ return sdkTraceNode.SamplingDecision.RECORD_AND_SAMPLED;
587
+ }
588
+ }
589
+
590
+ /**
591
+ * Resolves an application-owned provider factory or the globally registered
592
+ * provider. Exporters, sampling, resources, propagators, instrumentation, and
593
+ * provider shutdown remain application or ADOT responsibilities.
594
+ */
595
+ function createTracerProvider(config, idGenerator) {
596
+ if (config?.tracerProviderFactory) {
597
+ const createIdGenerator = (fallbackIdGenerator) => fallbackIdGenerator
598
+ ? new DeterministicIdGenerator(fallbackIdGenerator)
599
+ : idGenerator;
600
+ return {
601
+ tracerProvider: config.tracerProviderFactory(createIdGenerator),
602
+ usesGlobalProvider: false,
603
+ };
604
+ }
605
+ return {
606
+ tracerProvider: api.trace.getTracerProvider(),
607
+ usesGlobalProvider: true,
608
+ };
609
+ }
610
+
611
+ const ID_GENERATOR_FIELD = "_idGenerator";
612
+ function isIdGenerator(value) {
613
+ return (typeof value === "object" &&
614
+ value !== null &&
615
+ "generateTraceId" in value &&
616
+ typeof value.generateTraceId === "function" &&
617
+ "generateSpanId" in value &&
618
+ typeof value.generateSpanId === "function");
619
+ }
620
+ /**
621
+ * Installs deterministic durable IDs on an OpenTelemetry SDK tracer while
622
+ * preserving its configured generator for all unscoped ID generation.
623
+ *
624
+ * OpenTelemetry JavaScript does not expose this generator through its public
625
+ * API. SDK tracers have historically stored it in the TypeScript-private
626
+ * `_idGenerator` field, which remains writable at runtime.
627
+ */
628
+ function tryInstallGlobalIdGenerator(tracer) {
629
+ try {
630
+ const existingIdGenerator = Reflect.get(tracer, ID_GENERATOR_FIELD);
631
+ if (!isIdGenerator(existingIdGenerator)) {
632
+ return undefined;
633
+ }
634
+ if (existingIdGenerator instanceof DeterministicIdGenerator) {
635
+ return existingIdGenerator;
636
+ }
637
+ const deterministicIdGenerator = new DeterministicIdGenerator(existingIdGenerator);
638
+ if (!Reflect.set(tracer, ID_GENERATOR_FIELD, deterministicIdGenerator) ||
639
+ Reflect.get(tracer, ID_GENERATOR_FIELD) !== deterministicIdGenerator) {
640
+ return undefined;
641
+ }
642
+ return deterministicIdGenerator;
643
+ }
644
+ catch {
645
+ return undefined;
646
+ }
647
+ }
648
+
649
+ exports.DeterministicIdGenerator = DeterministicIdGenerator;
650
+ exports.canonicalTraceId = canonicalTraceId;
651
+ exports.createTracerProvider = createTracerProvider;
652
+ exports.deriveExecutionRootSpanId = deriveExecutionRootSpanId;
653
+ exports.deriveExecutionTraceId = deriveExecutionTraceId;
654
+ exports.deriveSpanIdFromOperationId = deriveSpanIdFromOperationId;
655
+ exports.deriveTraceIdFromArn = deriveTraceIdFromArn;
656
+ exports.deriveTraceIdFromXRayRoot = deriveTraceIdFromXRayRoot;
657
+ exports.deriveWorkflowSpanId = deriveWorkflowSpanId;
658
+ exports.resolveExecutionTraceContext = resolveExecutionTraceContext;
659
+ exports.rootSamplingDecision = rootSamplingDecision;
660
+ exports.tryInstallDurableSampler = tryInstallDurableSampler;
661
+ exports.tryInstallGlobalIdGenerator = tryInstallGlobalIdGenerator;
662
+ exports.w3cClientContextExtractor = w3cClientContextExtractor;
663
+ exports.xRayContextExtractor = xRayContextExtractor;
664
+ //# sourceMappingURL=global-id-generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"global-id-generator.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"],"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;IACjE;;IAGA,eAAe,GAAA;QACb,MAAM,OAAO,GAAG,wBAAwB,CAAC,WAAW,CAAC,QAAQ,EAAE,EAAE,OAAO;QACxE,IAAI,OAAO,EAAE;AACX,YAAA,OAAO,OAAO;QAChB;AACA,QAAA,OAAO,IAAI,CAAC,mBAAmB,CAAC,eAAe,EAAE;IACnD;;IAGA,cAAc,GAAA;QACZ,MAAM,QAAQ,GAAG,wBAAwB,CAAC,WAAW,CAAC,QAAQ,EAAE;AAChE,QAAA,IAAI,QAAQ,EAAE,MAAM,EAAE;AACpB,YAAA,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM;AAC9B,YAAA,QAAQ,CAAC,MAAM,GAAG,SAAS;AAC3B,YAAA,OAAO,MAAM;QACf;AACA,QAAA,OAAO,IAAI,CAAC,mBAAmB,CAAC,cAAc,EAAE;IAClD;;AAGF;;;;;;;AAOG;AACG,SAAU,yBAAyB,CACvC,QAAgB,EAAA;;IAGhB,IAAI,IAAI,GAAG,QAAQ;AACnB,IAAA,IAAI,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EA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