Search in sources :

Example 46 with Span

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();
    }
}
Also used : Scope(io.opentracing.Scope) Span(io.opentracing.Span) Test(org.junit.Test)

Example 47 with Span

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());
}
Also used : Scope(io.opentracing.Scope) Span(io.opentracing.Span) Test(org.junit.Test)

Example 48 with Span

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());
}
Also used : Scope(io.opentracing.Scope) Span(io.opentracing.Span) Test(org.junit.Test)

Example 49 with Span

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);
}
Also used : HashMap(java.util.HashMap) TextMapAdapter(io.opentracing.propagation.TextMapAdapter) Span(io.opentracing.Span) Test(org.junit.Test)

Example 50 with Span

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;
}
Also used : Span(io.opentracing.Span) TraceResponse(io.jaegertracing.crossdock.api.TraceResponse) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Aggregations

Span (io.opentracing.Span)370 Future (io.vertx.core.Future)182 HttpURLConnection (java.net.HttpURLConnection)174 Tracer (io.opentracing.Tracer)123 JsonObject (io.vertx.core.json.JsonObject)119 ClientErrorException (org.eclipse.hono.client.ClientErrorException)117 Map (java.util.Map)116 SpanContext (io.opentracing.SpanContext)115 Objects (java.util.Objects)109 List (java.util.List)104 TracingHelper (org.eclipse.hono.tracing.TracingHelper)104 Optional (java.util.Optional)102 Promise (io.vertx.core.Promise)98 Test (org.junit.jupiter.api.Test)96 MessageHelper (org.eclipse.hono.util.MessageHelper)89 Vertx (io.vertx.core.Vertx)84 Constants (org.eclipse.hono.util.Constants)82 ServerErrorException (org.eclipse.hono.client.ServerErrorException)80 Truth.assertThat (com.google.common.truth.Truth.assertThat)79 Mockito.mock (org.mockito.Mockito.mock)79