Search in sources :

Example 41 with Tracer

use of io.opentracing.Tracer in project hono by eclipse.

the class CoapOptionInjectExtractAdapterTest method testJaegerTracerInjectsAndExtractsSpanContext.

/**
 * Verifies that the Jaeger tracer implementation can successfully use the adapter to inject and extract
 * a SpanContext.
 */
@Test
public void testJaegerTracerInjectsAndExtractsSpanContext() {
    final Configuration config = new Configuration("test");
    final Tracer tracer = config.getTracer();
    final Span span = tracer.buildSpan("do").start();
    final OptionSet optionSet = new OptionSet();
    final CoapOptionInjectExtractAdapter injectAdapter = CoapOptionInjectExtractAdapter.forInjection(optionSet);
    tracer.inject(span.context(), Format.Builtin.BINARY, injectAdapter);
    final SpanContext context = CoapOptionInjectExtractAdapter.forExtraction(optionSet).map(carrier -> tracer.extract(Format.Builtin.BINARY, carrier)).orElse(null);
    assertThat(context.toSpanId()).isEqualTo(span.context().toSpanId());
}
Also used : Test(org.junit.jupiter.api.Test) Tracer(io.opentracing.Tracer) Format(io.opentracing.propagation.Format) Configuration(io.jaegertracing.Configuration) Span(io.opentracing.Span) OptionSet(org.eclipse.californium.core.coap.OptionSet) Truth.assertThat(com.google.common.truth.Truth.assertThat) SpanContext(io.opentracing.SpanContext) SpanContext(io.opentracing.SpanContext) Configuration(io.jaegertracing.Configuration) Tracer(io.opentracing.Tracer) OptionSet(org.eclipse.californium.core.coap.OptionSet) Span(io.opentracing.Span) Test(org.junit.jupiter.api.Test)

Example 42 with Tracer

use of io.opentracing.Tracer in project hono by eclipse.

the class ProtonBasedCommandRouterClientTest method setUp.

/**
 * Sets up the fixture.
 */
@BeforeEach
public void setUp() {
    span = TracingMockSupport.mockSpan();
    final Tracer tracer = TracingMockSupport.mockTracer(span);
    final EventBus eventBus = mock(EventBus.class);
    final Vertx vertx = mock(Vertx.class);
    when(vertx.eventBus()).thenReturn(eventBus);
    receiver = AmqpClientUnitTestHelper.mockProtonReceiver();
    sender = AmqpClientUnitTestHelper.mockProtonSender();
    final RequestResponseClientConfigProperties config = new RequestResponseClientConfigProperties();
    // don't let requestTimeout timer be started
    config.setRequestTimeout(0);
    connection = AmqpClientUnitTestHelper.mockHonoConnection(vertx, config, tracer);
    when(connection.isConnected(anyLong())).thenReturn(Future.succeededFuture());
    when(connection.createReceiver(anyString(), any(ProtonQoS.class), any(ProtonMessageHandler.class), VertxMockSupport.anyHandler())).thenReturn(Future.succeededFuture(receiver));
    when(connection.createSender(anyString(), any(ProtonQoS.class), VertxMockSupport.anyHandler())).thenReturn(Future.succeededFuture(sender));
    client = new ProtonBasedCommandRouterClient(connection, SendMessageSampler.Factory.noop());
}
Also used : ProtonQoS(io.vertx.proton.ProtonQoS) ProtonMessageHandler(io.vertx.proton.ProtonMessageHandler) RequestResponseClientConfigProperties(org.eclipse.hono.client.RequestResponseClientConfigProperties) Tracer(io.opentracing.Tracer) EventBus(io.vertx.core.eventbus.EventBus) Vertx(io.vertx.core.Vertx) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 43 with Tracer

use of io.opentracing.Tracer in project hono by eclipse.

the class TracingMockSupport method mockTracer.

/**
 * Creates a mocked OpenTracing Tracer that will use a given SpanBuilder.
 *
 * @param spanBuilder The object that the <em>buildSpan</em> method of the
 *                    returned tracer should return.
 * @return The tracer.
 */
