Jaeger中的OpenTracing注入/提取

时间:2019-03-04 18:56:11

标签: java opentracing jaeger

我是OpenTracing的新手。到目前为止,我主要从事房屋追踪工具。服务器无法提取跨度上下文。

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);
}

1 个答案:

答案 0 :(得分: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))

您似乎试图基于仅包含名为deviceKey的键的映射提取上下文。除非您使用自定义跟踪器,否则您实际上应该将所有HTTP标头传递给#extract()方法。