2

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
homerman
  • 3,369
  • 1
  • 16
  • 32
  • You can collect Cloud Trace data for Java applications by using OpenTelemetry. To collect traces with OpenTelemetry and Java, you do: Install the OpenTelemetry packages, Configure your application to export spans to Cloud Trace and Configure your platform. You can refer to the detailed steps mentioned in this [document](https://cloud.google.com/trace/docs/setup/java-ot). Do let me know if this works. – Bakul Mitra Sep 14 '21 at 14:53
  • `Configure your application to export spans to Cloud Trace` - HOW? – homerman Sep 14 '21 at 15:25
  • In the doc steps are mentioned. – Bakul Mitra Sep 14 '21 at 15:33
  • As I mentioned in my question, I'm trying to connect the automatic instrumentation generated by the OTel java agent to an exporter to Cloud Trace. Where in the documentation is this explained? Is this a viable approach? – homerman Sep 14 '21 at 16:08
  • yes [here](https://cloud.google.com/trace/docs/setup/java-ot#export) it is mentioned. – Bakul Mitra Sep 14 '21 at 16:31
  • I'm not sure you understand my question. The setup described in the docs sends traces to Cloud Trace if I manually instrument spans. But what I'm trying to do is upload spans that are _automatically generated by the OpenTel Java agent_. Can you point out where in the documentation it describes this setup? – homerman Sep 14 '21 at 19:04
  • Does this help https://github.com/GoogleCloudPlatform/opentelemetry-operations-java/tree/main/exporters/auto#autoinstrumentation-setup? – Srikanth Chekuri Sep 14 '21 at 19:38
  • @SrikanthChekuri yes thank you! I'll post a more complete answer – homerman Sep 14 '21 at 22:51

1 Answers1

5

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.

homerman
  • 3,369
  • 1
  • 16
  • 32
  • Since your issue is resolved can you please accept your answer, so that other community people will understand that your issue got resolved by these steps. – Bakul Mitra Sep 16 '21 at 08:29
  • @homerman For this setup, what kind of trace that you could see in cloud trace, also the code you provided as part of the question is not used when you have used javaagent.jar? I'm trying the same, but could not see any difference in trace views for my rest calls. – Coder Mar 08 '23 at 22:41