Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat(groq): implement emitting events in addition to current behavior #2888

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

LuizDMM
Copy link

@LuizDMM LuizDMM commented May 5, 2025

✅ PR Requirements

  • 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.
  • PR name follows conventional commits format: feat(instrumentation): ... or fix(instrumentation): ....
  • (If applicable) I have updated the documentation accordingly.

📌 Issue Requirements

  • Make sure to keep the current way of emitting events and the new (event-based) way with the official semantic
  • 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.
  • Propagate a new initialization parameter of the SDK called use_legacy_attributes that sets this config in all instrumentations.

Important

This PR implements event-based telemetry for Groq instrumentation, allowing toggling between legacy and new systems, and adds tests for both modes.

  • Behavior:
    • Introduces event-based telemetry in __init__.py with _emit_message_events() and _emit_choice_events().
    • Adds _emit_streaming_response_events() for streaming responses.
    • Config option use_legacy_attributes in config.py to toggle between legacy and event-based telemetry.
  • Event Handling:
    • Implements emit_event() in event_handler.py to emit MessageEvent and ChoiceEvent.
    • Adds is_content_enabled() and should_emit_events() in utils.py to control event emission.
  • Testing:
    • Adds tests in test_chat_tracing.py for both legacy and event-based telemetry.
    • Uses fixtures in conftest.py to configure test environments for different telemetry modes.

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

LuizDMM added 2 commits May 3, 2025 08:18
…urrent behavior

* Add "use_legacy_attributes" to Config and the Instrumentor constructor, defaulting to True;
* emit events for user prompts and AI responses, following [OpenTelemetry semantic conventions](https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-events/\\\);
* introduce a privacy safeguard by checking the OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT environment variable to enable or disable content capture in events;
* implement comprehensive tests to verify the new functionality and ensure that, when use_legacy_attributes == True, the existing behavior remains unchanged;
- Introduce TypedDicts and dataclasses to standardize inputs for event handling;
- Move `event_logger` to Config to centralize configuration and reduce complexity;
- Add `emit_event` method to encapsulate all event emission logic via `Event` instances;
- Refactor instrumentation to use `emit_event`, improving clarity and maintainability.
@LuizDMM LuizDMM changed the title Implement events groq feat(groq): implement emitting events in addition to current behaviour May 5, 2025
Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

Caution

Changes requested ❌

Reviewed everything up to c6805b2 in 3 minutes and 20 seconds. Click for details.
  • Reviewed 3988 lines of code in 15 files
  • Skipped 0 files when reviewing.
  • Skipped posting 11 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. packages/opentelemetry-instrumentation-groq/tests/traces/test_chat_tracing.py:12
  • Draft comment:
    The legacy test asserts that no logs are emitted when use_legacy_attributes is true. Ensure that the instrumentation configuration reliably sets this behavior and consider adding comments explaining why log emission is disabled in this mode.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
2. packages/opentelemetry-instrumentation-groq/tests/traces/test_chat_tracing.py:79
  • Draft comment:
    The 'assert_message_in_logs' helper is used with expected content for events. Verify that the asserted content matches the semantic conventions, especially for empty message bodies in no-content mode.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
3. packages/opentelemetry-instrumentation-groq/tests/traces/test_chat_tracing.py:412
  • Draft comment:
    In the async tests, ensure that the hard-coded response id ('chatcmpl-ec0a74e9-df7f-4e91-aa09-e9618451f5c9') is stable and correct for the mock response, or consider parameterizing this if the responses may change.
  • Reason this comment was not posted:
    Comment looked like it was already resolved.
4. packages/opentelemetry-instrumentation-groq/tests/traces/test_chat_tracing.py:421
  • Draft comment:
    The assert_message_in_logs helper is defined at the bottom. Consider documenting its purpose inline to improve clarity for future maintainers.
  • Reason this comment was not posted:
    Confidence changes required: 20% <= threshold 50% None
5. packages/opentelemetry-instrumentation-groq/tests/traces/test_chat_tracing.py:34
  • Draft comment:
    Consider parameterizing the hard-coded response ID (e.g. 'chatcmpl-645691ff-34af-4d0f-a1c1-fe888f8685cc') to improve test stability. Ideally, derive it dynamically or via a fixture.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.
6. packages/opentelemetry-instrumentation-groq/tests/traces/test_chat_tracing.py:421
  • Draft comment:
    Enhance the error messages in 'assert_message_in_logs' to provide more context when the assertion fails, aiding debugging.
  • Reason this comment was not posted:
    Comment did not seem useful. Confidence is useful = 0% <= threshold 50% This comment is purely informative and does not provide a specific suggestion or request for change. It does not align with the rules for good comments as it does not ask for a specific action or provide a specific suggestion.
7. packages/opentelemetry-instrumentation-groq/tests/traces/test_chat_tracing.py:129
  • Draft comment:
    When asserting events with no content, it may be beneficial to add a comment clarifying that an empty body is the expected behavior. This improves code clarity for future maintainers.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 10% vs. threshold = 50% The test name test_chat_with_events_with_no_content clearly indicates this is testing the no-content case. The empty dict {} is passed intentionally. The assert_message_in_logs function handles empty content explicitly. Adding a comment would be redundant given the clear test name and structure. The comment could help someone quickly scanning the code without reading the full context. Empty dicts can sometimes indicate errors or incomplete implementations. While true, test names should be descriptive enough to explain the test's purpose, which this one is. Adding redundant comments can actually reduce clarity by creating noise. The comment should be deleted as it suggests adding unnecessary redundancy to already clear test code.
8. packages/opentelemetry-instrumentation-groq/opentelemetry/instrumentation/groq/event_handler.py:97
  • Draft comment:
    Typographical issue: the comment text 'so remove the role from the body if it is the same as the in the event name' contains a redundant word. Consider revising it to 'so remove the role from the body if it is the same as in the event name'.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 10% vs. threshold = 50% While the comment is technically correct about the typo, it's an extremely minor issue in a code comment that doesn't affect functionality or code clarity. The meaning is still clear despite the small grammatical error. According to the rules, we should not make purely informative comments or comments about unimportant issues. The typo could be seen as reducing code quality and professionalism. Clear documentation is important. While clear documentation is important, this is such a minor grammatical issue that fixing it provides negligible value and creates unnecessary review noise. Delete this comment as it addresses an extremely minor documentation issue that doesn't meaningfully impact code quality or understanding.
9. packages/opentelemetry-instrumentation-groq/opentelemetry/instrumentation/groq/utils.py:47
  • Draft comment:
    Typo detected in log message: 'OpenLLMetry failed to trace in %s, error: %s'. Consider changing it to 'OpenTelemetry failed to trace in %s, error: %s' for clarity and consistency.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.
10. packages/opentelemetry-instrumentation-groq/tests/traces/cassettes/test_chat_tracing/test_chat_streaming_legacy.yaml:234
  • Draft comment:
    There appears to be a typographical error in the reassembled punchline. The segments of the word intended to form "challenged" are split as "-ch" + "alleng" + "ed" which, when combined, results in "challanged" missing an extra 'e'. Please correct the misspelling to "challenged" to ensure consistency in the joke.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.
11. packages/opentelemetry-instrumentation-groq/tests/traces/cassettes/test_chat_tracing/test_chat_streaming_with_events_with_content.yaml:231
  • Draft comment:
    It appears that the word intended to be 'challenged' is split incorrectly as 'alleng' (followed by 'ed'). Please correct this typographical error so that it reads 'challenged'.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 0% vs. threshold = 50% This is a test fixture file that records actual API responses. The "typo" is part of the streaming response data from the API and is intentionally recorded exactly as received. Modifying it would make the test fixture inaccurate. The apparent typo is just how the API chunks the response data and is not actually a problem that needs fixing. Could the typo cause issues for developers trying to understand the test? Could it be confusing to leave it as is? No - this is a test fixture that needs to accurately record the API's behavior, including how it chunks the response. Changing it would make the test less accurate. Delete the comment. The apparent typo is just how the API streams its response in chunks and should be preserved exactly as received in this test fixture.

Workflow ID: wflow_UX6CW31qCAsjEypJ

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

@LuizDMM LuizDMM changed the title feat(groq): implement emitting events in addition to current behaviour feat(groq): implement emitting events in addition to current behavior May 5, 2025
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.

1 participant