Skip to content

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

Merged
merged 32 commits into from
May 19, 2025

Conversation

askpt
Copy link
Member

@askpt askpt commented Mar 7, 2025

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

Fixes #381

@askpt askpt requested a review from a team as a code owner March 7, 2025 14:00
@askpt askpt linked an issue Mar 7, 2025 that may be closed by this pull request
@askpt askpt requested a review from Copilot March 7, 2025 14:00
@askpt askpt changed the title Add OTEL compatible telemetry object builder feat: Add OTEL compatible telemetry object builder Mar 7, 2025
Copy link

@Copilot Copilot AI left a 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;

@askpt askpt enabled auto-merge March 7, 2025 14:03
Copy link

codecov bot commented Mar 7, 2025

Codecov Report

Attention: Patch coverage is 97.14286% with 1 line in your changes missing coverage. Please review.

Project coverage is 87.08%. Comparing base (48f57cd) to head (b7d34fb).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
...rc/OpenFeature/Telemetry/EvaluationEventBuilder.cs 96.42% 0 Missing and 1 partial ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…e tests for missing flag metadata

Signed-off-by: André Silva <[email protected]>
@askpt askpt requested a review from Copilot March 7, 2025 14:33
Copy link

@Copilot Copilot AI left a 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]>
@askpt askpt force-pushed the askpt/381-add-opentelemetry-compatible-telemetry branch from e016fcf to 2d81ada Compare March 7, 2025 14:41
@toddbaert toddbaert requested a review from beeme1mr March 7, 2025 18:43
Copy link
Member

@beeme1mr beeme1mr left a 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.

@askpt askpt requested a review from beeme1mr March 11, 2025 16:27
Copy link
Member

@beeme1mr beeme1mr left a 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.

@beeme1mr
Copy link
Member

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!

@askpt askpt requested a review from beeme1mr May 15, 2025 15:16
@askpt askpt marked this pull request as draft May 15, 2025 15:30
@askpt askpt marked this pull request as ready for review May 15, 2025 15:41
@beeme1mr beeme1mr requested review from dyladan and kinyoklion May 15, 2025 18:05
@askpt askpt requested a review from arttonoyan May 19, 2025 07:16
@askpt askpt added this pull request to the merge queue May 19, 2025
Merged via the queue into main with commit 6c44db9 May 19, 2025
17 checks passed
@askpt askpt deleted the askpt/381-add-opentelemetry-compatible-telemetry branch May 19, 2025 15:04
askpt added a commit that referenced this pull request May 23, 2025
<!-- 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]>
github-merge-queue bot pushed a commit that referenced this pull request May 23, 2025
🤖 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]>
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 OpenTelemetry-Compatible Telemetry Utility Function
4 participants