-
Notifications
You must be signed in to change notification settings - Fork 809
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
Conversation
Kludex
commented
Apr 17, 2025
•
edited
Loading
edited
- Closes Instruction missing from the message history in logfire #1528
Docs Preview
|
tests/models/test_instrumented.py
Outdated
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'}, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cc @petyosi
@@ -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'}) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
tests/models/test_instrumented.py
Outdated
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'}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cc @petyosi