-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add content for Java's Tracers. #311
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,67 @@ | |
title: "Java: Tracers" | ||
--- | ||
|
||
* Setting up your tracer | ||
* Using the Global Tracer | ||
* Accessing the Active Span | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess it's missing this item: "Accessing the Active Span" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I covered that in the |
||
* Accessing tracer specific features. | ||
#### Setting up your Tracer | ||
|
||
Different **Tracer** implementations vary in how and what parameters they receive at initialization time, such as: | ||
|
||
* Component name for this application's traces. | ||
* Tracing endpoint. | ||
* Tracing credentials. | ||
* Sampling strategy. | ||
|
||
|
||
For example, initializing the **Tracer** implementation of `Jaeger` looks like this: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/looks like this/might look like this/ The "might" is because it could be also as simple as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
:) Makes sense, definitely. |
||
|
||
```java | ||
import io.opentracing.Tracer; | ||
|
||
SamplerConfiguration samplerConfig = new SamplerConfiguration("const", 1); | ||
ReporterConfiguration reporterConfig = new ReporterConfiguration(true, null, null, null, null); | ||
Configuration config = new Configuration(service, samplerConfig, reporterConfig); | ||
|
||
// Get the actual OpenTracing-compatible Tracer. | ||
Tracer tracer = config.getTracer(); | ||
``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be worth mentioning the Tracer Resolver as well. Something like:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, yes, had forgotten about it ;) |
||
|
||
One a **Tracer** instance is obtained, it can be used to manually create **Span**, or pass it to existing instrumentation for frameworks and libraries: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/One/Once/ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Damn, thanks, will fix ;) |
||
|
||
```java | ||
// OpenTracing Redis client. It can be *any* OT-compatible tracer. | ||
Tracer tracer = ...; | ||
new TracingJedis(tracer); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice name, I had to double check this was the real name, not a typo :D |
||
``` | ||
|
||
#### Global Tracer | ||
|
||
In order to not force the user to keep around a **Tracer**, the **io.opentracing.util** artifact includes a helper **GlobalTracer** class implementing the **io.opentracing.Tracer**, which, as the name implies, acts as as a global instance that can be used from anywhere. It works by forwarding all operations to another underlying **Tracer**, that will get registered at some future point. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be better to state the actual artifact coordinates using the standard There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I covered this in the |
||
|
||
By default, the underlying **Tracer** is a no-nop implementation. | ||
|
||
```java | ||
import io.opentracing.util.GlobalTracer; | ||
|
||
// As part of initialization, pass it as an actual Tracer | ||
// to code that will create Spans in the future. | ||
new TracingJedis(GlobalTracer.get()); | ||
|
||
// Eventually register it, so all the calls to GlobalTracer.get() | ||
// are forwarded to this object. Registration can happen only once. | ||
Tracer tracer = new CustomTracer(...); | ||
GlobalTracer.register(tracer); | ||
... | ||
|
||
// Create a Span as usually. This Span creation will happen | ||
// using your CustomTracer. | ||
Span span = GlobalTracer.get().buildSpan("foo").start(); | ||
``` | ||
|
||
#### Using Tracer specific features | ||
|
||
For using **Tracer**-specific features, the instance needs to be casted back to the original type: | ||
|
||
```java | ||
((CustomTracer)tracer).customFeature(100); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we should add a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, yes, I wondered about the same. Sounds like we should open an Issue in the java repo to keep track of this potential improvement? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
``` | ||
|
||
**GlobalTracer** does not expose the original **Tracer**, and thus is not possible to use **Tracer**-specific features through it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about a small intro here? Something like:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, will add it.