Skip to content

opentelemetry: add span event for instructions #1529

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 3 commits into from
Apr 18, 2025

Conversation

Kludex
Copy link
Member

@Kludex Kludex commented Apr 17, 2025

@Kludex Kludex requested a review from alexmojaki April 17, 2025 16:04
Copy link

github-actions bot commented Apr 17, 2025

Docs Preview

commit: 47648af
Preview URL: https://3dda9ad7-pydantic-ai-previews.pydantic.workers.dev

@Kludex Kludex closed this Apr 17, 2025
@Kludex Kludex reopened this Apr 17, 2025
InstrumentedModel.event_to_dict(e) for e in InstrumentedModel.messages_to_otel_events(messages)
] == snapshot(
[
{'content': 'system_prompt', 'role': 'system', 'event.name': 'gen_ai.system.message'},
Copy link
Member Author

Choose a reason for hiding this comment

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

It doesn't have the message_index, is that okay?

Copy link
Contributor

Choose a reason for hiding this comment

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

@@ -275,6 +277,10 @@ def messages_to_otel_events(messages: list[ModelMessage]) -> list[Event]:
**(event.attributes or {}),
}
events.extend(message_events)
if last_model_request and last_model_request.instructions:
events.insert(
0, Event('gen_ai.system.message', body={'content': last_model_request.instructions, 'role': 'system'})
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe setting the role to instructions would be clearer, but make sure it looks OK in the ui

Copy link
Member Author

@Kludex Kludex Apr 18, 2025

Choose a reason for hiding this comment

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

It does look OK in the UI.

InstrumentedModel.event_to_dict(e) for e in InstrumentedModel.messages_to_otel_events(messages)
] == snapshot(
[
{'content': 'system_prompt', 'role': 'system', 'event.name': 'gen_ai.system.message'},
Copy link
Contributor

Choose a reason for hiding this comment

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

@Kludex Kludex enabled auto-merge (squash) April 18, 2025 06:27
@Kludex Kludex merged commit d1dd64f into main Apr 18, 2025
13 checks passed
@Kludex Kludex deleted the add-genai-event-instructions branch April 18, 2025 06:29
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.

Instruction missing from the message history in logfire
2 participants