Search in sources :

Example 1 with CLIENT

use of brave.Span.Kind.CLIENT in project brave by openzipkin.

the class ITHttpClient method supportsPortableCustomization.

@Test
public void supportsPortableCustomization() throws IOException {
    String uri = "/foo/bar?z=2&yAA=1";
    closeClient(client);
    httpTracing = httpTracing.toBuilder().clientRequestParser((request, context, span) -> {
        span.name(request.method().toLowerCase() + " " + request.path());
        // just the path is tagged by default
        HttpTags.URL.tag(request, span);
        span.tag("request_customizer.is_span", (span instanceof brave.Span) + "");
    }).clientResponseParser((response, context, span) -> {
        HttpResponseParser.DEFAULT.parse(response, context, span);
        span.tag("response_customizer.is_span", (span instanceof brave.Span) + "");
    }).build().clientOf("remote-service");
    client = newClient(server.getPort());
    server.enqueue(new MockResponse());
    get(client, uri);
    MutableSpan span = testSpanHandler.takeRemoteSpan(CLIENT);
    assertThat(span.name()).isEqualTo("get /foo/bar");
    assertThat(span.remoteServiceName()).isEqualTo("remote-service");
    assertThat(span.tags()).containsEntry("http.url", url(uri)).containsEntry("request_customizer.is_span", "false").containsEntry("response_customizer.is_span", "false");
}
Also used : Arrays(java.util.Arrays) SpanCustomizer(brave.SpanCustomizer) HttpRuleSampler(brave.http.HttpRuleSampler) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Callable(java.util.concurrent.Callable) Extractor(brave.propagation.TraceContext.Extractor) Level(java.util.logging.Level) Sampler(brave.sampler.Sampler) ITRemote(brave.test.ITRemote) After(org.junit.After) MockWebServer(okhttp3.mockwebserver.MockWebServer) HttpResponseParser(brave.http.HttpResponseParser) SamplerFunction(brave.sampler.SamplerFunction) HttpRequest(brave.http.HttpRequest) Before(org.junit.Before) HttpAdapter(brave.http.HttpAdapter) HttpTracing(brave.http.HttpTracing) CLIENT(brave.Span.Kind.CLIENT) TraceContextOrSamplingFlags(brave.propagation.TraceContextOrSamplingFlags) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) IOException(java.io.IOException) Test(org.junit.Test) Logger(java.util.logging.Logger) TraceContext(brave.propagation.TraceContext) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) SocketPolicy(okhttp3.mockwebserver.SocketPolicy) Clock(brave.Clock) TimeUnit(java.util.concurrent.TimeUnit) HttpTags(brave.http.HttpTags) HttpRequestMatchers.pathStartsWith(brave.http.HttpRequestMatchers.pathStartsWith) Rule(org.junit.Rule) MutableSpan(brave.handler.MutableSpan) Scope(brave.propagation.CurrentTraceContext.Scope) SpanHandler(brave.handler.SpanHandler) SamplingFlags(brave.propagation.SamplingFlags) MockResponse(okhttp3.mockwebserver.MockResponse) HttpClientParser(brave.http.HttpClientParser) MockResponse(okhttp3.mockwebserver.MockResponse) MutableSpan(brave.handler.MutableSpan) MutableSpan(brave.handler.MutableSpan) Test(org.junit.Test)

Example 2 with CLIENT

use of brave.Span.Kind.CLIENT in project brave by openzipkin.

the class ITTracingFilter_Consumer method customParser.

