Skip to content

Commit

Permalink
renaming variables
Browse files Browse the repository at this point in the history
  • Loading branch information
andracc committed Jan 16, 2025
1 parent 4fabe09 commit 97e5a2b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
18 changes: 9 additions & 9 deletions Backend.Tests/Otel/OtelKernelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,33 @@ 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
TrackConsent(activity, httpContext.Request);
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]
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]
Expand All @@ -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);
Expand Down
24 changes: 12 additions & 12 deletions Backend/Otel/OtelKernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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");
Expand All @@ -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"));
}
}
}
Expand Down

0 comments on commit 97e5a2b

Please sign in to comment.