Search in sources :

Example 1 with Sender

use of zipkin2.reporter.Sender 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 Sender

use of zipkin2.reporter.Sender in project spring-cloud-gcp by spring-cloud.

the class StackdriverTraceAutoConfiguration method stackdriverReporter.

@Bean(REPORTER_BEAN_NAME)
@ConditionalOnMissingBean(name = REPORTER_BEAN_NAME)
public Reporter<Span> stackdriverReporter(ReporterMetrics reporterMetrics, GcpTraceProperties trace, @Qualifier(SENDER_BEAN_NAME) Sender sender) {
    AsyncReporter<Span> asyncReporter = AsyncReporter.builder(sender).queuedMaxSpans(1000).messageTimeout(trace.getMessageTimeout(), TimeUnit.SECONDS).metrics(reporterMetrics).build(StackdriverEncoder.V2);
    CheckResult checkResult = asyncReporter.check();
    if (!checkResult.ok()) {
        LOGGER.warn("Error when performing Stackdriver AsyncReporter health check.", checkResult.error());
    }
    return asyncReporter;
}
Also used : CheckResult(zipkin2.CheckResult) Span(zipkin2.Span) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 3 with Sender

use of zipkin2.reporter.Sender in project spring-cloud-gcp by spring-cloud.

the class StackdriverTraceAutoConfigurationTests method testAsyncReporterHealthCheck.

@Test
public void testAsyncReporterHealthCheck() {
    Sender senderMock = mock(Sender.class);
    when(senderMock.check()).thenReturn(CheckResult.OK);
    when(senderMock.encoding()).thenReturn(SpanBytesEncoder.PROTO3.encoding());
    this.contextRunner.withBean(StackdriverTraceAutoConfiguration.SENDER_BEAN_NAME, Sender.class, () -> senderMock).run(context -> {
        Reporter<Span> asyncReporter = context.getBean(Reporter.class);
        assertThat(asyncReporter).isNotNull();
        verify(senderMock, times(1)).check();
    });
}
Also used : Sender(zipkin2.reporter.Sender) Span(com.google.devtools.cloudtrace.v2.Span) Test(org.junit.Test)

Example 4 with Sender

use of zipkin2.reporter.Sender in project spring-cloud-sleuth by spring-cloud.

the class FactoryUser method should_work_with_flat_maps.

