@aws/durable-execution-sdk-js-otel 0.1.0 → 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 -516
  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 -519
  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 -64
  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,539 @@
1
+ import { trace, SpanKind, context, SpanStatusCode, ROOT_CONTEXT, isSpanContextValid, TraceFlags } from '@opentelemetry/api';
2
+ import { D as DeterministicIdGenerator, x as xRayContextExtractor, f as createTracerProvider, t as tryInstallDurableSampler, g as tryInstallGlobalIdGenerator, h as canonicalTraceId, r as resolveExecutionTraceContext, e as deriveWorkflowSpanId, a as deriveSpanIdFromOperationId, i as rootSamplingDecision } from './global-id-generator.mjs';
3
+ import { SamplingDecision } from '@opentelemetry/sdk-trace-node';
4
+
5
+ const DEFAULT_INSTRUMENTATION_NAME = "aws-durable-execution-sdk-js";
6
+ /**
7
+ * OpenTelemetry instrumentation plugin for durable executions.
8
+ *
9
+ * Implements the DurableInstrumentationPlugin interface. The Workflow span joins
10
+ * the execution trace by parenting onto the resolved execution ancestor (a
11
+ * propagated remote parent or a synthetic execution root), so the whole
12
+ * execution shares one trace. Operation spans parent onto the Workflow span and
13
+ * the per-invocation Invocation span is a correlation sibling (linked from, not
14
+ * a parent of, the operation spans). Both the Workflow span and each operation
15
+ * span are deferred: their identity is carried as a non-recording context and
16
+ * the single recording span is created and ended together at terminal /
17
+ * onOperationEnd, so nothing is left un-ended across invocations (issue #831).
18
+ */
19
+ class ExecutionOtelPlugin {
20
+ // Shared utilities (reused from existing package)
21
+ idGenerator;
22
+ contextExtractor;
23
+ // TracerProvider (global or application-owned)
24
+ tracerProvider;
25
+ tracer;
26
+ instrumentationName;
27
+ // Non-recording context carrying the deterministic Workflow identity; the real
28
+ // span is created+ended once, at the terminal invocation (issue #831).
29
+ workflowSpan;
30
+ invocationSpan;
31
+ // Holds only recording ATTEMPT spans; operation spans are deferred (see
32
+ // operationContexts), never recording between start and end.
33
+ spanMap;
34
+ // Deterministic non-recording placeholders for in-flight operations; the real
35
+ // span is created+ended once in onOperationEnd. Children/attempts parent onto it.
36
+ operationContexts;
37
+ // Naming/timing captured at start, reused when onOperationEnd omits them.
38
+ operationStarts;
39
+ executionArn;
40
+ executionTraceId;
41
+ executionTraceFlags = 0;
42
+ executionSamplingDecision;
43
+ // The execution ancestor the terminal Workflow span parents onto, and the
44
+ // backend execution start used to backdate it — both captured at invocation
45
+ // start and reused when the real span is created at terminal.
46
+ executionAncestor;
47
+ executionStartTimestamp;
48
+ usesGlobalProvider;
49
+ globalIdGeneratorInstalled;
50
+ durableSampler;
51
+ tracingEnabled = false;
52
+ // Workflow span name (configurable)
53
+ workflowSpanName;
54
+ // Whether enrichLogContext() contributes trace context to log records
55
+ enrichLogger;
56
+ constructor(config) {
57
+ const instrumentationName = config?.instrumentationName ?? DEFAULT_INSTRUMENTATION_NAME;
58
+ this.instrumentationName = instrumentationName;
59
+ this.idGenerator = new DeterministicIdGenerator();
60
+ this.contextExtractor = config?.contextExtractor ?? xRayContextExtractor;
61
+ this.workflowSpanName = config?.workflowSpanName ?? "Workflow";
62
+ this.enrichLogger = config?.enrichLogger ?? true;
63
+ const { tracerProvider, usesGlobalProvider } = createTracerProvider(config, this.idGenerator);
64
+ this.tracerProvider = tracerProvider;
65
+ this.usesGlobalProvider = usesGlobalProvider;
66
+ this.tracer = this.tracerProvider.getTracer(instrumentationName);
67
+ this.durableSampler = tryInstallDurableSampler(this.tracer);
68
+ this.globalIdGeneratorInstalled = !this.usesGlobalProvider;
69
+ if (this.usesGlobalProvider) {
70
+ const installedIdGenerator = tryInstallGlobalIdGenerator(this.tracer);
71
+ if (installedIdGenerator) {
72
+ this.idGenerator = installedIdGenerator;
73
+ this.globalIdGeneratorInstalled = true;
74
+ }
75
+ }
76
+ // Initialize per-invocation state
77
+ this.spanMap = new Map();
78
+ this.operationContexts = new Map();
79
+ this.operationStarts = new Map();
80
+ this.executionArn = "";
81
+ this.executionTraceId = "";
82
+ this.executionSamplingDecision = SamplingDecision.NOT_RECORD;
83
+ }
84
+ async onInvocationStart(info) {
85
+ this.resetInvocationState();
86
+ this.tracingEnabled = this.ensureGlobalIdGeneratorInstalled();
87
+ if (!this.tracingEnabled) {
88
+ return;
89
+ }
90
+ // 1. Store the execution ARN
91
+ this.executionArn = info.executionArn;
92
+ // 2. Extract trace context via context extractor (same as InvocationOtelPlugin)
93
+ const extractedContext = this.contextExtractor(info);
94
+ // 3. Resolve the one execution ancestor both spans parent onto, so they
95
+ // share a trace and a sampling decision. The canonical trace ID is the
96
+ // propagated remote trace when valid, else one derived from the ARN and
97
+ // start time. The execution ancestor is a complete remote parent, else a
98
+ // synthetic execution root. A live ambient span is not used as the ancestor
99
+ // (its trace is not stable across reinvocations).
100
+ const canonical = canonicalTraceId(extractedContext, info.executionArn, info.executionStartTimestamp);
101
+ const execTraceContext = resolveExecutionTraceContext(extractedContext, canonical, info.executionArn, () => rootSamplingDecision(this.tracer, canonical, this.workflowSpanName, {
102
+ "durable.execution.arn": info.executionArn,
103
+ }));
104
+ this.executionTraceId = canonical;
105
+ this.executionTraceFlags = execTraceContext.traceFlags;
106
+ this.executionSamplingDecision = execTraceContext.samplingDecision;
107
+ // 4. Derive the workflow span ID from execution ARN
108
+ const workflowSpanId = deriveWorkflowSpanId(info.executionArn);
109
+ // 5. Resolve the Workflow_Span identity as a NON-RECORDING context. A whole
110
+ // execution spans many invocations, so only the terminal one can complete
111
+ // the real span; carrying a real recording span across invocations would
112
+ // leak it un-ended (issue #831), and ending one per invocation would export
113
+ // duplicate (traceId, spanId). Operations parent onto this non-recording
114
+ // context (a valid parent that stamps the right traceId/parentSpanId on its
115
+ // children); the single real span is created and ended once, at the terminal
116
+ // invocation (see onInvocationEnd), parented onto the execution ancestor. It
117
+ // carries the execution sampled bit so a parent-based sampler stays
118
+ // consistent with the eventual root.
119
+ this.executionAncestor = execTraceContext.executionAncestor;
120
+ this.executionStartTimestamp =
121
+ info.executionStartTimestamp ??
122
+ this.executionStartTimestamp ??
123
+ new Date();
124
+ this.workflowSpan = trace.wrapSpanContext({
125
+ traceId: this.executionTraceId,
126
+ spanId: workflowSpanId,
127
+ traceFlags: execTraceContext.traceFlags,
128
+ isRemote: false,
129
+ });
130
+ // 6. Create Invocation_Span parented onto the same-trace ambient span when
131
+ // available, otherwise onto the execution ancestor so it stays within the
132
+ // execution trace. Provider ownership must not change trace topology.
133
+ const invocationParentContext = this.invocationParentContext(execTraceContext.executionAncestor, canonical);
134
+ const invocationAttributes = {
135
+ "durable.execution.arn": info.executionArn,
136
+ "durable.invocation.first": info.isFirstInvocation,
137
+ };
138
+ if (!this.usesGlobalProvider) {
139
+ // Set cloud.resource_id from Lambda environment variables
140
+ const functionName = process.env.AWS_LAMBDA_FUNCTION_NAME;
141
+ if (functionName) {
142
+ const region = process.env.AWS_REGION;
143
+ // Extract account ID from execution ARN (format: arn:aws:states:{region}:{account}:execution:{sm}:{exec})
144
+ const arnParts = info.executionArn.split(":");
145
+ const accountId = arnParts.length >= 5 ? arnParts[4] : undefined;
146
+ if (region && accountId) {
147
+ const version = process.env.AWS_LAMBDA_FUNCTION_VERSION;
148
+ const resourceId = `arn:aws:lambda:${region}:${accountId}:function:${functionName}${version ? ":" + version : ""}`;
149
+ invocationAttributes["cloud.resource_id"] = resourceId;
150
+ }
151
+ else {
152
+ invocationAttributes["cloud.resource_id"] = functionName;
153
+ }
154
+ }
155
+ // Set faas.max_memory if available
156
+ const memorySize = process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE;
157
+ if (memorySize) {
158
+ const parsed = parseInt(memorySize, 10);
159
+ if (!isNaN(parsed)) {
160
+ invocationAttributes["faas.max_memory"] = parsed;
161
+ }
162
+ }
163
+ }
164
+ this.invocationSpan = this.startSpan("Invocation", {
165
+ kind: SpanKind.INTERNAL,
166
+ attributes: invocationAttributes,
167
+ }, invocationParentContext);
168
+ }
169
+ wrapInvocation(_info, fn) {
170
+ if (!this.tracingEnabled || !this.workflowSpan) {
171
+ return fn();
172
+ }
173
+ return context.with(trace.setSpan(context.active(), this.workflowSpan), fn);
174
+ }
175
+ async onInvocationEnd(info) {
176
+ if (!this.tracingEnabled) {
177
+ this.resetInvocationState();
178
+ return;
179
+ }
180
+ // 1. Always end and export Invocation_Span
181
+ if (this.invocationSpan) {
182
+ this.invocationSpan.setAttribute("durable.invocation.status", info.status);
183
+ // Map PluginInvocationStatus to span status:
184
+ // FAILED -> ERROR
185
+ // SUCCEEDED / PENDING -> OK (PENDING is a normal suspension, not an error)
186
+ // RETRYING -> UNSET. The plugin interface cannot distinguish a STOPPED or
187
+ // TIMED_OUT invocation from a RETRYING one at onInvocationEnd, so RETRYING
188
+ // is intentionally left UNSET rather than reported as ERROR.
189
+ if (info.status === "FAILED") {
190
+ this.invocationSpan.setStatus({
191
+ code: SpanStatusCode.ERROR,
192
+ message: info.executionError?.message ?? "Execution failed",
193
+ });
194
+ }
195
+ else if (info.status === "SUCCEEDED" || info.status === "PENDING") {
196
+ this.invocationSpan.setStatus({ code: SpanStatusCode.OK });
197
+ }
198
+ // RETRYING: leave status UNSET (default)
199
+ this.invocationSpan.end();
200
+ }
201
+ // 2. Terminal invocation ONLY: create and end the one real Workflow_Span,
202
+ // so a single span ever claims the deterministic (traceId, spanId) and no
203
+ // span is left un-ended on a non-terminal invocation (issue #831). It is
204
+ // parented onto the execution ancestor (the join-trace model) and backdated
205
+ // to the execution start captured at invocation start. Skipped when the
206
+ // execution decision was not sampled, so a dropped execution does not export
207
+ // a lone root. PluginInvocationStatus collapses TIMED_OUT/STOPPED into
208
+ // FAILED -> ERROR.
209
+ if (this.executionSamplingDecision === SamplingDecision.RECORD_AND_SAMPLED &&
210
+ this.executionAncestor &&
211
+ (info.status === "SUCCEEDED" || info.status === "FAILED")) {
212
+ const workflowSpanId = deriveWorkflowSpanId(this.executionArn);
213
+ const executionAncestorContext = trace.setSpanContext(ROOT_CONTEXT, this.executionAncestor);
214
+ const workflowSpan = this.idGenerator.withIds({ spanId: workflowSpanId }, () => this.startSpan(this.workflowSpanName, {
215
+ kind: SpanKind.INTERNAL,
216
+ attributes: {
217
+ "durable.execution.arn": this.executionArn,
218
+ },
219
+ startTime: this.executionStartTimestamp ?? new Date(),
220
+ }, executionAncestorContext));
221
+ workflowSpan.setAttribute("durable.execution.status", info.status);
222
+ if (info.status === "FAILED") {
223
+ workflowSpan.setStatus({
224
+ code: SpanStatusCode.ERROR,
225
+ message: info.executionError?.message ?? "Execution failed",
226
+ });
227
+ }
228
+ else {
229
+ workflowSpan.setStatus({ code: SpanStatusCode.OK });
230
+ }
231
+ workflowSpan.end();
232
+ }
233
+ // Non-terminal (PENDING/RETRYING): no real Workflow_Span is created, so
234
+ // nothing to end — the identity was only ever a non-recording context.
235
+ // 3. End any attempt span still open (safeguard against a leak on a
236
+ // non-terminal invocation, issue #831). Operation placeholders have no
237
+ // recording span and are dropped in resetInvocationState.
238
+ for (const span of this.spanMap.values()) {
239
+ if (span.isRecording()) {
240
+ span.end();
241
+ }
242
+ }
243
+ // 4. Always flush TracerProvider at invocation boundaries
244
+ if ("forceFlush" in this.tracerProvider) {
245
+ try {
246
+ await this.tracerProvider.forceFlush();
247
+ }
248
+ catch (e) {
249
+ console.error("[ExecutionOtelPlugin] forceFlush failed:", e instanceof Error ? e.message : e);
250
+ }
251
+ }
252
+ // 5. Clear per-invocation state
253
+ this.resetInvocationState();
254
+ }
255
+ ensureGlobalIdGeneratorInstalled() {
256
+ if (!this.usesGlobalProvider || this.globalIdGeneratorInstalled) {
257
+ return true;
258
+ }
259
+ // A plugin constructed before zero-code instrumentation is registered sees
260
+ // a ProxyTracer without the SDK's ID generator. Resolve the global provider
261
+ // again at invocation start, after preload initialization has completed.
262
+ this.tracerProvider = trace.getTracerProvider();
263
+ this.tracer = this.tracerProvider.getTracer(this.instrumentationName);
264
+ this.durableSampler = tryInstallDurableSampler(this.tracer);
265
+ const installedIdGenerator = tryInstallGlobalIdGenerator(this.tracer);
266
+ if (installedIdGenerator) {
267
+ this.idGenerator = installedIdGenerator;
268
+ this.globalIdGeneratorInstalled = true;
269
+ return true;
270
+ }
271
+ console.warn("[ExecutionOtelPlugin] Expected a compatible OpenTelemetry SDK tracer at invocation start; telemetry is disabled for this invocation. Ensure the OpenTelemetry SDK is configured before invocation start.");
272
+ return false;
273
+ }
274
+ resetInvocationState() {
275
+ this.spanMap.clear();
276
+ this.operationContexts.clear();
277
+ this.operationStarts.clear();
278
+ this.workflowSpan = undefined;
279
+ this.invocationSpan = undefined;
280
+ this.executionAncestor = undefined;
281
+ this.executionStartTimestamp = undefined;
282
+ this.executionArn = "";
283
+ this.executionTraceId = "";
284
+ this.executionTraceFlags = 0;
285
+ this.executionSamplingDecision = SamplingDecision.NOT_RECORD;
286
+ this.tracingEnabled = false;
287
+ }
288
+ startSpan(name, options, parentContext) {
289
+ const fn = () => this.tracer.startSpan(name, options, parentContext);
290
+ return this.durableSampler
291
+ ? this.durableSampler.withDecision(this.executionSamplingDecision, fn)
292
+ : fn();
293
+ }
294
+ /**
295
+ * The parent context for the Invocation span: the active ambient span when it
296
+ * is already on the execution trace, otherwise the execution ancestor so the
297
+ * Invocation span stays within the same trace.
298
+ */
299
+ invocationParentContext(executionAncestor, canonical) {
300
+ const activeContext = context.active();
301
+ const ambient = trace.getSpanContext(activeContext);
302
+ // Adopt the ambient span as the Invocation parent only when it is on the
303
+ // execution trace AND carries the same sampled bit as the execution
304
+ // ancestor. Matching the trace ID alone is not enough: if the ambient span's
305
+ // sampled bit differs, the Invocation span would inherit the ambient
306
+ // decision and could export after an explicit Sampled=0, or drop after the
307
+ // root sampler chose sampled. On a mismatch, fall back to the execution
308
+ // ancestor, which carries the authoritative decision.
309
+ if (ambient &&
310
+ isSpanContextValid(ambient) &&
311
+ ambient.traceId === canonical &&
312
+ (ambient.traceFlags & TraceFlags.SAMPLED) ===
313
+ (executionAncestor.traceFlags & TraceFlags.SAMPLED)) {
314
+ return activeContext;
315
+ }
316
+ return trace.setSpanContext(ROOT_CONTEXT, executionAncestor);
317
+ }
318
+ /**
319
+ * Builds span links to the invocation span for child spans.
320
+ *
321
+ * Always links to the plugin-created Invocation_Span (this.invocationSpan),
322
+ * which is created in both default-provider and non-default modes.
323
+ */
324
+ buildInvocationLinks() {
325
+ if (this.invocationSpan) {
326
+ return [{ context: this.invocationSpan.spanContext() }];
327
+ }
328
+ return [];
329
+ }
330
+ async onOperationStart(info) {
331
+ if (!this.tracingEnabled) {
332
+ return;
333
+ }
334
+ // Defer the span: store only a deterministic non-recording placeholder that
335
+ // children/attempts parent onto; the real span is created in onOperationEnd.
336
+ const deterministicSpanId = deriveSpanIdFromOperationId(info.id, this.executionArn);
337
+ this.operationContexts.set(info.id, {
338
+ traceId: this.executionTraceId,
339
+ spanId: deterministicSpanId,
340
+ traceFlags: this.executionTraceFlags,
341
+ isRemote: false,
342
+ });
343
+ // Retain naming/timing for onOperationEnd, which may omit them. New
344
+ // operations can reach this hook before the checkpoint response supplies a
345
+ // backend start timestamp, so capture the hook time as the fallback. Keep
346
+ // the earliest observation if the same operation starts again on replay.
347
+ const existingStart = this.operationStarts.get(info.id);
348
+ const observedStart = info.startTimestamp ?? new Date();
349
+ this.operationStarts.set(info.id, {
350
+ name: info.name ?? existingStart?.name,
351
+ subType: info.subType ?? existingStart?.subType,
352
+ startTimestamp: this.earliestStart(existingStart?.startTimestamp, observedStart),
353
+ });
354
+ }
355
+ wrapChildContextFn(info, fn) {
356
+ if (!this.tracingEnabled) {
357
+ return fn();
358
+ }
359
+ // Make the operation's placeholder current so nested calls become its children.
360
+ const operationContext = this.operationContexts.get(info.id);
361
+ if (!operationContext) {
362
+ return fn();
363
+ }
364
+ return context.with(trace.setSpanContext(context.active(), operationContext), fn);
365
+ }
366
+ async onOperationEnd(info) {
367
+ if (!this.tracingEnabled) {
368
+ return;
369
+ }
370
+ // The only place an operation span is created: start+end it here under its
371
+ // deterministic ID, so it is exported exactly once even across suspend/resume.
372
+ const started = this.operationStarts.get(info.id);
373
+ this.operationContexts.delete(info.id);
374
+ this.operationStarts.delete(info.id);
375
+ // The end event may omit name/subType; fall back to what start captured.
376
+ const name = info.name ?? started?.name;
377
+ const subType = info.subType ?? started?.subType;
378
+ const spanName = name ?? info.type;
379
+ const parentContext = this.resolveOperationParentContext(info.parentId);
380
+ const attributes = {
381
+ "durable.execution.arn": this.executionArn,
382
+ "durable.operation.id": info.id,
383
+ "durable.operation.type": info.type,
384
+ };
385
+ if (name) {
386
+ attributes["durable.operation.name"] = name;
387
+ }
388
+ if (subType) {
389
+ attributes["durable.operation.subtype"] = subType;
390
+ }
391
+ if (info.status) {
392
+ attributes["durable.operation.status"] = info.status;
393
+ }
394
+ // durable.attempt.number for retriable operations (STEP, WAIT_FOR_CONDITION).
395
+ if ((info.type === "STEP" || subType === "WAIT_FOR_CONDITION") &&
396
+ info.attempt != null) {
397
+ attributes["durable.attempt.number"] = info.attempt;
398
+ }
399
+ const links = this.buildInvocationLinks();
400
+ // Earliest known start, so the span never begins after its own attempt/child
401
+ // spans (created earlier at start).
402
+ const startTime = this.earliestStart(started?.startTimestamp, info.startTimestamp);
403
+ const operationSpanId = deriveSpanIdFromOperationId(info.id, this.executionArn);
404
+ const span = this.idGenerator.withIds({
405
+ traceId: this.executionTraceId,
406
+ spanId: operationSpanId,
407
+ }, () => this.startSpan(spanName, { attributes, startTime, links }, parentContext));
408
+ if (info.error) {
409
+ span.setStatus({
410
+ code: SpanStatusCode.ERROR,
411
+ message: info.error.message,
412
+ });
413
+ span.recordException(info.error);
414
+ }
415
+ else if (info.status === "SUCCEEDED") {
416
+ // Stamp explicit OK ONLY on a SUCCEEDED terminal status. Terminal
417
+ // FAILURE statuses (TIMED_OUT/STOPPED/FAILED/CANCELLED) can arrive with
418
+ // NO error object (callback-timeout, chained-invoke fast paths); those
419
+ // must NOT be labelled OK, so they are left UNSET.
420
+ span.setStatus({ code: SpanStatusCode.OK });
421
+ }
422
+ span.end(info.endTimestamp);
423
+ }
424
+ /**
425
+ * The parent context for an operation or attempt span: the parent operation's
426
+ * deterministic placeholder context when known, otherwise the deferred
427
+ * Workflow span's context so the span still hangs off the execution trace.
428
+ */
429
+ resolveOperationParentContext(parentId) {
430
+ if (parentId) {
431
+ const parentContext = this.operationContexts.get(parentId);
432
+ if (parentContext) {
433
+ return trace.setSpanContext(context.active(), parentContext);
434
+ }
435
+ }
436
+ const workflowContext = this.workflowSpan?.spanContext();
437
+ if (workflowContext) {
438
+ return trace.setSpanContext(context.active(), workflowContext);
439
+ }
440
+ return context.active();
441
+ }
442
+ /** The earlier of two timestamps, ignoring undefined; undefined only when both are. */
443
+ earliestStart(a, b) {
444
+ if (!a) {
445
+ return b;
446
+ }
447
+ if (!b) {
448
+ return a;
449
+ }
450
+ return a.getTime() <= b.getTime() ? a : b;
451
+ }
452
+ getAttemptKey(id, attempt) {
453
+ return `${id}:attempt:${attempt}`;
454
+ }
455
+ async onOperationAttemptStart(info) {
456
+ if (!this.tracingEnabled) {
457
+ return;
458
+ }
459
+ const baseName = info.name ?? info.type;
460
+ const spanName = `${baseName} attempt ${info.attempt}`;
461
+ // Parent onto the operation's placeholder (the operation span is deferred).
462
+ const parentContext = this.resolveOperationParentContext(info.id);
463
+ const attributes = {
464
+ "durable.execution.arn": this.executionArn,
465
+ "durable.operation.id": info.id,
466
+ "durable.operation.type": info.type,
467
+ "durable.attempt.number": info.attempt,
468
+ };
469
+ if (info.name) {
470
+ attributes["durable.operation.name"] = info.name;
471
+ }
472
+ if (info.subType) {
473
+ attributes["durable.operation.subtype"] = info.subType;
474
+ }
475
+ const links = this.buildInvocationLinks();
476
+ const attemptSpan = this.startSpan(spanName, {
477
+ attributes,
478
+ startTime: info.startTimestamp,
479
+ links,
480
+ }, parentContext);
481
+ this.spanMap.set(this.getAttemptKey(info.id, info.attempt), attemptSpan);
482
+ }
483
+ wrapOperationAttemptFn(info, fn) {
484
+ if (!this.tracingEnabled) {
485
+ return fn();
486
+ }
487
+ const attemptSpan = this.spanMap.get(this.getAttemptKey(info.id, info.attempt));
488
+ if (!attemptSpan) {
489
+ return fn();
490
+ }
491
+ return context.with(trace.setSpan(context.active(), attemptSpan), fn);
492
+ }
493
+ async onOperationAttemptEnd(info) {
494
+ if (!this.tracingEnabled) {
495
+ return;
496
+ }
497
+ const key = this.getAttemptKey(info.id, info.attempt);
498
+ const attemptSpan = this.spanMap.get(key);
499
+ if (attemptSpan) {
500
+ attemptSpan.setAttribute("durable.attempt.outcome", info.outcome);
501
+ if (info.outcome === "FAILED") {
502
+ attemptSpan.setStatus({
503
+ code: SpanStatusCode.ERROR,
504
+ message: info.error?.message ?? "Attempt failed",
505
+ });
506
+ if (info.error) {
507
+ attemptSpan.recordException(info.error);
508
+ }
509
+ }
510
+ else {
511
+ // Non-failed attempt: stamp explicit OK (matches Python OTel #604).
512
+ attemptSpan.setStatus({ code: SpanStatusCode.OK });
513
+ }
514
+ attemptSpan.end(info.endTimestamp);
515
+ this.spanMap.delete(key);
516
+ }
517
+ }
518
+ async onOperationChange(_info) {
519
+ // No-op — same as InvocationOtelPlugin
520
+ }
521
+ enrichLogContext() {
522
+ if (!this.tracingEnabled || !this.enrichLogger) {
523
+ return undefined;
524
+ }
525
+ const span = trace.getSpan(context.active());
526
+ if (!span) {
527
+ return undefined;
528
+ }
529
+ const spanContext = span.spanContext();
530
+ return {
531
+ traceId: spanContext.traceId,
532
+ spanId: spanContext.spanId,
533
+ otelTraceSampled: (spanContext.traceFlags & 1) !== 0,
534
+ };
535
+ }
536
+ }
537
+
538
+ export { ExecutionOtelPlugin as E };
539
+ //# sourceMappingURL=execution-plugin.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execution-plugin.mjs","sources":["../src/execution-plugin.ts"],"names":[],"mappings":";;;;AA8CA,MAAM,4BAA4B,GAAG,8BAA8B;AAEnE;;;;;;;;;;;;AAYG;MACU,mBAAmB,CAAA;;AAEtB,IAAA,WAAW;AACF,IAAA,gBAAgB;;AAGzB,IAAA,cAAc;AACd,IAAA,MAAM;AACG,IAAA,mBAAmB;;;AAI5B,IAAA,YAAY;AACZ,IAAA,cAAc;;;AAGd,IAAA,OAAO;;;AAGP,IAAA,iBAAiB;;AAEjB,IAAA,eAAe;AAIf,IAAA,YAAY;AACZ,IAAA,gBAAgB;IAChB,mBAAmB,GAAW,CAAC;AAC/B,IAAA,yBAAyB;;;;AAIzB,IAAA,iBAAiB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