open-telemetry / opentelemetry-java-instrumentation

OpenTelemetry auto-instrumentation and instrumentation libraries for Java
https://opentelemetry.io
Apache License 2.0
1.97k stars 861 forks source link

Tracing Context Breaks with manual instrumentation when async method Invokes by ratpack for a single request #12363

Closed NaveenRamu closed 3 weeks ago

NaveenRamu commented 1 month ago

Describe the bug

When using Ratpack2 with OpenTelemetry (Otel) manual instrumentation in a reactive environment, tracing continuity can break when synchronous methods are invoked. This loss of trace context leads to incomplete or broken traces, resulting in the generation of a new tracing ID for subsequent invocations.

Steps to reproduce

Download the attached sample code and execute it. After execution, import the provided Postman collection and send the request. Observe the logs. GitHub Link

Expected behavior

Only one trace ID should be generated across all spans for a single API request to ensure continuity in tracing.

Actual behavior

Different trace ids are generated for each method execution.

Javaagent or library instrumentation version

ratpack-1.7

Environment

JDK: 1.8 OS: Linux Framework: Ratpack2 (version: 2.0.0-rc-1)

Additional context

No response

laurit commented 1 month ago

When using Ratpack2 with OpenTelemetry (Otel) manual instrumentation in a reactive environment, tracing continuity can break when synchronous methods are invoked. This loss of trace context leads to incomplete or broken traces, resulting in the generation of a new tracing ID for subsequent invocations.

When implementing manual instrumentation it is up to you to correctly propagate context.

Javaagent or library instrumentation version ratpack-1.7

Our ratpack-1.7 instrumentation does not work with ratpack2. As far as I can tell you have only included the jar, this doesn't do anything. To make it work I'd make a copy of the ratpack-1.7 instrumentation and compile it against ratpack2, fix all compile errors because of the moved classes and then add the instrumentation to the server like it is done in the test https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackHttpServerTest.groovy

Download the attached sample code and execute it. After execution, import the provided Postman collection and send the request. Observe the logs. GitHub Link

You could make life easier for everybody by adding the source of your test app directly to the github repo instead of adding a zip there.

github-actions[bot] commented 1 month ago

This has been automatically marked as stale because it has been marked as needing author feedback and has not had any activity for 7 days. It will be closed automatically if there is no response from the author within 7 additional days from this comment.

NaveenRamu commented 1 month ago

For reference, is there any project or example that uses Ratpack 1.7 library with manual instrumentation?

laurit commented 1 month ago

For reference, is there any project or example that uses Ratpack 1.7 library with manual instrumentation?

There are tests in https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/v1_7 that illustrate how the instrumentation can be used.

github-actions[bot] commented 4 weeks ago

This has been automatically marked as stale because it has been marked as needing author feedback and has not had any activity for 7 days. It will be closed automatically if there is no response from the author within 7 additional days from this comment.