Skip to content

fix(telemetry): record error.type on the inference operation details event - #7808

Draft
RKest wants to merge 1 commit into
google:mainfrom
RKest:fix-error-type-status-code
Draft

RKest wants to merge 1 commit into
google:mainfrom
RKest:fix-error-type-status-code

Conversation

@RKest

@RKest RKest commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

  • Closes: none
  • Related: none

2. Or, if no issue exists, describe the change:

Problem:
When a model call fails, ADK sets error.type on the inference span and on the
duration metric, but not on the gen_ai.client.inference.operation.details
event. The event of a failed call therefore has no error type, and the
instrumentor's event for the same call has error.type (429 for a
resource-exhausted error). The divergence is recorded as adk_bug in
tests/unittests/telemetry/functional_divergences.json.

Solution:
The completion event is emitted from an exit callback on the inference span's
exit stack. That callback was registered with ExitStack.callback, which drops
the exception that is unwinding through it. It is now registered with push,
which passes the exception, and when the call failed the event carries
error.type from tracing.resolve_error_type, the same value as the span.

The span and the duration metric are unchanged.

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

The change is covered by the functional telemetry goldens. Three inference-error
goldens gain the error.type line on the completion event, and the adk_bug
divergence entry is removed:

  • functional_goldens/agent/inference-error-resource-exhausted-schema-v2.json
    (error.type: "429")
  • functional_goldens/agent/inference-error-valueerror-schema-v2.json
    (error.type: "ValueError")
  • functional_goldens/agent/inference-error-valueerror-span-and-event-schema-v2.json
    (error.type: "ValueError")

Run with the goldens regenerated (python -m tests.unittests.telemetry.regenerate
was used to record them), the tests/unittests/telemetry suite was run both
before and after the change in the same environment: 101 failed, 885 passed, 3 xfailed in both runs, with the same set of failing tests. The failures are
the telemetry suite's divergence checks against the locally installed
opentelemetry-instrumentation-google-genai from its development branch, which
the committed divergence file does not describe. They are not caused by this
change. test_google_cloud.py was excluded because it imports a symbol the
locally installed opentelemetry-api does not provide.

Manual End-to-End (E2E) Tests:

Not run. The failing-call path is covered by the functional goldens above.

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.

…event

A failed model call set error.type on its span and on the duration metric,
but not on the gen_ai.client.inference.operation.details event, so the event
of a failed call had no error type. The completion event is now emitted from
an exit callback that receives the exception, and carries the same error.type
as the span.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant