Skip to content

Trace context lost in RxJava-based async flow (Flowable) #403

@dongsu90

Description

@dongsu90

Describe the bug
In ADK-Java, when using Flowable for asynchronous execution in runner.java and BaseAgent.java, the OpenTelemetry trace context is not properly propagated. As a result, the trace tree in the OpenTelemetry backend does not show the expected parent-child span relationships. This breaks the trace continuity and makes debugging and performance analysis difficult.

To Reproduce
Steps to reproduce the behavior:

  1. Clone the ADK-Java repository and set up a sample agent.
  2. Start the AdkWebServer.
  3. Observe the trace output in AdkWeb UI.
  4. Notice that spans created inside flatMap do not appear as children of the initial span.

Expected behavior
Spans created inside the Flowable chain (e.g., in BaseAgent.runAsync) should maintain the parent-child relationship with the span created in runner.runAsync. The trace tree should reflect the full execution flow, preserving context across asynchronous boundaries.

Screenshots
the trace tree showing disconnected spans.
Image

Desktop (please complete the following information):

  • OS: ubuntu-24
  • Java 17
  • adk-java v0.2.0

Additional context
This issue appears to be related to RxJava's handling of thread-local context. OpenTelemetry context is not automatically propagated across asynchronous boundaries in RxJava unless explicitly wrapped.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingwaiting on reporterWaiting for reaction by reporter. Failing that, maintainers will eventually closed it as stale.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions