Skip to content

Conversation

@danjuv
Copy link

@danjuv danjuv commented Feb 9, 2026

Changes

This PR:

  • Moves the span event creation logic to run in finally_after so it's run if the hook errors
  • Adds an optional parameter exclude_exception to conditionally generate an exception on error (defaults to false to avoid breaking changes)
  • Adds FLAG_KEY and RESULT_VALUE to the generated exception event

Done to align with the spec.

fixes #340

@danjuv danjuv requested review from a team as code owners February 9, 2026 04:18
@github-actions github-actions bot requested a review from federicobond February 9, 2026 04:19
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @danjuv, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the TracingHook in the OpenTelemetry integration to enhance its robustness and align with the OpenFeature specification for hook lifecycle management. The changes ensure that telemetry data, specifically span events, are reliably captured across various hook execution scenarios, including error conditions, and provide more detailed context for recorded exceptions.

Highlights

  • Hook Lifecycle Alignment: The span event creation logic has been moved from the after method to finally_after within the TracingHook. This ensures that span events are consistently generated, even if the hook encounters an error during its execution, aligning with the OpenFeature specification.
  • Conditional Exception Recording: A new exclude_exceptions parameter has been added to the TracingHook constructor. This boolean flag, defaulting to False, allows for conditionally preventing the recording of exceptions in the OpenTelemetry span, providing more control over telemetry data.
  • Enriched Exception Events: When an exception is recorded, the error method now includes additional attributes: FLAG_KEY and RESULT_VALUE. These attributes provide richer context to the exception event, making debugging and analysis more effective.
Changelog
  • hooks/openfeature-hooks-opentelemetry/src/openfeature/contrib/hook/opentelemetry/init.py
    • Renamed the after method to finally_after in the TracingHook class.
    • Added an __init__ method to TracingHook to introduce an exclude_exceptions boolean parameter, defaulting to False.
    • Modified the error method to check self.exclude_exceptions before recording an exception.
    • Enhanced the error method to include FLAG_KEY and RESULT_VALUE as attributes when recording an exception to the current span.
  • hooks/openfeature-hooks-opentelemetry/tests/test_otel.py
    • Renamed the test function test_after to test_finally_after to reflect the method change.
    • Updated calls to hook.after within tests to hook.finally_after.
    • Added attributes dictionary to the mock_span.record_exception assertion in test_error to match the updated method signature.
    • Introduced a new test case test_error_exclude_exceptions to verify that no exception is recorded when exclude_exceptions is set to True.
Activity
  • No specific activity (comments, reviews, or progress updates) has been provided for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the TracingHook to better align with the OpenFeature specification by moving logic to finally_after and enhancing the error hook. The changes are well-implemented and improve spec compliance.

One minor point of clarification: the pull request description mentions that exclude_exceptions defaults to true, but the implementation correctly defaults it to false to maintain backward compatibility. This is the right approach, but the description could be updated to avoid confusion.

I've added one suggestion to further improve alignment with the specification for error event attributes.

Comment on lines +68 to +71
attributes = {
EventAttributes.KEY: hook_context.flag_key,
EventAttributes.RESULT_VALUE: json.dumps(hook_context.default_value),
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

To better align with the OpenFeature specification, feature_flag.provider_name should be included in the attributes for an error event when available. This change will also require updating test_error to include provider_metadata in the HookContext and assert this new attribute.

Suggested change
attributes = {
EventAttributes.KEY: hook_context.flag_key,
EventAttributes.RESULT_VALUE: json.dumps(hook_context.default_value),
}
attributes = {
EventAttributes.KEY: hook_context.flag_key,
EventAttributes.RESULT_VALUE: json.dumps(hook_context.default_value),
}
if hook_context.provider_metadata:
attributes[EventAttributes.PROVIDER_NAME] = (
hook_context.provider_metadata.name
)

Copy link
Member

Choose a reason for hiding this comment

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

@danjuv I believe this is correct.

Copy link
Author

Choose a reason for hiding this comment

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

@danjuv danjuv changed the title Refactor: Align TracingHook with spec fix: Align TracingHook with spec Feb 9, 2026
…ated on failure

Signed-off-by: Danju Visvanathan <danju.visvanathan@gmail.com>
Signed-off-by: Danju Visvanathan <danju.visvanathan@gmail.com>
@danjuv danjuv force-pushed the feat/add-finally_after-stage branch from 0670bda to 8706459 Compare February 9, 2026 04:34
Signed-off-by: Danju Visvanathan <danju.visvanathan@gmail.com>
@danjuv danjuv requested a review from toddbaert February 11, 2026 23:03
Signed-off-by: Danju Visvanathan <danju.visvanathan@gmail.com>
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.

Add flag key on Tracking Hook error stage

3 participants