Search in sources :

Example 6 with Configuration

use of io.jaegertracing.Configuration 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 7 with Configuration

use of io.jaegertracing.Configuration in project hono by eclipse.

the class KafkaHeadersInjectExtractAdapterTest method testJaegerTracerCanUseAdapter.

/**
 * Verifies that the Jaeger tracer implementation can successfully use the adapters to inject and extract
 * a SpanContext.
 */
@Test
public void testJaegerTracerCanUseAdapter() {
    final Configuration config = new Configuration("test");
    final Tracer tracer = config.getTracer();
    final Span span = tracer.buildSpan("do").start();
    final List<KafkaHeader> headers = new ArrayList<>();
    final KafkaHeadersInjectAdapter injectAdapter = new KafkaHeadersInjectAdapter(headers);
    tracer.inject(span.context(), Format.Builtin.TEXT_MAP, injectAdapter);
    final SpanContext context = tracer.extract(Format.Builtin.TEXT_MAP, new KafkaHeadersExtractAdapter(headers));
    assertThat(context.toSpanId()).isEqualTo(span.context().toSpanId());
}
Also used : SpanContext(io.opentracing.SpanContext) Configuration(io.jaegertracing.Configuration) Tracer(io.opentracing.Tracer) ArrayList(java.util.ArrayList) Span(io.opentracing.Span) KafkaHeader(io.vertx.kafka.client.producer.KafkaHeader) Test(org.junit.jupiter.api.Test)

Example 8 with Configuration

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

the class MicrometerTest method testServiceLoader.

@Test
public void testServiceLoader() {
    System.setProperty(Configuration.JAEGER_SAMPLER_TYPE, ConstSampler.TYPE);
    System.setProperty(Configuration.JAEGER_SAMPLER_PARAM, "1");
    System.setProperty(Configuration.JAEGER_SERVICE_NAME, "Test");
    // the fact that there's a service on the classpath is enough to get it loaded, unless we have an env var
    // saying to skip it
    final Configuration configuration = Configuration.fromEnv();
    System.clearProperty(Configuration.JAEGER_SERVICE_NAME);
    System.clearProperty(Configuration.JAEGER_SAMPLER_TYPE);
    System.clearProperty(Configuration.JAEGER_SAMPLER_PARAM);
    PrometheusMeterRegistry registry = (PrometheusMeterRegistry) io.micrometer.core.instrument.Metrics.globalRegistry.getRegistries().iterator().next();
    configuration.getTracer().buildSpan("theoperation").start().finish(100);
    assertEquals(1, registry.get("jaeger_tracer_started_spans").tag("sampled", "y").counter().count(), 0);
}
Also used : PrometheusMeterRegistry(io.micrometer.prometheus.PrometheusMeterRegistry) Configuration(io.jaegertracing.Configuration) Test(org.junit.Test)

Example 9 with Configuration

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

the class JerseyServer method main.

public static void main(String[] args) throws Exception {
    BasicConfigurator.configure();
    String serviceName = serviceNameFromEnv();
    Configuration configuration = new Configuration(serviceName).withSampler(new SamplerConfiguration().withType(ConstSampler.TYPE).withParam(0)).withReporter(new ReporterConfiguration().withLogSpans(true));
    JerseyServer server = new JerseyServer("0.0.0.0", 8081, configuration, Arrays.asList(new TraceBehaviorResource(configuration.getTracer()), new EndToEndBehaviorResource(new EndToEndBehavior(getEvn(SAMPLING_HOST_PORT, "jaeger-agent:5778"), "crossdock-" + serviceName, senderFromEnv(getEvn(COLLECTOR_HOST_PORT, "jaeger-collector:14268"), getEvn(AGENT_HOST, "jaeger-agent")))), new HealthResource()));
    server.addNetworkListener(new NetworkListener("health", "0.0.0.0", 8080));
    Thread.currentThread().join();
}
Also used : EndToEndBehavior(io.jaegertracing.crossdock.resources.behavior.EndToEndBehavior) ReporterConfiguration(io.jaegertracing.Configuration.ReporterConfiguration) Configuration(io.jaegertracing.Configuration) SamplerConfiguration(io.jaegertracing.Configuration.SamplerConfiguration) TraceBehaviorResource(io.jaegertracing.crossdock.resources.behavior.http.TraceBehaviorResource) SamplerConfiguration(io.jaegertracing.Configuration.SamplerConfiguration) EndToEndBehaviorResource(io.jaegertracing.crossdock.resources.behavior.http.EndToEndBehaviorResource) ReporterConfiguration(io.jaegertracing.Configuration.ReporterConfiguration) HealthResource(io.jaegertracing.crossdock.resources.health.HealthResource) NetworkListener(org.glassfish.grizzly.http.server.NetworkListener)

Example 10 with Configuration

use of io.jaegertracing.Configuration in project carbon-apimgt by wso2.

the class JaegerTracer method getTracer.

