Search in sources :

Example 1 with SERVER

use of brave.Span.Kind.SERVER 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 2 with SERVER

use of brave.Span.Kind.SERVER 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;
            return String.valueOf(result.getValue());
        }
    };
    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 : DubboBootstrap(org.apache.dubbo.config.bootstrap.DubboBootstrap) 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) Test(org.junit.Test) TraceContext(brave.propagation.TraceContext) Result(org.apache.dubbo.rpc.Result) RpcTracing(brave.rpc.RpcTracing) B3SingleFormat(brave.propagation.B3SingleFormat) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) MutableSpan(brave.handler.MutableSpan) RpcRuleSampler(brave.rpc.RpcRuleSampler) NEVER_SAMPLE(brave.sampler.Sampler.NEVER_SAMPLE) ReferenceConfig(org.apache.dubbo.config.ReferenceConfig) Tag(brave.Tag) 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) TraceContext(brave.propagation.TraceContext) RpcTracing(brave.rpc.RpcTracing) Tag(brave.Tag) Result(org.apache.dubbo.rpc.Result) Test(org.junit.Test)

Aggregations

SERVER (brave.Span.Kind.SERVER)2 Tag (brave.Tag)2 B3SingleFormat (brave.propagation.B3SingleFormat)2 SamplingFlags (brave.propagation.SamplingFlags)2 TraceContext (brave.propagation.TraceContext)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 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)2 Before (org.junit.Before)2 Test (org.junit.Test)2 MutableSpan (brave.handler.MutableSpan)1 JavaBeanDescriptor (com.alibaba.dubbo.common.beanutil.JavaBeanDescriptor)1 ApplicationConfig (com.alibaba.dubbo.config.ApplicationConfig)1 ReferenceConfig (com.alibaba.dubbo.config.ReferenceConfig)1