use of io.opencensus.trace.export.SpanData in project instrumentation-java by census-instrumentation.
the class ZipkinExporterHandlerTest method generateSpan_ServerKind.
@Test
public void generateSpan_ServerKind() {
SpanData data = SpanData.create(SpanContext.create(TraceId.fromLowerBase16(TRACE_ID), SpanId.fromLowerBase16(SPAN_ID), TraceOptions.builder().setIsSampled(true).build()), // TODO SpanId.fromLowerBase16
SpanId.fromLowerBase16(PARENT_SPAN_ID), true, /* hasRemoteParent */
"Recv.helloworld.Greeter.SayHello", /* name */
Kind.SERVER, /* kind */
Timestamp.create(1505855794, 194009601), /* startTimestamp */
Attributes.create(attributes, 0), TimedEvents.create(annotations, 0), TimedEvents.create(messageEvents, 0), Links.create(Collections.<Link>emptyList(), 0), null, /* childSpanCount */
Status.OK, Timestamp.create(1505855799, 465726528));
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, "OK").build());
}
use of io.opencensus.trace.export.SpanData in project instrumentation-java by census-instrumentation.
the class ZipkinExporterHandlerTest method generateSpan_WithAttributes.
@Test
public void generateSpan_WithAttributes() {
Map<String, AttributeValue> attributeMap = new HashMap<String, AttributeValue>();
attributeMap.put("string", AttributeValue.stringAttributeValue("string value"));
attributeMap.put("boolean", AttributeValue.booleanAttributeValue(false));
attributeMap.put("long", AttributeValue.longAttributeValue(9999L));
SpanData data = SpanData.create(SpanContext.create(TraceId.fromLowerBase16(TRACE_ID), SpanId.fromLowerBase16(SPAN_ID), TraceOptions.builder().setIsSampled(true).build()), // TODO SpanId.fromLowerBase16
SpanId.fromLowerBase16(PARENT_SPAN_ID), true, /* hasRemoteParent */
"Sent.helloworld.Greeter.SayHello", /* name */
Kind.CLIENT, /* kind */
Timestamp.create(1505855794, 194009601), /* startTimestamp */
Attributes.create(attributeMap, 0), TimedEvents.create(annotations, 0), TimedEvents.create(messageEvents, 0), Links.create(Collections.<Link>emptyList(), 0), null, /* childSpanCount */
Status.OK, Timestamp.create(1505855799, 465726528));
assertThat(ZipkinExporterHandler.generateSpan(data, localEndpoint)).isEqualTo(Span.newBuilder().traceId(TRACE_ID).parentId(PARENT_SPAN_ID).id(SPAN_ID).kind(Span.Kind.CLIENT).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, "OK").putTag("string", "string value").putTag("boolean", "false").putTag("long", "9999").build());
}
use of io.opencensus.trace.export.SpanData in project instrumentation-java by census-instrumentation.
the class ZipkinExporterHandlerTest method generateSpan_WithErrorStatus.
@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), TimedEvents.create(annotations, 0), TimedEvents.create(messageEvents, 0), Links.create(Collections.<Link>emptyList(), 0), null, /* childSpanCount */
Status.DEADLINE_EXCEEDED.withDescription(errorMessage), Timestamp.create(1505855799, 465726528));
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());
}
use of io.opencensus.trace.export.SpanData in project instrumentation-java by census-instrumentation.
the class SpanBuilderImplTest method startSpanNullParentWithRecordEvents.
@Test
public void startSpanNullParentWithRecordEvents() {
RecordEventsSpanImpl span = (RecordEventsSpanImpl) SpanBuilderImpl.createWithParent(SPAN_NAME, null, spanBuilderOptions).setSampler(Samplers.neverSample()).setRecordEvents(true).startSpan();
assertThat(span.getContext().isValid()).isTrue();
assertThat(span.getOptions().contains(Options.RECORD_EVENTS)).isTrue();
assertThat(span.getContext().getTraceOptions().isSampled()).isFalse();
SpanData spanData = span.toSpanData();
assertThat(spanData.getParentSpanId()).isNull();
assertThat(spanData.getHasRemoteParent()).isNull();
}
use of io.opencensus.trace.export.SpanData in project instrumentation-java by census-instrumentation.
the class SpanBuilderImplTest method startRemoteSpanInvalidParent.
@Test
public void startRemoteSpanInvalidParent() {
RecordEventsSpanImpl span = (RecordEventsSpanImpl) SpanBuilderImpl.createWithRemoteParent(SPAN_NAME, SpanContext.INVALID, spanBuilderOptions).startSpan();
assertThat(span.getContext().isValid()).isTrue();
assertThat(span.getOptions().contains(Options.RECORD_EVENTS)).isTrue();
assertThat(span.getContext().getTraceOptions().isSampled()).isTrue();
SpanData spanData = span.toSpanData();
assertThat(spanData.getParentSpanId()).isNull();
assertThat(spanData.getHasRemoteParent()).isNull();
}
Aggregations