opentracing / opentracing-java

OpenTracing API for Java. 🛑 This library is DEPRECATED! https://github.com/opentracing/specification/issues/163
http://opentracing.io
Apache License 2.0
1.68k stars 344 forks source link

Unable to visualize the tags set in a span on Jaeger UI #294

Closed gvkarthik93 closed 6 years ago

gvkarthik93 commented 6 years ago

I have two microservices communicating with each other. I am able to set tags on Microservice A and send the span context using inject and extract methods. I am able to set baggage as well. I am able to see baggage items and values set during span creating on Microservice A after extracting that span in Microservice B, however, I am unable to see the tags and values of span set in Microservice A in Jaeger UI. Could someone provide any insights on why I can't see tags and values on UI?

yurishkuro commented 6 years ago

I suggest directing Jaeger-related questions to Jaeger chat room, not opentracing-java repo. You may also want to include sample code, as there's little to go on from your description.

gvkarthik93 commented 6 years ago

This is the code I am using currently to create the span, request in Microservice A.

@RequestMapping("/context") public String context() { try { HttpUrl url = new HttpUrl.Builder().scheme("http").host("localhost").port(8096).addPathSegment("process").build(); Request.Builder requestBuilder = new Request.Builder().url(url);

Span span = tracer.buildSpan("order-management").start(); Tags.SPAN_KIND.set(span, Tags.SPAN_KIND_CLIENT); Tags.HTTP_METHOD.set(span, "GET"); Tags.HTTP_URL.set(span, url.toString()); span.setTag("OrderID", "1"); span.setBaggageItem("greeting", "Hello"); span.log(ImmutableMap.of("event", "OM")); tracer.inject(span.context(), Format.Builtin.HTTP_HEADERS, new RequestBuilderCarrier(requestBuilder));

Request request = requestBuilder.build(); Response response = client.newCall(request).execute(); if (response.code() != 200) { throw new RuntimeException("Bad HTTP result: " + response); } System.out.println("Final Baggage: " + span.getBaggageItem("ApprovalStatus")); span.finish(); return "MANAGEMENT RESPONSE: " + response.body().string(); } catch (IOException e) { throw new RuntimeException(e); } }

This is the code I am currently using to retrieve the span and tags in Microservice B.

private Span getSpan(HttpHeaders httpHeaders) { Map<String, String> rawHeaders = httpHeaders.toSingleValueMap(); final HashMap<String, String> headers = new HashMap<String, String>(); for (String key : rawHeaders.keySet()) { headers.put(key, rawHeaders.get(key)); }

Tracer.SpanBuilder spanBuilder; try { SpanContext parentSpan = tracer.extract(Format.Builtin.HTTP_HEADERS, new TextMapExtractAdapter(headers)); if (parentSpan == null) { spanBuilder = tracer.buildSpan("order-processing"); } else { System.out.println("Building Child Span"); spanBuilder = tracer.buildSpan("order-processing").asChildOf(parentSpan); } } catch (IllegalArgumentException e) { spanBuilder = tracer.buildSpan("order-processing"); } return spanBuilder.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER).start(); }

  1. I am able to retrieve the baggage which I set on Microservice A in Microservice B. Hoever, I am unable to retrieve the tags set in the span on Microservice B in Microservice A. Now I know, the span I am using in Microservice B is a Child Span. How to access child span in Microservice A.

  2. And also, I went through opentracing tutorials provided which you have redirect me to, I am unable to find the code for extracting tags. I am able to extract baggage but how to extract tags from span. Span object only has setTags method in it.

yurishkuro commented 6 years ago

you cannot "extract tags". There is no OpenTracing API to read back the tags, and they are only meant to be recorded and reported to the tracing backend out of band.

gvkarthik93 commented 6 years ago

@yurishkuro Is there a way I can get all the child spans in the parent span, more like a hierarchy through Java code?

yurishkuro commented 6 years ago

There are two data streams involved in tracing: (a) the distributed context that's included with every RPC request and contains things like trace ID and baggage, and (b) performance data recorded in the span, including tags, which is collected by the tracing backend asynchronously, not on the execution path of the requests. Spans are fundamentally not designed to be passed around with the actual application traffic. If you need to pass data between services, you need to include it in your RPC data model. Data recorded in spans can only be analyzed offline after it's been collected by the tracing backend.

gvkarthik93 commented 6 years ago

@yurishkuro This perfectly answers my question. Thanks a lot for a good description. I am closing this ticket now.