當前位置: 首頁>>代碼示例>>Java>>正文


Java Tracer.extract方法代碼示例

本文整理匯總了Java中io.opentracing.Tracer.extract方法的典型用法代碼示例。如果您正苦於以下問題:Java Tracer.extract方法的具體用法?Java Tracer.extract怎麽用?Java Tracer.extract使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.opentracing.Tracer的用法示例。


在下文中一共展示了Tracer.extract方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: startServerSpan

import io.opentracing.Tracer; //導入方法依賴的package包/類
public static Scope startServerSpan(Tracer tracer, javax.ws.rs.core.HttpHeaders httpHeaders,
        String operationName) {
    // format the headers for extraction
    MultivaluedMap<String, String> rawHeaders = httpHeaders.getRequestHeaders();
    final HashMap<String, String> headers = new HashMap<String, String>();
    for (String key : rawHeaders.keySet()) {
        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);
    }
    // TODO could add more tags like http.url
    return spanBuilder.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER).startActive(true);
}
 
開發者ID:yurishkuro,項目名稱:opentracing-tutorial,代碼行數:24,代碼來源:Tracing.java

示例2: extractTraceInfo

import io.opentracing.Tracer; //導入方法依賴的package包/類
protected Span extractTraceInfo(Tracer tracer, Invoker<?> invoker, Invocation inv) {
    String operationName = JbootDubboTracingFilterKits.buildOperationName(invoker, inv);
    Tracer.SpanBuilder span = tracer.buildSpan(operationName);
    try {
        SpanContext spanContext = tracer.extract(Format.Builtin.TEXT_MAP, new TextMapExtractAdapter(inv.getAttachments()));
        if (spanContext != null) {
            span.asChildOf(spanContext);
        }
    } catch (Exception e) {
        span.withTag("Error", "extract from request fail, error msg:" + e.getMessage());
    }
    return span.startManual();
}
 
開發者ID:yangfuhai,項目名稱:jboot,代碼行數:14,代碼來源:JbootDubboProviderTracingFilter.java

示例3: extractTraceInfo

import io.opentracing.Tracer; //導入方法依賴的package包/類
protected Span extractTraceInfo(Request request, Tracer tracer) {
    String operationName = buildOperationName(request);
    Tracer.SpanBuilder span = tracer.buildSpan(operationName);
    try {
        SpanContext spanContext = tracer.extract(Format.Builtin.TEXT_MAP, new TextMapExtractAdapter(request.getAttachments()));
        if (spanContext != null) {
            span.asChildOf(spanContext);
        }
    } catch (Exception e) {
        span.withTag("Error", "extract from request fail, error msg:" + e.getMessage());
    }
    return span.startManual();
}
 
開發者ID:yangfuhai,項目名稱:jboot,代碼行數:14,代碼來源:JbootMotanTracingFilter.java

示例4: extract

import io.opentracing.Tracer; //導入方法依賴的package包/類
public static SpanContext extract(AMQP.BasicProperties props, Tracer tracer) {
  SpanContext spanContext = tracer
      .extract(Format.Builtin.TEXT_MAP, new HeadersMapExtractAdapter(props.getHeaders()));
  if (spanContext != null) {
    return spanContext;
  }

  Span span = tracer.activeSpan();
  if (span != null) {
    return span.context();
  }
  return null;
}
 
開發者ID:opentracing-contrib,項目名稱:java-rabbitmq-client,代碼行數:14,代碼來源:TracingUtils.java

示例5: extract

import io.opentracing.Tracer; //導入方法依賴的package包/類
/**
 * Extract span context from JMS message properties or active span
 *
 * @param message JMS message
 * @param tracer Tracer
 * @return extracted span context
 */
public static SpanContext extract(Message message, Tracer tracer) {
  SpanContext spanContext = tracer
      .extract(Format.Builtin.TEXT_MAP, new JmsTextMapExtractAdapter(message));
  if (spanContext != null) {
    return spanContext;
  }

  ActiveSpan span = tracer.activeSpan();
  if (span != null) {
    return span.context();
  }
  return null;
}
 
開發者ID:Estafet-LTD,項目名稱:estafet-microservices-scrum-api-project-burndown,代碼行數:21,代碼來源:PropagatingTracingMessageUtils.java

示例6: extract

import io.opentracing.Tracer; //導入方法依賴的package包/類
/**
 * Extract span context from JMS message properties or active span
 *
 * @param message JMS message
 * @param tracer Tracer
 * @return extracted span context
 */
public static SpanContext extract(Message message, Tracer tracer) {
  SpanContext spanContext = tracer
      .extract(Format.Builtin.TEXT_MAP, new JmsTextMapExtractAdapter(message));
  if (spanContext != null) {
    return spanContext;
  }

  Span span = tracer.activeSpan();
  if (span != null) {
    return span.context();
  }
  return null;
}
 
開發者ID:opentracing-contrib,項目名稱:java-jms,代碼行數:21,代碼來源:TracingMessageUtils.java

示例7: testExtract

import io.opentracing.Tracer; //導入方法依賴的package包/類
@Test
public void testExtract() {
    Tracer tracer = new StackDriverOTTracer(Trace.getTracer());

    Map<String, String> fakeHeaders = new HashMap<>();
    fakeHeaders.put(TextMapPropagator.FIELD_TRACE_ID, "ea3e3b18e8ce393683a2b1c533c5cb2c");
    fakeHeaders.put(TextMapPropagator.FIELD_SPAN_ID, "4994894571082534213");

    SpanContext extractedContext = tracer.extract(Format.Builtin.TEXT_MAP, new TextMapExtractAdapter(fakeHeaders));
    com.google.cloud.trace.core.SpanContext context = ((StackDriverOTSpanContext)extractedContext).getUnderlyingSpanContext();

    assertEquals(fakeHeaders.get(TextMapPropagator.FIELD_TRACE_ID), context.getTraceId().getApiString());
    assertEquals(fakeHeaders.get(TextMapPropagator.FIELD_SPAN_ID), context.getSpanId().getApiString());
}
 
開發者ID:connctd,項目名稱:stackdriver-opentracing,代碼行數:15,代碼來源:TextMapPropagatorTest.java

示例8: extract

import io.opentracing.Tracer; //導入方法依賴的package包/類
/**
 * Extract Span Context from record headers
 *
 * @param headers record headers
 * @return span context
 */
static SpanContext extract(Headers headers, Tracer tracer) {
  return tracer
      .extract(Format.Builtin.TEXT_MAP, new HeadersMapExtractAdapter(headers, false));
}
 
開發者ID:opentracing-contrib,項目名稱:java-kafka-client,代碼行數:11,代碼來源:TracingKafkaUtils.java

示例9: extractSpanContext

import io.opentracing.Tracer; //導入方法依賴的package包/類
/**
 * Extract Span Context from Consumer record headers
 *
 * @param headers Consumer record headers
 * @return span context
 */
public static SpanContext extractSpanContext(Headers headers, Tracer tracer) {
  return tracer
      .extract(Format.Builtin.TEXT_MAP, new HeadersMapExtractAdapter(headers, true));
}
 
開發者ID:opentracing-contrib,項目名稱:java-kafka-client,代碼行數:11,代碼來源:TracingKafkaUtils.java


注:本文中的io.opentracing.Tracer.extract方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。