Skip to content

InstrumentedModel and FallbackModel fixes #1121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 14, 2025
Merged

InstrumentedModel and FallbackModel fixes #1121

merged 6 commits into from
Mar 14, 2025

Conversation

alexmojaki
Copy link
Contributor

@alexmojaki alexmojaki commented Mar 14, 2025

Copy link

github-actions bot commented Mar 14, 2025

Docs Preview

commit: af74089
Preview URL: https://b7c48e28-pydantic-ai-previews.pydantic.workers.dev

@alexmojaki alexmojaki changed the title Fix instrumentation of FallbackModel again Instrumentation fixes Mar 14, 2025
@alexmojaki alexmojaki changed the title Instrumentation fixes InstrumentedModel and FallbackModel fixes Mar 14, 2025
@alexmojaki alexmojaki requested review from Kludex and dmontagu March 14, 2025 11:26
"""The system / model provider, n/a for fallback models."""
return None
def system(self) -> str:
return 'fallback'
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this include the systems of models that are fallen back to? E.g. 'fallback:openai:anthropic:function' or similar?

Related, if this never ends up in the otel system (e.g. because we use the value from the actual model that made the request), I think we don't necessarily need to include the fallback systems here but I would appreciate a comment explaining that.

(If it does end up in the otel, then it seems problematic. I'm assuming it doesn't though.)

Comment on lines 69 to 73
span = get_current_span()
if span.is_recording():
attributes = getattr(span, 'attributes', {})
if attributes.get('gen_ai.request.model') == self.model_name:
span.set_attributes(InstrumentedModel.model_attributes(model))
Copy link
Contributor

@dmontagu dmontagu Mar 14, 2025

Choose a reason for hiding this comment

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

I feel like this should be outside this try-except. Like, errors with otel shouldn't trigger fallback, it means something more fundamental is wrong

@alexmojaki alexmojaki merged commit 42dac78 into main Mar 14, 2025
15 checks passed
@alexmojaki alexmojaki deleted the alex/model-attrs branch March 14, 2025 13:56
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.

2 participants