Skip to content

Commit

Permalink
fix tests to account for conditioning Otel tags on consent
Browse files Browse the repository at this point in the history
  • Loading branch information
andracc committed Dec 13, 2024
1 parent b792db7 commit 1217a27
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions Backend.Tests/Otel/OtelKernelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ namespace Backend.Tests.Otel
{
public class OtelKernelTests : IDisposable
{

private const string FrontendConsentKey = "otelConsent";
private const string FrontendSessionIdKey = "sessionId";
private const string OtelConsentKey = "otelConsent";
private const string OtelSessionIdKey = "sessionId";
private const string OtelConsentBaggageKey = "otelConsentBaggage";
private const string OtelSessionBaggageKey = "sessionBaggage";

private LocationEnricher _locationEnricher = null!;

public void Dispose()
Expand All @@ -32,41 +37,46 @@ protected virtual void Dispose(bool disposing)
}

[Test]
public void BuildersSetSessionBaggageFromHeader()
public void BuildersSetConsentAndSessionBaggageFromHeader()
{
// Arrange
var httpContext = new DefaultHttpContext();
httpContext.Request.Headers[FrontendConsentKey] = "true";
httpContext.Request.Headers[FrontendSessionIdKey] = "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));
}

[Test]
public void OnEndSetsSessionTagFromBaggage()
public void OnEndSetsConsentAndSessionTagFromBaggage()
{
// Arrange
var activity = new Activity("testActivity").Start();
activity.SetBaggage(OtelConsentBaggageKey, "true");
activity.SetBaggage(OtelSessionBaggageKey, "test session id");

// Act
_locationEnricher.OnEnd(activity);

// Assert
Assert.That(activity.Tags.Any(_ => _.Key == OtelConsentKey));
Assert.That(activity.Tags.Any(_ => _.Key == OtelSessionIdKey));
}


[Test]
public void OnEndSetsLocationTags()
{
// Arrange
_locationEnricher = new LocationEnricher(new LocationProviderMock());
var activity = new Activity("testActivity").Start();
activity.SetBaggage(OtelConsentBaggageKey, "true");

// Act
_locationEnricher.OnEnd(activity);
Expand All @@ -81,11 +91,13 @@ public void OnEndSetsLocationTags()
Assert.That(activity.Tags, Is.SupersetOf(testLocation));
}

[Test]
public void OnEndRedactsIp()
{
// Arrange
_locationEnricher = new LocationEnricher(new LocationProviderMock());
var activity = new Activity("testActivity").Start();
activity.SetBaggage(OtelConsentBaggageKey, "true");
activity.SetTag("url.full", $"{LocationProvider.locationGetterUri}100.0.0.0");

// Act
Expand Down

0 comments on commit 1217a27

Please sign in to comment.