当前位置: 首页>>代码示例>>Java>>正文


Java TextMapExtractAdapter类代码示例

本文整理汇总了Java中io.opentracing.propagation.TextMapExtractAdapter的典型用法代码示例。如果您正苦于以下问题:Java TextMapExtractAdapter类的具体用法?Java TextMapExtractAdapter怎么用?Java TextMapExtractAdapter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TextMapExtractAdapter类属于io.opentracing.propagation包,在下文中一共展示了TextMapExtractAdapter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testExtract

import io.opentracing.propagation.TextMapExtractAdapter; //导入依赖的package包/类
@Test
public void testExtract() {
    UUID traceId = UUID.randomUUID();
    UUID spanId = UUID.randomUUID();
    UUID parentId = UUID.randomUUID();

    Map<String, String> carrierValues = new HashMap<>();
    carrierValues.put("Baggage-TEST", "TEXT");
    carrierValues.put("Trace-ID", traceId.toString());
    carrierValues.put("Span-ID", spanId.toString());
    carrierValues.put("Parent-ID", parentId.toString());

    TextMap carrier = new TextMapExtractAdapter(carrierValues);

    SpanContext context = tracer.extract(Format.Builtin.TEXT_MAP, carrier);

    Assert.assertEquals(context.getTraceId(), traceId);
    Assert.assertEquals(context.getSpanId(), spanId);
    Assert.assertEquals(context.getParentId(), parentId);
    Assert.assertEquals(context.getBaggage().size(), 1);
    Assert.assertEquals(context.getBaggageItem("TEST"), "TEXT");
}
 
开发者ID:ExpediaDotCom,项目名称:haystack-client-java,代码行数:23,代码来源:TracerPropagationTest.java

示例2: testExtractIgnoreUnknowns

import io.opentracing.propagation.TextMapExtractAdapter; //导入依赖的package包/类
@Test
public void testExtractIgnoreUnknowns() {
    UUID traceId = UUID.randomUUID();
    UUID spanId = UUID.randomUUID();
    UUID parentId = UUID.randomUUID();

    Map<String, String> carrierValues = new HashMap<>();
    carrierValues.put("Trace-ID", traceId.toString());
    carrierValues.put("Span-ID", spanId.toString());
    carrierValues.put("Parent-ID", parentId.toString());

    carrierValues.put("JunkKey", parentId.toString());
    carrierValues.put("JunkKey2", parentId.toString());

    TextMap carrier = new TextMapExtractAdapter(carrierValues);

    SpanContext context = tracer.extract(Format.Builtin.HTTP_HEADERS, carrier);

    Assert.assertEquals(context.getTraceId(), traceId);
    Assert.assertEquals(context.getSpanId(), spanId);
    Assert.assertEquals(context.getParentId(), parentId);
    Assert.assertEquals(context.getBaggage().size(), 0);
}
 
开发者ID:ExpediaDotCom,项目名称:haystack-client-java,代码行数:24,代码来源:TracerPropagationTest.java

示例3: testExtractURLEncoded

import io.opentracing.propagation.TextMapExtractAdapter; //导入依赖的package包/类
@Test
public void testExtractURLEncoded() {
    UUID traceId = UUID.randomUUID();
    UUID spanId = UUID.randomUUID();
    UUID parentId = UUID.randomUUID();

    Map<String, String> carrierValues = new HashMap<>();
    carrierValues.put("Baggage-TEST", "!%40%23%23*%5E%20%25%5E%26%26(*");
    carrierValues.put("Baggage-!%40%23%23*%5E%20%25%5E%26%26(*", "TEST");
    carrierValues.put("Trace-ID", traceId.toString());
    carrierValues.put("Span-ID", spanId.toString());
    carrierValues.put("Parent-ID", parentId.toString());

    TextMap carrier = new TextMapExtractAdapter(carrierValues);

    SpanContext context = tracer.extract(Format.Builtin.HTTP_HEADERS, carrier);

    Assert.assertEquals(context.getTraceId(), traceId);
    Assert.assertEquals(context.getSpanId(), spanId);
    Assert.assertEquals(context.getParentId(), parentId);
    Assert.assertEquals(context.getBaggage().size(), 2);
    Assert.assertEquals(context.getBaggageItem("TEST"), "[email protected]##*^ %^&&(*");
    Assert.assertEquals(context.getBaggageItem("[email protected]##*^ %^&&(*"), "TEST");
}
 
开发者ID:ExpediaDotCom,项目名称:haystack-client-java,代码行数:25,代码来源:TracerPropagationTest.java

示例4: getSpan

import io.opentracing.propagation.TextMapExtractAdapter; //导入依赖的package包/类
protected Span getSpan(String methodName, Map<String, String> headers, OrangeContext context) {
    Span span = null;
    if (tracer != null) {
        SpanContext spanContext = tracer.extract(Format.Builtin.HTTP_HEADERS, new TextMapExtractAdapter(headers));
        if (spanContext != null) {
            span = tracer.buildSpan(methodName).asChildOf(spanContext).start();
        } else {
            span = tracer.buildSpan(methodName).start();
        }
        span.setTag("correlation_id", context.getCorrelationId());
        Tags.SPAN_KIND.set(span, Tags.SPAN_KIND_SERVER);
        Tags.PEER_SERVICE.set(span, context.getRpcOriginService());
        context.setTracingContext(span.context());
    }
    return span;
}
 
