openllmetry icon indicating copy to clipboard operation
openllmetry copied to clipboard

feat(alephalpha): implement emitting events in addition to current behaviour

Open LuizDMM opened this issue 9 months ago • 0 comments

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): ... or fix(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 TypedDicts and dataclasses to standardize the event formats expected across instrumentations.
  • The new event_handler.emit_event function centralizes the emission process. It checks whether the event should be emitted based on Config.use_legacy_attributes, formats the event accordingly (including logic to omit content when needed), and then dispatches it using OpenTelemetry's EventLogger.

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__.py using emit_event().
    • Introduces use_legacy_attributes config in config.py to toggle event emission.
    • Implements _chat_completion_to_event() and _completion_to_event() for event conversion.
  • Event Handling:
    • New event_handler.py for event logic, including emit_event(), _emit_message_event(), and _emit_choice_event().
    • Defines MessageEvent and ChoiceEvent dataclasses for event structure.
  • Utilities:
    • Adds is_content_enabled() and should_emit_events() in utils.py for event control.
  • Testing:
    • Adds tests in test_completion.py for both legacy and event-based logging.
    • Uses conftest.py to configure test fixtures for different logging modes.

This description was created by Ellipsis for 98da08ddba68be69f34846ee5f477d274bbe858a. You can customize this summary. It will automatically update as commits are pushed.

LuizDMM avatar May 03 '25 02:05 LuizDMM