public Object getFieldValue(_Fields field) { switch (field) { case TRACE_ID: return Long.valueOf(getTrace_id()); case NAME: return getName(); case ID: return Long.valueOf(getId()); case PARENT_ID: return Long.valueOf(getParent_id()); case ANNOTATIONS: return getAnnotations(); case BINARY_ANNOTATIONS: return getBinary_annotations(); case DEBUG: return Boolean.valueOf(isDebug()); } throw new IllegalStateException(); }
public Object getFieldValue(_Fields field) { switch (field) { case TRACE_ID: return Long.valueOf(getTrace_id()); case NAME: return getName(); case ID: return Long.valueOf(getId()); case PARENT_ID: return Long.valueOf(getParent_id()); case ANNOTATIONS: return getAnnotations(); case BINARY_ANNOTATIONS: return getBinary_annotations(); case DEBUG: return Boolean.valueOf(isDebug()); } throw new IllegalStateException(); }
public Object getFieldValue(_Fields field) { switch (field) { case TRACE_ID: return Long.valueOf(getTrace_id()); case NAME: return getName(); case ID: return Long.valueOf(getId()); case PARENT_ID: return Long.valueOf(getParent_id()); case ANNOTATIONS: return getAnnotations(); case BINARY_ANNOTATIONS: return getBinary_annotations(); case DEBUG: return Boolean.valueOf(isDebug()); } throw new IllegalStateException(); }
private void endTrace(HttpServletRequest req, Span span, Stopwatch watch) { // ss annotation span.addToAnnotations( Annotation.create(Times.currentMicros(), TraceConstants.ANNO_SS, Endpoint.create(span.getName(), ServerInfo.IP4, req.getLocalPort()))); span.setDuration(watch.stop().elapsed(TimeUnit.MICROSECONDS)); // send trace spans agent.send(TraceContext.getSpans()); }
/** * Interface method implementation. * @see com.github.kristofa.brave.SpanCollector#collect(com.twitter.zipkin.gen.Span) */ public void collect(Span span) { if (!defaultAnnotations.isEmpty()) { for (final BinaryAnnotation ba : defaultAnnotations) { span.addToBinary_annotations(ba); } } ServiceProxyEvent.Builder eventBuilder = new ServiceProxyEvent.Builder(span.getName(),TRACING_COLLECTOR); eventBuilder.withSpan(span); this.eventProducer.publishEvent(eventBuilder.build()); }
private void endTrace(Invoker invoker, Result result, Span consumeSpan, Stopwatch watch) { consumeSpan.setDuration(watch.stop().elapsed(TimeUnit.MICROSECONDS)); // cr annotation URL provider = invoker.getUrl(); consumeSpan.addToAnnotations( Annotation.create(Times.currentMicros(), TraceConstants.ANNO_CR, Endpoint.create(consumeSpan.getName(), Networks.ip2Num(provider.getHost()), provider.getPort()))); // exception catch Throwable throwable = result.getException(); if (throwable != null){ // attach exception consumeSpan.addToBinary_annotations(BinaryAnnotation.create( "Exception", Throwables.getStackTraceAsString(throwable), null )); } // collect the span TraceContext.addSpan(consumeSpan); } }
@Test public void testSimpleTraces() throws IOException, InterruptedException { FakeZipkinTransport transport = new FakeZipkinTransport(); Tracer tracer = newTracer(transport); Span rootSpan = new MilliSpan.Builder(). description("root"). spanId(new SpanId(100, 100)). tracerId("test"). begin(System.currentTimeMillis()). build(); TraceScope rootScope = tracer.newScope("root"); TraceScope innerOne = tracer.newScope("innerOne"); TraceScope innerTwo = tracer.newScope("innerTwo"); innerTwo.close(); Assert.assertTrue(transport.nextMessageAsSpan().getName().contains("innerTwo")); innerOne.close(); Assert.assertTrue(transport.nextMessageAsSpan().getName().contains("innerOne")); rootSpan.addKVAnnotation("foo", "bar"); rootSpan.addTimelineAnnotation("timeline"); rootScope.close(); Assert.assertTrue(transport.nextMessageAsSpan().getName().contains("root")); tracer.close(); }
private void assertSpansAreEquivalent(Span s, com.twitter.zipkin.gen.Span zs) { assertTrue("zipkin doesn't support multiple parents to a single span.", s.getParents().length <= 1); if (s.getParents().length == 1) { assertEquals(s.getParents()[0].getLow(), zs.getParent_id()); } assertEquals(s.getSpanId().getLow(), zs.getId()); Assert.assertNotNull(zs.getAnnotations()); if (ROOT_SPAN_DESC.equals(zs.getName())) { assertEquals(5, zs.getAnnotations().size());// two start, two stop + one timeline annotation assertEquals(1, zs.getBinary_annotations().size()); } else { assertEquals(4, zs.getAnnotations().size()); } } }
private Span convert(com.twitter.zipkin.gen.Span span) { Span.Builder builder = new Span.Builder(); builder.name(span.getName()) .id(span.id) .parentId(span.isSetParent_id() ? span.parent_id : null) .traceId(span.trace_id) .timestamp(span.timestamp) .duration(span.duration) .debug(span.debug); List<com.twitter.zipkin.gen.Annotation> annotations = span.annotations; if (annotations != null) { for (com.twitter.zipkin.gen.Annotation annotation : annotations) { builder.addAnnotation(convert(annotation)); } } List<com.twitter.zipkin.gen.BinaryAnnotation> binaries = span.binary_annotations; if (binaries != null) { for (com.twitter.zipkin.gen.BinaryAnnotation annotation : binaries) { builder.addBinaryAnnotation(convert(annotation)); } } return builder.build(); }
Span span = new Span(); new TDeserializer(new TBinaryProtocol.Factory()).deserialize(span, it.next().message()); Assert.assertEquals("The span name should match our scope description", span.getName(), scopeName);
public static zipkin2.v1.V1Span toZipkin(Span span) { zipkin2.v1.V1Span.Builder result = zipkin2.v1.V1Span.newBuilder(); result.traceId(span.getTrace_id()); result.traceIdHigh(span.getTrace_id_high()); result.id(span.getId()); result.parentId(span.getParent_id() != null ? span.getParent_id() : 0L); result.name(span.getName()); result.timestamp(span.getTimestamp() != null ? span.getTimestamp() : 0L); result.duration(span.getDuration() != null ? span.getDuration() : 0L); result.debug(span.isDebug()); for (Annotation a : span.getAnnotations()) { result.addAnnotation(a.timestamp, a.value, a.host != null ? a.host.toV2() : null); } for (BinaryAnnotation a : span.getBinary_annotations()) { zipkin2.Endpoint endpoint = a.host != null ? a.host.toV2() : null; if (a.type == AnnotationType.STRING) { result.addBinaryAnnotation(a.key, new String(a.value, UTF_8), endpoint); } else if (a.type == AnnotationType.BOOL && endpoint != null) { result.addBinaryAnnotation(a.key, endpoint); } } return result.build(); }
private static zipkin.Span from(Span in) { zipkin.Span.Builder result = new zipkin.Span.Builder(); result.traceId(in.getTrace_id()); result.id(in.getId()); result.parentId(in.getParent_id()); result.name(in.getName()); result.timestamp(in.getTimestamp()); result.duration(in.getDuration()); result.debug(in.isDebug()); for (Annotation a : in.getAnnotations()) { result.addAnnotation(zipkin.Annotation.create(a.timestamp, a.value, from(a.host))); } for (BinaryAnnotation a : in.getBinary_annotations()) { result.addBinaryAnnotation(new zipkin.BinaryAnnotation.Builder() .key(a.key) .value(a.value) .type(Type.fromValue(a.type.getValue())) .endpoint(from(a.host)) .build()); } return result.build(); }