Skip to content

Commit bfaf37d

Browse files
committed
Instrumenting RequestHandler: added 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 8561cf6 commit bfaf37d

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ private void setFinalResult(
281281
logServerWarnings(response.warnings);
282282
}
283283
callback.onSet(connection, response, info, statement, System.nanoTime() - startTime);
284+
tracingInfo.setStatus(TracingInfo.StatusCode.OK);
284285
tracingInfo.tracingFinished();
285286
} catch (Exception e) {
286287
callback.onException(
@@ -290,6 +291,8 @@ private void setFinalResult(
290291
System.nanoTime() - startTime, /*unused*/
291292
0);
292293

294+
tracingInfo.setStatus(TracingInfo.StatusCode.ERROR, e.toString());
295+
tracingInfo.recordException(e);
293296
tracingInfo.tracingFinished();
294297
}
295298
}
@@ -315,6 +318,8 @@ private void setFinalException(
315318

316319
cancelPendingExecutions(execution);
317320

321+
tracingInfo.recordException(exception);
322+
tracingInfo.setStatus(TracingInfo.StatusCode.ERROR, exception.toString());
318323
tracingInfo.tracingFinished();
319324

320325
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)