• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java TextMap类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: testInject

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


示例2: testInjectURLEncoded

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


示例3: testExtract

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


示例4: testExtractIgnoreUnknowns

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


示例5: testExtractURLEncoded

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


示例6: run

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


示例7: extract

import io.opentracing.propagation.TextMap; //导入依赖的package包/类
public SpanContext extract(com.google.cloud.trace.Tracer tracer, TextMap textMap) {
    String traceId = null;
    String spanId = null;

    Iterator<Map.Entry<String, String>> iter = textMap.iterator();
    while(iter.hasNext()) {
        Map.Entry<String, String> currEntry = iter.next();

        if (currEntry.getKey().compareToIgnoreCase(FIELD_TRACE_ID) == 0) {
            traceId = currEntry.getValue();
        } else if (currEntry.getKey().compareToIgnoreCase(FIELD_SPAN_ID) == 0) {
            spanId = currEntry.getValue();
        }
    }

    return buildSpanContext(tracer, traceId, spanId);
}
 
开发者ID:connctd,项目名称:stackdriver-opentracing,代码行数:18,代码来源:TextMapPropagator.java


示例8: extract

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


示例9: extract

import io.opentracing.propagation.TextMap; //导入依赖的package包/类
@Override
public <C> MockContext extract(Format<C> format, C carrier) {
  TextMap textMap = (TextMap) carrier;
  Map<String, String> baggage = new HashMap<>();
  for (Iterator<Map.Entry<String, String>> iter = textMap.iterator(); iter.hasNext(); ) {
    Map.Entry<String, String> entry = iter.next();
    String key = entry.getKey().toLowerCase();
    String value = entry.getValue();
    if (TRACE_ID.equals(key)) {
      baggage.put(TRACE_ID, value);
    } else if (key.startsWith(BAGGAGE_PREFIX) && key.length() > BAGGAGE_PREFIX.length()) {
      baggage.put(key.substring(BAGGAGE_PREFIX.length()), value);
    }
  }
  return new MockContext(0, 0, baggage);
}
 
开发者ID:yarpc,项目名称:yarpc-java,代码行数:17,代码来源:CrossdockUtils.java


示例10: canUseCustomFormatKeys

import io.opentracing.propagation.TextMap; //导入依赖的package包/类
@Test public void canUseCustomFormatKeys() throws Exception {
  Format<TextMap> B3 = new Format<TextMap>() {
  };
  opentracing = BraveTracer.newBuilder(brave)
      .textMapPropagation(B3, Propagation.B3_STRING).build();

  TraceContext context = TraceContext.newBuilder()
      .traceId(1L)
      .spanId(2L)
      .sampled(true).build();

  Map<String, String> map = new LinkedHashMap<>();
  TextMapInjectAdapter carrier = new TextMapInjectAdapter(map);
  opentracing.inject(BraveSpanContext.wrap(context), B3, carrier);

  assertThat(map).containsExactly(
      entry("X-B3-TraceId", "0000000000000001"),
      entry("X-B3-SpanId", "0000000000000002"),
      entry("X-B3-Sampled", "1")
  );
}
 
开发者ID:openzipkin-contrib,项目名称:brave-opentracing,代码行数:22,代码来源:BraveTracerTest.java


示例11: afterMethod

import io.opentracing.propagation.TextMap; //导入依赖的package包/类
@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
    Class<?>[] argumentsTypes, Object ret) throws Throwable {
    Format format = (Format)allArguments[1];
    if (Format.Builtin.TEXT_MAP.equals(format) || Format.Builtin.HTTP_HEADERS.equals(format)) {
        TextMap carrier = (TextMap)allArguments[2];
        ContextCarrier contextCarrier = new ContextCarrier();
        ContextManager.inject(contextCarrier);
        CarrierItem next = contextCarrier.items();
        while (next.hasNext()) {
            next = next.next();
            carrier.put(next.getHeadKey(), next.getHeadValue());
        }
    } else {
        //Don't support other format yet.
    }

    return null;
}
 
开发者ID:apache,项目名称:incubator-skywalking,代码行数:20,代码来源:SkywalkingTracerInjectInterceptor.java


示例12: afterMethod

import io.opentracing.propagation.TextMap; //导入依赖的package包/类
@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
    Class<?>[] argumentsTypes, Object ret) throws Throwable {
    Format format = (Format)allArguments[0];
    if (Format.Builtin.TEXT_MAP.equals(format) || Format.Builtin.HTTP_HEADERS.equals(format)) {
        TextMap textMapCarrier = (TextMap)allArguments[1];

        ContextCarrier contextCarrier = new ContextCarrier();
        CarrierItem next = contextCarrier.items();
        while (next.hasNext()) {
            next = next.next();
            Iterator<Map.Entry<String, String>> iterator = textMapCarrier.iterator();
            while (iterator.hasNext()) {
                Map.Entry<String, String> entry = iterator.next();
                if (next.getHeadKey().equals(entry.getKey())) {
                    next.setHeadValue(entry.getValue());
                    break;
                }
            }
        }
        ContextManager.extract(contextCarrier);
    }
    return new TextMapContext();
}
 
开发者ID:apache,项目名称:incubator-skywalking,代码行数:25,代码来源:SkywalkingTracerExtractInterceptor.java


示例13: attachTraceInfo

import io.opentracing.propagation.TextMap; //导入依赖的package包/类
protected void attachTraceInfo(Tracer tracer, Span span, final Invocation inv) {
    tracer.inject(span.context(), Format.Builtin.TEXT_MAP, new TextMap() {

        @Override
        public void put(String key, String value) {
            inv.getAttachments().put(key, value);
        }

        @Override
        public Iterator<Map.Entry<String, String>> iterator() {
            throw new UnsupportedOperationException("TextMapInjectAdapter should only be used with Tracer.inject()");
        }
    });
}
 
