简体   繁体   English

Jaeger 中的 OpenTracing 注入/提取

[英]OpenTracing inject/extract in Jaeger

I'm new to OpenTracing.我是 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);
}
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 .您似乎试图根据仅包含名为deviceKey的键的地图提取上下文。 Unless you are using a custom tracer, you should really be passing all HTTP headers to the #extract() method.除非您使用自定义跟踪器,否则您真的应该将所有 HTTP 标头传递给#extract()方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM