-
Notifications
You must be signed in to change notification settings - Fork 21
feat: Add OTEL compatible telemetry object builder #397
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
feat: Add OTEL compatible telemetry object builder #397
Conversation
Signed-off-by: André Silva <[email protected]>
Signed-off-by: André Silva <[email protected]>
Signed-off-by: André Silva <[email protected]>
…tionEventFactory for event creation Signed-off-by: André Silva <[email protected]>
…tory for event creation Signed-off-by: André Silva <[email protected]>
…eature flags Signed-off-by: André Silva <[email protected]>
…ation Signed-off-by: André Silva <[email protected]>
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.
PR Overview
This PR adds OTEL-compatible telemetry support to the OpenFeature library by introducing new classes, constants, and tests for building evaluation events used in feature flag evaluations.
- Added telemetry constants and flag metadata classes.
- Implemented an evaluation event builder to construct OTEL-compliant evaluation events.
- Included unit tests to verify the correct construction of evaluation events.
Reviewed Changes
File | Description |
---|---|
src/OpenFeature/Telemetry/TelemetryConstants.cs | Introduces constants for telemetry event attributes. |
src/OpenFeature/Telemetry/EvaluationEventBuilder.cs | Implements the builder for evaluation events. |
test/OpenFeature.Tests/Telemetry/EvaluationEventBuilderTests.cs | Adds tests to validate evaluation event building, including error handling and missing variants. |
src/OpenFeature/Telemetry/TelemetryFlagMetadata.cs | Defines well-known metadata keys for telemetry. |
src/OpenFeature/Telemetry/TelemetryEvaluationData.cs | Adds evaluation data constants for telemetry events. |
src/OpenFeature/Telemetry/EvaluationEvent.cs | Provides the EvaluationEvent class used to represent an event. |
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (2)
src/OpenFeature/Telemetry/EvaluationEventBuilder.cs:28
- The reference 'Reason.Unknown' is undefined in this context; please ensure that the appropriate constant or enum is referenced instead.
attributes[TelemetryConstants.Reason] = !string.IsNullOrWhiteSpace(details.Reason) ? details.Reason?.ToLowerInvariant() : Reason.Unknown;
test/OpenFeature.Tests/Telemetry/EvaluationEventBuilderTests.cs:2
- The using directive 'using OpenFeature.Constant;' in the test file does not match the namespace of TelemetryConstants. Please update it to 'using OpenFeature.Telemetry;' to ensure consistency.
using OpenFeature.Constant;
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #397 +/- ##
==========================================
+ Coverage 86.87% 87.08% +0.20%
==========================================
Files 43 45 +2
Lines 1722 1757 +35
Branches 180 184 +4
==========================================
+ Hits 1496 1530 +34
Misses 187 187
- Partials 39 40 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…e tests for missing flag metadata Signed-off-by: André Silva <[email protected]>
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.
PR Overview
This PR adds support for OTEL-compatible telemetry events for feature flags in the OpenFeature library. The changes include the creation of new classes for evaluation events and their builders, the definition of related constants, and comprehensive tests for the new functionality.
- Added telemetry constants and flag metadata definitions.
- Introduced the EvaluationEvent and EvaluationEventBuilder classes.
- Added unit tests to verify the behavior of evaluation event creation.
Reviewed Changes
File | Description |
---|---|
src/OpenFeature/Telemetry/TelemetryConstants.cs | Defines constants for telemetry attribute keys. |
src/OpenFeature/Telemetry/EvaluationEventBuilder.cs | Provides a builder for creating evaluation events; review notes below. |
test/OpenFeature.Tests/Telemetry/EvaluationEventBuilderTests.cs | Contains tests that verify evaluation event creation behavior. |
src/OpenFeature/Telemetry/TelemetryEvaluationData.cs | Defines additional telemetry event data constants. |
src/OpenFeature/Telemetry/TelemetryFlagMetadata.cs | Specifies well-known flag metadata attribute keys. |
src/OpenFeature/Telemetry/EvaluationEvent.cs | Implements the evaluation event model with attributes and body. |
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Comments suppressed due to low confidence (2)
src/OpenFeature/Telemetry/EvaluationEventBuilder.cs:2
- The using directive 'OpenFeature.Constant' appears inconsistent with the location of TelemetryConstants, which is in the 'OpenFeature.Telemetry' namespace. Consider updating or removing this directive to avoid potential namespace conflicts.
using OpenFeature.Constant;
src/OpenFeature/Telemetry/EvaluationEventBuilder.cs:31
- The use of 'Reason.Unknown' appears to reference an undefined member. Consider defining a constant (e.g., TelemetryConstants.DefaultReason or similar) or replacing it with an appropriate default value such as "unknown".
attributes[TelemetryConstants.Reason] = !string.IsNullOrWhiteSpace(details.Reason) ? details.Reason?.ToLowerInvariant() : Reason.Unknown;
…er and add corresponding unit tests Signed-off-by: André Silva <[email protected]>
e016fcf
to
2d81ada
Compare
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.
Looks good but please make sure error code
and reason
is lowercase.
test/OpenFeature.Tests/Telemetry/EvaluationEventBuilderTests.cs
Outdated
Show resolved
Hide resolved
Signed-off-by: André Silva <[email protected]>
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.
FYI @askpt, I found out yesterday that the OTel team has required some changes to the semcon. Let's wait on merging until we have further clarity.
Hey @askpt, all the upstream blockers have been resolved. I've left some feedback on what you have so far. We should be able to get this in as soon as those issues are addressed. Thanks! |
Signed-off-by: André Silva <[email protected]>
Signed-off-by: André Silva <[email protected]>
…ctor constants Signed-off-by: André Silva <[email protected]>
…nd include value attribute Signed-off-by: André Silva <[email protected]>
…adata and streamline reason assignment Signed-off-by: André Silva <[email protected]>
Signed-off-by: André Silva <[email protected]>
…ead-only in EvaluationEvent Signed-off-by: André Silva <[email protected]>
…thod calls in tests Signed-off-by: André Silva <[email protected]>
<!-- Please use this template for your pull request. --> <!-- Please use the sections that you need and delete other sections --> ## This PR This pull request introduces a feature for generating telemetry events to track feature flag evaluations. It adds a new `EvaluationEvent` class, a builder for creating these events, constants for telemetry attributes, and metadata definitions. It also includes comprehensive unit tests to ensure the correctness of the implementation. ### New Feature: Telemetry Event Generation * **`EvaluationEvent` class**: Added a new class to represent evaluation events for feature flags, including properties for the event name and attributes. (`src/OpenFeature/Telemetry/EvaluationEvent.cs`) * **`EvaluationEventBuilder` class**: Introduced a static builder class to construct `EvaluationEvent` instances using flag evaluation details and hook context. (`src/OpenFeature/Telemetry/EvaluationEventBuilder.cs`) ### Supporting Components * **Telemetry constants**: Defined a set of constants in `TelemetryConstants` to standardize attribute keys for OpenTelemetry-compliant feature flag events. (`src/OpenFeature/Telemetry/TelemetryConstants.cs`) * **Flag metadata attributes**: Added `TelemetryFlagMetadata` to define well-known metadata attributes for telemetry events, such as `contextId`, `flagSetId`, and `version`. (`src/OpenFeature/Telemetry/TelemetryFlagMetadata.cs`) ### Unit Tests * **`EvaluationEventBuilderTests`**: Added unit tests to validate the behavior of `EvaluationEventBuilder`, including scenarios for handling errors, missing metadata, and missing attributes. (`test/OpenFeature.Tests/Telemetry/EvaluationEventBuilderTests.cs`) ### Related Issues <!-- add here the GitHub issue that this PR resolves if applicable --> Fixes #381 --------- Signed-off-by: André Silva <[email protected]>
🤖 I have created a release *beep* *boop* --- ## [2.6.0](v2.5.0...v2.6.0) (2025-05-23) ### ✨ New Features * add AddHandler extension method to Dependency Injection package ([#462](#462)) ([ff414b8](ff414b8)) * Add Extension Method for adding global Hook via DependencyInjection ([#459](#459)) ([9b04485](9b04485)) * Add OTEL compatible telemetry object builder ([#397](#397)) ([6c44db9](6c44db9)) ### 🧹 Chore * Cleanup .props file ([#476](#476)) ([6d7a535](6d7a535)) * **deps:** update actions/attest-build-provenance action to v2.3.0 ([#464](#464)) ([0a5ab0c](0a5ab0c)) * **deps:** update codecov/codecov-action action to v5.4.3 ([#475](#475)) ([fbcf3a4](fbcf3a4)) * **deps:** update github/codeql-action digest to 60168ef ([#463](#463)) ([ea76351](ea76351)) * **deps:** update github/codeql-action digest to ff0a06e ([#473](#473)) ([af1b20f](af1b20f)) * **deps:** update spec digest to edf0deb ([#474](#474)) ([fc3bdfe](fc3bdfe)) ### 📚 Documentation * Add AspNetCore sample app ([#477](#477)) ([9742a0d](9742a0d)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). --------- Signed-off-by: OpenFeature Bot <[email protected]> Signed-off-by: André Silva <[email protected]> Co-authored-by: André Silva <[email protected]>
This PR
This pull request introduces a feature for generating telemetry events to track feature flag evaluations. It adds a new
EvaluationEvent
class, a builder for creating these events, constants for telemetry attributes, and metadata definitions. It also includes comprehensive unit tests to ensure the correctness of the implementation.New Feature: Telemetry Event Generation
EvaluationEvent
class: Added a new class to represent evaluation events for feature flags, including properties for the event name and attributes. (src/OpenFeature/Telemetry/EvaluationEvent.cs
)EvaluationEventBuilder
class: Introduced a static builder class to constructEvaluationEvent
instances using flag evaluation details and hook context. (src/OpenFeature/Telemetry/EvaluationEventBuilder.cs
)Supporting Components
TelemetryConstants
to standardize attribute keys for OpenTelemetry-compliant feature flag events. (src/OpenFeature/Telemetry/TelemetryConstants.cs
)TelemetryFlagMetadata
to define well-known metadata attributes for telemetry events, such ascontextId
,flagSetId
, andversion
. (src/OpenFeature/Telemetry/TelemetryFlagMetadata.cs
)Unit Tests
EvaluationEventBuilderTests
: Added unit tests to validate the behavior ofEvaluationEventBuilder
, including scenarios for handling errors, missing metadata, and missing attributes. (test/OpenFeature.Tests/Telemetry/EvaluationEventBuilderTests.cs
)Related Issues
Fixes #381