diff --git a/src/OpenFeature.Contrib.Hooks.Otel/OpenFeature.Contrib.Hooks.Otel.csproj b/src/OpenFeature.Contrib.Hooks.Otel/OpenFeature.Contrib.Hooks.Otel.csproj index a4f54a75..ed5beadd 100644 --- a/src/OpenFeature.Contrib.Hooks.Otel/OpenFeature.Contrib.Hooks.Otel.csproj +++ b/src/OpenFeature.Contrib.Hooks.Otel/OpenFeature.Contrib.Hooks.Otel.csproj @@ -13,8 +13,7 @@ - - + diff --git a/src/OpenFeature.Contrib.Hooks.Otel/TracingHook.cs b/src/OpenFeature.Contrib.Hooks.Otel/TracingHook.cs index 6d0c2289..66692d86 100644 --- a/src/OpenFeature.Contrib.Hooks.Otel/TracingHook.cs +++ b/src/OpenFeature.Contrib.Hooks.Otel/TracingHook.cs @@ -1,6 +1,7 @@ using OpenFeature.Model; using System.Threading.Tasks; using System.Collections.Generic; +using System.Diagnostics; using OpenTelemetry.Trace; namespace OpenFeature.Contrib.Hooks.Otel @@ -22,17 +23,16 @@ public class TracingHook : Hook public override Task After(HookContext context, FlagEvaluationDetails details, IReadOnlyDictionary hints = null) { - var span = Tracer.CurrentSpan; - if (span != null) - { - var attributes = new Dictionary + Activity.Current? + .SetTag("feature_flag.key", details.FlagKey) + .SetTag("feature_flag.variant", details.Variant) + .SetTag("feature_flag.provider_name", context.ProviderMetadata.Name) + .AddEvent(new ActivityEvent("feature_flag", tags: new ActivityTagsCollection { - {"feature_flag.key", details.FlagKey}, - {"feature_flag.variant", details.Variant}, - {"feature_flag.provider_name", context.ProviderMetadata.Name} - }; - span.AddEvent("feature_flag", new SpanAttributes(attributes)); - } + ["feature_flag.key"] = details.FlagKey, + ["feature_flag.variant"] = details.Variant, + ["feature_flag.provider_name"] = context.ProviderMetadata.Name + })); return Task.CompletedTask; } @@ -47,11 +47,7 @@ public override Task After(HookContext context, FlagEvaluationDetails d public override Task Error(HookContext context, System.Exception error, IReadOnlyDictionary hints = null) { - var span = Tracer.CurrentSpan; - if (span != null) - { - span.RecordException(error); - } + Activity.Current?.RecordException(error); return Task.CompletedTask; }