Skip to content

Commit c60c4ff

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 bcdb2b7 commit c60c4ff

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

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

Lines changed: 19 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,9 @@ private void setFinalResult(
290295
System.nanoTime() - startTime, /*unused*/
291296
0);
292297

298+
tracingInfo.recordException(e);
299+
tracingInfo.setStatus(TracingInfo.StatusCode.ERROR, e.toString());
300+
tracingInfo.recordException(e);
293301
tracingInfo.tracingFinished();
294302
}
295303
}
@@ -315,6 +323,8 @@ private void setFinalException(
315323

316324
cancelPendingExecutions(execution);
317325

326+
tracingInfo.recordException(exception);
327+
tracingInfo.setStatus(TracingInfo.StatusCode.ERROR, exception.toString());
318328
tracingInfo.tracingFinished();
319329

320330
try {
@@ -327,6 +337,7 @@ private void setFinalException(
327337
// Triggered when an execution reaches the end of the query plan.
328338
// This is only a failure if there are no other running executions.
329339
private void reportNoMoreHosts(SpeculativeExecution execution) {
340+
execution.parentTracingInfo.setStatus(TracingInfo.StatusCode.ERROR);
330341
execution.parentTracingInfo.tracingFinished();
331342
runningExecutions.remove(execution);
332343
if (runningExecutions.isEmpty())
@@ -669,6 +680,7 @@ void cancel() {
669680
CancelledSpeculativeExecutionException.INSTANCE,
670681
System.nanoTime() - startTime);
671682
}
683+
parentTracingInfo.setStatus(TracingInfo.StatusCode.OK);
672684
parentTracingInfo.tracingFinished();
673685
return;
674686
} else if (!previous.inProgress
@@ -682,6 +694,7 @@ void cancel() {
682694
CancelledSpeculativeExecutionException.INSTANCE,
683695
System.nanoTime() - startTime);
684696
}
697+
parentTracingInfo.setStatus(TracingInfo.StatusCode.OK);
685698
parentTracingInfo.tracingFinished();
686699
return;
687700
}
@@ -698,6 +711,7 @@ public Message.Request request() {
698711
@Override
699712
public void onSet(
700713
Connection connection, Message.Response response, long latency, int retryCount) {
714+
currentChildTracingInfo.setStatus(TracingInfo.StatusCode.OK);
701715
currentChildTracingInfo.tracingFinished();
702716

703717
QueryState queryState = queryStateRef.get();
@@ -1008,6 +1022,8 @@ public boolean onTimeout(Connection connection, long latency, int retryCount) {
10081022
@Override
10091023
public void onException(
10101024
Connection connection, Exception exception, long latency, int retryCount) {
1025+
currentChildTracingInfo.recordException(exception);
1026+
currentChildTracingInfo.setStatus(TracingInfo.StatusCode.ERROR);
10111027
currentChildTracingInfo.tracingFinished();
10121028

10131029
QueryState queryState = queryStateRef.get();
@@ -1047,6 +1063,7 @@ public void onException(
10471063

10481064
@Override
10491065
public boolean onTimeout(Connection connection, long latency, int retryCount) {
1066+
currentChildTracingInfo.setStatus(TracingInfo.StatusCode.ERROR, "timeout");
10501067
currentChildTracingInfo.tracingFinished();
10511068

10521069
QueryState queryState = queryStateRef.get();
@@ -1090,11 +1107,13 @@ public int retryCount() {
10901107
}
10911108

10921109
private void setFinalException(Connection connection, Exception exception) {
1110+
parentTracingInfo.setStatus(TracingInfo.StatusCode.ERROR);
10931111
parentTracingInfo.tracingFinished();
10941112
RequestHandler.this.setFinalException(this, connection, exception);
10951113
}
10961114

10971115
private void setFinalResult(Connection connection, Message.Response response) {
1116+
parentTracingInfo.setStatus(TracingInfo.StatusCode.OK);
10981117
parentTracingInfo.tracingFinished();
10991118
RequestHandler.this.setFinalResult(this, connection, response);
11001119
}

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)