开发者ID:Sixt,项目名称:ja-micro,代码行数:17,代码来源:RpcHandler.java

示例5: startServerSpan

import io.opentracing.propagation.TextMapExtractAdapter; //导入依赖的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

示例6: getSpanFromHeaders

import io.opentracing.propagation.TextMapExtractAdapter; //导入依赖的package包/类
/**
 * Extract OpenTracing context from head, and create span.
 * @param headers HTTP headers.
 * @param operationName span's operation name.
 * @return
 */
private Span getSpanFromHeaders(Map<String, String> headers, String operationName) {
    Span span;
    try {
        SpanContext parentSpanCtx = tracer.extract(Format.Builtin.HTTP_HEADERS,
            new TextMapExtractAdapter(headers));
        if (parentSpanCtx == null) {
            span = tracer.buildSpan(operationName).start();
        } else {
            span = tracer.buildSpan(operationName).asChildOf(parentSpanCtx).start();
        }
    } catch (IllegalArgumentException iae){
        span = tracer.buildSpan(operationName)
            .withTag("Error", "Extract failed and an IllegalArgumentException was thrown")
            .start();
    }
    return span;
}
 
开发者ID:opentracing-contrib,项目名称:java-hprose,代码行数:24,代码来源:HttpServiceTracingInvokeHandler.java

示例7: extractTraceContext

import io.opentracing.propagation.TextMapExtractAdapter; //导入依赖的package包/类
@Test public void extractTraceContext() throws Exception {
  Map<String, String> map = new LinkedHashMap<>();
  map.put("X-B3-TraceId", "0000000000000001");
  map.put("X-B3-SpanId", "0000000000000002");
  map.put("X-B3-Sampled", "1");

  BraveSpanContext openTracingContext =
      (BraveSpanContext) opentracing.extract(Format.Builtin.HTTP_HEADERS,
          new TextMapExtractAdapter(map));

  assertThat(openTracingContext.unwrap())
      .isEqualTo(TraceContext.newBuilder()
          .traceId(1L)
          .spanId(2L)
          .sampled(true).build());
}
 
开发者ID:openzipkin-contrib,项目名称:brave-opentracing,代码行数:17,代码来源:BraveTracerTest.java

示例8: extractTraceContextTextMap

import io.opentracing.propagation.TextMapExtractAdapter; //导入依赖的package包/类
@Test public void extractTraceContextTextMap() throws Exception {
  Map<String, String> map = new LinkedHashMap<>();
  map.put("X-B3-TraceId", "0000000000000001");
  map.put("X-B3-SpanId", "0000000000000002");
  map.put("X-B3-Sampled", "1");

  BraveSpanContext openTracingContext =
      (BraveSpanContext) opentracing.extract(Format.Builtin.TEXT_MAP,
          new TextMapExtractAdapter(map));

  assertThat(openTracingContext.unwrap())
      .isEqualTo(TraceContext.newBuilder()
          .traceId(1L)
          .spanId(2L)
          .sampled(true).build());
}
 
开发者ID:openzipkin-contrib,项目名称:brave-opentracing,代码行数:17,代码来源:BraveTracerTest.java

示例9: extractTraceContextCaseInsensitive

import io.opentracing.propagation.TextMapExtractAdapter; //导入依赖的package包/类
@Test public void extractTraceContextCaseInsensitive() throws Exception {
  Map<String, String> map = new LinkedHashMap<>();
  map.put("X-B3-TraceId", "0000000000000001");
  map.put("x-b3-spanid", "0000000000000002");
  map.put("x-b3-SaMpLeD", "1");
  map.put("other", "1");

  BraveSpanContext openTracingContext =
      (BraveSpanContext) opentracing.extract(Format.Builtin.HTTP_HEADERS,
          new TextMapExtractAdapter(map));

  assertThat(openTracingContext.unwrap())
      .isEqualTo(TraceContext.newBuilder()
          .traceId(1L)
          .spanId(2L)
          .sampled(true).build());
}
 
开发者ID:openzipkin-contrib,项目名称:brave-opentracing,代码行数:18,代码来源:BraveTracerTest.java

示例10: handle1

import io.opentracing.propagation.TextMapExtractAdapter; //导入依赖的package包/类
public void handle1(Message message) {
    SpanContext spanCtx = getTracer().extract(Format.Builtin.TEXT_MAP,
            new TextMapExtractAdapter(message.getHeaders()));

    // Top level, so create Tracer and root span
    Span serverSpan = getTracer().buildSpan("Server")
            .asChildOf(spanCtx)
            .withTag(Constants.ZIPKIN_BIN_ANNOTATION_HTTP_URL, "http://localhost:8080/inbound?orderId=123&verbose=true")
            .withTag(Constants.PROP_TRANSACTION_NAME, SYNC_TXN_NAME_1)
            .withTag(ORDER_ID_NAME, ORDER_ID_VALUE)
            .start();

    delay(500);

    component(serverSpan);

    serverSpan.setTag("fault", MY_FAULT);

    delay(500);

    serverSpan.finish();

    serverSpan.close();
}
 
