Skip to content

Update Code Origin span tags #7685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 26, 2024
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.datadog.debugger.probe;

import static com.datadog.debugger.codeorigin.DebuggerConfiguration.isDebuggerEnabled;
import static datadog.trace.api.DDTags.DD_CODE_ORIGIN_SNAPSHOT_ID;
import static datadog.trace.api.DDTags.DD_STACK_CODE_ORIGIN_FRAME;
import static datadog.trace.api.DDTags.DD_STACK_CODE_ORIGIN_TYPE;
import static java.lang.String.format;
Expand All @@ -13,7 +12,6 @@
import com.datadog.debugger.instrumentation.InstrumentationResult;
import com.datadog.debugger.sink.Snapshot;
import com.datadog.debugger.util.ClassNameFiltering;
import datadog.trace.api.DDTags;
import datadog.trace.bootstrap.debugger.CapturedContext;
import datadog.trace.bootstrap.debugger.MethodLocation;
import datadog.trace.bootstrap.debugger.ProbeId;
Expand Down Expand Up @@ -91,28 +89,9 @@ public void commit(

private void applySpanOriginTags(AgentSpan span, String snapshotId) {
List<StackTraceElement> entries = getUserStackFrames();
recordCodeOrigin(span, entries, snapshotId);
recordStackFrames(span, entries, snapshotId);
}

private void recordCodeOrigin(
AgentSpan span, List<StackTraceElement> entries, String snapshotId) {
if (entrySpanProbe && !entries.isEmpty()) {
StackTraceElement entry = entries.get(0);
List<AgentSpan> list = asList(span, span.getLocalRootSpan());
for (AgentSpan s : list) {
s.setTag(DDTags.DD_CODE_ORIGIN_FILE, toFileName(entry.getClassName()));
s.setTag(DDTags.DD_CODE_ORIGIN_METHOD, entry.getMethodName());
s.setTag(DDTags.DD_CODE_ORIGIN_LINE, entry.getLineNumber());
s.setTag(DDTags.DD_CODE_ORIGIN_TYPE, entry.getClassName());
s.setTag(DDTags.DD_CODE_ORIGIN_METHOD_SIGNATURE, signature);
if (snapshotId != null) {
s.setTag(DD_CODE_ORIGIN_SNAPSHOT_ID, snapshotId);
}
}
}
}

private void recordStackFrames(
AgentSpan span, List<StackTraceElement> entries, String snapshotId) {
List<AgentSpan> agentSpans =
Expand All @@ -127,6 +106,9 @@ private void recordStackFrames(
s.setTag(format(DD_STACK_CODE_ORIGIN_FRAME, i, "method"), info.getMethodName());
s.setTag(format(DD_STACK_CODE_ORIGIN_FRAME, i, "line"), info.getLineNumber());
s.setTag(format(DD_STACK_CODE_ORIGIN_FRAME, i, "type"), info.getClassName());
if (i == 0 && signature != null) {
s.setTag(format(DD_STACK_CODE_ORIGIN_FRAME, i, "signature"), signature);
}
if (i == 0 && snapshotId != null) {
s.setTag(format(DD_STACK_CODE_ORIGIN_FRAME, i, "snapshot_id"), snapshotId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import com.datadog.debugger.util.TestTraceInterceptor;
import datadog.trace.agent.tooling.TracerInstaller;
import datadog.trace.api.Config;
import datadog.trace.api.DDTags;
import datadog.trace.api.InstrumenterConfig;
import datadog.trace.api.interceptor.MutableSpan;
import datadog.trace.bootstrap.debugger.DebuggerContext;
Expand Down Expand Up @@ -191,20 +190,16 @@ private void waitForInstrumentation() {

private static void checkEntrySpanTags(MutableSpan span, boolean includeSnapshot) {
String keys = format("Existing keys for %s: %s", span.getOperationName(), ldKeys(span));
assertKeyPresent(span, DDTags.DD_CODE_ORIGIN_FILE);
assertKeyPresent(span, DDTags.DD_CODE_ORIGIN_LINE);
assertKeyPresent(span, DDTags.DD_CODE_ORIGIN_METHOD);
assertKeyPresent(span, DDTags.DD_CODE_ORIGIN_METHOD_SIGNATURE);

assertEquals(span.getTag(DD_STACK_CODE_ORIGIN_TYPE), "entry", keys);
assertKeyPresent(span, DD_STACK_CODE_ORIGIN_TYPE);
assertKeyPresent(span, format(DD_STACK_CODE_ORIGIN_FRAME, 0, "file"));
assertKeyPresent(span, format(DD_STACK_CODE_ORIGIN_FRAME, 0, "line"));
assertKeyPresent(span, format(DD_STACK_CODE_ORIGIN_FRAME, 0, "method"));
assertKeyPresent(span, format(DD_STACK_CODE_ORIGIN_FRAME, 0, "signature"));
assertKeyPresent(span, format(DD_STACK_CODE_ORIGIN_FRAME, 0, "type"));

if (includeSnapshot) {
assertKeyPresent(span, DDTags.DD_CODE_ORIGIN_SNAPSHOT_ID);
assertKeyPresent(span, format(DD_STACK_CODE_ORIGIN_FRAME, 0, "snapshot_id"));
}
}
Expand All @@ -229,12 +224,6 @@ private static void checkExitSpanTags(MutableSpan span, boolean includeSnapshot)
String keys =
format("Existing keys for %s: %s", span.getOperationName(), new TreeSet<>(ldKeys(span)));

assertKeyNotPresent(span, DDTags.DD_CODE_ORIGIN_FILE);
assertKeyNotPresent(span, DDTags.DD_CODE_ORIGIN_LINE);
assertKeyNotPresent(span, DDTags.DD_CODE_ORIGIN_METHOD);
assertKeyNotPresent(span, DDTags.DD_CODE_ORIGIN_METHOD_SIGNATURE);
assertKeyNotPresent(span, DDTags.DD_CODE_ORIGIN_SNAPSHOT_ID);

assertKeyPresent(span, DD_STACK_CODE_ORIGIN_TYPE);
assertKeyPresent(span, format(DD_STACK_CODE_ORIGIN_FRAME, 0, "file"));
assertKeyPresent(span, format(DD_STACK_CODE_ORIGIN_FRAME, 0, "line"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ class TagsAssert {
assertedTags.add(DDTags.PROFILING_ENABLED)
assertedTags.add(DDTags.PROFILING_CONTEXT_ENGINE)
assertedTags.add(DDTags.BASE_SERVICE)
assertedTags.add(DDTags.DD_CODE_ORIGIN_FILE)
assertedTags.add(DDTags.DD_CODE_ORIGIN_METHOD)
assertedTags.add(DDTags.DD_CODE_ORIGIN_LINE)
assertedTags.add(DDTags.DD_CODE_ORIGIN_METHOD_SIGNATURE)
assertedTags.add(DDTags.DSM_ENABLED)
assertedTags.add(DDTags.DJM_ENABLED)
assertedTags.add(DDTags.PARENT_ID)
Expand Down
14 changes: 3 additions & 11 deletions dd-trace-api/src/main/java/datadog/trace/api/DDTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,12 @@
public class DDTags {

private static final String DD_LD_PREFIX = "_dd.ld.";
public static final String DD_STACK_CODE_ORIGIN_PREFIX = "_dd.stack.code_origin.";
public static final String DD_STACK_CODE_ORIGIN_PREFIX = DD_LD_PREFIX + "code_origin.";

public static final String DD_STACK_CODE_ORIGIN_TYPE = DD_STACK_CODE_ORIGIN_PREFIX + "type";
// _dd.stack.code_origin.frame.%d.file|line|method|type|snapshot_id
// _dd.ld.code_origin.frames.%d.file|line|method|type|snapshot_id
public static final String DD_STACK_CODE_ORIGIN_FRAME =
DD_STACK_CODE_ORIGIN_PREFIX + "frame.%d.%s";

public static final String DD_CODE_ORIGIN_FILE = DD_LD_PREFIX + "code_origin.file";
public static final String DD_CODE_ORIGIN_METHOD = DD_LD_PREFIX + "code_origin.method";
public static final String DD_CODE_ORIGIN_METHOD_SIGNATURE =
DD_LD_PREFIX + "code_origin.signature";
public static final String DD_CODE_ORIGIN_LINE = DD_LD_PREFIX + "code_origin.line";
public static final String DD_CODE_ORIGIN_SNAPSHOT_ID = DD_LD_PREFIX + "code_origin.snapshot_id";
public static final String DD_CODE_ORIGIN_TYPE = DD_LD_PREFIX + "code_origin.type";
DD_STACK_CODE_ORIGIN_PREFIX + "frames.%d.%s";

public static final String SPAN_TYPE = "span.type";
public static final String SERVICE_NAME = "service.name";
Expand Down