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


Java Format类代码示例

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


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

示例1: inject

import io.opentracing.propagation.Format; //导入依赖的package包/类
private AMQP.BasicProperties inject(AMQP.BasicProperties properties, Span span) {

    // Headers of AMQP.BasicProperties is unmodifiableMap therefore we build new AMQP.BasicProperties
    // with injected span context into headers
    Map<String, Object> headers = new HashMap<>();

    tracer.inject(span.context(), Format.Builtin.TEXT_MAP, new HeadersMapInjectAdapter(headers));

    if (properties == null) {
      return new AMQP.BasicProperties().builder().headers(headers).build();
    }

    if (properties.getHeaders() != null) {
      headers.putAll(properties.getHeaders());
    }

    return properties.builder()
        .headers(headers)
        .build();
  }
 
开发者ID:opentracing-contrib,项目名称:java-rabbitmq-client,代码行数:21,代码来源:TracingChannel.java

示例2: filter

import io.opentracing.propagation.Format; //导入依赖的package包/类
@Override
public void filter(ContainerRequestContext context) throws IOException {
    if (!shouldFilter(context, resourceInfo)) {
        // do nothing if the filter doesn't apply
        return;
    }

    try {
        Tracer.SpanBuilder builder = tracer.buildSpan(getOperationName(context, resourceInfo))
            .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER)
            .withTag(Tags.HTTP_METHOD.getKey(), context.getMethod())
            .withTag(Tags.HTTP_URL.getKey(), context.getUriInfo().getAbsolutePath().toString());

        builder.asChildOf(tracer.extract(Format.Builtin.HTTP_HEADERS, new ContainerRequestContextTextMap(context)));
        final Span span = builder.startManual();

        context.setProperty(SERVER_SPAN_CONTEXT_KEY, span);
    } catch (Exception e) {
        LOGGER.error("Server Request Filter failed", e);
    }
}
 
开发者ID:ExpediaDotCom,项目名称:haystack-client-java,代码行数:22,代码来源:ServerFilter.java

示例3: testInject

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

    Map<String, String> carrierValues = new HashMap<>();
    TextMap carrier = new TextMapInjectAdapter(carrierValues);

    SpanContext context = new SpanContext(traceId, spanId, parentId).addBaggage("TEST", "TEXT");

    tracer.inject(context, Format.Builtin.TEXT_MAP, carrier);

    Assert.assertEquals(carrierValues.size(), 4);
    Assert.assertEquals(carrierValues.get("Trace-ID"), traceId.toString());
    Assert.assertEquals(carrierValues.get("Span-ID"), spanId.toString());
    Assert.assertEquals(carrierValues.get("Parent-ID"), parentId.toString());
    Assert.assertEquals(carrierValues.get("Baggage-TEST"), "TEXT");

}
 
开发者ID:ExpediaDotCom,项目名称:haystack-client-java,代码行数:21,代码来源:TracerPropagationTest.java

示例4: testInjectURLEncoded

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

    Map<String, String> carrierValues = new HashMap<>();
    TextMap carrier = new TextMapInjectAdapter(carrierValues);

    SpanContext context = new SpanContext(traceId, spanId, parentId).addBaggage("TEST", "[email protected]##*^ %^&&(*").addBaggage("[email protected]##*^ %^&&(*", "TEXT");

    tracer.inject(context, Format.Builtin.HTTP_HEADERS, carrier);

    Assert.assertEquals(carrierValues.size(), 5);
    Assert.assertEquals(carrierValues.get("Trace-ID"), traceId.toString());
    Assert.assertEquals(carrierValues.get("Span-ID"), spanId.toString());
    Assert.assertEquals(carrierValues.get("Parent-ID"), parentId.toString());
    Assert.assertEquals(carrierValues.get("Baggage-TEST"), "%21%40%23%23*%5E+%25%5E%26%26%28*");
    Assert.assertEquals(carrierValues.get("Baggage-%21%40%23%23*%5E+%25%5E%26%26%28*"), "TEXT");

}
 
开发者ID:ExpediaDotCom,项目名称:haystack-client-java,代码行数:22,代码来源:TracerPropagationTest.java

示例5: testExtract

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

示例6: testExtractIgnoreUnknowns

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

示例7: testExtractURLEncoded

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

示例8: getSpan

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

示例9: testSpanContextPropagation

import io.opentracing.propagation.Format; //导入依赖的package包/类
@Test
public void testSpanContextPropagation() throws IOException {
    MockSpan foo = (MockSpan) mockTracer.buildSpan("foo").startManual();
    {
        Map<String, String> injectMap = new HashMap<>();
        mockTracer.inject(foo.context(), Format.Builtin.HTTP_HEADERS, new TextMapInjectAdapter(injectMap));

        OkHttpClient client = new OkHttpClient();
        Request request = new Request.Builder()
                .url(localRequestUrl("/hello"))
                .headers(Headers.of(injectMap))
                .build();

        client.newCall(request).execute();
        Awaitility.await().until(reportedSpansSize(), IsEqual.equalTo(1));
    }

    List<MockSpan> mockSpans = mockTracer.finishedSpans();
    Assert.assertEquals(1, mockSpans.size());
    assertOnErrors(mockSpans);

    MockSpan mockSpan = mockSpans.get(0);
    Assert.assertEquals(foo.context().spanId(), mockSpan.parentId());
    Assert.assertEquals(foo.context().traceId(), mockSpan.context().traceId());
}
 
