Skip to content
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

Fix Span Decoration probe evaluateAt=ENTRY #7238

Closed
wants to merge 1 commit into from
Closed
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
Expand Up @@ -19,6 +19,7 @@
import com.datadog.debugger.util.ExceptionHelper;
import datadog.trace.agent.tooling.AgentStrategies;
import datadog.trace.api.Config;
import datadog.trace.bootstrap.debugger.MethodLocation;
import datadog.trace.bootstrap.debugger.ProbeId;
import datadog.trace.bootstrap.debugger.ProbeImplementation;
import datadog.trace.util.Strings;
Expand Down Expand Up @@ -581,12 +582,19 @@ private List<ToInstrumentInfo> filterAndSortDefinitions(List<ProbeDefinition> de
}

// Log & Span Decoration probes share the same instrumentor so only one definition should be
// selected to
// generate the instrumentation. Log probes needs capture limits provided by the configuration
// so if the list of definition contains at least 1 log probe this is the log probe that need to
// be picked.
// selected to generate the instrumentation. Log probes needs capture limits provided by the
// configuration so if the list of definition contains at least 1 log probe this is the log probe
// that need to be picked.
// TODO: handle the conflicting limits for log probes + mixing CaptureSnapshot or not
private ProbeDefinition selectReferenceDefinition(List<ProbeDefinition> capturedContextProbes) {
ProbeDefinition atEntryProbe =
capturedContextProbes.stream()
.filter(probeDefinition -> probeDefinition.getEvaluateAt() == MethodLocation.ENTRY)
.findAny()
.orElse(null);
if (atEntryProbe != null) {
return atEntryProbe;
}
ProbeDefinition first = capturedContextProbes.get(0);
return capturedContextProbes.stream()
.filter(it -> it instanceof LogProbe)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,11 @@ public void addTag(String tagName, String tagValue) {
public List<Pair<String, String>> getTagsToDecorate() {
return tagsToDecorate;
}

@Override
public boolean isCapturing() {
return true;
}
}

public static SpanDecorationProbe.Builder builder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,36 @@ PROBE_ID, ACTIVE, singletonList(decoration), CLASS_NAME, "process", null, null)
assertNotNull(intLocal);
}

@Test
public void mixedEntryExit() throws IOException, URISyntaxException {
final String CLASS_NAME = "com.datadog.debugger.CapturedSnapshot20";
SpanDecorationProbe.Decoration decoration1 = createDecoration("tag1", "{intLocal}");
SpanDecorationProbe.Decoration decoration2 = createDecoration("tag2", "{arg}");
SpanDecorationProbe spanDecoProbe1 =
createProbeBuilder(
PROBE_ID1, ACTIVE, singletonList(decoration1), CLASS_NAME, "process", null, null)
.evaluateAt(MethodLocation.EXIT)
.build();
SpanDecorationProbe spanDecoProbe2 =
createProbeBuilder(
PROBE_ID2, ACTIVE, singletonList(decoration2), CLASS_NAME, "process", null, null)
.evaluateAt(MethodLocation.ENTRY)
.build();
Configuration configuration =
Configuration.builder()
.setService(SERVICE_NAME)
.add(spanDecoProbe1)
.add(spanDecoProbe2)
.build();
installSpanDecorationProbes(CLASS_NAME, configuration);
Class<?> testClass = compileAndLoadClass(CLASS_NAME);
int result = Reflect.on(testClass).call("main", "1").get();
assertEquals(84, result);
MutableSpan span = traceInterceptor.getFirstSpan();
assertEquals("84", span.getTags().get("tag1"));
assertEquals("1", span.getTags().get("tag2"));
}

@Test
public void keywordRedaction() throws IOException, URISyntaxException {
final String CLASS_NAME = "com.datadog.debugger.CapturedSnapshot28";
Expand Down
Loading