-
Notifications
You must be signed in to change notification settings - Fork 334
Expand file tree
/
Copy pathDebuggerTracer.java
More file actions
72 lines (62 loc) · 2.34 KB
/
DebuggerTracer.java
File metadata and controls
72 lines (62 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package com.datadog.debugger.agent;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.NOOP_TRACER;
import com.datadog.debugger.sink.ProbeStatusSink;
import datadog.trace.bootstrap.debugger.DebuggerContext;
import datadog.trace.bootstrap.debugger.DebuggerSpan;
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
import datadog.trace.bootstrap.instrumentation.api.AgentTracer;
public class DebuggerTracer implements DebuggerContext.Tracer {
public static final String OPERATION_NAME = "dd.dynamic.span";
private final ProbeStatusSink probeStatusSink;
public DebuggerTracer(ProbeStatusSink probeStatusSink) {
this.probeStatusSink = probeStatusSink;
}
@Override
public DebuggerSpan createSpan(String encodedProbeId, String resourceName, String[] tags) {
AgentTracer.TracerAPI tracerAPI = AgentTracer.get();
if (tracerAPI == null || tracerAPI == NOOP_TRACER) {
return DebuggerSpan.NOOP_SPAN;
}
AgentSpan dynamicSpan =
tracerAPI.buildSpan("debugger", OPERATION_NAME).withResourceName(resourceName).start();
if (tags != null) {
for (String tag : tags) {
int idx = tag.indexOf(':');
if (idx == -1) {
continue;
}
dynamicSpan.setTag(tag.substring(0, idx), tag.substring(idx + 1));
}
}
AgentScope scope = tracerAPI.activateManualSpan(dynamicSpan);
return new DebuggerSpanImpl(dynamicSpan, scope, probeStatusSink, encodedProbeId);
}
static class DebuggerSpanImpl implements DebuggerSpan {
final AgentSpan underlyingSpan;
final AgentScope currentScope;
final ProbeStatusSink probeStatusSink;
final String encodedProbeId;
public DebuggerSpanImpl(
AgentSpan underlyingSpan,
AgentScope currentScope,
ProbeStatusSink probeStatusSink,
String encodedProbeId) {
this.underlyingSpan = underlyingSpan;
this.currentScope = currentScope;
this.probeStatusSink = probeStatusSink;
this.encodedProbeId = encodedProbeId;
}
@Override
public void finish() {
currentScope.close();
underlyingSpan.finish();
probeStatusSink.addEmitting(encodedProbeId);
}
@Override
public void setError(Throwable t) {
underlyingSpan.setError(true);
underlyingSpan.addThrowable(t);
}
}
}