public static Tracer mockTracer(final SpanBuilder spanBuilder) {
    final Tracer tracer = mock(Tracer.class);
    when(tracer.buildSpan(anyString())).thenReturn(spanBuilder);
    return tracer;
}
Also used : Tracer(io.opentracing.Tracer)

Example 44 with Tracer

use of io.opentracing.Tracer in project cxf by apache.

the class Client method main.

public static void main(final String[] args) throws Exception {
    final Tracer tracer = new Configuration("tracer-client").withSampler(new SamplerConfiguration().withType(ConstSampler.TYPE).withParam(1)).withReporter(new ReporterConfiguration().withSender(new SenderConfiguration() {

        @Override
        public Sender getSender() {
            return new Slf4jLogSender();
        }
    })).getTracer();
    final OpenTracingClientProvider provider = new OpenTracingClientProvider(tracer);
    final Response response = WebClient.create("http://localhost:9000/catalog", Arrays.asList(provider)).accept(MediaType.APPLICATION_JSON).get();
    System.out.println(response.readEntity(String.class));
    response.close();
}
Also used : Slf4jLogSender(demo.jaxrs.tracing.Slf4jLogSender) Sender(io.jaegertracing.spi.Sender) Response(javax.ws.rs.core.Response) SenderConfiguration(io.jaegertracing.Configuration.SenderConfiguration) ReporterConfiguration(io.jaegertracing.Configuration.ReporterConfiguration) Configuration(io.jaegertracing.Configuration) SamplerConfiguration(io.jaegertracing.Configuration.SamplerConfiguration) Tracer(io.opentracing.Tracer) OpenTracingClientProvider(org.apache.cxf.tracing.opentracing.jaxrs.OpenTracingClientProvider) SamplerConfiguration(io.jaegertracing.Configuration.SamplerConfiguration) Slf4jLogSender(demo.jaxrs.tracing.Slf4jLogSender) SenderConfiguration(io.jaegertracing.Configuration.SenderConfiguration) ReporterConfiguration(io.jaegertracing.Configuration.ReporterConfiguration)

Example 45 with Tracer

use of io.opentracing.Tracer in project jaeger-client-java by jaegertracing.

the class EndToEndBehaviorResourceTest method setUp.

@Before
public void setUp() throws Exception {
    reporter = new InMemoryReporter();
    Tracer tracer = new JaegerTracer.Builder("crossdock-java").withReporter(reporter).withSampler(new ConstSampler(true)).build();
    Map<String, Tracer> tracers = new HashMap<>();
    tracers.put("const", tracer);
    resource = new EndToEndBehaviorResource(new EndToEndBehavior(tracers));
}
Also used : InMemoryReporter(io.jaegertracing.internal.reporters.InMemoryReporter) EndToEndBehavior(io.jaegertracing.crossdock.resources.behavior.EndToEndBehavior) HashMap(java.util.HashMap) Tracer(io.opentracing.Tracer) JaegerTracer(io.jaegertracing.internal.JaegerTracer) ConstSampler(io.jaegertracing.internal.samplers.ConstSampler) JaegerTracer(io.jaegertracing.internal.JaegerTracer) Before(org.junit.Before)

Aggregations

Tracer (io.opentracing.Tracer)104 Span (io.opentracing.Span)49 SpanContext (io.opentracing.SpanContext)30 Map (java.util.Map)21 Vertx (io.vertx.core.Vertx)19 HashMap (java.util.HashMap)19 Test (org.junit.Test)19 BeforeEach (org.junit.jupiter.api.BeforeEach)19 Test (org.junit.jupiter.api.Test)19 Future (io.vertx.core.Future)18 Buffer (io.vertx.core.buffer.Buffer)16 HttpURLConnection (java.net.HttpURLConnection)14 EventBus (io.vertx.core.eventbus.EventBus)13 JsonObject (io.vertx.core.json.JsonObject)12 Objects (java.util.Objects)12 Logger (org.slf4j.Logger)11 LoggerFactory (org.slf4j.LoggerFactory)11 Tags (io.opentracing.tag.Tags)9 Scope (io.opentracing.Scope)8 GlobalTracer (io.opentracing.util.GlobalTracer)8