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(); }
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { if ("com.alibaba.dubbo.monitor.MonitorService".equals(invoker.getInterface().getName())) { return invoker.invoke(invocation); } RpcContext context = RpcContext.getContext(); //Request中的spanId是上一个Span的id,当前的spanId在后面会重新join一次,所以此处添加spanId理解不对 serverRequestInterceptor.handle(new DubboServerRequestAdapter(context, invocation)); //ServerTrace Add to MDC ServerSpan serverSpan = serverSpanThreadBinder.getCurrentServerSpan(); if(Objects.equal(Boolean.TRUE,serverSpan.getSample())){ Span span = serverSpan.getSpan(); MDC.put(ZIPKIN_TRACEID_MDC, convertToString(span.getTrace_id())); MDC.put(ZIPKIN_SPANID_MDC, convertToString(span.getId())); if (span.getParent_id() != null) { MDC.put(ZIPKIN_PARENTID_MDC, convertToString(span.getParent_id())); } else { MDC.remove(ZIPKIN_PARENTID_MDC); } } Result result = invoker.invoke(invocation); serverResponseInterceptor.handle(new DubboServerResponseAdapter(result)); MDC.remove(ZIPKIN_TRACEID_MDC); MDC.remove(ZIPKIN_SPANID_MDC); MDC.remove(ZIPKIN_PARENTID_MDC); return result; }
MDC.put(ZIPKIN_TRACEID_MDC, convertToString(span.getTrace_id())); MDC.put(ZIPKIN_SPANID_MDC, convertToString(span.getId())); if (span.getParent_id() != null) { MDC.put(ZIPKIN_PARENTID_MDC, convertToString(span.getParent_id())); } else { MDC.remove(ZIPKIN_PARENTID_MDC);
@Override public SpanId context(Span span) { if (span.context != null) return span.context; // If we got here, some implementation of state passed a deprecated span // If no ids were set, it is junk, so return null if (span.trace_id == 0 && span.parent_id == null && span.id == 0) return null; // Attempt to backfill the span context synchronized (span) { if (span.context != null) return span.context; span.context = SpanId.builder() .traceIdHigh(span.getTrace_id_high()) .traceId(span.getTrace_id()) .parentId(span.getParent_id()) .spanId(span.getId()) .debug(span.debug != null ? span.debug : false) .build(); } return span.context; } };
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 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 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(); }