Skip to content

Latest commit

 

History

History
87 lines (68 loc) · 2.92 KB

README.md

File metadata and controls

87 lines (68 loc) · 2.92 KB

brave-instrumentation-dubbo

This is a tracing filter for RPC providers and consumers in Apache Dubbo 2.7+

When used on a consumer, TracingFilter adds trace state as attachments to outgoing requests. When a provider, it extracts trace state from incoming requests. In either case, the filter reports to Zipkin how long each request took, along with any error information.

Note: A Dubbo Provider is a server, and a Dubbo Consumer is a client in Zipkin terminology.

Configuration

The filter "tracing" requires an extension of type brave.Tracing named "tracing" configured. Once that's configured, you assign the filter to your providers and consumers like so:

Here's an example of with Spring 2.5+ XML

<!-- default to trace all services -->
<dubbo:consumer filter="tracing" />
<dubbo:provider filter="tracing" />

Here's an example with dubbo.properties:

dubbo.provider.filter=tracing
dubbo.consumer.filter=tracing

Registering the brave.rpc.RpcTracing extension with Spring

Most typically, the brave.rpc.RpcTracing extension is provided by Spring, so have this in place before proceeding. The bean must be named "rpcTracing"

Here's an example in XML.

Registering the brave.rpc.RpcTracing extension with Java

Dubbo supports custom extensions. You can supply your own instance of tracing by creating and registering an extension factory:

create an extension factory that returns brave.rpc.RpcTracing

package com.yourcompany.dubbo;

import brave.Tracing;
import brave.rpc.RpcTracing;
import brave.rpc.RpcRuleSampler;
import org.apache.dubbo.common.extension.ExtensionFactory;
import zipkin2.reporter.AsyncReporter;
import zipkin2.Span;

import static brave.rpc.RpcRequestMatchers.methodEquals;
import static brave.sampler.Matchers.and;

public class TracingExtensionFactory implements ExtensionFactory {

  @Override public <T> T getExtension(Class<T> type, String name) {
    if (type != RpcTracing.class) return null;

    return (T) RpcTracing.newBuilder(tracing())
                         .serverSampler(serverSampler())
                         .build();
  }

  RpcRuleSampler serverSampler() {
    return RpcRuleSampler.newBuilder()
      .putRule(methodEquals("sayHello"), Sampler.NEVER_SAMPLE)
      .build();
  }

  Tracing tracing() {
    return Tracing.newBuilder()
                  .localServiceName("my-service")
                  .spanReporter(spanReporter())
                  .build();
  }

  // NOTE: The reporter should be closed with a shutdown hook
  AsyncReporter<Span> spanReporter() {
--snip--

Register that factory using META-INF

Make sure the following line is in META-INF/dubbo/org.apache.dubbo.common.extension.ExtensionFactory in your classpath:

tracing=com.yourcompany.dubbo.TracingExtensionFactory