-
Notifications
You must be signed in to change notification settings - Fork 26
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 custom dimensions for metrics #122
Closed
Closed
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4de9a9a
Adding class for MetricHookCustomDimensions
askpt e700a53
Add support for custom dimensions in MetricsHook
askpt e0be24e
Refactor MetricHookCustomDimensions to use List<KeyValuePair> instead…
askpt 674b984
Update MetricsHook to use KeyValuePair array for custom dimensions
askpt 1450022
Remove unused using statements and update MetricsHook constructor
askpt 3edc462
Adding documentation.
askpt a62f7e8
Added unit tests.
askpt 08ce525
Merge branch 'main' into askpt/118-add-custom-metrics
askpt f152a94
Merge branch 'main' into askpt/118-add-custom-metrics
askpt 37f8b44
Initial attempt for custom function.
askpt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
src/OpenFeature.Contrib.Hooks.Otel/MetricHookCustomDimensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace OpenFeature.Contrib.Hooks.Otel | ||
{ | ||
/// <summary> | ||
/// Represents a custom dimension list for a metric hook. | ||
/// </summary> | ||
public class MetricHookCustomDimensions | ||
{ | ||
private readonly List<KeyValuePair<string, object>> _keyValuePairs = new List<KeyValuePair<string, object>>(); | ||
|
||
/// <summary> | ||
/// Adds a custom dimension to the list. | ||
/// </summary> | ||
/// <param name="key">The key of the custom dimension.</param> | ||
/// <param name="value">The value of the custom dimension.</param> | ||
/// <returns>The custom dimension list.</returns> | ||
public MetricHookCustomDimensions Add(string key, object value) | ||
{ | ||
_keyValuePairs.Add(new KeyValuePair<string, object>(key, value)); | ||
return this; | ||
} | ||
|
||
internal KeyValuePair<string, object>[] GetTagList() | ||
{ | ||
return _keyValuePairs.ToArray(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
test/OpenFeature.Contrib.Hooks.Otel.Test/MetricHookCustomDimensionsTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using Xunit; | ||
|
||
namespace OpenFeature.Contrib.Hooks.Otel.Test | ||
{ | ||
public class MetricHookCustomDimensionsTest | ||
{ | ||
[Fact] | ||
public void Adds_CustomDimension_HasValues() | ||
{ | ||
// Arrange | ||
var customDimensions = new MetricHookCustomDimensions(); | ||
string key = "dimensionKey"; | ||
object value = "dimensionValue"; | ||
|
||
// Act | ||
customDimensions.Add(key, value); | ||
|
||
// Assert | ||
var tagList = customDimensions.GetTagList(); | ||
Assert.Single(tagList); | ||
Assert.Equal(key, tagList[0].Key); | ||
Assert.Equal(value, tagList[0].Value); | ||
} | ||
|
||
[Fact] | ||
public void CustomDimensionToList_IsEmpty() | ||
{ | ||
// Arrange | ||
var customDimensions = new MetricHookCustomDimensions(); | ||
|
||
// Act | ||
|
||
// Assert | ||
var tagList = customDimensions.GetTagList(); | ||
Assert.Empty(tagList); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The flexibility of this approach is a bit limited. I think a functional approach might be better. Instead of allowing users to define k/v pairs, I would recommend you allow users to define a function that takes an FlagEvaluationDetails object as a param, and returns a tuple or k/v set that will be added. Then users can build whatever data they want and add it as metrics. This will be even more valuable when we add flag metadata to this SDK.
We do something similar in JS: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/hooks/open-telemetry/README.md#custom-attributes
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.
@toddbaert I was looking into the Java implementation and they offer a Flag Metadata (that is not implemented on dotnet SDK yet) and uses a custom dimensions that have a predefined list. Might be interesting to keep the extra dictionary and when we have the flag metadata implemented at SDK level, we use the FlagEvaluationDetails metadata?
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.
Sorry I missed this comment for so long @askpt . I'm not sure I fully understand what you're proposing. Maybe you can clarify.
In any case, I think that once you implement the metadata here, the functional approach used in Java and JS should work.