The OpenCensus Agent for Java collects and sends latency data about your Java process to
OpenCensus backends such as Zipkin, Stackdriver Trace, etc. for analysis and visualization.
The OpenCensus Agent for Java is in an early development stage. The following features are
currently implemented:
TODO(stschmidt): Update README.md along with implementation.
The context of the caller of Executor#execute
is automatically propagated to the submitted Runnable.
The context of the caller of Thread#start
is automatically propagated to the new thread.
As a proof-of-concept, the agent wraps the execution of
URL#getContent in a new
trace span.
We see tracing as a cross-cutting concern which the OpenCensus Agent for Java weaves into
existing Java bytecode (the application and its libraries) at runtime, typically when first loading
the concerned bytecode.
This approach allows us to instrument arbitrary code without having to touch the source code of the
application or its dependencies. Furthermore, we don't require the application owner to upgrade any
of the application's third-party dependencies to specific versions. As long as the interface (e.g.
java.sql.Driver#connect)
stays as-is across the supported versions, the Java agent's bytecode weaver will be able to
instrument the code.
The OpenCensus Agent for Java uses Byte Buddy, a widely used and
well-maintained bytecode manipulation library, for instrumenting selected Java methods at class
load-time. Which Java methods we want to intercept/instrument obviously depends on the library
(MongoDB vs. Redis, etc.) and the application.
Download the latest version of the OpenCensus Agent for Java .jar
file
from Maven Central. Store it somewhere on disk.
To enable the OpenCensus Agent for Java for your application, add the option-javaagent:path/to/opencensus-contrib-agent-X.Y.Z.jar
to the invocation of the java
executable as shown in the following example. Replace X.Y.Z
with the actual version number.
java -javaagent:path/to/opencensus-contrib-agent-X.Y.Z.jar ...
The OpenCensus Agent for Java uses Typesafe's configuration
library for all user-configurable settings. Please refer to
reference.conf for the available configuration knobs and their
defaults.
You can override the default configuration in different
ways.
For example, to disable the automatic context propagation for Executors, add a system property as
follows:
java -javaagent:path/to/opencensus-contrib-agent-X.Y.Z.jar \
-Dopencensus.contrib.agent.context-propagation.executor.enabled=false \
...