Search in sources :

Example 1 with RpcTracing

use of brave.rpc.RpcTracing in project brave by openzipkin.

the class BaseITTracingServerInterceptor method customSampler.

/* RpcTracing-specific feature tests */
@Test
public void customSampler() throws IOException {
    RpcTracing rpcTracing = RpcTracing.newBuilder(tracing).serverSampler(RpcRuleSampler.newBuilder().putRule(methodEquals("SayHelloWithManyReplies"), NEVER_SAMPLE).putRule(serviceEquals("helloworld.greeter"), ALWAYS_SAMPLE).build()).build();
    grpcTracing = GrpcTracing.create(rpcTracing);
    init();
    // unsampled
    // NOTE: An iterator request is lazy: invoking the iterator invokes the request
    GreeterGrpc.newBlockingStub(client).sayHelloWithManyReplies(HELLO_REQUEST).hasNext();
    // sampled
    GreeterGrpc.newBlockingStub(client).sayHello(HELLO_REQUEST);
    assertThat(testSpanHandler.takeRemoteSpan(Span.Kind.SERVER).name()).isEqualTo("helloworld.Greeter/SayHello");
// @After will also check that sayHelloWithManyReplies was not sampled
}
Also used : RpcTracing(brave.rpc.RpcTracing) Test(org.junit.Test)

Example 2 with RpcTracing

use of brave.rpc.RpcTracing in project brave by openzipkin.

the class ITTracingFilter_Provider method customSampler.

/* RpcTracing-specific feature tests */
@Test
public void customSampler() {
    RpcTracing rpcTracing = RpcTracing.newBuilder(tracing).serverSampler(RpcRuleSampler.newBuilder().putRule(methodEquals("sayGoodbye"), NEVER_SAMPLE).putRule(serviceEquals("brave.dubbo"), ALWAYS_SAMPLE).build()).build();
    init().setRpcTracing(rpcTracing);
    // unsampled
    client.get().sayGoodbye("jorge");
    // sampled
    client.get().sayHello("jorge");
    assertThat(testSpanHandler.takeRemoteSpan(SERVER).name()).endsWith("sayHello");
// @After will also check that sayGoodbye was not sampled
}
Also used : RpcTracing(brave.rpc.RpcTracing) Test(org.junit.Test)

Example 3 with RpcTracing

use of brave.rpc.RpcTracing 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 4 with RpcTracing

use of brave.rpc.RpcTracing in project brave by openzipkin.

the class ITTracingFilter_Provider 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).serverResponseParser((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(SERVER).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) JavaBeanDescriptor(com.alibaba.dubbo.common.beanutil.JavaBeanDescriptor) ApplicationConfig(com.alibaba.dubbo.config.ApplicationConfig) Test(org.junit.Test) TraceContext(brave.propagation.TraceContext) RpcTracing(brave.rpc.RpcTracing) B3SingleFormat(brave.propagation.B3SingleFormat) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) RpcRuleSampler(brave.rpc.RpcRuleSampler) NEVER_SAMPLE(brave.sampler.Sampler.NEVER_SAMPLE) Tag(brave.Tag) RpcContext(com.alibaba.dubbo.rpc.RpcContext) SamplingFlags(brave.propagation.SamplingFlags) SERVER(brave.Span.Kind.SERVER) RpcRequestMatchers.methodEquals(brave.rpc.RpcRequestMatchers.methodEquals) RpcRequestMatchers.serviceEquals(brave.rpc.RpcRequestMatchers.serviceEquals) Before(org.junit.Before) 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 5 with RpcTracing

use of brave.rpc.RpcTracing 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)

Aggregations

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