javaopen-telemetrygoogle-cloud-trace

How can I export traces generated by the OpenTelemetry Java agent to Google Cloud Trace?


I've got a Spring Boot application that'd I'd like to automatically generate traces for using the OpenTelemetry Java agent, and subsequently upload those traces to Google Cloud Trace.

I've added the following code to the entry point of my application for sending traces:

OpenTelemetrySdk.builder()
    .setTracerProvider(
        SdkTracerProvider.builder()
            .addSpanProcessor(
                SimpleSpanProcessor.create(TraceExporter.createWithDefaultConfiguration())
            )
            .build()
    )
    .buildAndRegisterGlobal();

...and I'm running my application with the following system properties:

-javaagent:path/to/opentelemetry-javaagent-all.jar \
-jar myapp.jar

...but I don't know how to connect the two.

Is there some agent configuration I can apply? Something like:

-Dotel.traces.exporter=google_cloud_trace

Solution

  • I ended up resolving this as follows:

    1. Clone the GoogleCloudPlatform / opentelemetry-operations-java repo

    git clone git@github.com:GoogleCloudPlatform/opentelemetry-operations-java.git

    1. Build the exporter-auto project

    ./gradlew clean :exporter-auto:shadowJar

    1. Copy the jar produced in exporter-auto/build/libs to my target project

    2. Run the application with the following arguments:

    -javaagent:path/to/opentelemetry-javaagent-all.jar
    -Dotel.javaagent.experimental.extensions=[artifact-from-step-3].jar
    -Dotel.traces.exporter=google_cloud_trace
    -Dotel.metrics.exporter=none
    -jar myapp.jar

    Note: This setup does not require any explicit code changes in the target code base.