Skip to content
Merged
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 @@ -23,7 +23,6 @@
import datadog.trace.util.stacktrace.StackWalkerFactory;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
Expand All @@ -38,7 +37,7 @@ public class DefaultCodeOriginRecorder implements CodeOriginRecorder {

private final ConfigurationUpdater configurationUpdater;

private final Map<String, CodeOriginProbe> probesByFingerprint = new HashMap<>();
private final Map<String, CodeOriginProbe> probesByFingerprint = new ConcurrentHashMap<>();

private final Map<String, CodeOriginProbe> probes = new ConcurrentHashMap<>();
private final Map<String, LogProbe> logProbes = new ConcurrentHashMap<>();
Expand Down Expand Up @@ -75,8 +74,6 @@ public String captureCodeOrigin(boolean entry) {
null,
String.valueOf(element.getLineNumber()));
probe = createProbe(fingerprint, entry, where);

LOG.debug("Creating probe for location {}", where);
}
return probe.getId();
}
Expand Down Expand Up @@ -110,11 +107,13 @@ public void registerLogProbe(CodeOriginProbe probe) {
}

private CodeOriginProbe createProbe(String fingerPrint, boolean entry, Where where) {
CodeOriginProbe probe;
AgentSpan span = AgentTracer.activeSpan();

probe = new CodeOriginProbe(ProbeId.newId(), entry, where);
addFingerprint(fingerPrint, probe);
CodeOriginProbe probe = new CodeOriginProbe(ProbeId.newId(), entry, where);
CodeOriginProbe existing;
if ((existing = probesByFingerprint.putIfAbsent(fingerPrint, probe)) != null) {
// concurrent calls, considered the probe already installed
return existing;
}
LOG.debug("Creating probe for location {}", where);
CodeOriginProbe installed = probes.putIfAbsent(probe.getId(), probe);

// i think this check is unnecessary at this point time but leaving for now to be safe
Expand All @@ -126,6 +125,7 @@ private CodeOriginProbe createProbe(String fingerPrint, boolean entry, Where whe
}
// committing here manually so that first run probe encounters decorate the span until the
// instrumentation gets installed
AgentSpan span = AgentTracer.activeSpan();
if (span != null) {
probe.commit(
CapturedContext.EMPTY_CONTEXT, CapturedContext.EMPTY_CONTEXT, Collections.emptyList());
Expand All @@ -142,10 +142,6 @@ private StackTraceElement findPlaceInStack() {
.orElse(null));
}

void addFingerprint(String fingerprint, CodeOriginProbe probe) {
probesByFingerprint.putIfAbsent(fingerprint, probe);
}

public void installProbes() {
scheduler.execute(() -> configurationUpdater.accept(CODE_ORIGIN, getProbes()));
}
Expand Down
Loading