开发者ID:opentracing-contrib,项目名称:java-web-servlet-filter,代码行数:26,代码来源:TracingFilterTest.java

示例10: run

import io.opentracing.propagation.Format; //导入依赖的package包/类
@Override
public Object run() {
  RequestContext ctx = RequestContext.getCurrentContext();

  // span is a child of one created in servlet-filter
  Span span = tracer.buildSpan(ctx.getRequest().getMethod())
      .withTag(Tags.COMPONENT.getKey(), COMPONENT_NAME)
      .startManual();

  tracer.inject(span.context(), Format.Builtin.HTTP_HEADERS,
      new TextMapInjectAdapter(ctx.getZuulRequestHeaders()));

  ctx.set(CONTEXT_SPAN_KEY, span);

  return null;
}
 
开发者ID:opentracing-contrib,项目名称:java-spring-cloud,代码行数:17,代码来源:TracePreZuulFilter.java

示例11: testPreSendServerSpan

import io.opentracing.propagation.Format; //导入依赖的package包/类
@Test
public void testPreSendServerSpan() {
  MessageBuilder<String> messageBuilder = MessageBuilder.withPayload("Hi")
      .setHeader(TracingChannelInterceptor.SIMP_MESSAGE_TYPE, SimpMessageType.MESSAGE)
      .setHeader(TracingChannelInterceptor.SIMP_DESTINATION, TEST_DESTINATION);

  MockSpan parentSpan = mockTracer.buildSpan("parent").startManual();
  mockTracer.inject(parentSpan.context(), Format.Builtin.TEXT_MAP,
      new TextMapInjectAdapter(messageBuilder));

  TracingChannelInterceptor interceptor = new TracingChannelInterceptor(mockTracer,
      Tags.SPAN_KIND_SERVER);

  Message<?> processed = interceptor.preSend(messageBuilder.build(), null);

  // Verify span cached with message is child of propagated parentSpan span context
  assertTrue(processed.getHeaders().containsKey(TracingChannelInterceptor.OPENTRACING_SPAN));
  MockSpan childSpan = (MockSpan) processed.getHeaders()
      .get(TracingChannelInterceptor.OPENTRACING_SPAN);
  assertEquals(parentSpan.context().spanId(), childSpan.parentId());
  assertEquals(parentSpan.context().traceId(), childSpan.context().traceId());
  assertEquals(TEST_DESTINATION, childSpan.operationName());
  assertEquals(Tags.SPAN_KIND_SERVER, childSpan.tags().get(Tags.SPAN_KIND.getKey()));
  assertEquals(TracingChannelInterceptor.WEBSOCKET,
      childSpan.tags().get(Tags.COMPONENT.getKey()));
}
 
开发者ID:opentracing-contrib,项目名称:java-spring-cloud,代码行数:27,代码来源:TracingChannelInterceptorTest.java

示例12: extract

import io.opentracing.propagation.Format; //导入依赖的package包/类
/**
 * Extract context from headers or from active Span
 *
 * @param request http request
 * @return extracted context
 */
private SpanContext extract(HttpRequest request) {
  SpanContext spanContext = tracer.extract(Format.Builtin.HTTP_HEADERS,
      new HttpTextMapExtractAdapter(request));

  if (spanContext != null) {
    return spanContext;
  }

  Span span = tracer.activeSpan();
  if (span != null) {
    return span.context();
  }

  return null;
}
 
开发者ID:opentracing-contrib,项目名称:java-elasticsearch-client,代码行数:22,代码来源:TracingHttpClientConfigCallback.java

示例13: run

import io.opentracing.propagation.Format; //导入依赖的package包/类
Map<String, String> run() {
  ActiveSpan span = tracer.buildSpan("main")
      .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER)
      .startActive();

  waitABit();

  childOperation();

  span.close();

  Map<String, String> map = new HashMap<>();
  TextMap carrier = new TextMapInjectAdapter(map);
  tracer.inject(span.context(), Format.Builtin.TEXT_MAP, carrier);

  return map;
}
 
开发者ID:jeqo,项目名称:talk-observing-distributed-systems,代码行数:18,代码来源:Process.java

示例14: startServerSpan

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

示例15: extract

import io.opentracing.propagation.Format; //导入依赖的package包/类
@Override
public <C> SpanContext extract(Format<C> format, C carrier) {
  if (format.equals(Format.Builtin.TEXT_MAP) || format.equals(Format.Builtin.HTTP_HEADERS)) {
    if (!(carrier instanceof TextMap)) {
      throw new IllegalArgumentException("Unsupported payload: " + carrier);
    }
    return new TextMapContext((TextMap) carrier);
  } else if (format.equals(Format.Builtin.BINARY)) {
    if (!(carrier instanceof ByteBuffer)) {
      throw new IllegalArgumentException("Unsupported payload: " + carrier);
    }
    return new ByteBufferContext((ByteBuffer) carrier);
  } else {
    throw new IllegalArgumentException("Unsupported format: " + format);
  }
}
 
开发者ID:instana,项目名称:instana-java-opentracing,代码行数:17,代码来源:InstanaTracer.java


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