The LightStep distributed tracing library for the standard Java runtime environment.
The JRE library is hosted on Bintray, jcenter, and Maven Central. The Bintray lightstep-tracer-jre project contains additional installation and setup information for using the library with various build systems such as Ivy and Maven.
<dependency>
<groupId>com.lightstep.tracer</groupId>
<artifactId>lightstep-tracer-jre</artifactId>
<version> VERSION </version>
</dependency>
- Be sure to replace
VERSION
with the current version of the library
In most cases, modifying your build.gradle
with the below is all that is required:
repositories {
mavenCentral() // OR jcenter()
}
dependencies {
compile 'com.lightstep.tracer:lightstep-tracer-jre:VERSION'
}
- Be sure to replace
VERSION
with the current version of the library - The artifact is published to both
jcenter()
andmavenCentral()
. Use whichever you prefer.
// Important the OpenTracing interfaces
import io.opentracing.Span;
import io.opentracing.Tracer;
// ...
// Initialize the OpenTracing Tracer with LightStep's implementation
Tracer tracer = new com.lightstep.tracer.jre.JRETracer(
new com.lightstep.tracer.shared.Options.OptionsBuilder()
.withAccessToken("{your_access_token}")
.build()
);
// Start and finish a Span
Span span = this.tracer.buildSpan("my_span").start();
this.doSomeWorkHere();
span.finish();
Tracing instrumentation should use the OpenTracing APIs to stay portable and in sync with the standard:
For reference, the generated LightStep documentation is also available:
To set the name used in the LightStep UI for this instance of the Tracer, call withComponentName()
on the OptionsBuilder
object:
options = new com.lightstep.tracer.shared.Options.OptionsBuilder()
.withAccessToken("{your_access_token}")
.withComponentName("your_custom_name")
.build();
By default, the Java library does a report of any buffered data on a fairly regular interval. To disable this behavior and rely only on explicit calls to flush()
to report data, initialize with:
options = new com.lightstep.tracer.shared.Options.OptionsBuilder()
.withAccessToken("{your_access_token}")
.withDisableReportingLoop(true)
.build();
To then manually flush by using the LightStep tracer object directly:
// Flush any buffered tracing data
((com.lightstep.tracer.jre.JRETracer)tracer).flush();
In order to send a final flush of the data prior to exit, clients should manually flush by using the LightStep tracer object as described above.
By default, the Java library performs clock correction based on timestamp information provided in the spans. To disable this behavior, initialize with:
options = new com.lightstep.tracer.shared.Options.OptionsBuilder()
.withAccessToken("{your_access_token}")
.withClockSkewCorrection(false)
.build();
See DEV.md for information on contributing to this instrumentation library.