-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Replace OtelHook with TracingHook. Deprecating OtelHook (#116)
Signed-off-by: André Silva <[email protected]>
- Loading branch information
Showing
4 changed files
with
77 additions
and
26 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using OpenFeature.Model; | ||
using System.Threading.Tasks; | ||
using System.Collections.Generic; | ||
using OpenTelemetry.Trace; | ||
|
||
namespace OpenFeature.Contrib.Hooks.Otel | ||
|
||
{ | ||
/// <summary> | ||
/// Stub. | ||
/// </summary> | ||
public class TracingHook : Hook | ||
{ | ||
|
||
/// <summary> | ||
/// After is executed after a feature flag has been evaluated. | ||
/// </summary> | ||
/// <param name="context">The hook context</param> | ||
/// <param name="details">The result of the feature flag evaluation</param> | ||
/// <param name="hints">Hints for the feature flag evaluation</param> | ||
/// <returns>An awaitable Task object</returns> | ||
public override Task After<T>(HookContext<T> context, FlagEvaluationDetails<T> details, | ||
IReadOnlyDictionary<string, object> hints = null) | ||
{ | ||
var span = Tracer.CurrentSpan; | ||
if (span != null) | ||
{ | ||
var attributes = new Dictionary<string, object> | ||
{ | ||
{"feature_flag.key", details.FlagKey}, | ||
{"feature_flag.variant", details.Variant}, | ||
{"feature_flag.provider_name", context.ProviderMetadata.Name} | ||
}; | ||
span.AddEvent("feature_flag", new SpanAttributes(attributes)); | ||
} | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
/// <summary> | ||
/// Error is executed when an error during a feature flag evaluation occured. | ||
/// </summary> | ||
/// <param name="context">The hook context</param> | ||
/// <param name="error">The exception thrown by feature flag provider</param> | ||
/// <param name="hints">Hints for the feature flag evaluation</param> | ||
/// <returns>An awaitable Task object</returns> | ||
public override Task Error<T>(HookContext<T> context, System.Exception error, | ||
IReadOnlyDictionary<string, object> hints = null) | ||
{ | ||
var span = Tracer.CurrentSpan; | ||
if (span != null) | ||
{ | ||
span.RecordException(error); | ||
} | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
} | ||
} | ||
|
||
|
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