diff --git a/README.md b/README.md index 49e74f8075..c1464ca21b 100644 --- a/README.md +++ b/README.md @@ -35,26 +35,9 @@ Download the latest Datadog Java Agent: wget -O dd-java-agent.jar 'https://search.maven.org/remote_content?g=com.datadoghq&a=dd-java-agent&v=LATEST' ``` -Then create a file `dd-trace.yaml` anywhere in your application's classpath (or provide the file's path via `-Ddd.trace.configurationFile` when starting the application): +Then configure your application using either environment variables or system properties (on the command line via `-D`). See the [config](#configuration) section for details. -```yaml -# Main service name for the app -defaultServiceName: my-java-app - -writer: - type: DDAgentWriter # send traces to Datadog Trace Agent; only other option is LoggingWriter - host: localhost # host/IP address where Datadog Trace Agent listens - port: 8126 # port where Datadog Trace Agent listens - -sampler: - type: AllSampler # Collect 100% of traces; only other option is RateSample -# rate: 0.5 # if using type: RateSample, uncomment to collect only 50% of traces - -# Skip traces whose root span tag values matches some these regexps; useful if you want to skip health checks traces from your service stats -# skipTagsPatterns: {"http.url": ".*/demo/add.*"} -``` - -**Note:** this configuration file is also required for [Manual Instrumentation](#manual-instrumentation) with the Datadog Tracer. +**Note:** configuration is also required for [Manual Instrumentation](#manual-instrumentation) with the Datadog Tracer. Finally, add the following JVM argument when starting your application—in your IDE, your Maven or gradle application script, or your `java -jar` command: @@ -64,6 +47,17 @@ Finally, add the following JVM argument when starting your application—in your The Java Agent—once passed to your application—automatically traces requests to the frameworks, application servers, and databases shown below. It does this by using various libraries from [opentracing-contrib](https://github.com/opentracing-contrib). In most cases you don't need to install or configure anything; traces will automatically show up in your Datadog dashboards. +#### Configuration + +| Config | System Property | Environment Variable | Default | +| ------------- | ---------------- | -------------------- | ------------------ | +| service.name | dd.service.name | DD_SERVICE_NAME | `unnamed-java-app` | +| writer.type | dd.writer.type | DD_WRITER_TYPE | `DDAgentWriter` | +| agent.host | dd.agent.host | DD_AGENT_HOST | `localhost` | +| agent.port | dd.agent.port | DD_AGENT_PORT | `8126` | +| sampler.type | dd.sampler.type | DD_SAMPLER_TYPE | `AllSampler` | +| sampler.rate | dd.sampler.rate | DD_SAMPLER_RATE | `1.0` | + #### Application Servers | Server | Versions | Comments | @@ -91,17 +85,6 @@ Also, frameworks like Spring Boot and Dropwizard inherently work because they us | [MongoDB](https://github.com/opentracing-contrib/java-mongo-driver) | 3.x | Intercepts all the calls from the MongoDB client | | [Cassandra](https://github.com/opentracing-contrib/java-cassandra-driver) | 3.2.x | Intercepts all the calls from the Cassandra client | -To disable tracing for any of these libraries, list them in `disabledInstrumentations` within `dd-trace.yaml`: - -```yaml -... - -# Disable tracing on these -disabledInstrumentations: ["opentracing-apache-httpclient", "opentracing-mongo-driver", "opentracing-web-servlet-filter"] -``` - -See [this YAML file](dd-java-agent/src/main/resources/dd-trace-supported-framework.yaml) for the proper names of all supported libraries (i.e. the names as you must list them in `disabledInstrumentations`). - ### The `@Trace` Annotation The Java Agent lets you add a `@Trace` annotation to any method to measure its execution time. Setup the [Java Agent](#java-agent-setup) first if you haven't done so. @@ -124,12 +107,6 @@ For gradle, add: compile group: 'com.datadoghq', name: 'dd-trace-annotations', version: {version} ``` -Then, in `dd-trace.yaml`, list any applications where you want to use `@Trace`: - -```yaml -enableCustomAnnotationTracingOver: ["com.example.myproject"]`. -``` - The Java Agent lets you use `@Trace` not just for `com.example.myproject`, but also for any application whose name _begins_ like that, e.g. `com.example.myproject.foobar`. If you're tempted to list something like `["com", "io"]` to avoid having to fuss with this configuration as you add new projects, be careful; providing `@Trace`-ability to too many applications could hurt your package's build time. #### Example @@ -193,6 +170,8 @@ compile group: 'io.opentracing', name: 'opentracing-util', version: "0.30.0" compile group: 'com.datadoghq', name: 'dd-trace', version: "${dd-trace-java.version}" ``` +Configure your application using environment variables or system properties as discussed in the [config](#configuration) section. + #### Examples Rather than referencing classes directly from `dd-trace` (other than registering `DDTracer`), we strongly suggest using the [OpenTracing API](https://github.com/opentracing/opentracing-java). @@ -204,7 +183,7 @@ Let's look at a simple example. class InstrumentedClass { void method0() { - // 1. Make sure dd-trace.yaml is in your resources directory + // 1. Configure your application using environment variables or system properties // 2. If using the Java Agent (-javaagent;/path/to/agent.jar), do not instantiate the GlobalTracer; the Agent instantiates it for you Tracer tracer = io.opentracing.util.GlobalTracer.get(); @@ -261,8 +240,6 @@ public class Application { } ``` -`DDTracerFactory` looks for `dd-trace.yaml` in the classpath. - ## Further Reading - Browse the [example applications](dd-trace-examples) in this repository to see Java tracing in action diff --git a/dd-java-agent-ittests/dd-java-agent-ittests.gradle b/dd-java-agent-ittests/dd-java-agent-ittests.gradle index 40074a30fe..e88fa566c2 100644 --- a/dd-java-agent-ittests/dd-java-agent-ittests.gradle +++ b/dd-java-agent-ittests/dd-java-agent-ittests.gradle @@ -40,7 +40,7 @@ dependencies { } test { - jvmArgs "-Ddd.trace.configurationFile=${project.buildDir}/resources/test/dd-trace.yaml" + jvmArgs "-Ddd.writer.type=ListWriter", "-Ddd.service.name=java-app" jvmArgs "-Ddd.slf4j.simpleLogger.defaultLogLevel=debug" jvmArgs "-Dorg.slf4j.simpleLogger.defaultLogLevel=debug" diff --git a/dd-java-agent-ittests/src/test/resources/dd-trace.yaml b/dd-java-agent-ittests/src/test/resources/dd-trace.yaml deleted file mode 100644 index 04a1463814..0000000000 --- a/dd-java-agent-ittests/src/test/resources/dd-trace.yaml +++ /dev/null @@ -1,27 +0,0 @@ -# Service name used if none is provided in the app -defaultServiceName: java-app - -# The writer to use. -# Could be: LoggingWriter or DDAgentWriter (default) -writer: - # LoggingWriter: Spans are logged using the application configuration - # DDAgentWriter: Spans are forwarding to a Datadog Agent - # - Param 'host': the hostname where the DD Agent running (default: localhost) - # - Param 'port': the port to reach the DD Agent (default: 8126) - type: ListWriter - -# The sampler to use. -# Could be: AllSampler (default) or RateSampler -sampler: - # AllSampler: all spans are reported to the writer - # RateSample: only a portion of spans are reported to the writer - # - Param 'rate': the portion of spans to keep - type: AllSampler - # Skip some traces if the root span tag values matches some regexp patterns - # skipTagsPatterns: {"http.url": ".*/demo/add.*"} - -# Enable custom annotation tracing over a selected set of packages -enableCustomAnnotationTracingOver: ["com.datadoghq.agent.test"] - -# Disable some instrumentations -# disabledInstrumentations: ["apache http", "mongo", "jetty", "tomcat", ...] diff --git a/dd-java-agent/src/main/resources/dd-trace.yaml b/dd-java-agent/src/main/resources/dd-trace.yaml deleted file mode 100644 index 8922992e75..0000000000 --- a/dd-java-agent/src/main/resources/dd-trace.yaml +++ /dev/null @@ -1,23 +0,0 @@ -# Service name used if none is provided in the app -defaultServiceName: java-app - -# The writer to use. -# Could be: LoggingWriter or DDAgentWriter (default) -writer: - # LoggingWriter: Spans are logged using the application configuration - # DDAgentWriter: Spans are forwarding to a Datadog Agent - # - Param 'host': the hostname where the DD Agent running (default: localhost) - # - Param 'port': the port to reach the DD Agent (default: 8126) - type: DDAgentWriter - host: localhost - port: 8126 - -# The sampler to use. -# Could be: AllSampler (default) or RateSampler -sampler: - # AllSampler: all spans are reported to the writer - # RateSample: only a portion of spans are reported to the writer - # - Param 'rate': the portion of spans to keep - type: AllSampler - # Skip some traces if the root span tag values matches some regexp patterns - # skipTagsPatterns: {"http.url": ".*/demo/add.*"} diff --git a/dd-trace-examples/dropwizard-mongo-client/README.md b/dd-trace-examples/dropwizard-mongo-client/README.md index 47a771043d..cd7c1f5f8b 100644 --- a/dd-trace-examples/dropwizard-mongo-client/README.md +++ b/dd-trace-examples/dropwizard-mongo-client/README.md @@ -27,12 +27,12 @@ A valid ``DD_API_KEY`` is required to post collected traces to the Datadog backe Launch the application using the run wrapper you've built during the ``installDist`` step: ```bash -JAVA_OPTS=-javaagent:../../dd-java-agent/build/libs/dd-java-agent-{version}.jar build/install/dropwizard-mongo-client/bin/dropwizard-mongo-client server +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: ```bash -java -javaagent:../../dd-java-agent/build/libs/dd-java-agent-{version}.jar -jar build/libs/dropwizard-mongo-client-demo-all.jar server +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. diff --git a/dd-trace-examples/dropwizard-mongo-client/dropwizard-mongo-client.gradle b/dd-trace-examples/dropwizard-mongo-client/dropwizard-mongo-client.gradle index d6edc6e18d..96707d4884 100644 --- a/dd-trace-examples/dropwizard-mongo-client/dropwizard-mongo-client.gradle +++ b/dd-trace-examples/dropwizard-mongo-client/dropwizard-mongo-client.gradle @@ -9,6 +9,8 @@ apply from: "${rootDir}/gradle/jacoco.gradle" version = 'demo' description = 'dropwizard-mongo-client' mainClassName = 'com.datadoghq.example.dropwizard.BookApplication' +applicationDefaultJvmArgs = ["-Ddd.service.name=dropwizard-example"] + sourceCompatibility = 1.8 targetCompatibility = 1.8 diff --git a/dd-trace-examples/dropwizard-mongo-client/src/main/resources/dd-trace.yaml b/dd-trace-examples/dropwizard-mongo-client/src/main/resources/dd-trace.yaml deleted file mode 100644 index b2d30e3c2c..0000000000 --- a/dd-trace-examples/dropwizard-mongo-client/src/main/resources/dd-trace.yaml +++ /dev/null @@ -1,29 +0,0 @@ -# Service name used if none is provided in the app -defaultServiceName: dropwizard-example - -# The writer to use. -# Could be: LoggingWriter or DDAgentWriter (default) -writer: - # LoggingWriter: Spans are logged using the application configuration - # DDAgentWriter: Spans are forwarding to a Datadog Agent - # - Param 'host': the hostname where the DD Agent running (default: localhost) - # - Param 'port': the port to reach the DD Agent (default: 8126) - type: DDAgentWriter - host: localhost - port: 8126 - -# The sampling to use. -# Could be: AllSampler (default) or RateSampler -sampler: - # AllSampler: all spans are reported to the writer - # RateSample: only a portion of spans are reported to the writer - # - Param 'rate': the portion of spans to keep - type: AllSampler - # Skip some traces if the root span tag values matches some regexp patterns - # skipTagsPatterns: {"http.url": ".*/demo/add.*"} - -# Enable custom annotation tracing over a selected set of packages -enableCustomAnnotationTracingOver: ["com.datadoghq.example"] - -# Disable some instrumentations -# disabledInstrumentations: ["apache http", "mongo", "jetty", "tomcat", ...] diff --git a/dd-trace-examples/rest-spark/README.md b/dd-trace-examples/rest-spark/README.md index af6ef611bd..2cd2685854 100644 --- a/dd-trace-examples/rest-spark/README.md +++ b/dd-trace-examples/rest-spark/README.md @@ -33,7 +33,7 @@ A valid ``DD_API_KEY`` is required to post collected traces to the Datadog backe Launch the application using the run wrapper you've built during the ``installDist`` step: ```bash -JAVA_OPTS=-javaagent:../../dd-java-agent/build/libs/dd-java-agent-{version}.jar build/install/rest-spark/bin/rest-spark +JAVA_OPTS=-javaagent:../../dd-java-agent/build/libs/dd-java-agent-{version}.jar -Ddd.service.name=rest-spark build/install/rest-spark/bin/rest-spark ``` ``0.2.0-SNAPSHOT`` is an example of what ``{version}`` looks like. diff --git a/dd-trace-examples/rest-spark/rest-spark.gradle b/dd-trace-examples/rest-spark/rest-spark.gradle index edb3d50078..24fccd4c7e 100644 --- a/dd-trace-examples/rest-spark/rest-spark.gradle +++ b/dd-trace-examples/rest-spark/rest-spark.gradle @@ -9,6 +9,7 @@ apply from: "${rootDir}/gradle/jacoco.gradle" version = 'demo' description = 'rest-spark' mainClassName = 'com.datadoghq.example.restspark.SparkApplication' +applicationDefaultJvmArgs = ["-Ddd.service.name=rest-spark"] sourceCompatibility = 1.8 targetCompatibility = 1.8 diff --git a/dd-trace-examples/rest-spark/src/main/resources/dd-trace.yaml b/dd-trace-examples/rest-spark/src/main/resources/dd-trace.yaml deleted file mode 100644 index ff3815988f..0000000000 --- a/dd-trace-examples/rest-spark/src/main/resources/dd-trace.yaml +++ /dev/null @@ -1,9 +0,0 @@ -defaultServiceName: rest-spark - -writer: - type: DDAgentWriter - host: localhost - port: 8126 - -sampler: - type: AllSampler diff --git a/dd-trace-examples/spring-boot-jdbc/README.md b/dd-trace-examples/spring-boot-jdbc/README.md index 3c0e7cb77b..e43407fec1 100644 --- a/dd-trace-examples/spring-boot-jdbc/README.md +++ b/dd-trace-examples/spring-boot-jdbc/README.md @@ -36,7 +36,7 @@ stop it.* Or as an executable jar: ```bash -java -javaagent:../../dd-java-agent/build/libs/dd-java-agent-{version}.jar -jar build/libs/spring-boot-jdbc-demo.jar +java -javaagent:../../dd-java-agent/build/libs/dd-java-agent-{version}.jar -Ddd.service.name=spring-boot-jdbc -jar build/libs/spring-boot-jdbc-demo.jar ``` ### Generate traces diff --git a/dd-trace-examples/spring-boot-jdbc/spring-boot-jdbc.gradle b/dd-trace-examples/spring-boot-jdbc/spring-boot-jdbc.gradle index 49efbf7a02..13f0377389 100644 --- a/dd-trace-examples/spring-boot-jdbc/spring-boot-jdbc.gradle +++ b/dd-trace-examples/spring-boot-jdbc/spring-boot-jdbc.gradle @@ -22,9 +22,9 @@ bootRepackage { bootRun { if (project.hasProperty('javaagent')) { - jvmArgs = ["-javaagent:$javaagent"] + jvmArgs = ["-javaagent:$javaagent", "-Ddd.service.name=spring-boot-jdbc"] } else { - jvmArgs = ["-javaagent:${project(':dd-java-agent').tasks.shadowJar.outputs.files.getFiles().iterator().next()}"] + jvmArgs = ["-javaagent:${project(':dd-java-agent').tasks.shadowJar.outputs.files.getFiles().iterator().next()}", "-Ddd.service.name=spring-boot-jdbc"] } } diff --git a/dd-trace-examples/spring-boot-jdbc/src/main/resources/dd-trace.yaml b/dd-trace-examples/spring-boot-jdbc/src/main/resources/dd-trace.yaml deleted file mode 100644 index b142bec72f..0000000000 --- a/dd-trace-examples/spring-boot-jdbc/src/main/resources/dd-trace.yaml +++ /dev/null @@ -1,9 +0,0 @@ -defaultServiceName: example-spring-boot - -writer: - type: DDAgentWriter - host: localhost - port: 8126 - -sampler: - type: AllSampler diff --git a/dd-trace/src/test/resources/dd-trace-1.yaml b/dd-trace/src/test/resources/dd-trace-1.yaml deleted file mode 100644 index 4b62c03757..0000000000 --- a/dd-trace/src/test/resources/dd-trace-1.yaml +++ /dev/null @@ -1,24 +0,0 @@ -# Service name used if none is provided in the app -defaultServiceName: java-app - -# The writer to use. -# Could be: LoggingWritter or DDAgentWriter (default) -writer: - # LoggingWriter: Spans are logged using the application configuration - # DDAgentWriter: Spans are forwarding to a Datadog Agent - # - Param 'host': the hostname where the DD Agent running (default: localhost) - # - Param 'port': the port to reach the DD Agent (default: 8126) - type: DDAgentWriter - host: foo - port: 123 - -# The sampler to use. -# Could be: AllSampler (default) or RateSampler -sampler: - # AllSampler: all spans are reported to the writer - # RateSample: only a portion of spans are reported to the writer - # - Param 'rate': the portion of spans to keep - type: AllSampler - -# Enable custom tracing (annotations) -# enableCustomTracing: true \ No newline at end of file diff --git a/dd-trace/src/test/resources/dd-trace-2.yml b/dd-trace/src/test/resources/dd-trace-2.yml deleted file mode 100644 index 9e5ded6b1c..0000000000 --- a/dd-trace/src/test/resources/dd-trace-2.yml +++ /dev/null @@ -1,23 +0,0 @@ -# Service name used if none is provided in the app -defaultServiceName: java-app - -# The writer to use. -# Could be: LoggingWritter or DDAgentWriter (default) -writer: - # LoggingWriter: Spans are logged using the application configuration - # DDAgentWriter: Spans are forwarding to a Datadog Agent - # - Param 'host': the hostname where the DD Agent running (default: localhost) - # - Param 'port': the port to reach the DD Agent (default: 8126) - type: DDAgentWriter - -# The sampler to use. -# Could be: AllSampler (default) or RateSampler -sampler: - # AllSampler: all spans are reported to the writer - # RateSample: only a portion of spans are reported to the writer - # - Param 'rate': the portion of spans to keep - type: RateSampler - rate: 0.4 - -# Enable custom tracing (annotations) -# enableCustomTracing: true \ No newline at end of file diff --git a/dd-trace/src/test/resources/dd-trace-default.yml b/dd-trace/src/test/resources/dd-trace-default.yml deleted file mode 100644 index e5cf339b08..0000000000 --- a/dd-trace/src/test/resources/dd-trace-default.yml +++ /dev/null @@ -1 +0,0 @@ -defaultServiceName: java-app-default diff --git a/dd-trace/src/test/resources/dd-trace.yaml b/dd-trace/src/test/resources/dd-trace.yaml deleted file mode 100644 index 35acb48f47..0000000000 --- a/dd-trace/src/test/resources/dd-trace.yaml +++ /dev/null @@ -1,7 +0,0 @@ -defaultServiceName: java-app -writer: - type: DDAgentWriter - host: localhost - port: 10000 -sampler: - type: AllSampler \ No newline at end of file