Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import datadog.trace.bootstrap.instrumentation.api.AgentSpanContext;
import datadog.trace.bootstrap.instrumentation.api.AgentTracer;
import datadog.trace.bootstrap.instrumentation.api.InternalSpanTypes;
import datadog.trace.bootstrap.instrumentation.api.ResourceNamePriorities;
import datadog.trace.config.inversion.ConfigHelper;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.type.TypeDescription;
Expand Down Expand Up @@ -126,6 +127,21 @@ static void exit(
String lambdaRequestId = awsContext.getAwsRequestId();

AgentTracer.get().notifyAppSecEnd(span);
// Force the resource name back to the literal placeholder marker right
// before finish so that the Datadog Lambda Extension's filter
// (filter_span_from_lambda_library_or_runtime in
// bottlecap/src/traces/trace_processor.rs, which compares
// span.resource == "dd-tracer-serverless-span") drops the placeholder.
// Other instrumentation (HTTP/JAX-RS) may have overwritten it with the
// route ("POST /") during the invocation, in which case the extension
// would fail to dedup, leading to the placeholder leaking to the backend
// with parent_id=0 and detaching the inferred apigateway root from the
// rest of the trace.
// Use MANUAL_INSTRUMENTATION priority because DDSpanContext.setResourceName
// ignores writes whose priority is below the current resource priority,
// and the HTTP/JAX-RS instrumentation will already have written
// HTTP_FRAMEWORK_ROUTE (3) by this point.
span.setResourceName(INVOCATION_SPAN_NAME, ResourceNamePriorities.MANUAL_INSTRUMENTATION);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve user-set resource names on Lambda span

Overwriting the resource unconditionally at method exit with MANUAL_INSTRUMENTATION can clobber a resource name that application code intentionally set on the active Lambda span with the same priority during handler execution. AgentSpan#setResourceName uses last-write-wins for equal priority, so this line will replace those user values every time, which regresses resource naming whenever the placeholder span is ultimately emitted (for example if extension communication fails or is disabled). Consider only resetting when the current priority is framework-level (e.g., <= HTTP_FRAMEWORK_ROUTE) rather than overriding manual-level values.

Useful? React with 👍 / 👎.

span.finish();
AgentTracer.get().notifyExtensionEnd(span, result, null != throwable, lambdaRequestId);
} finally {
Expand Down
Loading