Skip to content

Latest commit

 

History

History

autoconfigure

SDK autoconfiguration example

This is a simple example that demonstrates the usage of the OpenTelemetry SDK Autoconfigure module.

Prerequisites

  • Java 1.8

How to run

First build this example application:

../gradlew shadowJar

Then start the example application with the logging exporter configured:

java -Dotel.traces.exporter=console \
     -Dotel.metrics.exporter=console \
     -Dotel.logs.exporter=console \
     -cp build/libs/opentelemetry-examples-autoconfigure-0.1.0-SNAPSHOT-all.jar \
     io.opentelemetry.example.autoconfigure.AutoConfigExample

Alternatively, instead of system properties you can use environment variables:

export OTEL_TRACES_EXPORTER=console
export OTEL_METRICS_EXPORTER=console
export OTEL_LOGS_EXPORTER=console

java -cp build/libs/opentelemetry-examples-autoconfigure-0.1.0-SNAPSHOT-all.jar \
     io.opentelemetry.example.autoconfigure.AutoConfigExample

Full documentation of all supported properties can be found in the OpenTelemetry SDK Autoconfigure README.

After running the app you should see the trace printed out in the console:

...
INFO: 'important work' : ca3938a5793f6f9aba5c757f536a50cb b5e826c981112198 INTERNAL [tracer: io.opentelemetry.example.autoconfigure.AutoConfigExample:] AttributesMap{data={foo=42, bar=a string!}, capacity=128, totalAddedValues=2}
...

Congratulations! You are now collecting traces using OpenTelemetry.