2.6 KiB
Dropwizard
This project provides a simple Dropwizard example. This is a supported framework that uses auto-instrumentation for all endpoints. Manual instrumentation has been added as example.
Run the demo
Prerequisites
Be sure to build the project so that the latest version of dd-trace-java
components are used. You can build
all libraries and examples launching from the dd-trace-java
root folder:
./gradlew clean shadowJar installDist
Then you can start all services via Docker:
cd examples/dropwizard-mongo-client
DD_API_KEY=<your_datadog_api_key> docker-compose up -d
A valid DD_API_KEY
is required to post collected traces to the Datadog backend.
Run the application
Launch the application using the run wrapper you've built during the installDist
step:
JAVA_OPTS="-javaagent:../../dd-java-agent/build/libs/dd-java-agent-{version}.jar -Ddd.service.name=dropwizard-example" build/install/dropwizard-mongo-client/bin/dropwizard-mongo-client server
Or as an executable jar:
java -javaagent:../../dd-java-agent/build/libs/dd-java-agent-{version}.jar -Ddd.service.name=dropwizard-example -jar build/libs/dropwizard-mongo-client-demo-all.jar server
0.2.0-SNAPSHOT
is an example of what {version}
looks like.
Generate traces
With your web browser
Once the application runs. Go to the following url:
Then get back to Datadog and wait a bit to see a trace coming.
Cross process tracing: with the provided TracedClient
class
The TracedClient
class includes an example of what you can use to do distributed tracing. The class must be
auto-instrumented with the Java Agent as above, so that OkHttpClient
adds the required headers to continue
the tracing cross process.
To run the distributed example, first start the dropwizard app, the mongo db and finally run the main
from com.example.helloworld.client.TracedClient
Auto-instrumentation with the dd-trace-agent
The instrumentation is entirely done by the Java Agent which embed a set of rules that automatically recognizes & instruments:
- The Java servlet filters
- The Mongo client
- The
@Trace
annotation - The OkHTTP client (in the
TracedClient
class)
The Java Agent embeds the OpenTracing Java Agent.