use of io.opentracing.propagation.TextMapExtractAdapter in project jaeger-client-java by jaegertracing.
the class PropagationTest method testDebugCorrelationId.
@Test
public void testDebugCorrelationId() {
Tracer tracer = new Tracer.Builder("test", new InMemoryReporter(), new ConstSampler(true)).build();
Map<String, String> headers = new HashMap<>();
headers.put(Constants.DEBUG_ID_HEADER_KEY, "Coraline");
TextMap carrier = new TextMapExtractAdapter(headers);
SpanContext spanContext = (SpanContext) tracer.extract(Format.Builtin.TEXT_MAP, carrier);
assertTrue(spanContext.isDebugIdContainerOnly());
assertEquals("Coraline", spanContext.getDebugId());
Span span = (Span) tracer.buildSpan("span").asChildOf(spanContext).start();
spanContext = (SpanContext) span.context();
assertTrue(spanContext.isSampled());
assertTrue(spanContext.isDebug());
assertEquals("Coraline", span.getTags().get(Constants.DEBUG_ID_HEADER_KEY));
}
use of io.opentracing.propagation.TextMapExtractAdapter in project motan by weibocom.
the class OpenTracingFilter method extractTraceInfo.
protected Span extractTraceInfo(Request request, Tracer tracer) {
String operationName = buildOperationName(request);
SpanBuilder span = tracer.buildSpan(operationName);
try {
SpanContext spanContext = tracer.extract(Format.Builtin.TEXT_MAP, new TextMapExtractAdapter(request.getAttachments()));
if (spanContext != null) {
span.asChildOf(spanContext);
}
} catch (Exception e) {
span.withTag("Error", "extract from request fail, error msg:" + e.getMessage());
}
return span.start();
}
use of io.opentracing.propagation.TextMapExtractAdapter in project wso2-synapse by wso2.
the class JaegerSpanHandler method startSpan.
/**
* Starts a span, and stores necessary information in the span store to retrieve them back when needed.
* @param statisticDataUnit Statistic data unit object, which was collected during a statistic event.
* @param synCtx Message context.
* @param spanStore Span store object.
*/
private void startSpan(StatisticDataUnit statisticDataUnit, MessageContext synCtx, SpanStore spanStore) {
SpanWrapper parentSpanWrapper = ParentResolver.resolveParent(statisticDataUnit, spanStore, synCtx);
Span parentSpan = null;
if (parentSpanWrapper != null) {
parentSpan = parentSpanWrapper.getSpan();
}
Span span;
SpanContext spanContext;
Map<String, String> tracerSpecificCarrier = new HashMap<>();
Map headersMap = (Map) ((Axis2MessageContext) synCtx).getAxis2MessageContext().getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
Object statusCode = ((Axis2MessageContext) synCtx).getAxis2MessageContext().getProperty("HTTP_SC");
Object statusDescription = ((Axis2MessageContext) synCtx).getAxis2MessageContext().getProperty("HTTP_DESC");
// We only need to extract span context from headers when there are trp headers available
if (isOuterLevelSpan(statisticDataUnit, spanStore) && headersMap != null) {
// Extract span context from headers
spanContext = tracer.extract(Format.Builtin.HTTP_HEADERS, new TextMapExtractAdapter(headersMap));
span = tracer.buildSpan(statisticDataUnit.getComponentName()).asChildOf(spanContext).start();
} else {
span = tracer.buildSpan(statisticDataUnit.getComponentName()).asChildOf(parentSpan).start();
spanContext = span.context();
}
// Fix null pointer issue occurs when spanContext become null
if (spanContext != null) {
// Set tracing headers
tracer.inject(spanContext, Format.Builtin.HTTP_HEADERS, new TextMapInjectAdapter(tracerSpecificCarrier));
}
// <property name="TRANSPORT_HEADERS" action="remove" scope="axis2"/>
if (headersMap != null) {
headersMap.putAll(tracerSpecificCarrier);
statisticDataUnit.setTransportHeaderMap(headersMap);
}
if (statusCode != null) {
statisticDataUnit.setStatusCode(statusCode.toString());
}
if (statusDescription != null) {
statisticDataUnit.setStatusDescription(statusDescription.toString());
}
if (statisticDataUnit.getComponentType() != null & statisticDataUnit.getComponentType() == ComponentType.ENDPOINT) {
statisticDataUnit.setEndpoint(synCtx.getEndpoint(statisticDataUnit.getComponentName()));
}
String spanId = TracingUtils.extractId(statisticDataUnit);
SpanWrapper spanWrapper = spanStore.addSpanWrapper(spanId, span, statisticDataUnit, parentSpanWrapper, synCtx);
if (isOuterLevelSpan(statisticDataUnit, spanStore)) {
spanStore.assignOuterLevelSpan(spanWrapper);
}
}
Aggregations