Search in sources :

Example 1 with HttpTracing

use of brave.http.HttpTracing in project brave by openzipkin.

the class DelegatingTracingFilter method init.

@Override
public void init(FilterConfig filterConfig) {
    ApplicationContext ctx = getRequiredWebApplicationContext(filterConfig.getServletContext());
    HttpTracing httpTracing = WebMvcRuntime.get().httpTracing(ctx);
    delegate = TracingFilter.create(httpTracing);
}
Also used : WebApplicationContextUtils.getRequiredWebApplicationContext(org.springframework.web.context.support.WebApplicationContextUtils.getRequiredWebApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) HttpTracing(brave.http.HttpTracing)

Example 2 with HttpTracing

use of brave.http.HttpTracing in project brave by openzipkin.

the class WebMvcRuntimeTest method WebMvc25_httpTracing_byName.

/**
 * Spring 2.5 cannot get beans by type, so fallback to name
 */
@Test
public void WebMvc25_httpTracing_byName() {
    ApplicationContext context = mock(ApplicationContext.class);
    when(context.containsBean("httpTracing")).thenReturn(true);
    when(context.getBean("httpTracing")).thenReturn(mock(HttpTracing.class));
    new WebMvc25().httpTracing(context);
    verify(context).containsBean("httpTracing");
    verify(context).getBean("httpTracing");
    verifyNoMoreInteractions(context);
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) HttpTracing(brave.http.HttpTracing) WebMvc25(brave.spring.webmvc.WebMvcRuntime.WebMvc25) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with HttpTracing

use of brave.http.HttpTracing in project spring-cloud-sleuth by spring-cloud.

the class TraceFilterTests method createsChildFromHeadersWhenJoinUnsupported.

@Test
public void createsChildFromHeadersWhenJoinUnsupported() throws Exception {
    Tracing tracing = Tracing.newBuilder().currentTraceContext(CurrentTraceContext.Default.create()).spanReporter(this.reporter).supportsJoin(false).build();
    HttpTracing httpTracing = HttpTracing.create(tracing);
    this.request = builder().header(SPAN_ID_NAME, PARENT_ID).header(TRACE_ID_NAME, SpanUtil.idToHex(20L)).buildRequest(new MockServletContext());
    TracingFilter.create(httpTracing).doFilter(this.request, this.response, this.filterChain);
    then(Tracing.current().tracer().currentSpan()).isNull();
    then(this.reporter.getSpans()).hasSize(1);
    then(this.reporter.getSpans().get(0).parentId()).isEqualTo(PARENT_ID);
}
Also used : HttpTracing(brave.http.HttpTracing) Tracing(brave.Tracing) HttpTracing(brave.http.HttpTracing) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.Test)

Example 4 with HttpTracing

use of brave.http.HttpTracing in project spring-cloud-sleuth by spring-cloud.

the class TraceFilterTests method neverSampleFilter.

private Filter neverSampleFilter() {
    Tracing tracing = Tracing.newBuilder().currentTraceContext(CurrentTraceContext.Default.create()).spanReporter(this.reporter).sampler(Sampler.NEVER_SAMPLE).supportsJoin(false).build();
    HttpTracing httpTracing = HttpTracing.newBuilder(tracing).clientParser(new SleuthHttpClientParser(this.traceKeys)).serverParser(new SleuthHttpServerParser(this.traceKeys, new ExceptionMessageErrorParser())).serverSampler(new SleuthHttpSampler(() -> Pattern.compile(""))).build();
    return TracingFilter.create(httpTracing);
}
Also used : HttpTracing(brave.http.HttpTracing) ExceptionMessageErrorParser(org.springframework.cloud.sleuth.ExceptionMessageErrorParser) Tracing(brave.Tracing) HttpTracing(brave.http.HttpTracing)

Example 5 with HttpTracing

use of brave.http.HttpTracing in project zipkin by openzipkin.

the class ZipkinElasticsearchStorageConfiguration method esTracing.

