Skip to content
This repository has been archived by the owner on Dec 23, 2023. It is now read-only.

Commit

Permalink
Upgrade google-cloud-logging and set new LogEntry spanId field.
Browse files Browse the repository at this point in the history
  • Loading branch information
sebright committed Jun 12, 2018
1 parent edb8a46 commit d1bb669
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ subprojects {
errorprone: "com.google.errorprone:error_prone_annotations:${errorProneVersion}",
findbugs_annotations: "com.google.code.findbugs:annotations:${findBugsVersion}",
google_auth: "com.google.auth:google-auth-library-credentials:${googleAuthVersion}",
google_cloud_logging: "com.google.cloud:google-cloud-logging:1.30.0",
google_cloud_logging: "com.google.cloud:google-cloud-logging:1.33.0",
google_cloud_logging_logback: "com.google.cloud:google-cloud-logging-logback:0.48.0-alpha",
google_cloud_trace: "com.google.cloud:google-cloud-trace:${googleCloudVersion}",
zipkin_reporter: "io.zipkin.reporter2:zipkin-reporter:${zipkinReporterVersion}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
*/
@ExperimentalApi
public final class OpenCensusTraceLoggingEnhancer implements LoggingEnhancer {
private static final String SPAN_ID_KEY = "span_id";
private static final String SAMPLED_KEY = "sampled";

private static final Tracer tracer = Tracing.getTracer();
Expand All @@ -44,9 +43,9 @@ public OpenCensusTraceLoggingEnhancer() {}
public void enhanceLogEntry(LogEntry.Builder builder) {
SpanContext span = tracer.getCurrentSpan().getContext();
builder.setTrace(formatTraceId(span.getTraceId()));
builder.setSpanId(span.getSpanId().toLowerBase16());

// TODO(sebright): Find the correct way to add span ID and sampling decision.
builder.addLabel(SPAN_ID_KEY, span.getSpanId().toLowerBase16());
// TODO(sebright): Find the correct way to add the sampling decision.
builder.addLabel(SAMPLED_KEY, Boolean.toString(span.getTraceOptions().isSampled()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ private static void testLoggingEnhancer(
LogEntry.Builder builder = LogEntry.newBuilder(null);
new OpenCensusTraceLoggingEnhancer().enhanceLogEntry(builder);
LogEntry logEntry = builder.build();
assertThat(logEntry.getLabels().get("span_id")).isEqualTo(spanId);
assertThat(logEntry.getLabels().get("sampled")).isEqualTo(isSampled ? "true" : "false");
assertThat(logEntry.getTrace()).isEqualTo("projects/" + projectId + "/traces/" + traceId);
assertThat(logEntry.getSpanId()).isEqualTo(spanId);
} finally {
scope.close();
}
Expand All @@ -101,10 +101,10 @@ public void enhanceLogEntry_BlankSpan() {
LogEntry.Builder builder = LogEntry.newBuilder(null);
new OpenCensusTraceLoggingEnhancer().enhanceLogEntry(builder);
LogEntry logEntry = builder.build();
assertThat(logEntry.getLabels().get("span_id")).isEqualTo("0000000000000000");
assertThat(logEntry.getLabels().get("sampled")).isEqualTo("false");
assertThat(logEntry.getTrace())
.isEqualTo("projects/my-test-project-3/traces/00000000000000000000000000000000");
assertThat(logEntry.getSpanId()).isEqualTo("0000000000000000");
} finally {
scope.close();
}
Expand Down

0 comments on commit d1bb669

Please sign in to comment.