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

Exporter/Zipkin: Add a note about status tags. #1931

Merged
merged 2 commits into from
Jun 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static java.util.concurrent.TimeUnit.NANOSECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;

import com.google.common.annotations.VisibleForTesting;
import io.opencensus.common.Duration;
import io.opencensus.common.Function;
import io.opencensus.common.Functions;
Expand Down Expand Up @@ -53,8 +54,13 @@
final class ZipkinExporterHandler extends TimeLimitedHandler {
private static final Logger logger = Logger.getLogger(ZipkinExporterHandler.class.getName());
private static final String EXPORT_SPAN_NAME = "SendZipkinSpans";
private static final String STATUS_CODE = "census.status_code";
private static final String STATUS_DESCRIPTION = "census.status_description";

// The naming follows Zipkin convention. As an example see:
// https://github.com/apache/incubator-zipkin-brave/blob/643b7245c462dc14d47afcdb076b2603fd421497/instrumentation/grpc/src/main/java/brave/grpc/GrpcParser.java#L67-L73
@VisibleForTesting static final String STATUS_CODE = "census.status_code";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one important thing is that we do use non-ok as "error" message. this controls analysis etc, so I would recommend including this logic here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, added in c1f588a.

@VisibleForTesting static final String STATUS_DESCRIPTION = "census.status_description";
@VisibleForTesting static final String STATUS_ERROR = "error";

private final SpanBytesEncoder encoder;
private final Sender sender;
private final Endpoint localEndpoint;
Expand Down Expand Up @@ -130,6 +136,9 @@ static Span generateSpan(SpanData spanData, Endpoint localEndpoint) {
if (status.getDescription() != null) {
spanBuilder.putTag(STATUS_DESCRIPTION, status.getDescription());
}
if (!status.isOk()) {
spanBuilder.putTag(STATUS_ERROR, status.getCanonicalCode().toString());
}
}

for (TimedEvent<Annotation> annotation : spanData.getAnnotations().getEvents()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void generateSpan_NoKindAndRemoteParent() {
.localEndpoint(localEndpoint)
.addAnnotation(1505855799000000L + 433901068L / 1000, "RECEIVED")
.addAnnotation(1505855799000000L + 459486280L / 1000, "SENT")
.putTag("census.status_code", "OK")
.putTag(ZipkinExporterHandler.STATUS_CODE, "OK")
.build());
}

Expand Down Expand Up @@ -143,7 +143,7 @@ public void generateSpan_ServerKind() {
.localEndpoint(localEndpoint)
.addAnnotation(1505855799000000L + 433901068L / 1000, "RECEIVED")
.addAnnotation(1505855799000000L + 459486280L / 1000, "SENT")
.putTag("census.status_code", "OK")
.putTag(ZipkinExporterHandler.STATUS_CODE, "OK")
.build());
}

Expand Down Expand Up @@ -184,7 +184,7 @@ public void generateSpan_ClientKind() {
.localEndpoint(localEndpoint)
.addAnnotation(1505855799000000L + 433901068L / 1000, "RECEIVED")
.addAnnotation(1505855799000000L + 459486280L / 1000, "SENT")
.putTag("census.status_code", "OK")
.putTag(ZipkinExporterHandler.STATUS_CODE, "OK")
.build());
}

Expand Down Expand Up @@ -229,10 +229,53 @@ public void generateSpan_WithAttributes() {
.localEndpoint(localEndpoint)
.addAnnotation(1505855799000000L + 433901068L / 1000, "RECEIVED")
.addAnnotation(1505855799000000L + 459486280L / 1000, "SENT")
.putTag("census.status_code", "OK")
.putTag(ZipkinExporterHandler.STATUS_CODE, "OK")
.putTag("string", "string value")
.putTag("boolean", "false")
.putTag("long", "9999")
.build());
}

@Test
public void generateSpan_WithErrorStatus() {
String errorMessage = "timeout";
SpanData data =
SpanData.create(
SpanContext.create(
TraceId.fromLowerBase16(TRACE_ID),
SpanId.fromLowerBase16(SPAN_ID),
TraceOptions.builder().setIsSampled(true).build()),
SpanId.fromLowerBase16(PARENT_SPAN_ID),
true, /* hasRemoteParent */
"Recv.helloworld.Greeter.SayHello", /* name */
Kind.SERVER, /* kind */
Timestamp.create(1505855794, 194009601) /* startTimestamp */,
Attributes.create(attributes, 0 /* droppedAttributesCount */),
TimedEvents.create(annotations, 0 /* droppedEventsCount */),
TimedEvents.create(messageEvents, 0 /* droppedEventsCount */),
Links.create(Collections.<Link>emptyList(), 0 /* droppedLinksCount */),
null, /* childSpanCount */
Status.DEADLINE_EXCEEDED.withDescription(errorMessage),
Timestamp.create(1505855799, 465726528) /* endTimestamp */);

assertThat(ZipkinExporterHandler.generateSpan(data, localEndpoint))
.isEqualTo(
Span.newBuilder()
.traceId(TRACE_ID)
.parentId(PARENT_SPAN_ID)
.id(SPAN_ID)
.kind(Span.Kind.SERVER)
.name(data.getName())
.timestamp(1505855794000000L + 194009601L / 1000)
.duration(
(1505855799000000L + 465726528L / 1000)
- (1505855794000000L + 194009601L / 1000))
.localEndpoint(localEndpoint)
.addAnnotation(1505855799000000L + 433901068L / 1000, "RECEIVED")
.addAnnotation(1505855799000000L + 459486280L / 1000, "SENT")
.putTag(ZipkinExporterHandler.STATUS_CODE, "DEADLINE_EXCEEDED")
.putTag(ZipkinExporterHandler.STATUS_DESCRIPTION, errorMessage)
.putTag(ZipkinExporterHandler.STATUS_ERROR, "DEADLINE_EXCEEDED")
.build());
}
}