开发者ID:hawkular,项目名称:hawkular-apm,代码行数:25,代码来源:SyncService.java

示例11: handle2

import io.opentracing.propagation.TextMapExtractAdapter; //导入依赖的package包/类
public void handle2(Message message) {
    SpanContext spanCtx = getTracer().extract(Format.Builtin.TEXT_MAP,
            new TextMapExtractAdapter(message.getHeaders()));

    // Top level, so create Tracer and root span
    Span serverSpan = getTracer().buildSpan("Server")
            .asChildOf(spanCtx)
            .withTag(Constants.ZIPKIN_BIN_ANNOTATION_HTTP_URL, "http://localhost:8080/inbound?orderId=123&verbose=true")
            .withTag(ORDER_ID_NAME, ORDER_ID_VALUE)
            .start();

    delay(500);

    component(serverSpan);

    serverSpan.setTag("fault", MY_FAULT);

    delay(500);

    serverSpan.finish();

    serverSpan.close();
}
 
开发者ID:hawkular,项目名称:hawkular-apm,代码行数:24,代码来源:SyncService.java

示例12: handle

import io.opentracing.propagation.TextMapExtractAdapter; //导入依赖的package包/类
public void handle(Message message) {
    SpanContext spanCtx = getTracer().extract(Format.Builtin.TEXT_MAP,
            new TextMapExtractAdapter(message.getHeaders()));

    // Top level, so create Tracer and root span
    Span serverSpan = getTracer().buildSpan("Server")
            .asChildOf(spanCtx)
            .withTag(Constants.ZIPKIN_BIN_ANNOTATION_HTTP_URL, "http://localhost:8080/inbound?orderId=123&verbose=true")
            .withTag("orderId", "1243343456455")
            .start();

    delay(500);

    component1(serverSpan);

    serverSpan.finish();

    serverSpan.close();
}
 
开发者ID:hawkular,项目名称:hawkular-apm,代码行数:20,代码来源:SpawnService.java

示例13: handle

import io.opentracing.propagation.TextMapExtractAdapter; //导入依赖的package包/类
public void handle(Message message) {
    SpanContext spanCtx = getTracer().extract(Format.Builtin.TEXT_MAP,
            new TextMapExtractAdapter(message.getHeaders()));

    // Top level, so create Tracer and root span
    Span serverSpan = getTracer().buildSpan("Server")
            .asChildOf(spanCtx)
            .withTag(Constants.ZIPKIN_BIN_ANNOTATION_HTTP_URL, "http://localhost:8080/inbound?orderId=123&verbose=true")
            .withTag("orderId", "1243343456455")
            .start();

    delay(500);

    ForkJoinPool pool = new ForkJoinPool();
    for (int i = 0; i < 5; i++) {
        int pos = i;
        pool.execute(() -> component(serverSpan, pos));
    }

    pool.awaitQuiescence(5, TimeUnit.SECONDS);

    serverSpan.finish();

    serverSpan.close();
}
 
开发者ID:hawkular,项目名称:hawkular-apm,代码行数:26,代码来源:ForkJoinService.java

示例14: handle

import io.opentracing.propagation.TextMapExtractAdapter; //导入依赖的package包/类
public void handle(Message message, Handler handler) {
    SpanContext spanCtx = getTracer().extract(Format.Builtin.TEXT_MAP,
            new TextMapExtractAdapter(message.getHeaders()));

    // Top level, so create Tracer and root span
    Span serverSpan = getTracer().buildSpan("Server")
            .asChildOf(spanCtx)
            .withTag(Constants.ZIPKIN_BIN_ANNOTATION_HTTP_URL,
                    "http://localhost:8080/inbound?orderId=123&verbose=true")
            .withTag("orderId", "1243343456455")
            .start();

    delay(500);

    callService(serverSpan, obj -> {

        serverSpan.finish();

        handler.handle(obj);
    });
}
 
开发者ID:hawkular,项目名称:hawkular-apm,代码行数:22,代码来源:AsyncService.java

示例15: hello

import io.opentracing.propagation.TextMapExtractAdapter; //导入依赖的package包/类
@GET
@Path("/hello")
public Response hello(@Context HttpHeaders headers) {
    SpanContext spanContext =
            tracer.extract(Format.Builtin.TEXT_MAP, new TextMapExtractAdapter(Utils.extractHeaders(headers)));

    Span span = tracer.buildSpan("hello")
            .asChildOf(spanContext)
            .start();
    /**
     * Some business logic
     */
    span.close();

    return Response.ok("Hello from WildFly Swarm! [java]").build();
}
 
开发者ID:hawkular,项目名称:hawkular-apm,代码行数:17,代码来源:HelloHandler.java


注:本文中的io.opentracing.propagation.TextMapExtractAdapter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。