开发者ID:yangfuhai,项目名称:jboot,代码行数:15,代码来源:JbootDubboConsumerTracingFilter.java


示例14: attachTraceInfo

import io.opentracing.propagation.TextMap; //导入依赖的package包/类
protected void attachTraceInfo(Tracer tracer, Span span, final Request request) {
    tracer.inject(span.context(), Format.Builtin.TEXT_MAP, new TextMap() {

        @Override
        public void put(String key, String value) {
            request.setAttachment(key, value);
        }

        @Override
        public Iterator<Map.Entry<String, String>> iterator() {
            throw new UnsupportedOperationException("TextMapInjectAdapter should only be used with Tracer.inject()");
        }
    });
}
 
开发者ID:yangfuhai,项目名称:jboot,代码行数:15,代码来源:JbootMotanTracingFilter.java


示例15: inject

import io.opentracing.propagation.TextMap; //导入依赖的package包/类
@Override
public void inject(SpanContext context, TextMap carrier) {
    put(carrier, convention.traceIdKey(), context.getTraceId());
    put(carrier, convention.spanIdKey(), context.getSpanId());
    put(carrier, convention.parentIdKey(), context.getParentId());

    for (Map.Entry<String, String> baggage : context.baggageItems()) {
        put(carrier, prefixKey(convention.baggagePrefix(), baggage.getKey()), baggage.getValue());
    }
}
 
开发者ID:ExpediaDotCom,项目名称:haystack-client-java,代码行数:11,代码来源:TextMapPropagator.java


示例16: extract

import io.opentracing.propagation.TextMap; //导入依赖的package包/类
@Override
public SpanContext extract(TextMap carrier) {
    String traceId = null;
    String parentId = null;
    String spanId = null;

    final Map<String,String> baggage = new HashMap<>();

    for (Map.Entry<String, String> entry : carrier) {
        final String key = entry.getKey();
        if (keyCodex.decode(key).startsWith(convention.baggagePrefix())) {
            baggage.put(unprefixKey(convention.baggagePrefix(), keyCodex.decode(key)), valueCodex.decode(entry.getValue()));
        } else if (convention.traceIdKeyAliases().contains(keyCodex.decode(key))) {
            traceId = valueCodex.decode(entry.getValue());
        } else if (convention.parentIdKeyAliases().contains(keyCodex.decode(key))) {
            parentId = valueCodex.decode(entry.getValue());
        } else if (convention.spanIdKeyAliases().contains(keyCodex.decode(key))) {
            spanId = valueCodex.decode(entry.getValue());
        }
    }

    if (traceId == null || spanId == null) {
        // throw an IllegalArgumentException due to invalid propagation?
        return null;
    }

    SpanContext context = new SpanContext(UUID.fromString(traceId),
                                          UUID.fromString(spanId),
                                          UUID.fromString(parentId));
    return context.addBaggage(baggage);
}
 
开发者ID:ExpediaDotCom,项目名称:haystack-client-java,代码行数:32,代码来源:TextMapPropagator.java


示例17: Builder

import io.opentracing.propagation.TextMap; //导入依赖的package包/类
public Builder(String serviceName, Dispatcher dispatcher) {
    this.serviceName = serviceName;
    this.dispatcher = dispatcher;

    TextMapPropagator textMapPropagator = new TextMapPropagator.Builder().build();
    withFormat(Format.Builtin.TEXT_MAP, (Injector<TextMap>) textMapPropagator);
    withFormat(Format.Builtin.TEXT_MAP, (Extractor<TextMap>) textMapPropagator);

    TextMapPropagator httpPropagator = new TextMapPropagator.Builder().withURLCodex().build();
    withFormat(Format.Builtin.HTTP_HEADERS, (Injector<TextMap>) httpPropagator);
    withFormat(Format.Builtin.HTTP_HEADERS, (Extractor<TextMap>) httpPropagator);

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


示例18: testExtractInvalid

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

    Map<String, String> carrierValues = new HashMap<>();
    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, null);
}
 
开发者ID:ExpediaDotCom,项目名称:haystack-client-java,代码行数:16,代码来源:TracerPropagationTest.java


示例19: run

import io.opentracing.propagation.TextMap; //导入依赖的package包/类
public void run(Map<String, String> map) {
  TextMap carrier = new TextMapExtractAdapter(map);
  SpanContext spanContext = tracer.extract(Format.Builtin.TEXT_MAP, carrier);

  ActiveSpan span = tracer.buildSpan("main")
      .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT)
      .addReference(References.FOLLOWS_FROM, spanContext)
      .startActive();

  waitABit();

  span.close();
}
 
开发者ID:jeqo,项目名称:talk-observing-distributed-systems,代码行数:14,代码来源:AnotherProcess.java


示例20: attachTraceInfo

import io.opentracing.propagation.TextMap; //导入依赖的package包/类
protected void attachTraceInfo(Tracer tracer, Span span, final Request request) {
    tracer.inject(span.context(), Format.Builtin.TEXT_MAP, new TextMap() {

        @Override
        public void put(String key, String value) {
            request.setAttachment(key, value);
        }

        @Override
        public Iterator<Entry<String, String>> iterator() {
            throw new UnsupportedOperationException("TextMapInjectAdapter should only be used with Tracer.inject()");
        }
    });
}
 
开发者ID:SkywalkingTest,项目名称:docker-skywalking-test-cluster,代码行数:15,代码来源:OpenTracingFilter.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java MXBeanLookup类代码示例发布时间:2022-05-21
下一篇:
Java GraphName类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap