Skip to content

Latest commit

 

History

History
52 lines (37 loc) · 1.72 KB

File metadata and controls

52 lines (37 loc) · 1.72 KB

SDK Autoconfiguration Example

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

Prerequisites

  • Java 17 or higher is required to run Gradle and build this example
  • Java 8 or higher may be used to run the example once it has been built

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.