feat(alephalpha): implement emitting events in addition to current behaviour
Related to #2456
✅ PR Requirements
- [x] I have added tests that cover my changes.
- [ ] If adding a new instrumentation or changing an existing one, I've added screenshots from some observability platform showing the change.
- [x] PR name follows conventional commits format:
feat(instrumentation): ...orfix(instrumentation): .... - [ ] (If applicable) I have updated the documentation accordingly.
📌 Issue Requirements
- [x] Make sure to keep the current way of emitting events and the new (event-based) way with the official semantic
- [x] Add a config to each instrumentation called use_legacy_attributes which defaults to true, and if set to false emit events instead of the prompt / completion attributes.
- [x] Propagate a new initialization parameter of the SDK called use_legacy_attributes that sets this config in all instrumentations.
✍️ Comments
Hey @nirga, as per your guidance on #2810, I’ve broken down the larger PR and refactored the event emission logic.
- I introduced a new module to encapsulate the event handling flow. It includes a couple of
TypedDictsanddataclassesto standardize the event formats expected across instrumentations. - The new
event_handler.emit_eventfunction centralizes the emission process. It checks whether the event should be emitted based onConfig.use_legacy_attributes, formats the event accordingly (including logic to omit content when needed), and then dispatches it using OpenTelemetry'sEventLogger.
Note: You’ll notice that the event_handler module is somewhat overengineered for AlephAlpha, as it also includes logic for handling tool_calls, which aren’t currently relevant here. My intention is to generalize this handler—or use it as a base—for the same logic across other instrumentations, and I’d appreciate your feedback on that direction.
With your approval on this PR, I’ll start applying the same pattern to the rest of my previous work, submitting smaller follow-up PRs along the way
[!IMPORTANT] This PR adds event emission to AlephAlpha instrumentation, allowing toggling between legacy and event-based logging, with new tests to verify functionality.
- Behavior:
- Adds event emission alongside existing behavior in
__init__.pyusingemit_event().- Introduces
use_legacy_attributesconfig inconfig.pyto toggle event emission.- Implements
_chat_completion_to_event()and_completion_to_event()for event conversion.- Event Handling:
- New
event_handler.pyfor event logic, includingemit_event(),_emit_message_event(), and_emit_choice_event().- Defines
MessageEventandChoiceEventdataclasses for event structure.- Utilities:
- Adds
is_content_enabled()andshould_emit_events()inutils.pyfor event control.- Testing:
- Adds tests in
test_completion.pyfor both legacy and event-based logging.- Uses
conftest.pyto configure test fixtures for different logging modes.This description was created by
for 98da08ddba68be69f34846ee5f477d274bbe858a. You can customize this summary. It will automatically update as commits are pushed.