@Bean
@Qualifier(QUALIFIER)
@ConditionalOnSelfTracing
Consumer<ClientOptionsBuilder> esTracing(Optional<HttpTracing> maybeHttpTracing) {
    if (!maybeHttpTracing.isPresent()) {
        // Alternatively, check why we would ever get here if ConditionalOnSelfTracing matches
        return client -> {
        };
    }
    HttpTracing httpTracing = maybeHttpTracing.get().clientOf("elasticsearch");
    SpanCustomizer spanCustomizer = CurrentSpanCustomizer.create(httpTracing.tracing());
    return client -> {
        client.decorator((delegate, ctx, req) -> {
            // We only need the name if it's available and can unsafely access the partially filled log.
            RequestLog log = ctx.log().partial();
            if (log.isAvailable(RequestLogProperty.NAME)) {
                String name = log.name();
                if (name != null) {
                    // override the span name if set
                    spanCustomizer.name(name);
                }
            }
            return delegate.execute(ctx, req);
        });
        // the tracing decorator is added last so that it encloses the attempt to overwrite the name.
        client.decorator(BraveClient.newDecorator(httpTracing));
    };
}
Also used : CurrentSpanCustomizer(brave.CurrentSpanCustomizer) SessionProtocol(com.linecorp.armeria.common.SessionProtocol) ConditionalOnSelfTracing(zipkin2.server.internal.ConditionalOnSelfTracing) SpanCustomizer(brave.SpanCustomizer) ScheduledFuture(java.util.concurrent.ScheduledFuture) BraveClient(com.linecorp.armeria.client.brave.BraveClient) RequestLog(com.linecorp.armeria.common.logging.RequestLog) Supplier(java.util.function.Supplier) ElasticsearchStorage(zipkin2.elasticsearch.ElasticsearchStorage) NamedThreadFactory(io.micrometer.core.instrument.util.NamedThreadFactory) Value(org.springframework.beans.factory.annotation.Value) ConditionContext(org.springframework.context.annotation.ConditionContext) RequestLogProperty(com.linecorp.armeria.common.logging.RequestLogProperty) EnableConfigurationProperties(org.springframework.boot.context.properties.EnableConfigurationProperties) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Qualifier(org.springframework.beans.factory.annotation.Qualifier) StorageComponent(zipkin2.storage.StorageComponent) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty) ClientFactoryBuilder(com.linecorp.armeria.client.ClientFactoryBuilder) HttpTracing(brave.http.HttpTracing) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Ssl(zipkin2.server.internal.elasticsearch.ZipkinElasticsearchStorageProperties.Ssl) ClientFactory(com.linecorp.armeria.client.ClientFactory) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) Condition(org.springframework.context.annotation.Condition) KeyManagerFactory(javax.net.ssl.KeyManagerFactory) EndpointGroup(com.linecorp.armeria.client.endpoint.EndpointGroup) IOException(java.io.IOException) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Configuration(org.springframework.context.annotation.Configuration) List(java.util.List) ClientOptionsBuilder(com.linecorp.armeria.client.ClientOptionsBuilder) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Optional(java.util.Optional) Bean(org.springframework.context.annotation.Bean) Conditional(org.springframework.context.annotation.Conditional) AnnotatedTypeMetadata(org.springframework.core.type.AnnotatedTypeMetadata) HttpTracing(brave.http.HttpTracing) RequestLog(com.linecorp.armeria.common.logging.RequestLog) CurrentSpanCustomizer(brave.CurrentSpanCustomizer) SpanCustomizer(brave.SpanCustomizer) ConditionalOnSelfTracing(zipkin2.server.internal.ConditionalOnSelfTracing) Qualifier(org.springframework.beans.factory.annotation.Qualifier) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

HttpTracing (brave.http.HttpTracing)5 Tracing (brave.Tracing)2 Test (org.junit.Test)2 ApplicationContext (org.springframework.context.ApplicationContext)2 CurrentSpanCustomizer (brave.CurrentSpanCustomizer)1 SpanCustomizer (brave.SpanCustomizer)1 WebMvc25 (brave.spring.webmvc.WebMvcRuntime.WebMvc25)1 ClientFactory (com.linecorp.armeria.client.ClientFactory)1 ClientFactoryBuilder (com.linecorp.armeria.client.ClientFactoryBuilder)1 ClientOptionsBuilder (com.linecorp.armeria.client.ClientOptionsBuilder)1 BraveClient (com.linecorp.armeria.client.brave.BraveClient)1 EndpointGroup (com.linecorp.armeria.client.endpoint.EndpointGroup)1 SessionProtocol (com.linecorp.armeria.common.SessionProtocol)1 RequestLog (com.linecorp.armeria.common.logging.RequestLog)1 RequestLogProperty (com.linecorp.armeria.common.logging.RequestLogProperty)1 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)1 NamedThreadFactory (io.micrometer.core.instrument.util.NamedThreadFactory)1 IOException (java.io.IOException)1 List (java.util.List)1 Optional (java.util.Optional)1