Skip to content

Commit f8bbb2a

Browse files
lym953claude
andauthored
fix: [SVLS-8538] apply durable function tags via setTag on the active span (#762)
* fix: [SVLS-8538] apply durable function tags via setTag on the active span Tags for aws_lambda.durable_function.* were set through options.tags in tracer.wrap(), but that path does not reliably reach the aws.lambda span. Apply them directly via span.setTag() in onEndingInvocation(), the same way http.status_code is applied. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * remove logDebug from durable function tag application Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * add back logDebug for durable function tag application Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent e7477a4 commit f8bbb2a

2 files changed

Lines changed: 32 additions & 7 deletions

File tree

src/trace/listener.spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,4 +544,28 @@ describe("TraceListener", () => {
544544
);
545545
});
546546
});
547+
548+
it("sets durable function context tags directly on the aws.lambda span", async () => {
549+
const mockSetTag = jest.fn();
550+
const mockSpan = { setTag: mockSetTag };
551+
const currentSpanSpy = jest.spyOn(TracerWrapper.prototype, "currentSpan", "get").mockReturnValue(mockSpan);
552+
553+
try {
554+
const listener = new TraceListener(defaultConfig);
555+
const durableEvent = {
556+
DurableExecutionArn:
557+
"arn:aws:lambda:us-east-1:123456789012:function:my-func:1/durable-execution/my-execution/550e8400-e29b-41d4-a716-446655440004",
558+
};
559+
await listener.onStartInvocation(durableEvent, context as any);
560+
listener.onEndingInvocation(durableEvent, {}, false);
561+
562+
expect(mockSetTag).toHaveBeenCalledWith("aws_lambda.durable_function.execution_name", "my-execution");
563+
expect(mockSetTag).toHaveBeenCalledWith(
564+
"aws_lambda.durable_function.execution_id",
565+
"550e8400-e29b-41d4-a716-446655440004",
566+
);
567+
} finally {
568+
currentSpanSpy.mockRestore();
569+
}
570+
});
547571
});

src/trace/listener.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,14 @@ export class TraceListener {
226226
}
227227
}
228228
}
229+
if (this.durableFunctionContext) {
230+
logDebug("Applying durable function context to the aws.lambda span");
231+
for (const [key, value] of Object.entries(this.durableFunctionContext)) {
232+
if (value !== undefined) {
233+
this.tracerWrapper.currentSpan.setTag(key, value);
234+
}
235+
}
236+
}
229237

230238
let rootSpan = this.inferredSpan;
231239
if (!rootSpan) {
@@ -337,13 +345,6 @@ export class TraceListener {
337345
...this.stepFunctionContext,
338346
};
339347
}
340-
if (this.durableFunctionContext) {
341-
logDebug("Applying durable function context to the aws.lambda span");
342-
options.tags = {
343-
...options.tags,
344-
...this.durableFunctionContext,
345-
};
346-
}
347348
if (this.lambdaSpanParentContext) {
348349
options.childOf = this.lambdaSpanParentContext;
349350
}

0 commit comments

Comments
 (0)