Skip to content

Commit a9a4a8d

Browse files
committed
Tracing: added request status codes and exceptions
After a request is completed, its status code (OK or ERROR) is added to trace data, as well as exception information (if one occured).
1 parent 725cd33 commit a9a4a8d

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

driver-core/src/main/java/com/datastax/driver/core/RequestHandler.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,11 @@ private void setFinalResult(
281281
logServerWarnings(response.warnings);
282282
}
283283
callback.onSet(connection, response, info, statement, System.nanoTime() - startTime);
284+
285+
tracingInfo.setStatus(
286+
response.type == Message.Response.Type.ERROR
287+
? TracingInfo.StatusCode.ERROR
288+
: TracingInfo.StatusCode.OK);
284289
tracingInfo.tracingFinished();
285290
} catch (Exception e) {
286291
callback.onException(
@@ -290,6 +295,8 @@ private void setFinalResult(
290295
System.nanoTime() - startTime, /*unused*/
291296
0);
292297

298+
tracingInfo.setStatus(TracingInfo.StatusCode.ERROR, e.toString());
299+
tracingInfo.recordException(e);
293300
tracingInfo.tracingFinished();
294301
}
295302
}
@@ -315,6 +322,8 @@ private void setFinalException(
315322

316323
cancelPendingExecutions(execution);
317324

325+
tracingInfo.recordException(exception);
326+
tracingInfo.setStatus(TracingInfo.StatusCode.ERROR, exception.toString());
318327
tracingInfo.tracingFinished();
319328

320329
try {

driver-core/src/main/java/com/datastax/driver/core/tracing/NoopTracingInfoFactory.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ private static class NoopTracingInfo implements TracingInfo {
2222
@Override
2323
public void setNameAndStartTime(String name) {}
2424

25+
@Override
26+
public void recordException(Exception exception) {}
27+
28+
@Override
29+
public void setStatus(StatusCode code, String description) {}
30+
31+
@Override
32+
public void setStatus(StatusCode code) {}
33+
2534
@Override
2635
public void tracingFinished() {}
2736
}

driver-core/src/main/java/com/datastax/driver/core/tracing/TracingInfo.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
*/
2323
public interface TracingInfo {
2424

25+
/** Final status of the traced execution. */
26+
enum StatusCode {
27+
OK,
28+
ERROR,
29+
}
30+
2531
/**
2632
* Starts a span corresponding to this {@link TracingInfo} object. Must be called exactly once,
2733
* before any other method, at the beginning of the traced execution.
@@ -30,6 +36,28 @@ public interface TracingInfo {
3036
*/
3137
void setNameAndStartTime(String name);
3238

39+
/**
40+
* Records in the trace that the provided exception occured.
41+
*
42+
* @param exception the exception to be recorded.
43+
*/
44+
void recordException(Exception exception);
45+
46+
/**
47+
* Sets the final status of the traced execution.
48+
*
49+
* @param code the status code to be set.
50+
*/
51+
void setStatus(StatusCode code);
52+
53+
/**
54+
* Sets the final status of the traced execution, with additional description.
55+
*
56+
* @param code the status code to be set.
57+
* @param description the additional description of the status.
58+
*/
59+
void setStatus(StatusCode code, String description);
60+
3361
/** Must be always called exactly once at the logical end of traced execution. */
3462
void tracingFinished();
3563
}

0 commit comments

Comments
 (0)