@Override
public Tracer getTracer(String serviceName) {
    String hostname = configuration.getFirstProperty(TracingConstants.JAEGER_CONFIG_HOST) != null ? configuration.getFirstProperty(TracingConstants.JAEGER_CONFIG_HOST) : TracingConstants.JAEGER_DEFAULT_HOST;
    int port = configuration.getFirstProperty(TracingConstants.JAEGER_CONFIG_PORT) != null ? Integer.parseInt(configuration.getFirstProperty(TracingConstants.JAEGER_CONFIG_PORT)) : TracingConstants.JAEGER_DEFAULT_PORT;
    String samplerType = configuration.getFirstProperty(TracingConstants.CONFIG_SAMPLER_TYPE) != null ? configuration.getFirstProperty(TracingConstants.CONFIG_SAMPLER_TYPE) : TracingConstants.DEFAULT_SAMPLER_TYPE;
    float samplerParam = configuration.getFirstProperty(TracingConstants.CONFIG_SAMPLER_PARAM) != null ? Float.parseFloat(configuration.getFirstProperty(TracingConstants.CONFIG_SAMPLER_PARAM)) : TracingConstants.DEFAULT_SAMPLER_PARAM;
    int reporterFlushInterval = configuration.getFirstProperty(TracingConstants.CONFIG_REPORTER_FLUSH_INTERVAL) != null ? Integer.parseInt(configuration.getFirstProperty(TracingConstants.CONFIG_REPORTER_FLUSH_INTERVAL)) : TracingConstants.DEFAULT_REPORTER_FLUSH_INTERVAL;
    int reporterBufferSize = configuration.getFirstProperty(TracingConstants.CONFIG_REPORTER_BUFFER_SIZE) != null ? Integer.parseInt(configuration.getFirstProperty(TracingConstants.CONFIG_REPORTER_BUFFER_SIZE)) : TracingConstants.DEFAULT_REPORTER_BUFFER_SIZE;
    boolean tracerLogEnabled = Boolean.parseBoolean(configuration.getFirstProperty(TracingConstants.CONFIG_TRACER_LOG_ENABLED) != null ? configuration.getFirstProperty(TracingConstants.CONFIG_TRACER_LOG_ENABLED) : TracingConstants.DEFAULT_TRACER_LOG_ENABLED);
    Configuration.SamplerConfiguration samplerConfig = new Configuration.SamplerConfiguration().withType(samplerType).withParam(samplerParam);
    Configuration.SenderConfiguration senderConfig = new Configuration.SenderConfiguration().withAgentHost(hostname).withAgentPort(port);
    Configuration.ReporterConfiguration reporterConfig = new Configuration.ReporterConfiguration().withLogSpans(true).withFlushInterval(reporterFlushInterval).withMaxQueueSize(reporterBufferSize).withSender(senderConfig);
    Tracer tracer = new Configuration(serviceName).withSampler(samplerConfig).withReporter(reporterConfig).getTracer();
    if (tracerLogEnabled) {
        Reporter reporter = new TracingReporter(LogFactory.getLog(TracingConstants.TRACER));
        Tracer tracerR = new TracerR(tracer, reporter, new ThreadLocalScopeManager());
        GlobalTracer.register(tracerR);
        return tracerR;
    } else {
        GlobalTracer.register(tracer);
        return tracer;
    }
}
Also used : APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) Configuration(io.jaegertracing.Configuration) ThreadLocalScopeManager(io.opentracing.util.ThreadLocalScopeManager) Tracer(io.opentracing.Tracer) GlobalTracer(io.opentracing.util.GlobalTracer) Reporter(io.opentracing.contrib.reporter.Reporter) TracerR(io.opentracing.contrib.reporter.TracerR)

Aggregations

Configuration (io.jaegertracing.Configuration)15 Tracer (io.opentracing.Tracer)7 Span (io.opentracing.Span)5 SpanContext (io.opentracing.SpanContext)5 Test (org.junit.Test)5 Test (org.junit.jupiter.api.Test)5 ReporterConfiguration (io.jaegertracing.Configuration.ReporterConfiguration)4 SamplerConfiguration (io.jaegertracing.Configuration.SamplerConfiguration)4 JaegerTracer (io.jaegertracing.internal.JaegerTracer)2 ConstSampler (io.jaegertracing.internal.samplers.ConstSampler)2 Sampler (io.jaegertracing.spi.Sampler)2 PrometheusMeterRegistry (io.micrometer.prometheus.PrometheusMeterRegistry)2 ArrayList (java.util.ArrayList)2 Before (org.junit.Before)2 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 Slf4jLogSender (demo.jaxrs.tracing.Slf4jLogSender)1 CodecConfiguration (io.jaegertracing.Configuration.CodecConfiguration)1 SenderConfiguration (io.jaegertracing.Configuration.SenderConfiguration)1 JerseyServer (io.jaegertracing.crossdock.JerseyServer)1 EndToEndBehavior (io.jaegertracing.crossdock.resources.behavior.EndToEndBehavior)1