Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/trace/listener.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,4 +544,28 @@ describe("TraceListener", () => {
);
});
});

it("sets durable function context tags directly on the aws.lambda span", async () => {
const mockSetTag = jest.fn();
const mockSpan = { setTag: mockSetTag };
const currentSpanSpy = jest.spyOn(TracerWrapper.prototype, "currentSpan", "get").mockReturnValue(mockSpan);

try {
const listener = new TraceListener(defaultConfig);
const durableEvent = {
DurableExecutionArn:
"arn:aws:lambda:us-east-1:123456789012:function:my-func:1/durable-execution/my-execution/550e8400-e29b-41d4-a716-446655440004",
};
await listener.onStartInvocation(durableEvent, context as any);
listener.onEndingInvocation(durableEvent, {}, false);

expect(mockSetTag).toHaveBeenCalledWith("aws_lambda.durable_function.execution_name", "my-execution");
expect(mockSetTag).toHaveBeenCalledWith(
"aws_lambda.durable_function.execution_id",
"550e8400-e29b-41d4-a716-446655440004",
);
} finally {
currentSpanSpy.mockRestore();
}
});
});
15 changes: 8 additions & 7 deletions src/trace/listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,14 @@ export class TraceListener {
}
}
}
if (this.durableFunctionContext) {
logDebug("Applying durable function context to the aws.lambda span");
for (const [key, value] of Object.entries(this.durableFunctionContext)) {
if (value !== undefined) {
this.tracerWrapper.currentSpan.setTag(key, value);
}
}
}

let rootSpan = this.inferredSpan;
if (!rootSpan) {
Expand Down Expand Up @@ -337,13 +345,6 @@ export class TraceListener {
...this.stepFunctionContext,
};
}
if (this.durableFunctionContext) {
logDebug("Applying durable function context to the aws.lambda span");
options.tags = {
...options.tags,
...this.durableFunctionContext,
};
}
if (this.lambdaSpanParentContext) {
options.childOf = this.lambdaSpanParentContext;
}
Expand Down
Loading