Search in sources :

Example 1 with Tag

use of brave.Tag 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 2 with Tag

use of brave.Tag 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 3 with Tag

use of brave.Tag 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 Tag

use of brave.Tag 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

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 RpcTracing (brave.rpc.RpcTracing)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 Test (org.junit.Test)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