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