Skip to content

[opentelemetry-instrumentation-genai-agno] Add instrumentation for agno model calls - #773

Open
DylanRussell wants to merge 30 commits into
DylanRussell/more_agno_instrumentation_4from
DylanRussell/more_agno_instrumentation_5
Open

DylanRussell wants to merge 30 commits into
DylanRussell/more_agno_instrumentation_4from
DylanRussell/more_agno_instrumentation_5

Conversation

@DylanRussell

Copy link
Copy Markdown
Contributor

Description

Probably want to wait until #765 lands to avoid duplicate inference calls, but eventually we will want this and that PR will not change the implementation here.

I think once this lands we will have reached parity with the agno instrumentations in open inference and other places..

Type of change

  • New feature (non-breaking change which adds functionality)

How has this been tested?

Unot tests

Checklist

  • Followed the style guidelines of this project
  • Changelog updated if the change requires an entry
  • Unit tests added
  • Documentation updated

Instrument agno.models.base.Model response and streaming methods to emit standard GenAI chat spans with complete request/response attributes, usage metrics, and content capture.

Assisted-by: Claude Opus 4.6
Replace Any with concrete Agno Model, Message, MessageData, and ModelResponse types in model patching, stream wrapping, and provider resolution functions.

Assisted-by: Claude Opus 4.6
…tent variable

Remove redundant capture_content local variables and function parameters, relying directly on invocation.should_capture_content property on InferenceInvocation and RetrievalInvocation.

Assisted-by: Claude Opus 4.6
Replace repetitive try/except type conversions with safe_int and safe_float helpers across retrieval, model inference, and streaming wrappers.

Assisted-by: Claude Opus 4.6
…hecks

Let opentelemetry-util-genai handle None values directly across model response token metrics, embedder tokens, dimension count, and query text.

Assisted-by: Claude Opus 4.6
Avoid repeated checks of getattr(model, 'vertexai', False) and GOOGLE_GENAI_USE_VERTEXAI by caching the boolean in is_vertex.

Assisted-by: Claude Opus 4.6
Eliminate repetitive is_vertex if/else branching by determining google_provider once at function start.

Assisted-by: Claude Opus 4.6
Consolidate duplicate provider resolution logic across resolve_embedder_provider and resolve_model_provider into a single _resolve_provider helper.

Assisted-by: Claude Opus 4.6
…_model_output_message

Drop unnecessary cast(object, ...) and cast(list[Any], ...) calls and share tool call part extraction via _extract_tool_call_parts.

Assisted-by: Claude Opus 4.6
…nput_messages

Use list[dict[str, Any]] | None for tool_calls and Iterable[Message] for messages, accessing Message attributes directly.

Assisted-by: Claude Opus 4.6
…n embedder functions

Use concrete Model | Embedder and Embedder annotations in _resolve_provider, resolve_embedder_provider, and embedder wrappers.

Assisted-by: Claude Opus 4.6
… | ModelResponse

Assisted-by: Claude Opus 4.6
Assisted-by: Claude Opus 4.6
@DylanRussell
DylanRussell requested a review from a team as a code owner September 22, 2026 14:43
@DylanRussell DylanRussell changed the title [] Add instrumentation for agno model calls [opentelemetry-instrumentation-genai-agno] Add instrumentation for agno model calls Sep 22, 2026
@DylanRussell
DylanRussell added this pull request to stack #732 September 22, 2026 14:44
@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Waiting on reviewers · refreshed 2026-09-23 20:44 UTC

Review the latest changes.

Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Model spans start after inference, stream managers are wrapped incorrectly, and required tests are missing.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 2 High severity · 1 Medium severity · 3 Low severity

Open (6)
What changed in this PR

Adds Agno model-call telemetry for synchronous, asynchronous, streaming, multimodal, and error paths.

Changes:

  • Adds GenAI chat instrumentation and stream wrappers.
  • Adds provider/message/media extraction utilities.
  • Adds model tests and documentation.
File Description
patch.py Patches model response processing.
stream.py Adds model stream telemetry wrappers.
utils.py Adds model and multimodal extraction.
test_model.py Tests model instrumentation.
test_embedder.py Makes Gemini tests optional.
README.rst Documents model operations.
.changelog/​773.added Records the feature.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread instrumentation/opentelemetry-instrumentation-genai-agno/README.rst
…sell/more_agno_instrumentation_4

# Conflicts:
#	instrumentation/opentelemetry-instrumentation-genai-agno/README.rst
#	instrumentation/opentelemetry-instrumentation-genai-agno/src/opentelemetry/instrumentation/genai/agno/utils.py
…sell/more_agno_instrumentation_5

# Conflicts:
#	instrumentation/opentelemetry-instrumentation-genai-agno/src/opentelemetry/instrumentation/genai/agno/patch.py
#	instrumentation/opentelemetry-instrumentation-genai-agno/src/opentelemetry/instrumentation/genai/agno/stream.py
@linux-foundation-easycla

linux-foundation-easycla Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

@DylanRussell
DylanRussell force-pushed the DylanRussell/more_agno_instrumentation_5 branch from 24e7603 to 2c94b98 Compare September 22, 2026 18:32
…sell/more_agno_instrumentation_5

# Conflicts:
#	instrumentation/opentelemetry-instrumentation-genai-agno/src/opentelemetry/instrumentation/genai/agno/patch.py
#	instrumentation/opentelemetry-instrumentation-genai-agno/src/opentelemetry/instrumentation/genai/agno/stream.py
…sell/more_agno_instrumentation_5

# Conflicts:
#	instrumentation/opentelemetry-instrumentation-genai-agno/src/opentelemetry/instrumentation/genai/agno/patch.py
…sell/more_agno_instrumentation_5

# Conflicts:
#	instrumentation/opentelemetry-instrumentation-genai-agno/src/opentelemetry/instrumentation/genai/agno/patch.py

This branch has not been deployed

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants