use of io.opentracing.SpanContext in project jaeger-client-java by jaegertracing.
the class FilterIntegrationTest method testExtractorReturnsNullWhenTracerStateHeaderIsMissing.
/*
* This test exists because opentracing's convention around missing tracer
* state headers may change to stop supporting the automatic creation of
* building a span.
*/
@Test
public void testExtractorReturnsNullWhenTracerStateHeaderIsMissing() {
ContainerRequestContext reqContext = mock(ContainerRequestContext.class);
given(reqContext.getHeaders()).willReturn(new MultivaluedHashMap<String, String>());
ServerRequestCarrier carrier = new ServerRequestCarrier(reqContext);
SpanContext spanCtx = tracer.extract(Format.Builtin.HTTP_HEADERS, carrier);
assertNull(spanCtx);
}
use of io.opentracing.SpanContext in project wildfly-swarm by wildfly-swarm.
the class HealthServlet method doGet.
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
Tracer tracer = GlobalTracer.get();
SpanContext context = (SpanContext) req.getAttribute(SERVER_SPAN_CONTEXT);
tracer.buildSpan("health-check-1").asChildOf(context).startActive(true).close();
resp.getWriter().write("alive");
}
use of io.opentracing.SpanContext in project wildfly-swarm by wildfly-swarm.
the class SimpleServlet method doGet.
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
Tracer tracer = GlobalTracer.get();
SpanContext context = (SpanContext) req.getAttribute(SERVER_SPAN_CONTEXT);
tracer.buildSpan("business-operation-1").asChildOf(context).startActive(true).close();
resp.getWriter().write("world");
}
use of io.opentracing.SpanContext in project ballerina by ballerina-lang.
the class StartSpanWithParentContext method execute.
@Override
public void execute(Context context) {
String serviceName = context.getStringArgument(0);
String spanName = context.getStringArgument(1);
BMap tags = (BMap) context.getRefArgument(0);
String reference = context.getRefArgument(1).stringValue();
BStruct parentSpanContextStruct = (BStruct) context.getRefArgument(2);
PrintStream err = System.err;
Map<String, SpanContext> extractedSpanContextMap;
if (ReferenceType.valueOf(reference) != ReferenceType.ROOT && parentSpanContextStruct != null && parentSpanContextStruct.getRefField(0) != null) {
Map<String, String> parentSpanContextMap = Utils.toStringMap((BMap) parentSpanContextStruct.getRefField(0));
extractedSpanContextMap = OpenTracerBallerinaWrapper.getInstance().extract(parentSpanContextMap);
} else {
extractedSpanContextMap = Collections.emptyMap();
}
String spanId = OpenTracerBallerinaWrapper.getInstance().startSpan(serviceName, spanName, Utils.toStringMap(tags), ReferenceType.valueOf(reference), extractedSpanContextMap);
if (spanId != null) {
context.setReturnValues(Utils.createSpanStruct(context, spanId, serviceName, spanName));
} else {
context.setReturnValues(Utils.createSpanStruct(context, null, null, null));
err.println("ballerina: Can not use tracing API when tracing is disabled");
}
}
use of io.opentracing.SpanContext in project ballerina by ballerina-lang.
the class OpenTracerBallerinaWrapper method startSpan.
/**
* Method to start a span using parent span context.
*
* @param serviceName name of the service the span should belong to
* @param spanName name of the span
* @param tags key value paired tags to attach to the span
* @param referenceType type of reference to any parent span
* @param parentSpanContext map of the parent span context
* @return unique id of the created span
*/
public String startSpan(String serviceName, String spanName, Map<String, String> tags, ReferenceType referenceType, Map<String, SpanContext> parentSpanContext) {
if (enabled) {
Map<String, Span> spanMap = new HashMap<>();
Map<String, SpanContext> spanContextMap = new HashMap<>();
Map<String, Tracer> tracers = tracerStore.getTracers(serviceName);
tracers.forEach((tracerName, tracer) -> {
Tracer.SpanBuilder spanBuilder = tracer.buildSpan(spanName);
for (Map.Entry<String, String> tag : tags.entrySet()) {
spanBuilder = spanBuilder.withTag(tag.getKey(), tag.getValue());
}
if (parentSpanContext != null && !parentSpanContext.isEmpty()) {
spanBuilder = setParent(referenceType, parentSpanContext, spanBuilder, tracerName);
}
Span span = spanBuilder.start();
spanMap.put(tracerName, span);
spanContextMap.put(tracerName, span.context());
});
String spanId = UUID.randomUUID().toString();
spanStore.addSpan(spanId, spanMap);
spanStore.addSpanContext(spanId, spanContextMap);
return spanId;
} else {
return null;
}
}
Aggregations