openzipkin / brave

Java distributed tracing implementation compatible with Zipkin backend services.
Apache License 2.0
2.36k stars 714 forks source link

Add Api configuration demo for dubbo #632

Open codefromthecrypt opened 6 years ago

codefromthecrypt commented 6 years ago

Most things out there use spring or spring boot. It would be nice to have a demo for how to configure tracing for dubbo when someone is only using the api (per @chickenlj)

http://dubbo.io/books/dubbo-user-book-en/configuration/api.html

One challenge is I can't see how Dubbo manages lifecycle if any for extensions. It would seem instructions should include shutting down the component.

At any rate I don't know how to do this, except maybe a hard-coded extension factory like so:

public class TracingExtensionFactory implements ExtensionFactory {
  public <T> T getExtension(Class<T> type, String name) {
    if (type != Tracing.class) return null;

    final AsyncReporter<Span> spanReporter =
        AsyncReporter.create(URLConnectionSender.create("http://127.0.0.1:9411/api/v2/spans"));

    // flush spans on ctrl-c
    Runtime.getRuntime()
        .addShutdownHook(
            new Thread() {
              @Override
              public void run() {
                spanReporter.close();
              }
            });

    return Tracing.newBuilder()
        .localServiceName(/** where to get dubbo's application name */, "foo")
        .currentTraceContext(MDCCurrentTraceContext.create()) // puts trace IDs into logs
        .spanReporter(spanReporter)
        .build();
  }
}
codefromthecrypt commented 6 years ago

I tried integrating this with spring boot and found I had to manually call the tracing filter setter:

    // TODO: Why isn't TracingFilter.setTracing called automatically by Dubbo's spring stuff
    ((TracingFilter) ExtensionLoader.getExtensionLoader(Filter.class)
        .getExtension("tracing"))
        .setTracing(tracing);

If anyone can try this branch and help me figure out what I don't understand, I would appreciate it. Also we can then have simple instructions for those wanting to try this.

cc @xionghuiCoder @chickenlj

https://github.com/openzipkin/sleuth-webmvc-example/compare/add-dubbo-tracing

codefromthecrypt commented 6 years ago

sent email to dev@dubbo.apache.org

chickenlj commented 6 years ago

Everything in the example related with dubbo seems to be in the right way, i have also tested TraceFilter in a separate Spring project and it works fine (tracing can be auto injected).

Will give a check on the “sleuth-webmvc-example” later, as i have no access to my computer now.

mercyblitz commented 6 years ago

@adriancole please use official dubbo-spring-boot-starter

chickenlj commented 6 years ago

@mercyblitz The dubbo-spring-boot-starter adriancole use is the official one.

codefromthecrypt commented 6 years ago

progress on the spring boot (via spring-cloud-sleuth) side https://github.com/spring-cloud/spring-cloud-sleuth/pull/885

codefromthecrypt commented 6 years ago

@chickenlj @mercyblitz so I still have one question, which is how to externally register a filter so that all providers and consumers use it (as opposed to setting it on an annotation). We will need this for sleuth as we don't want users to have to change their annotations to switch on tracing

chickenlj commented 6 years ago

Check concepts of Consumer and Provider in dubbo:

http://dubbo.io/books/dubbo-user-book-en/references/xml/dubbo-consumer.html http://dubbo.io/books/dubbo-user-book-en/references/xml/dubbo-consumer.html http://dubbo.io/books/dubbo-user-book-en/references/xml/dubbo-provider.html http://dubbo.io/books/dubbo-user-book-en/references/xml/dubbo-provider.html

XML looks like this:

And annotation or spring boot, use .properties instead, for example:

dubbo.consumer.filter="tracing"

Is this what you want? Adrian

Best regards, Jun Liu

On 6 Mar 2018, at 3:58 PM, Adrian Cole notifications@github.com wrote:

@chickenlj https://github.com/chickenlj @mercyblitz https://github.com/mercyblitz so I still have one question, which is how to externally register a filter so that all providers and consumers use it (as opposed to setting it on an annotation). We will need this for sleuth as we don't want users to have to change their annotations to switch on tracing

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/openzipkin/brave/issues/632#issuecomment-370695232, or mute the thread https://github.com/notifications/unsubscribe-auth/ARQliQy8Fx6W2c1t1vy_eerUof8K3-gMks5tbkG0gaJpZM4Sa2cy.

codefromthecrypt commented 6 years ago

spring boot (via sleuth) side of things is near perfect I added some notes https://github.com/openzipkin/sleuth-webmvc-example/compare/add-dubbo-tracing

I will update the readme shortly about manual config