@Test
public void customParser() {
    Tag<DubboResponse> javaValue = new Tag<DubboResponse>("dubbo.result_value") {

        @Override
        protected String parseValue(DubboResponse input, TraceContext context) {
            Result result = input.result();
            if (result == null)
                return null;
            return String.valueOf(result.getValue());
        }
    };
    RpcTracing rpcTracing = RpcTracing.newBuilder(tracing).clientResponseParser((res, context, span) -> {
        RpcResponseParser.DEFAULT.parse(res, context, span);
        if (res instanceof DubboResponse) {
            javaValue.tag((DubboResponse) res, span);
        }
    }).build();
    init().setRpcTracing(rpcTracing);
    String javaResult = client.get().sayHello("jorge");
    assertThat(testSpanHandler.takeRemoteSpan(CLIENT).tags()).containsEntry("dubbo.result_value", javaResult);
}
Also used : ExtensionLoader(org.apache.dubbo.common.extension.ExtensionLoader) RpcResponseParser(brave.rpc.RpcResponseParser) RpcContext(org.apache.dubbo.rpc.RpcContext) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ALWAYS_SAMPLE(brave.sampler.Sampler.ALWAYS_SAMPLE) AssertableCallback(brave.test.util.AssertableCallback) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) RpcRuleSampler(brave.rpc.RpcRuleSampler) After(org.junit.After) ReferenceConfig(org.apache.dubbo.config.ReferenceConfig) RpcRequestMatchers.methodEquals(brave.rpc.RpcRequestMatchers.methodEquals) RpcRequestMatchers.serviceEquals(brave.rpc.RpcRequestMatchers.serviceEquals) Before(org.junit.Before) DubboBootstrap(org.apache.dubbo.config.bootstrap.DubboBootstrap) CLIENT(brave.Span.Kind.CLIENT) Test(org.junit.Test) RpcException(org.apache.dubbo.rpc.RpcException) TraceContext(brave.propagation.TraceContext) Result(org.apache.dubbo.rpc.Result) Clock(brave.Clock) RpcTracing(brave.rpc.RpcTracing) MutableSpan(brave.handler.MutableSpan) NEVER_SAMPLE(brave.sampler.Sampler.NEVER_SAMPLE) Scope(brave.propagation.CurrentTraceContext.Scope) Tag(brave.Tag) Filter(org.apache.dubbo.rpc.Filter) SamplingFlags(brave.propagation.SamplingFlags) TraceContext(brave.propagation.TraceContext) RpcTracing(brave.rpc.RpcTracing) Tag(brave.Tag) Result(org.apache.dubbo.rpc.Result) Test(org.junit.Test)

Example 3 with CLIENT

use of brave.Span.Kind.CLIENT in project brave by openzipkin.

the class ITTracingFilter_Consumer method customParser.

@Test
public void customParser() {
    Tag<DubboResponse> javaValue = new Tag<DubboResponse>("dubbo.result_value") {

        @Override
        protected String parseValue(DubboResponse input, TraceContext context) {
            Result result = input.result();
            if (result == null)
                return null;
            Object value = result.getValue();
            if (value instanceof JavaBeanDescriptor) {
                return String.valueOf(((JavaBeanDescriptor) value).getProperty("value"));
            }
            return null;
        }
    };
    RpcTracing rpcTracing = RpcTracing.newBuilder(tracing).clientResponseParser((res, context, span) -> {
        RpcResponseParser.DEFAULT.parse(res, context, span);
        if (res instanceof DubboResponse) {
            javaValue.tag((DubboResponse) res, span);
        }
    }).build();
    init().setRpcTracing(rpcTracing);
    String javaResult = client.get().sayHello("jorge");
    assertThat(testSpanHandler.takeRemoteSpan(CLIENT).tags()).containsEntry("dubbo.result_value", javaResult);
}
Also used : ReferenceConfig(com.alibaba.dubbo.config.ReferenceConfig) Result(com.alibaba.dubbo.rpc.Result) RpcResponseParser(brave.rpc.RpcResponseParser) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ALWAYS_SAMPLE(brave.sampler.Sampler.ALWAYS_SAMPLE) ApplicationConfig(com.alibaba.dubbo.config.ApplicationConfig) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) RpcRuleSampler(brave.rpc.RpcRuleSampler) RpcContext(com.alibaba.dubbo.rpc.RpcContext) RpcRequestMatchers.methodEquals(brave.rpc.RpcRequestMatchers.methodEquals) RpcRequestMatchers.serviceEquals(brave.rpc.RpcRequestMatchers.serviceEquals) Before(org.junit.Before) CLIENT(brave.Span.Kind.CLIENT) JavaBeanDescriptor(com.alibaba.dubbo.common.beanutil.JavaBeanDescriptor) Test(org.junit.Test) RpcException(com.alibaba.dubbo.rpc.RpcException) TraceContext(brave.propagation.TraceContext) Clock(brave.Clock) RpcTracing(brave.rpc.RpcTracing) MutableSpan(brave.handler.MutableSpan) ExtensionLoader(com.alibaba.dubbo.common.extension.ExtensionLoader) NEVER_SAMPLE(brave.sampler.Sampler.NEVER_SAMPLE) Scope(brave.propagation.CurrentTraceContext.Scope) Tag(brave.Tag) SamplingFlags(brave.propagation.SamplingFlags) Filter(com.alibaba.dubbo.rpc.Filter) JavaBeanDescriptor(com.alibaba.dubbo.common.beanutil.JavaBeanDescriptor) TraceContext(brave.propagation.TraceContext) RpcTracing(brave.rpc.RpcTracing) Tag(brave.Tag) Result(com.alibaba.dubbo.rpc.Result) Test(org.junit.Test)

