use of io.jaegertracing.internal.JaegerSpanContext in project cxf by apache.
the class OpenTracingTracingTest method testThatOuterSpanIsCreatedUsingAsyncInvocation.
@Test
public void testThatOuterSpanIsCreatedUsingAsyncInvocation() {
final JaegerSpanContext spanId = fromRandom();
final Response r = withTrace(createWebClient("/bookstore/books/async/notrace"), spanId).get();
assertEquals(Status.OK.getStatusCode(), r.getStatus());
assertThat(REPORTER.getSpans().size(), equalTo(1));
assertThat(REPORTER.getSpans().get(0).getOperationName(), equalTo("GET /bookstore/books/async/notrace"));
}
use of io.jaegertracing.internal.JaegerSpanContext in project cxf by apache.
the class OpenTracingTracingTest method testThatNewInnerSpanIsCreated.
@Test
public void testThatNewInnerSpanIsCreated() {
final JaegerSpanContext spanId = fromRandom();
final Response r = withTrace(createWebClient("/bookstore/books"), spanId).get();
assertEquals(Status.OK.getStatusCode(), r.getStatus());
assertThat(REPORTER.getSpans().size(), equalTo(2));
assertThat(REPORTER.getSpans().get(0).getOperationName(), equalTo("Get Books"));
assertThat(REPORTER.getSpans().get(1).getOperationName(), equalTo("GET /bookstore/books"));
}
use of io.jaegertracing.internal.JaegerSpanContext in project jaeger-client-java by jaegertracing.
the class TextMapCodec method extract.
@Override
public JaegerSpanContext extract(TextMap carrier) {
JaegerSpanContext context = null;
Map<String, String> baggage = null;
String debugId = null;
for (Map.Entry<String, String> entry : carrier) {
String key = entry.getKey();
if (key.equalsIgnoreCase(contextKey)) {
context = contextFromString(decodedValue(entry.getValue()));
} else if (key.equalsIgnoreCase(Constants.DEBUG_ID_HEADER_KEY)) {
debugId = decodedValue(entry.getValue());
} else if (key.regionMatches(true, 0, baggagePrefix, 0, baggagePrefix.length())) {
if (baggage == null) {
baggage = new HashMap<>();
}
baggage.put(keys.unprefixedKey(key.toLowerCase(Locale.ROOT), baggagePrefix), decodedValue(entry.getValue()));
} else if (key.equalsIgnoreCase(Constants.BAGGAGE_HEADER_KEY)) {
baggage = parseBaggageHeader(decodedValue(entry.getValue()), baggage);
}
}
if (debugId == null && baggage == null) {
return context;
}
return objectFactory.createSpanContext(context == null ? 0L : context.getTraceIdHigh(), context == null ? 0L : context.getTraceIdLow(), context == null ? 0L : context.getSpanId(), context == null ? 0L : context.getParentId(), context == null ? (byte) 0 : context.getFlags(), baggage, debugId);
}
use of io.jaegertracing.internal.JaegerSpanContext in project jaeger-client-java by jaegertracing.
the class ConfigurationTest method testPropagationB3Only.
@Test
public void testPropagationB3Only() {
System.setProperty(Configuration.JAEGER_PROPAGATION, "b3");
System.setProperty(Configuration.JAEGER_SERVICE_NAME, "Test");
long traceIdLow = 1234L;
long spanId = 5678L;
TestTextMap textMap = new TestTextMap();
JaegerSpanContext spanContext = new JaegerSpanContext(0, traceIdLow, spanId, 0, (byte) 0);
JaegerTracer tracer = Configuration.fromEnv().getTracer();
tracer.inject(spanContext, Format.Builtin.TEXT_MAP, textMap);
assertNotNull(textMap.get("X-B3-TraceId"));
assertNotNull(textMap.get("X-B3-SpanId"));
assertNull(textMap.get("uber-trace-id"));
JaegerSpanContext extractedContext = tracer.extract(Format.Builtin.TEXT_MAP, textMap);
assertEquals(traceIdLow, extractedContext.getTraceIdLow());
assertEquals(0, extractedContext.getTraceIdHigh());
assertEquals(spanId, extractedContext.getSpanId());
}
use of io.jaegertracing.internal.JaegerSpanContext in project jaeger-client-java by jaegertracing.
the class TraceContextCodec method extractContextFromTraceParent.
private JaegerSpanContext extractContextFromTraceParent(String traceparent, String tracestate, String debugId) {
// TODO(bdrutu): Do we need to verify that version is hex and that
// for the version the length is the expected one?
boolean isValid = traceparent != null && traceparent.charAt(TRACE_OPTION_OFFSET - 1) == TRACEPARENT_DELIMITER && (traceparent.length() == TRACEPARENT_HEADER_SIZE || (traceparent.length() > TRACEPARENT_HEADER_SIZE && traceparent.charAt(TRACEPARENT_HEADER_SIZE) == TRACEPARENT_DELIMITER)) && traceparent.charAt(SPAN_ID_OFFSET - 1) == TRACEPARENT_DELIMITER && traceparent.charAt(TRACE_OPTION_OFFSET - 1) == TRACEPARENT_DELIMITER;
if (!isValid) {
log.warn("Unparseable traceparent header. Returning null span context.");
return null;
}
Long traceIdHigh = HexCodec.hexToUnsignedLong(traceparent, TRACE_ID_OFFSET, TRACE_ID_OFFSET + 16);
Long traceIdLow = HexCodec.hexToUnsignedLong(traceparent, TRACE_ID_OFFSET + 16, TRACE_ID_OFFSET + 32);
Long spanId = HexCodec.hexToUnsignedLong(traceparent, SPAN_ID_OFFSET, SPAN_ID_OFFSET + 16);
boolean sampled = false;
long traceContextFlags = HexCodec.hexToUnsignedLong(traceparent, TRACE_OPTION_OFFSET, TRACE_OPTION_OFFSET + 2);
if ((traceContextFlags & SAMPLED_FLAG) == SAMPLED_FLAG) {
sampled = true;
}
if (traceIdLow == null || traceIdLow == 0 || spanId == null || spanId == 0) {
log.warn("Unparseable traceparent header. Returning null span context.");
return null;
}
JaegerSpanContext spanContext = this.objectFactory.createSpanContext(traceIdHigh, traceIdLow, spanId, 0, sampled ? (byte) 1 : (byte) 0, Collections.<String, String>emptyMap(), debugId);
return spanContext.withTraceState(tracestate);
}
Aggregations