use of io.opentracing.Span in project jaeger-client-java by jaegertracing.
the class RemovedFrom032Test method testScope_span.
@Test
public void testScope_span() {
Span span = tracer.buildSpan(SPAN_NAME).start();
Scope scope = tracer.scopeManager().activate(span);
try {
assertEquals(span, scope.span());
} finally {
scope.close();
}
}
use of io.opentracing.Span in project jaeger-client-java by jaegertracing.
the class ActiveSpanTest method testIgnoreActiveSpan.
@Test
public void testIgnoreActiveSpan() {
Span span = tracer.buildSpan("parent").start();
try (Scope ignored = tracer.activateSpan(span)) {
tracer.buildSpan("child").ignoreActiveSpan().start().finish();
} finally {
span.finish();
}
assertEquals(2, reporter.getSpans().size());
JaegerSpan childSpan = reporter.getSpans().get(0);
JaegerSpan parentSpan = reporter.getSpans().get(1);
JaegerSpanContext parentSpanContext = parentSpan.context();
JaegerSpanContext childSpanContext = childSpan.context();
assertTrue((reporter.getSpans().get(0)).getReferences().isEmpty());
assertTrue((reporter.getSpans().get(1)).getReferences().isEmpty());
assertNotEquals(parentSpanContext.getTraceId(), childSpanContext.getTraceId());
assertEquals(0, childSpanContext.getParentId());
}
use of io.opentracing.Span in project jaeger-client-java by jaegertracing.
the class ActiveSpanTest method testActiveSpanNotAutoFinishOnClose.
@Test
public void testActiveSpanNotAutoFinishOnClose() {
Span span = tracer.buildSpan("parent").start();
try (Scope ignored = tracer.activateSpan(span)) {
// noop
}
assertTrue(reporter.getSpans().isEmpty());
span.finish();
assertEquals(1, reporter.getSpans().size());
}
use of io.opentracing.Span in project jaeger-client-java by jaegertracing.
the class AdhocHeadersTest method testJoinTraceWithAdhocBaggage.
@Test
public void testJoinTraceWithAdhocBaggage() {
Span span = tracer.buildSpan("test").start();
Map<String, String> headers = new HashMap<String, String>();
tracer.inject(span.context(), Format.Builtin.HTTP_HEADERS, new TextMapAdapter(headers));
assertEquals(1, headers.size());
traceWithAdhocBaggage(headers);
}
use of io.opentracing.Span in project jaeger-client-java by jaegertracing.
the class TraceBehaviorResource method startTrace.
@POST
@Path("start_trace")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public TraceResponse startTrace(StartTraceRequest startRequest) throws Exception {
log.info("http:start_trace request: {}", mapper.writeValueAsString(startRequest));
// TODO should be starting new root span
String baggage = startRequest.getBaggage();
Span span = tracer.activeSpan();
span.setBaggageItem(Constants.BAGGAGE_KEY, baggage);
if (startRequest.isSampled()) {
Tags.SAMPLING_PRIORITY.set(span, 1);
}
TraceResponse response = behavior.prepareResponse(startRequest.getDownstream());
log.info("http:start_trace response: {}", mapper.writeValueAsString(response));
return response;
}
Aggregations