Example 4 with CLIENT

use of brave.Span.Kind.CLIENT in project brave by openzipkin.

the class ITTracingHttpAsyncClientBuilder method currentSpanVisibleToUserFilters.

@Test
public void currentSpanVisibleToUserFilters() throws IOException {
    server.enqueue(new MockResponse());
    closeClient(client);
    client = TracingHttpAsyncClientBuilder.create(httpTracing).addInterceptorLast((HttpRequestInterceptor) (request, context) -> request.setHeader("my-id", currentTraceContext.get().traceIdString())).build();
    client.start();
    get(client, "/foo");
    RecordedRequest request = takeRequest();
    assertThat(request.getHeader("x-b3-traceId")).isEqualTo(request.getHeader("my-id"));
    testSpanHandler.takeRemoteSpan(CLIENT);
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TimeoutException(java.util.concurrent.TimeoutException) HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) EntityUtils(org.apache.http.util.EntityUtils) Future(java.util.concurrent.Future) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) BiConsumer(java.util.function.BiConsumer) URI(java.net.URI) NStringEntity(org.apache.http.nio.entity.NStringEntity) HttpRequestInterceptor(org.apache.http.HttpRequestInterceptor) CLIENT(brave.Span.Kind.CLIENT) ITHttpAsyncClient(brave.test.http.ITHttpAsyncClient) CancellationException(java.util.concurrent.CancellationException) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) HttpOptions(org.apache.http.client.methods.HttpOptions) IOException(java.io.IOException) FutureCallback(org.apache.http.concurrent.FutureCallback) CloseableHttpAsyncClient(org.apache.http.impl.nio.client.CloseableHttpAsyncClient) Test(org.junit.Test) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) MockResponse(okhttp3.mockwebserver.MockResponse) UTF_8(org.apache.commons.codec.Charsets.UTF_8) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) Test(org.junit.Test)

Aggregations

CLIENT (brave.Span.Kind.CLIENT)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 Test (org.junit.Test)4 Clock (brave.Clock)3 MutableSpan (brave.handler.MutableSpan)3 Scope (brave.propagation.CurrentTraceContext.Scope)3 SamplingFlags (brave.propagation.SamplingFlags)3 TraceContext (brave.propagation.TraceContext)3 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)3 Before (org.junit.Before)3 Tag (brave.Tag)2 RpcRequestMatchers.methodEquals (brave.rpc.RpcRequestMatchers.methodEquals)2 RpcRequestMatchers.serviceEquals (brave.rpc.RpcRequestMatchers.serviceEquals)2 RpcResponseParser (brave.rpc.RpcResponseParser)2 RpcRuleSampler (brave.rpc.RpcRuleSampler)2 RpcTracing (brave.rpc.RpcTracing)2 ALWAYS_SAMPLE (brave.sampler.Sampler.ALWAYS_SAMPLE)2 NEVER_SAMPLE (brave.sampler.Sampler.NEVER_SAMPLE)2 After (org.junit.After)2 SpanCustomizer (brave.SpanCustomizer)1