0

I'm new to OpenTracing. Until now I was mainly working in house tracing tool. The server is not able to extract the span context.

MultivaluedMap<String, String> rawHeaders = httpHeaders.getRequestHeaders();
final HashMap<String, String> headers = new HashMap<String, String>();
for (String key : rawHeaders.keySet()) {
    if(key.contentEquals("deviceKey"))
        headers.put(key, rawHeaders.get(key).get(0));
}
Tracer.SpanBuilder spanBuilder;
try {
    SpanContext parentSpanCtx = tracer.extract(Format.Builtin.HTTP_HEADERS, new TextMapExtractAdapter(headers));
    if (parentSpanCtx == null) {
        spanBuilder = tracer.buildSpan(operationName);
    }

    else {
        spanBuilder = tracer.buildSpan(operationName).asChildOf(parentSpanCtx);
    }

}
catch (IllegalArgumentException e) {
    spanBuilder = tracer.buildSpan(operationName);
}
karel
  • 5,489
  • 46
  • 45
  • 50

1 Answers1

0
final HashMap<String, String> headers = new HashMap<String, String>();

...

if(key.contentEquals("deviceKey"))
    headers.put(key, rawHeaders.get(key).get(0));

...

tracer.extract(Format.Builtin.HTTP_HEADERS, new TextMapExtractAdapter(headers))

You seem to be trying to extract a context based on a map containing only a key named deviceKey. Unless you are using a custom tracer, you should really be passing all HTTP headers to the #extract() method.

jpkroehling
  • 13,881
  • 1
  • 37
  • 39