Search in sources :

Example 1 with Reporter

use of zipkin2.reporter.Reporter in project carbon-apimgt by wso2.

the class ZipkinTracer method getTracer.

@Override
public Tracer getTracer(String serviceName) {
    String hostname = configuration.getFirstProperty(TracingConstants.ZIPKIN_CONFIG_HOST) != null ? configuration.getFirstProperty(TracingConstants.ZIPKIN_CONFIG_HOST) : TracingConstants.ZIPKIN_DEFAULT_HOST;
    int port = configuration.getFirstProperty(TracingConstants.ZIPKIN_CONFIG_PORT) != null ? Integer.parseInt(configuration.getFirstProperty(TracingConstants.ZIPKIN_CONFIG_PORT)) : TracingConstants.ZIPKIN_DEFAULT_PORT;
    boolean tracerLogEnabled = Boolean.parseBoolean(configuration.getFirstProperty(TracingConstants.CONFIG_TRACER_LOG_ENABLED) != null ? configuration.getFirstProperty(TracingConstants.CONFIG_TRACER_LOG_ENABLED) : TracingConstants.DEFAULT_TRACER_LOG_ENABLED);
    OkHttpSender sender = OkHttpSender.create("http://" + hostname + ":" + port + TracingConstants.ZIPKIN_API_CONTEXT);
    Tracer tracer = BraveTracer.create(Tracing.newBuilder().localServiceName(serviceName).spanReporter(AsyncReporter.builder(sender).build()).propagationFactory(ExtraFieldPropagation.newFactory(B3Propagation.FACTORY, TracingConstants.REQUEST_ID)).build());
    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 : OkHttpSender(zipkin2.reporter.okhttp3.OkHttpSender) ThreadLocalScopeManager(io.opentracing.util.ThreadLocalScopeManager) BraveTracer(brave.opentracing.BraveTracer) Tracer(io.opentracing.Tracer) GlobalTracer(io.opentracing.util.GlobalTracer) Reporter(io.opentracing.contrib.reporter.Reporter) AsyncReporter(zipkin2.reporter.AsyncReporter) TracerR(io.opentracing.contrib.reporter.TracerR)

Example 2 with Reporter

use of zipkin2.reporter.Reporter in project brave by openzipkin.

the class TracerTest method toString_withSpanReporter.

@Test
public void toString_withSpanReporter() {
    tracer = Tracing.newBuilder().addSpanHandler(new SpanHandler() {

        @Override
        public boolean end(TraceContext context, MutableSpan span, Cause cause) {
            return true;
        }

        @Override
        public String toString() {
            return "MyHandler";
        }
    }).spanReporter(new Reporter<zipkin2.Span>() {

        @Override
        public void report(zipkin2.Span span) {
        }

        @Override
        public String toString() {
            return "MyReporter";
        }
    }).build().tracer();
    assertThat(tracer).hasToString("Tracer{spanHandler=[MyHandler, MyReporter]}");
}
Also used : MutableSpan(brave.handler.MutableSpan) Reporter(zipkin2.reporter.Reporter) StrictCurrentTraceContext(brave.propagation.StrictCurrentTraceContext) CurrentTraceContext(brave.propagation.CurrentTraceContext) TraceContext(brave.propagation.TraceContext) TestSpanHandler(brave.test.TestSpanHandler) SpanHandler(brave.handler.SpanHandler) MutableSpan(brave.handler.MutableSpan) Test(org.junit.Test)

Aggregations

MutableSpan (brave.handler.MutableSpan)1 SpanHandler (brave.handler.SpanHandler)1 BraveTracer (brave.opentracing.BraveTracer)1 CurrentTraceContext (brave.propagation.CurrentTraceContext)1 StrictCurrentTraceContext (brave.propagation.StrictCurrentTraceContext)1 TraceContext (brave.propagation.TraceContext)1 TestSpanHandler (brave.test.TestSpanHandler)1 Tracer (io.opentracing.Tracer)1 Reporter (io.opentracing.contrib.reporter.Reporter)1 TracerR (io.opentracing.contrib.reporter.TracerR)1 GlobalTracer (io.opentracing.util.GlobalTracer)1 ThreadLocalScopeManager (io.opentracing.util.ThreadLocalScopeManager)1 Test (org.junit.Test)1 AsyncReporter (zipkin2.reporter.AsyncReporter)1 Reporter (zipkin2.reporter.Reporter)1 OkHttpSender (zipkin2.reporter.okhttp3.OkHttpSender)1