Skip to content

runner: start a span before BeforeRunCallback so plugin rows share the invocation's trace #1884

Open

Description

@wojtas000

ADK Go opens its first OpenTelemetry span in agent.Run (agent.go#L163). That happens after the runner has already called OnUserMessageCallback and BeforeRunCallback (runner.go#L702-L714), so rows a plugin writes in those two callbacks can't carry the trace ID of ADK's spans.

With #1787 and ADK telemetry on, the BigQuery Agent Analytics plugin writes USER_MESSAGE_RECEIVED and INVOCATION_STARTING under one trace ID and every later row of the same invocation under ADK's (trace_manager.go#L319-L337). The same span_id (the invocation span) therefore appears under two trace IDs, and anything that rebuilds a trace by trace_id splits the invocation in two.

adk-python avoids this because its runner's invocation span already exists when the plugin starts, which keeps "every event in the invocation" on one trace ID (bigquery_agent_analytics_plugin.py#L2862-L2868, #L2897-L2900).

A fix should give every plugin callback of one invocation the same trace when ADK telemetry is on.

Activity

  1. ktsoator commented on Oct 17, 2026

    @ktsoator
    Contributor

    If I understand correctly, the invocation span needs to start before OnUserMessageCallback as well as BeforeRunCallback, so the early plugin events share the same trace as the agent execution. It should also inherit any existing parent trace. RunLive seems worth checking separately, since the session continues after the method returns. Does that sound right?

  2. ktsoator commented on Oct 18, 2026

    @ktsoator
    Contributor

    I've opened #1898 with a proposed fix. If anyone spots something I've missed or has a better approach, I'd be happy to hear it and learn from it.

    Thx! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions