Skip to content

Commit e149fa6

Browse files
committed
update comments
1 parent ad4a2c4 commit e149fa6

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

src/trace/context/extractors/durable-execution.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -591,11 +591,12 @@ export function getCompletedOperationCount(event: unknown): number {
591591
}
592592

593593
/**
594-
* Create (or re-emit) the durable execution root span.
594+
* Create the durable execution root span for likely first invocations only.
595595
*
596-
* Every invocation emits this span with the same propagated root span_id.
597-
* The Datadog backend deduplicates by span_id, so the last invocation's
598-
* version wins with the correct total duration (start → final end).
596+
* Replay invocations return null. The current first-invocation heuristic is:
597+
* - no trace checkpoint operation exists
598+
* - no operation has terminal status
599+
* - operation count is <= 1
599600
*
600601
* Returns an object with { span, finish() } or null if not a durable execution.
601602
* Caller must call finish() when the invocation ends.
@@ -669,8 +670,8 @@ export function createDurableExecutionRootSpan(
669670

670671
const span = tracer.startSpan("aws.durable-execution", spanOptions);
671672

672-
// Re-emit root span using the extracted root span_id so all invocations
673-
// refer to the same durable execution root (propagated by checkpoints).
673+
// Use the extracted durable root span_id when available to keep the
674+
// durable root identity stable with propagated checkpoint context.
674675
try {
675676
if (rootSpanId) {
676677
span.context()._spanId = id(rootSpanId, 10);

src/trace/listener.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,10 @@ export class TraceListener {
145145
traceSource: this.contextService.traceSource,
146146
});
147147
}
148-
// Create the durable execution root span before everything else.
149-
// This span uses the propagated root span_id and is re-emitted on every
150-
// invocation (last one wins in the backend with correct total duration).
148+
// Create the durable execution root span before everything else so later
149+
// spans can parent correctly. Root creation is gated in
150+
// createDurableExecutionRootSpan() and only happens for likely first
151+
// invocations; replay invocations return null.
151152
this.durableRootSpan = createDurableExecutionRootSpan(event, spanContextWrapper) ?? undefined;
152153

153154
if (this.config.createInferredSpan) {

0 commit comments

Comments
 (0)