Skip to content

Commit b22e723

Browse files
committed
Rename exceptionId to exceptionCaptureId
add exceptionHash and frame index in snapshot attributes
1 parent fe9f968 commit b22e723

File tree

6 files changed

+40
-18
lines changed

6 files changed

+40
-18
lines changed

dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/exception/DefaultExceptionDebugger.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
public class DefaultExceptionDebugger implements DebuggerContext.ExceptionDebugger {
2929
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultExceptionDebugger.class);
3030
public static final String DD_DEBUG_ERROR_PREFIX = "_dd.debug.error.";
31-
public static final String DD_DEBUG_ERROR_EXCEPTION_ID = DD_DEBUG_ERROR_PREFIX + "exception_id";
31+
public static final String DD_DEBUG_ERROR_EXCEPTION_CAPTURE_ID =
32+
DD_DEBUG_ERROR_PREFIX + "exception_capture_id";
3233
public static final String DD_DEBUG_ERROR_EXCEPTION_HASH =
3334
DD_DEBUG_ERROR_PREFIX + "exception_hash";
3435
public static final String ERROR_DEBUG_INFO_CAPTURED = "error.debug_info_captured";
@@ -129,7 +130,7 @@ private static void processSnapshotsAndSetTags(
129130
ThrowableState state,
130131
List<Throwable> chainedExceptions,
131132
String fingerprint) {
132-
if (span.getTag(DD_DEBUG_ERROR_EXCEPTION_ID) != null) {
133+
if (span.getTag(DD_DEBUG_ERROR_EXCEPTION_CAPTURE_ID) != null) {
133134
LOGGER.debug("Clear previous frame tags");
134135
// already set for this span, clear the frame tags
135136
span.getTags()
@@ -159,17 +160,21 @@ private static void processSnapshotsAndSetTags(
159160
span.setTag(tagName, snapshot.getId());
160161
LOGGER.debug("add tag to span[{}]: {}: {}", span.getSpanId(), tagName, snapshot.getId());
161162
if (!state.isSnapshotSent()) {
163+
// decorate snapshot with specific exception information
164+
snapshot.setFrameIndex(String.valueOf(frameIndex));
165+
snapshot.setExceptionHash(fingerprint);
166+
snapshot.setExceptionCaptureId(state.getExceptionId());
162167
DebuggerAgent.getSink().addSnapshot(snapshot);
163168
}
164169
snapshotAssigned = true;
165170
}
166171
if (snapshotAssigned) {
167172
state.markAsSnapshotSent();
168-
span.setTag(DD_DEBUG_ERROR_EXCEPTION_ID, state.getExceptionId());
173+
span.setTag(DD_DEBUG_ERROR_EXCEPTION_CAPTURE_ID, state.getExceptionId());
169174
LOGGER.debug(
170175
"add tag to span[{}]: {}: {}",
171176
span.getSpanId(),
172-
DD_DEBUG_ERROR_EXCEPTION_ID,
177+
DD_DEBUG_ERROR_EXCEPTION_CAPTURE_ID,
173178
state.getExceptionId());
174179
span.setTag(ERROR_DEBUG_INFO_CAPTURED, true);
175180
span.setTag(DD_DEBUG_ERROR_EXCEPTION_HASH, fingerprint);

dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/exception/ExceptionProbeManager.java

-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ public void addSnapshot(Snapshot snapshot) {
160160
ThrowableState state =
161161
snapshotsByThrowable.computeIfAbsent(
162162
throwable, key -> new ThrowableState(RandomUtils.randomUUID().toString()));
163-
snapshot.setExceptionId(state.getExceptionId());
164163
state.addSnapshot(snapshot);
165164
}
166165

dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/probe/ExceptionProbe.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public void commit(
138138
"committing exception probe id={}, snapshot id={}, exception id={}",
139139
id,
140140
snapshot.getId(),
141-
snapshot.getExceptionId());
141+
snapshot.getExceptionCaptureId());
142142
}
143143
}
144144

dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/sink/Snapshot.java

+15-5
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ public class Snapshot {
3232
private List<EvaluationError> evaluationErrors;
3333
private transient String message;
3434
private final transient int maxDepth;
35-
private String exceptionId;
35+
private String exceptionHash;
36+
private String exceptionCaptureId;
37+
private String frameIndex;
3638
private transient int chainedExceptionIdx;
3739

3840
public Snapshot(java.lang.Thread thread, ProbeImplementation probeImplementation, int maxDepth) {
@@ -88,8 +90,16 @@ public void setMessage(String message) {
8890
this.message = message;
8991
}
9092

91-
public void setExceptionId(String exceptionId) {
92-
this.exceptionId = exceptionId;
93+
public void setExceptionHash(String exceptionHash) {
94+
this.exceptionHash = exceptionHash;
95+
}
96+
97+
public void setExceptionCaptureId(String exceptionCaptureId) {
98+
this.exceptionCaptureId = exceptionCaptureId;
99+
}
100+
101+
public void setFrameIndex(String frameIndex) {
102+
this.frameIndex = frameIndex;
93103
}
94104

95105
public void setChainedExceptionIdx(int chainedExceptionIdx) {
@@ -179,8 +189,8 @@ public int getMaxDepth() {
179189
return maxDepth;
180190
}
181191

182-
public String getExceptionId() {
183-
return exceptionId;
192+
public String getExceptionCaptureId() {
193+
return exceptionCaptureId;
184194
}
185195

186196
public int getChainedExceptionIdx() {

dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/exception/DefaultExceptionDebuggerTest.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ public void nestedException() {
116116
.getExceptionProbeManager()
117117
.getStateByThrowable(ExceptionHelper.getInnerMostThrowable(exception));
118118
assertEquals(
119-
state.getExceptionId(), spanTags.get(DefaultExceptionDebugger.DD_DEBUG_ERROR_EXCEPTION_ID));
119+
state.getExceptionId(),
120+
spanTags.get(DefaultExceptionDebugger.DD_DEBUG_ERROR_EXCEPTION_CAPTURE_ID));
120121
Map<String, Snapshot> snapshotMap =
121122
listener.snapshots.stream().collect(toMap(Snapshot::getId, Function.identity()));
122123
List<String> lines = parseStackTrace(exception);
@@ -190,7 +191,8 @@ public void doubleNestedException() {
190191
.getExceptionProbeManager()
191192
.getStateByThrowable(ExceptionHelper.getInnerMostThrowable(nestedException));
192193
assertEquals(
193-
state.getExceptionId(), spanTags.get(DefaultExceptionDebugger.DD_DEBUG_ERROR_EXCEPTION_ID));
194+
state.getExceptionId(),
195+
spanTags.get(DefaultExceptionDebugger.DD_DEBUG_ERROR_EXCEPTION_CAPTURE_ID));
194196
Map<String, Snapshot> snapshotMap =
195197
listener.snapshots.stream().collect(toMap(Snapshot::getId, Function.identity()));
196198
List<String> lines = parseStackTrace(nestedException);
@@ -255,7 +257,8 @@ public void nestedExceptionFullThirdParty() {
255257
.getExceptionProbeManager()
256258
.getStateByThrowable(ExceptionHelper.getInnerMostThrowable(exception));
257259
assertEquals(
258-
state.getExceptionId(), spanTags.get(DefaultExceptionDebugger.DD_DEBUG_ERROR_EXCEPTION_ID));
260+
state.getExceptionId(),
261+
spanTags.get(DefaultExceptionDebugger.DD_DEBUG_ERROR_EXCEPTION_CAPTURE_ID));
259262
Map<String, Snapshot> snapshotMap =
260263
listener.snapshots.stream().collect(toMap(Snapshot::getId, Function.identity()));
261264
List<String> lines = parseStackTrace(exception);

dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/exception/ExceptionProbeInstrumentationTest.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.datadog.debugger.exception;
22

33
import static com.datadog.debugger.agent.ConfigurationAcceptor.Source.REMOTE_CONFIG;
4+
import static com.datadog.debugger.exception.DefaultExceptionDebugger.DD_DEBUG_ERROR_EXCEPTION_CAPTURE_ID;
45
import static com.datadog.debugger.exception.DefaultExceptionDebugger.DD_DEBUG_ERROR_EXCEPTION_HASH;
5-
import static com.datadog.debugger.exception.DefaultExceptionDebugger.DD_DEBUG_ERROR_EXCEPTION_ID;
66
import static com.datadog.debugger.exception.DefaultExceptionDebugger.ERROR_DEBUG_INFO_CAPTURED;
77
import static com.datadog.debugger.exception.DefaultExceptionDebugger.SNAPSHOT_ID_TAG_FMT;
88
import static com.datadog.debugger.util.MoshiSnapshotTestHelper.getValue;
@@ -145,7 +145,8 @@ public void instrumentAndCaptureSnapshots() throws Exception {
145145
assertEquals(
146146
location.getType() + "." + location.getMethod(), snapshot0.getStack().get(0).getFunction());
147147
MutableSpan span = traceInterceptor.getFirstSpan();
148-
assertEquals(snapshot0.getExceptionId(), span.getTags().get(DD_DEBUG_ERROR_EXCEPTION_ID));
148+
assertEquals(
149+
snapshot0.getExceptionCaptureId(), span.getTags().get(DD_DEBUG_ERROR_EXCEPTION_CAPTURE_ID));
149150
assertEquals(fingerprint, span.getTags().get(DD_DEBUG_ERROR_EXCEPTION_HASH));
150151
assertEquals(Boolean.TRUE, span.getTags().get(ERROR_DEBUG_INFO_CAPTURED));
151152
assertEquals(snapshot0.getId(), span.getTags().get(String.format(SNAPSHOT_ID_TAG_FMT, 0)));
@@ -187,11 +188,15 @@ public void differentExceptionsSameStack() throws Exception {
187188
assertProbeId(probeIdsByMethodName, "processWithException", snapshot1.getProbe().getId());
188189
assertExceptionMsg("illegal argument", snapshot1);
189190
MutableSpan span0 = traceInterceptor.getAllTraces().get(0).get(0);
190-
assertEquals(snapshot0.getExceptionId(), span0.getTags().get(DD_DEBUG_ERROR_EXCEPTION_ID));
191+
assertEquals(
192+
snapshot0.getExceptionCaptureId(),
193+
span0.getTags().get(DD_DEBUG_ERROR_EXCEPTION_CAPTURE_ID));
191194
assertEquals(Boolean.TRUE, span0.getTags().get(ERROR_DEBUG_INFO_CAPTURED));
192195
assertEquals(snapshot0.getId(), span0.getTags().get(String.format(SNAPSHOT_ID_TAG_FMT, 0)));
193196
MutableSpan span1 = traceInterceptor.getAllTraces().get(1).get(0);
194-
assertEquals(snapshot1.getExceptionId(), span1.getTags().get(DD_DEBUG_ERROR_EXCEPTION_ID));
197+
assertEquals(
198+
snapshot1.getExceptionCaptureId(),
199+
span1.getTags().get(DD_DEBUG_ERROR_EXCEPTION_CAPTURE_ID));
195200
assertEquals(Boolean.TRUE, span1.getTags().get(ERROR_DEBUG_INFO_CAPTURED));
196201
assertEquals(snapshot1.getId(), span1.getTags().get(String.format(SNAPSHOT_ID_TAG_FMT, 0)));
197202
}

0 commit comments

Comments
 (0)