@Test
public void should_work_with_flat_maps() {
    // given
    ConfigurableApplicationContext context = new SpringApplicationBuilder(FlatMapTests.TestConfiguration.class, Issue866Configuration.class).web(WebApplicationType.REACTIVE).properties("server.port=0", "spring.jmx.enabled=false", "spring.application.name=TraceWebFluxTests", "security.basic.enabled=false", "management.security.enabled=false").run();
    ArrayListSpanReporter accumulator = context.getBean(ArrayListSpanReporter.class);
    int port = context.getBean(Environment.class).getProperty("local.server.port", Integer.class);
    RequestSender sender = context.getBean(RequestSender.class);
    TestConfiguration config = context.getBean(TestConfiguration.class);
    FactoryUser factoryUser = context.getBean(FactoryUser.class);
    sender.port = port;
    accumulator.clear();
    Awaitility.await().untilAsserted(() -> {
        // when
        accumulator.clear();
        String firstTraceId = flatMapTraceId(accumulator, callFlatMap(port).block());
        // then
        thenAllWebClientCallsHaveSameTraceId(firstTraceId, sender);
        thenSpanInFooHasSameTraceId(firstTraceId, config);
        accumulator.clear();
        // when
        String secondTraceId = flatMapTraceId(accumulator, callFlatMap(port).block());
        // then
        then(firstTraceId).as("Id will not be reused between calls").isNotEqualTo(secondTraceId);
        thenSpanInFooHasSameTraceId(secondTraceId, config);
        // and
        then(Arrays.stream(capture.toString().split("\n")).filter(s -> s.contains("Received a request to uri")).map(s -> s.split(",")[1]).collect(Collectors.toList())).as("TraceFilter should not have any trace when receiving a request").containsOnly("");
        // and #866
        then(factoryUser.wasSchedulerWrapped).isTrue();
    });
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) Arrays(java.util.Arrays) ReactiveUserDetailsServiceAutoConfiguration(org.springframework.boot.autoconfigure.security.reactive.ReactiveUserDetailsServiceAutoConfiguration) BeforeClass(org.junit.BeforeClass) LoggerFactory(org.slf4j.LoggerFactory) WebClient(org.springframework.web.reactive.function.client.WebClient) Hooks(reactor.core.publisher.Hooks) Span(zipkin2.Span) Scheduler(reactor.core.scheduler.Scheduler) Sampler(brave.sampler.Sampler) ArrayListSpanReporter(org.springframework.cloud.sleuth.util.ArrayListSpanReporter) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) Schedulers(reactor.core.scheduler.Schedulers) Issue866Configuration(org.springframework.cloud.sleuth.instrument.reactor.Issue866Configuration) OutputCapture(org.springframework.boot.test.rule.OutputCapture) RouterFunctions.route(org.springframework.web.reactive.function.server.RouterFunctions.route) ReactiveSecurityAutoConfiguration(org.springframework.boot.autoconfigure.security.reactive.ReactiveSecurityAutoConfiguration) AfterClass(org.junit.AfterClass) ClientResponse(org.springframework.web.reactive.function.client.ClientResponse) Tracer(brave.Tracer) Logger(org.slf4j.Logger) EnableAutoConfiguration(org.springframework.boot.autoconfigure.EnableAutoConfiguration) SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) Import(org.springframework.context.annotation.Import) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) BDDAssertions.then(org.assertj.core.api.BDDAssertions.then) Collectors(java.util.stream.Collectors) Configuration(org.springframework.context.annotation.Configuration) Flux(reactor.core.publisher.Flux) List(java.util.List) Rule(org.junit.Rule) RouterFunction(org.springframework.web.reactive.function.server.RouterFunction) Environment(org.springframework.core.env.Environment) ServerResponse(org.springframework.web.reactive.function.server.ServerResponse) WebApplicationType(org.springframework.boot.WebApplicationType) GET(org.springframework.web.reactive.function.server.RequestPredicates.GET) Bean(org.springframework.context.annotation.Bean) Awaitility(org.awaitility.Awaitility) SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) Environment(org.springframework.core.env.Environment) Issue866Configuration(org.springframework.cloud.sleuth.instrument.reactor.Issue866Configuration) ArrayListSpanReporter(org.springframework.cloud.sleuth.util.ArrayListSpanReporter) Test(org.junit.Test)

Example 5 with Sender

use of zipkin2.reporter.Sender in project instrumentation-java by census-instrumentation.

the class ZipkinTraceExporter method createAndRegister.

/**
 * Creates and registers the Zipkin Trace exporter to the OpenCensus library. Only one Zipkin
 * exporter can be registered at any point.
 *
 * @param configuration configuration for this exporter.
 * @throws IllegalStateException if a Zipkin exporter is already registered.
 * @since 0.22
 */
public static void createAndRegister(ZipkinExporterConfiguration configuration) {
    synchronized (monitor) {
        checkState(handler == null, "Zipkin exporter is already registered.");
        Sender sender = configuration.getSender();
        if (sender == null) {
            sender = URLConnectionSender.create(configuration.getV2Url());
        }
        Handler newHandler = new ZipkinExporterHandler(configuration.getEncoder(), sender, configuration.getServiceName(), configuration.getDeadline());
        handler = newHandler;
        register(Tracing.getExportComponent().getSpanExporter(), newHandler);
    }
}
Also used : URLConnectionSender(zipkin2.reporter.urlconnection.URLConnectionSender) Sender(zipkin2.reporter.Sender) Handler(io.opencensus.trace.export.SpanExporter.Handler)

Aggregations

Test (org.junit.Test)2 Bean (org.springframework.context.annotation.Bean)2 Span (zipkin2.Span)2 Tracer (brave.Tracer)1 BraveTracer (brave.opentracing.BraveTracer)1 Sampler (brave.sampler.Sampler)1 Span (com.google.devtools.cloudtrace.v2.Span)1 Handler (io.opencensus.trace.export.SpanExporter.Handler)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 Arrays (java.util.Arrays)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 BDDAssertions.then (org.assertj.core.api.BDDAssertions.then)1 Awaitility (org.awaitility.Awaitility)1 AfterClass (org.junit.AfterClass)1 BeforeClass (org.junit.BeforeClass)1