use of zipkin2.Span.Kind.SERVER in project zipkin by openzipkin.
the class V1SpanConverter method processAnnotations.
void processAnnotations(V1Span source) {
for (int i = 0, length = source.annotations.size(); i < length; i++) {
V1Annotation a = source.annotations.get(i);
Span.Builder currentSpan = forEndpoint(source, a.endpoint);
// core annotations require an endpoint. Don't give special treatment when that's missing
if (a.value.length() == 2 && a.endpoint != null) {
if (a.value.equals("cs")) {
currentSpan.kind(Kind.CLIENT);
cs = a;
} else if (a.value.equals("sr")) {
currentSpan.kind(Kind.SERVER);
sr = a;
} else if (a.value.equals("ss")) {
currentSpan.kind(Kind.SERVER);
ss = a;
} else if (a.value.equals("cr")) {
currentSpan.kind(Kind.CLIENT);
cr = a;
} else if (a.value.equals("ms")) {
currentSpan.kind(Kind.PRODUCER);
ms = a;
} else if (a.value.equals("mr")) {
currentSpan.kind(Kind.CONSUMER);
mr = a;
} else if (a.value.equals("ws")) {
ws = a;
} else if (a.value.equals("wr")) {
wr = a;
} else {
currentSpan.addAnnotation(a.timestamp, a.value);
}
} else {
currentSpan.addAnnotation(a.timestamp, a.value);
}
}
// When bridging between event and span model, you can end up missing a start annotation
if (cs == null && endTimestampReflectsSpanDuration(cr, source)) {
cs = V1Annotation.create(source.timestamp, "cs", cr.endpoint);
}
if (sr == null && endTimestampReflectsSpanDuration(ss, source)) {
sr = V1Annotation.create(source.timestamp, "sr", ss.endpoint);
}
if (cs != null && sr != null) {
// in a shared span, the client side owns span duration by annotations or explicit timestamp
maybeTimestampDuration(source, cs, cr);
// special-case loopback: We need to make sure on loopback there are two span2s
Span.Builder client = forEndpoint(source, cs.endpoint);
Span.Builder server;
if (hasSameServiceName(cs.endpoint, sr.endpoint)) {
client.kind(Kind.CLIENT);
// fork a new span for the server side
server = newSpanBuilder(source, sr.endpoint).kind(Kind.SERVER);
} else {
server = forEndpoint(source, sr.endpoint);
}
// the server side is smaller than that, we have to read annotations to find out
server.shared(true).timestamp(sr.timestamp);
if (ss != null)
server.duration(ss.timestamp - sr.timestamp);
// one-way has no duration
if (cr == null && source.duration == 0)
client.duration(null);
} else if (cs != null && cr != null) {
maybeTimestampDuration(source, cs, cr);
} else if (sr != null && ss != null) {
maybeTimestampDuration(source, sr, ss);
} else {
// otherwise, the span is incomplete. revert special-casing
handleIncompleteRpc(source);
}
// implied shared. When we only see the server-side, carry this signal over.
if (cs == null && sr != null && // case could be due to the client-side of that RPC.
(source.timestamp == 0 || (ss != null && source.duration == 0))) {
forEndpoint(source, sr.endpoint).shared(true);
}
// ms and mr are not supposed to be in the same span, but in case they are..
if (ms != null && mr != null) {
// special-case loopback: We need to make sure on loopback there are two span2s
Span.Builder producer = forEndpoint(source, ms.endpoint);
Span.Builder consumer;
if (hasSameServiceName(ms.endpoint, mr.endpoint)) {
producer.kind(Kind.PRODUCER);
// fork a new span for the consumer side
consumer = newSpanBuilder(source, mr.endpoint).kind(Kind.CONSUMER);
} else {
consumer = forEndpoint(source, mr.endpoint);
}
consumer.shared(true);
if (wr != null) {
consumer.timestamp(wr.timestamp).duration(mr.timestamp - wr.timestamp);
} else {
consumer.timestamp(mr.timestamp);
}
producer.timestamp(ms.timestamp).duration(ws != null ? ws.timestamp - ms.timestamp : null);
} else if (ms != null) {
maybeTimestampDuration(source, ms, ws);
} else if (mr != null) {
if (wr != null) {
maybeTimestampDuration(source, wr, mr);
} else {
maybeTimestampDuration(source, mr, null);
}
} else {
if (ws != null)
forEndpoint(source, ws.endpoint).addAnnotation(ws.timestamp, ws.value);
if (wr != null)
forEndpoint(source, wr.endpoint).addAnnotation(wr.timestamp, wr.value);
}
}
use of zipkin2.Span.Kind.SERVER in project zipkin by openzipkin.
the class V2SpanConverter method convert.
public V1Span convert(Span value) {
md.parse(value);
result.clear().traceId(value.traceId()).parentId(value.parentId()).id(value.id()).name(value.name()).debug(value.debug());
// Don't report timestamp and duration on shared spans (should be server, but not necessarily)
if (!Boolean.TRUE.equals(value.shared())) {
result.timestamp(value.timestampAsLong());
result.duration(value.durationAsLong());
}
boolean beginAnnotation = md.startTs != 0L && md.begin != null;
boolean endAnnotation = md.endTs != 0L && md.end != null;
Endpoint ep = value.localEndpoint();
int annotationCount = value.annotations().size();
if (beginAnnotation) {
annotationCount++;
result.addAnnotation(md.startTs, md.begin, ep);
}
for (int i = 0, length = value.annotations().size(); i < length; i++) {
Annotation a = value.annotations().get(i);
if (beginAnnotation && a.value().equals(md.begin))
continue;
if (endAnnotation && a.value().equals(md.end))
continue;
result.addAnnotation(a.timestamp(), a.value(), ep);
}
if (endAnnotation) {
annotationCount++;
result.addAnnotation(md.endTs, md.end, ep);
}
for (Map.Entry<String, String> b : value.tags().entrySet()) {
result.addBinaryAnnotation(b.getKey(), b.getValue(), ep);
}
boolean writeLocalComponent = annotationCount == 0 && ep != null && value.tags().isEmpty();
boolean hasRemoteEndpoint = md.addr != null && value.remoteEndpoint() != null;
// write an empty "lc" annotation to avoid missing the localEndpoint in an in-process span
if (writeLocalComponent)
result.addBinaryAnnotation("lc", "", ep);
if (hasRemoteEndpoint)
result.addBinaryAnnotation(md.addr, value.remoteEndpoint());
return result.build();
}
use of zipkin2.Span.Kind.SERVER in project java by wavefrontHQ.
the class ZipkinPortUnificationHandlerTest method testZipkinHandler.
@Test
public void testZipkinHandler() throws Exception {
ZipkinPortUnificationHandler handler = new ZipkinPortUnificationHandler("9411", new NoopHealthCheckManager(), mockTraceHandler, mockTraceSpanLogsHandler, null, () -> false, () -> false, null, new SpanSampler(new RateSampler(1.0D), () -> null), "ProxyLevelAppTag", null);
Endpoint localEndpoint1 = Endpoint.newBuilder().serviceName("frontend").ip("10.0.0.1").build();
zipkin2.Span spanServer1 = zipkin2.Span.newBuilder().traceId("2822889fe47043bd").id("2822889fe47043bd").kind(zipkin2.Span.Kind.SERVER).name("getservice").timestamp(startTime * 1000).duration(1234 * 1000).localEndpoint(localEndpoint1).putTag("http.method", "GET").putTag("http.url", "none+h1c://localhost:8881/").putTag("http.status_code", "200").build();
Endpoint localEndpoint2 = Endpoint.newBuilder().serviceName("backend").ip("10.0.0.1").build();
zipkin2.Span spanServer2 = zipkin2.Span.newBuilder().traceId("2822889fe47043bd").id("d6ab73f8a3930ae8").parentId("2822889fe47043bd").kind(zipkin2.Span.Kind.SERVER).name("getbackendservice").timestamp(startTime * 1000).duration(2234 * 1000).localEndpoint(localEndpoint2).putTag("http.method", "GET").putTag("http.url", "none+h2c://localhost:9000/api").putTag("http.status_code", "200").putTag("component", "jersey-server").putTag("application", "SpanLevelAppTag").addAnnotation(startTime * 1000, "start processing").build();
zipkin2.Span spanServer3 = zipkin2.Span.newBuilder().traceId("2822889fe47043bd").id("d6ab73f8a3930ae8").kind(zipkin2.Span.Kind.CLIENT).name("getbackendservice2").timestamp(startTime * 1000).duration(2234 * 1000).localEndpoint(localEndpoint2).putTag("http.method", "GET").putTag("http.url", "none+h2c://localhost:9000/api").putTag("http.status_code", "200").putTag("component", "jersey-server").putTag("application", "SpanLevelAppTag").putTag("emptry.tag", "").addAnnotation(startTime * 1000, "start processing").build();
List<zipkin2.Span> zipkinSpanList = ImmutableList.of(spanServer1, spanServer2, spanServer3);
// Validate all codecs i.e. JSON_V1, JSON_V2, THRIFT and PROTO3.
for (SpanBytesEncoder encoder : SpanBytesEncoder.values()) {
ByteBuf content = Unpooled.copiedBuffer(encoder.encodeList(zipkinSpanList));
// take care of mocks.
doMockLifecycle(mockTraceHandler, mockTraceSpanLogsHandler);
ChannelHandlerContext mockCtx = createNiceMock(ChannelHandlerContext.class);
doMockLifecycle(mockCtx);
FullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "http://localhost:9411/api/v1/spans", content, true);
handler.handleHttpMessage(mockCtx, httpRequest);
verify(mockTraceHandler, mockTraceSpanLogsHandler);
}
}
use of zipkin2.Span.Kind.SERVER in project java by wavefrontHQ.
the class ZipkinPortUnificationHandlerTest method testZipkinPreprocessedDerivedMetrics.
/**
* Test for derived metrics emitted from Zipkin trace listeners. Derived metrics should report
* tag values post applying preprocessing rules to the span.
*/
@Test
public void testZipkinPreprocessedDerivedMetrics() throws Exception {
Supplier<ReportableEntityPreprocessor> preprocessorSupplier = () -> {
ReportableEntityPreprocessor preprocessor = new ReportableEntityPreprocessor();
PreprocessorRuleMetrics preprocessorRuleMetrics = new PreprocessorRuleMetrics(null, null, null);
preprocessor.forSpan().addTransformer(new SpanReplaceRegexTransformer(APPLICATION_TAG_KEY, "^Zipkin.*", PREPROCESSED_APPLICATION_TAG_VALUE, null, null, false, x -> true, preprocessorRuleMetrics));
preprocessor.forSpan().addTransformer(new SpanReplaceRegexTransformer(SERVICE_TAG_KEY, "^test.*", PREPROCESSED_SERVICE_TAG_VALUE, null, null, false, x -> true, preprocessorRuleMetrics));
preprocessor.forSpan().addTransformer(new SpanReplaceRegexTransformer("sourceName", "^zipkin.*", PREPROCESSED_SOURCE_VALUE, null, null, false, x -> true, preprocessorRuleMetrics));
preprocessor.forSpan().addTransformer(new SpanReplaceRegexTransformer(CLUSTER_TAG_KEY, "^none.*", PREPROCESSED_CLUSTER_TAG_VALUE, null, null, false, x -> true, preprocessorRuleMetrics));
preprocessor.forSpan().addTransformer(new SpanReplaceRegexTransformer(SHARD_TAG_KEY, "^none.*", PREPROCESSED_SHARD_TAG_VALUE, null, null, false, x -> true, preprocessorRuleMetrics));
return preprocessor;
};
ZipkinPortUnificationHandler handler = new ZipkinPortUnificationHandler("9411", new NoopHealthCheckManager(), mockTraceHandler, mockTraceSpanLogsHandler, mockWavefrontSender, () -> false, () -> false, preprocessorSupplier, new SpanSampler(new RateSampler(1.0D), () -> null), null, null);
Endpoint localEndpoint1 = Endpoint.newBuilder().serviceName("testService").ip("10.0.0.1").build();
zipkin2.Span spanServer1 = zipkin2.Span.newBuilder().traceId("2822889fe47043bd").id("2822889fe47043bd").kind(zipkin2.Span.Kind.SERVER).name("getservice").timestamp(startTime * 1000).duration(1234 * 1000).localEndpoint(localEndpoint1).build();
List<zipkin2.Span> zipkinSpanList = ImmutableList.of(spanServer1);
// Reset mock
reset(mockTraceHandler, mockWavefrontSender);
// Set Expectation
mockTraceHandler.report(Span.newBuilder().setCustomer("dummy").setStartMillis(startTime).setDuration(1234).setName("getservice").setSource(PREPROCESSED_SOURCE_VALUE).setSpanId("00000000-0000-0000-2822-889fe47043bd").setTraceId("00000000-0000-0000-2822-889fe47043bd").setAnnotations(ImmutableList.of(new Annotation("zipkinSpanId", "2822889fe47043bd"), new Annotation("zipkinTraceId", "2822889fe47043bd"), new Annotation("span.kind", "server"), new Annotation("service", PREPROCESSED_SERVICE_TAG_VALUE), new Annotation("application", PREPROCESSED_APPLICATION_TAG_VALUE), new Annotation("cluster", PREPROCESSED_CLUSTER_TAG_VALUE), new Annotation("shard", PREPROCESSED_SHARD_TAG_VALUE), new Annotation("ipv4", "10.0.0.1"))).build());
expectLastCall();
Capture<HashMap<String, String>> tagsCapture = EasyMock.newCapture();
mockWavefrontSender.sendMetric(eq(HEART_BEAT_METRIC), eq(1.0), anyLong(), eq(PREPROCESSED_SOURCE_VALUE), EasyMock.capture(tagsCapture));
expectLastCall().anyTimes();
replay(mockTraceHandler, mockWavefrontSender);
ChannelHandlerContext mockCtx = createNiceMock(ChannelHandlerContext.class);
doMockLifecycle(mockCtx);
ByteBuf content = Unpooled.copiedBuffer(SpanBytesEncoder.JSON_V2.encodeList(zipkinSpanList));
FullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "http://localhost:9411/api/v2/spans", content, true);
handler.handleHttpMessage(mockCtx, httpRequest);
handler.run();
verifyWithTimeout(500, mockTraceHandler, mockWavefrontSender);
HashMap<String, String> tagsReturned = tagsCapture.getValue();
assertEquals(PREPROCESSED_APPLICATION_TAG_VALUE, tagsReturned.get(APPLICATION_TAG_KEY));
assertEquals(PREPROCESSED_SERVICE_TAG_VALUE, tagsReturned.get(SERVICE_TAG_KEY));
assertEquals(PREPROCESSED_CLUSTER_TAG_VALUE, tagsReturned.get(CLUSTER_TAG_KEY));
assertEquals(PREPROCESSED_SHARD_TAG_VALUE, tagsReturned.get(SHARD_TAG_KEY));
}
use of zipkin2.Span.Kind.SERVER in project brave by openzipkin.
the class ITTracingFilter_Consumer method addsErrorTag_onUnimplemented.
@Test
public void addsErrorTag_onUnimplemented() throws Exception {
server.stop();
server = new TestServer();
server.service.setRef((method, parameterTypes, args) -> args);
server.start();
try {
client.get().sayHello("jorge");
failBecauseExceptionWasNotThrown(RpcException.class);
} catch (RpcException e) {
}
Span span = spans.take();
assertThat(span.tags().get("dubbo.error_code")).isEqualTo("1");
assertThat(span.tags().get("error")).contains("Not found exported service");
}
Aggregations