diff --git a/Backend.Tests/Otel/OtelKernelTests.cs b/Backend.Tests/Otel/OtelKernelTests.cs index ee8db14d3..8b1cbfc85 100644 --- a/Backend.Tests/Otel/OtelKernelTests.cs +++ b/Backend.Tests/Otel/OtelKernelTests.cs @@ -33,8 +33,8 @@ public void BuildersSetBaggageFromHeader() { // Arrange var httpContext = new DefaultHttpContext(); - httpContext.Request.Headers[FrontendConsentKey] = "true"; - httpContext.Request.Headers[FrontendSessionIdKey] = "123"; + httpContext.Request.Headers[FrontendConsent] = "true"; + httpContext.Request.Headers[FrontendSessionId] = "123"; var activity = new Activity("testActivity").Start(); // Act @@ -42,8 +42,8 @@ public void BuildersSetBaggageFromHeader() TrackSession(activity, httpContext.Request); // Assert - Assert.That(activity.Baggage.Any(_ => _.Key == OtelConsentBaggageKey)); - Assert.That(activity.Baggage.Any(_ => _.Key == OtelSessionBaggageKey)); + Assert.That(activity.Baggage.Any(_ => _.Key == OtelConsentBaggage)); + Assert.That(activity.Baggage.Any(_ => _.Key == OtelSessionBaggage)); } [Test] @@ -51,15 +51,15 @@ public void OnEndSetsTagsFromBaggage() { // Arrange var activity = new Activity("testActivity").Start(); - activity.SetBaggage(OtelConsentBaggageKey, "true"); - activity.SetBaggage(OtelSessionBaggageKey, "test session id"); + activity.SetBaggage(OtelConsentBaggage, "true"); + activity.SetBaggage(OtelSessionBaggage, "test session id"); // Act _locationEnricher.OnEnd(activity); // Assert - Assert.That(activity.Tags.Any(_ => _.Key == OtelConsentKey)); - Assert.That(activity.Tags.Any(_ => _.Key == OtelSessionIdKey)); + Assert.That(activity.Tags.Any(_ => _.Key == OtelConsent)); + Assert.That(activity.Tags.Any(_ => _.Key == OtelSessionId)); } [Test] @@ -68,7 +68,7 @@ public void OnEndSetsLocationTags() // Arrange _locationEnricher = new LocationEnricher(new LocationProviderMock()); var activity = new Activity("testActivity").Start(); - activity.SetBaggage(OtelConsentBaggageKey, "true"); + activity.SetBaggage(OtelConsentBaggage, "true"); // Act _locationEnricher.OnEnd(activity); diff --git a/Backend/Otel/OtelKernel.cs b/Backend/Otel/OtelKernel.cs index 8213091d4..1dee0bb6e 100644 --- a/Backend/Otel/OtelKernel.cs +++ b/Backend/Otel/OtelKernel.cs @@ -17,12 +17,12 @@ namespace BackendFramework.Otel public static class OtelKernel { public const string SourceName = "Backend-Otel"; - public const string FrontendConsentKey = "otelConsent"; - public const string FrontendSessionIdKey = "sessionId"; - public const string OtelConsentKey = "otelConsent"; - public const string OtelSessionIdKey = "sessionId"; - public const string OtelConsentBaggageKey = "otelConsentBaggage"; - public const string OtelSessionBaggageKey = "sessionBaggage"; + public const string FrontendConsent = "otelConsent"; + public const string FrontendSessionId = "sessionId"; + public const string OtelConsent = "otelConsent"; + public const string OtelSessionId = "sessionId"; + public const string OtelConsentBaggage = "otelConsentBaggage"; + public const string OtelSessionBaggage = "sessionBaggage"; public static void AddOpenTelemetryInstrumentation(this IServiceCollection services) { @@ -50,15 +50,15 @@ internal static void TrackConsent(Activity activity, HttpRequest request) } activity.SetTag("consent string", valueString.ToString()); - activity.SetBaggage(OtelConsentBaggageKey, consent.ToString()); + activity.SetBaggage(OtelConsentBaggage, consent.ToString()); } internal static void TrackSession(Activity activity, HttpRequest request) { - var sessionId = request.Headers.TryGetValue(FrontendSessionIdKey, out var values) ? values.FirstOrDefault() : null; + var sessionId = request.Headers.TryGetValue(FrontendSessionId, out var values) ? values.FirstOrDefault() : null; if (sessionId is not null) { - activity.SetBaggage(OtelSessionBaggageKey, sessionId); + activity.SetBaggage(OtelSessionBaggage, sessionId); } } @@ -119,8 +119,8 @@ internal class LocationEnricher(ILocationProvider locationProvider) : BaseProces { public override async void OnEnd(Activity data) { - var consentString = data.GetBaggageItem(OtelConsentBaggageKey); - data.AddTag(OtelConsentKey, consentString); + var consentString = data.GetBaggageItem(OtelConsentBaggage); + data.AddTag(OtelConsent, consentString); if (bool.TryParse(consentString, out bool consent) && consent) { var uriPath = (string?)data.GetTagItem("url.full"); @@ -132,7 +132,7 @@ public override async void OnEnd(Activity data) data.AddTag("regionName", location?.RegionName); data.AddTag("city", location?.City); } - data.SetTag(OtelSessionIdKey, data?.GetBaggageItem("sessionBaggage")); + data.SetTag(OtelSessionId, data?.GetBaggageItem("sessionBaggage")); } } }