|
5 | 5 | import static datadog.trace.api.DDTags.DD_CODE_ORIGIN_TYPE; |
6 | 6 | import static java.lang.String.format; |
7 | 7 | import static java.util.Arrays.asList; |
8 | | -import static java.util.Collections.emptyList; |
9 | 8 | import static java.util.Collections.singletonList; |
10 | 9 |
|
11 | 10 | import com.datadog.debugger.agent.DebuggerAgent; |
@@ -68,63 +67,53 @@ public void commit( |
68 | 67 | LOGGER.debug("Could not find the span for probeId {}", id); |
69 | 68 | return; |
70 | 69 | } |
71 | | - String snapshotId = null; |
| 70 | + List<AgentSpan> agentSpans = applyCodeOriginTags(span); |
| 71 | + |
72 | 72 | DebuggerSink sink = DebuggerAgent.getSink(); |
73 | 73 | if (isDebuggerEnabled(span) && sink != null) { |
74 | 74 | Snapshot snapshot = createSnapshot(); |
75 | 75 | if (fillSnapshot(entryContext, exitContext, caughtExceptions, snapshot)) { |
76 | | - snapshotId = snapshot.getId(); |
| 76 | + String snapshotId = snapshot.getId(); |
77 | 77 | LOGGER.debug("committing code origin probe id={}, snapshot id={}", id, snapshotId); |
78 | 78 | commitSnapshot(snapshot, sink); |
| 79 | + |
| 80 | + for (AgentSpan agentSpan : agentSpans) { |
| 81 | + if (agentSpan.getTag(format(DD_CODE_ORIGIN_FRAME, 0, "snapshot_id")) == null) { |
| 82 | + agentSpan.setTag(format(DD_CODE_ORIGIN_FRAME, 0, "snapshot_id"), snapshotId); |
| 83 | + } |
| 84 | + } |
79 | 85 | } |
80 | 86 | } |
81 | | - applySpanOriginTags(span, snapshotId); |
82 | 87 | if (sink != null) { |
83 | 88 | sink.getProbeStatusSink().addEmitting(probeId); |
84 | 89 | } |
85 | 90 | span.getLocalRootSpan().setTag(getId(), (String) null); // clear possible span reference |
86 | 91 | } |
87 | 92 |
|
88 | | - private List<StackTraceElement> findLocation() { |
89 | | - if (entrySpanProbe && stackTraceElements == null) { |
90 | | - ProbeLocation probeLocation = getLocation(); |
91 | | - List<String> lines = probeLocation.getLines(); |
92 | | - int line = lines == null ? -1 : Integer.parseInt(lines.get(0)); |
93 | | - stackTraceElements = |
94 | | - singletonList( |
95 | | - new StackTraceElement( |
96 | | - probeLocation.getType(), |
97 | | - probeLocation.getMethod(), |
98 | | - probeLocation.getFile(), |
99 | | - line)); |
100 | | - } |
101 | | - return stackTraceElements != null ? stackTraceElements : emptyList(); |
102 | | - } |
103 | | - |
104 | | - private void applySpanOriginTags(AgentSpan span, String snapshotId) { |
| 93 | + private List<AgentSpan> applyCodeOriginTags(AgentSpan span) { |
105 | 94 | List<StackTraceElement> entries = |
106 | 95 | stackTraceElements != null ? stackTraceElements : getUserStackFrames(); |
107 | 96 | List<AgentSpan> agentSpans = |
108 | 97 | entrySpanProbe ? asList(span, span.getLocalRootSpan()) : singletonList(span); |
109 | 98 |
|
110 | 99 | for (AgentSpan s : agentSpans) { |
111 | | - s.setTag(DD_CODE_ORIGIN_TYPE, entrySpanProbe ? "entry" : "exit"); |
112 | | - |
113 | | - for (int i = 0; i < entries.size(); i++) { |
114 | | - StackTraceElement info = entries.get(i); |
115 | | - String fileName = info.getFileName(); |
116 | | - s.setTag(format(DD_CODE_ORIGIN_FRAME, i, "file"), fileName); |
117 | | - s.setTag(format(DD_CODE_ORIGIN_FRAME, i, "method"), info.getMethodName()); |
118 | | - s.setTag(format(DD_CODE_ORIGIN_FRAME, i, "line"), info.getLineNumber()); |
119 | | - s.setTag(format(DD_CODE_ORIGIN_FRAME, i, "type"), info.getClassName()); |
120 | | - if (i == 0 && entrySpanProbe) { |
121 | | - s.setTag(format(DD_CODE_ORIGIN_FRAME, i, "signature"), where.getSignature()); |
122 | | - } |
123 | | - if (i == 0 && snapshotId != null) { |
124 | | - s.setTag(format(DD_CODE_ORIGIN_FRAME, i, "snapshot_id"), snapshotId); |
| 100 | + if (s.getTag(DD_CODE_ORIGIN_TYPE) == null) { |
| 101 | + s.setTag(DD_CODE_ORIGIN_TYPE, entrySpanProbe ? "entry" : "exit"); |
| 102 | + |
| 103 | + for (int i = 0; i < entries.size(); i++) { |
| 104 | + StackTraceElement info = entries.get(i); |
| 105 | + String fileName = info.getFileName(); |
| 106 | + s.setTag(format(DD_CODE_ORIGIN_FRAME, i, "file"), fileName); |
| 107 | + s.setTag(format(DD_CODE_ORIGIN_FRAME, i, "method"), info.getMethodName()); |
| 108 | + s.setTag(format(DD_CODE_ORIGIN_FRAME, i, "line"), info.getLineNumber()); |
| 109 | + s.setTag(format(DD_CODE_ORIGIN_FRAME, i, "type"), info.getClassName()); |
| 110 | + if (i == 0 && entrySpanProbe) { |
| 111 | + s.setTag(format(DD_CODE_ORIGIN_FRAME, i, "signature"), where.getSignature()); |
| 112 | + } |
125 | 113 | } |
126 | 114 | } |
127 | 115 | } |
| 116 | + return agentSpans; |
128 | 117 | } |
129 | 118 |
|
130 | 119 | public boolean entrySpanProbe() { |
|
0 commit comments