本文整理汇总了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");
}
示例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);
}
示例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");
}
示例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;
}
示例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);
}
示例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;
}
示例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());
}
示例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());
}
示例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());
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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);
});
}
示例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();
}