Skip to content

Commit

Permalink
fix propagator usages in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaspimentel committed Oct 21, 2024
1 parent c752bb4 commit c2e67f9
Show file tree
Hide file tree
Showing 12 changed files with 830 additions and 658 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Amazon.EventBridge.Model;
using Datadog.Trace.ClrProfiler.AutoInstrumentation.AWS.EventBridge;
using Datadog.Trace.DuckTyping;
using Datadog.Trace.Propagators;
using Datadog.Trace.Vendors.Newtonsoft.Json;
using FluentAssertions;
using Xunit;
Expand Down Expand Up @@ -46,7 +47,7 @@ public void InjectTracingContext_EmptyDetail_AddsTraceContext()

var proxy = request.DuckCast<IPutEventsRequest>();

ContextPropagation.InjectTracingContext(proxy, _spanContext);
ContextPropagation.InjectContext(proxy, new PropagationContext(_spanContext, baggage: null));

var entries = (IList)proxy.Entries.Value!;
entries.Count.Should().Be(1);
Expand Down Expand Up @@ -79,7 +80,7 @@ public void InjectTracingContext_ExistingDetail_AddsTraceContext()

var proxy = request.DuckCast<IPutEventsRequest>();

ContextPropagation.InjectTracingContext(proxy, _spanContext);
ContextPropagation.InjectContext(proxy, new PropagationContext(_spanContext, baggage: null));

var entries = (IList)proxy.Entries.Value!;
entries.Count.Should().Be(1);
Expand Down Expand Up @@ -113,7 +114,7 @@ public void InjectTracingContext_NullDetail_AddsTraceContext()

var proxy = request.DuckCast<IPutEventsRequest>();

ContextPropagation.InjectTracingContext(proxy, _spanContext);
ContextPropagation.InjectContext(proxy, new PropagationContext(_spanContext, baggage: null));

var entries = (IList)proxy.Entries.Value!;
entries.Count.Should().Be(1);
Expand Down Expand Up @@ -146,7 +147,7 @@ public void InjectTracingContext_InvalidDetail_DoesNotAddTraceContext()

var proxy = request.DuckCast<IPutEventsRequest>();

ContextPropagation.InjectTracingContext(proxy, _spanContext);
ContextPropagation.InjectContext(proxy, new PropagationContext(_spanContext, baggage: null));

var entries = (IList)proxy.Entries.Value!;
entries.Count.Should().Be(1);
Expand All @@ -165,7 +166,7 @@ public void InjectTracingContext_MultipleEntries_AddsTraceContextToAll()

var proxy = request.DuckCast<IPutEventsRequest>();

ContextPropagation.InjectTracingContext(proxy, _spanContext);
ContextPropagation.InjectContext(proxy, new PropagationContext(_spanContext, baggage: null));

var entries = (IList)proxy.Entries.Value!;
entries.Count.Should().Be(2);
Expand Down Expand Up @@ -201,7 +202,7 @@ public void InjectTracingContext_NullEventBusName_OmitsResourceName()

var proxy = request.DuckCast<IPutEventsRequest>();

ContextPropagation.InjectTracingContext(proxy, _spanContext);
ContextPropagation.InjectContext(proxy, new PropagationContext(_spanContext, baggage: null));

var entries = (IList)proxy.Entries.Value!;
entries.Count.Should().Be(1);
Expand Down Expand Up @@ -235,7 +236,7 @@ public void InjectTracingContext_PayloadTooLarge_DoesNotAddTraceContext()

var proxy = request.DuckCast<IPutEventsRequest>();

ContextPropagation.InjectTracingContext(proxy, _spanContext);
ContextPropagation.InjectContext(proxy, new PropagationContext(_spanContext, baggage: null));

var entries = (IList)proxy.Entries.Value!;
entries.Count.Should().Be(1);
Expand All @@ -255,7 +256,7 @@ public void InjectTracingContext_PayloadJustUnderLimit_AddsTraceContext()

var proxy = request.DuckCast<IPutEventsRequest>();

ContextPropagation.InjectTracingContext(proxy, _spanContext);
ContextPropagation.InjectContext(proxy, new PropagationContext(_spanContext, baggage: null));

var entries = (IList)proxy.Entries.Value!;
entries.Count.Should().Be(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Amazon.Kinesis.Model;
using Datadog.Trace.ClrProfiler.AutoInstrumentation.AWS.Kinesis;
using Datadog.Trace.DuckTyping;
using Datadog.Trace.Propagators;
using FluentAssertions;
using Newtonsoft.Json;
using Xunit;
Expand Down Expand Up @@ -74,7 +75,7 @@ public void InjectTraceIntoRecords_WithJsonString_AddsTraceContext()

var proxy = request.DuckCast<IPutRecordsRequest>();

ContextPropagation.InjectTraceIntoRecords(proxy, _spanContext);
ContextPropagation.InjectTraceIntoRecords(proxy, new PropagationContext(_spanContext, baggage: null));

var firstRecord = proxy.Records[0].DuckCast<IContainsData>();

Expand Down Expand Up @@ -105,7 +106,7 @@ public void InjectTraceIntoRecords_WithString_SkipsAddingTraceContext()

var proxy = request.DuckCast<IPutRecordsRequest>();

ContextPropagation.InjectTraceIntoRecords(proxy, _spanContext);
ContextPropagation.InjectTraceIntoRecords(proxy, new PropagationContext(_spanContext, baggage: null));

var firstRecord = proxy.Records[0].DuckCast<IContainsData>();

Expand All @@ -124,7 +125,7 @@ public void InjectTraceIntoData_WithJsonString_AddsTraceContext()

var proxy = request.DuckCast<IPutRecordRequest>();

ContextPropagation.InjectTraceIntoData(proxy, _spanContext);
ContextPropagation.InjectTraceIntoData(proxy, new PropagationContext(_spanContext, baggage: null));

// Naively deserialize in order to not use tracer extraction logic
var jsonString = Encoding.UTF8.GetString(proxy.Data.ToArray());
Expand Down Expand Up @@ -155,7 +156,7 @@ public void InjectTraceIntoData_WithLargeJsonString_SkipsAddingTraceContext()

var proxy = request.DuckCast<IPutRecordRequest>();

ContextPropagation.InjectTraceIntoData(proxy, _spanContext);
ContextPropagation.InjectTraceIntoData(proxy, new PropagationContext(_spanContext, baggage: null));

var data = proxy.Data;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Amazon.SimpleNotificationService.Model;
using Datadog.Trace.ClrProfiler.AutoInstrumentation.AWS.SNS;
using Datadog.Trace.DuckTyping;
using Datadog.Trace.Propagators;
using Datadog.Trace.Vendors.Newtonsoft.Json;
using FluentAssertions;
using Xunit;
Expand Down Expand Up @@ -81,7 +82,9 @@ public void InjectHeadersIntoBatch_EmptyMessageAttributes_AddsTraceContext()

var proxy = request.DuckCast<IPublishBatchRequest>();

ContextPropagation.InjectHeadersIntoBatch<PublishBatchRequest, IPublishBatchRequest>(proxy, _spanContext);
ContextPropagation.InjectHeadersIntoBatch<PublishBatchRequest, IPublishBatchRequest>(
proxy,
new PropagationContext(_spanContext, baggage: null));

for (int i = 0; i < proxy.PublishBatchRequestEntries.Count; i++)
{
Expand Down Expand Up @@ -126,7 +129,9 @@ public void InjectHeadersIntoBatch_WithMessageAttributes_AddsTraceContext()

var proxy = request.DuckCast<IPublishBatchRequest>();

ContextPropagation.InjectHeadersIntoBatch<PublishBatchRequest, IPublishBatchRequest>(proxy, _spanContext);
ContextPropagation.InjectHeadersIntoBatch<PublishBatchRequest, IPublishBatchRequest>(
proxy,
new PropagationContext(_spanContext, baggage: null));

for (int i = 0; i < proxy.PublishBatchRequestEntries.Count; i++)
{
Expand Down Expand Up @@ -170,7 +175,9 @@ public void InjectHeadersIntoBatch_FullMessageAttributes_SkipsAddingTraceContext
});

var proxy = request.DuckCast<IPublishBatchRequest>();
ContextPropagation.InjectHeadersIntoBatch<PublishBatchRequest, IPublishBatchRequest>(proxy, _spanContext);
ContextPropagation.InjectHeadersIntoBatch<PublishBatchRequest, IPublishBatchRequest>(
proxy,
new PropagationContext(_spanContext, baggage: null));

for (int i = 0; i < proxy.PublishBatchRequestEntries.Count; i++)
{
Expand Down Expand Up @@ -199,7 +206,9 @@ public void InjectHeadersIntoMessage_EmptyMessageAttributes_AddsTraceContext()

var proxy = request.DuckCast<IPublishRequest>();

ContextPropagation.InjectHeadersIntoMessage<PublishRequest, IPublishRequest>(proxy, _spanContext);
ContextPropagation.InjectHeadersIntoMessage<PublishRequest, IPublishRequest>(
proxy,
new PropagationContext(_spanContext, baggage: null));

// Hard-casting into PublishBatchRequestEntry because trace context assertion is needed
var messageAttributes = (Dictionary<string, MessageAttributeValue>)proxy.MessageAttributes;
Expand Down Expand Up @@ -229,7 +238,9 @@ public void InjectHeadersIntoMessage_WithMessageAttributes_AddsTraceContext()

var proxy = request.DuckCast<IPublishRequest>();

ContextPropagation.InjectHeadersIntoMessage<PublishRequest, IPublishRequest>(proxy, _spanContext);
ContextPropagation.InjectHeadersIntoMessage<PublishRequest, IPublishRequest>(
proxy,
new PropagationContext(_spanContext, baggage: null));

// Hard-casting into PublishBatchRequestEntry because trace context assertion is needed
var messageAttributes = (Dictionary<string, MessageAttributeValue>)proxy.MessageAttributes;
Expand Down Expand Up @@ -259,7 +270,9 @@ public void InjectHeadersIntoMessage_FullMessageAttributes_AddsTraceContext()

var proxy = request.DuckCast<IPublishRequest>();

ContextPropagation.InjectHeadersIntoMessage<PublishRequest, IPublishRequest>(proxy, _spanContext);
ContextPropagation.InjectHeadersIntoMessage<PublishRequest, IPublishRequest>(
proxy,
new PropagationContext(_spanContext, baggage: null));

// Hard-casting into PublishBatchRequestEntry because trace context assertion is needed
var messageAttributes = (Dictionary<string, MessageAttributeValue>)proxy.MessageAttributes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ public void SamplingDecisionIsMadeWhenPropagating()
traceContext.SamplingPriority.Should().BeNull();

var headers = new NameValueCollection();
SpanContextPropagator.Instance.Inject(scope1.Span.Context, headers.Wrap());
SpanContextPropagator.Instance.Inject(
new PropagationContext(scope1.Span.Context, baggage: null),
headers.Wrap());

// sampling decision IS taken before propagating
sampler.Verify(s => s.MakeSamplingDecision(It.IsAny<Span>()), Times.Once);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ public void GetDistributedTrace()

using (var scope = Tracer.Instance.StartActive("Test"))
{
var spanContext = SpanContextPropagator.Instance.Extract(automaticTracer.GetDistributedTrace());
var context = SpanContextPropagator.Instance.Extract(automaticTracer.GetDistributedTrace());
var spanContext = context.SpanContext!;

spanContext.Should().NotBeNull();
spanContext.TraceId128.Should().Be(((Scope)scope).Span.TraceId128);
Expand Down
Loading

0 comments on commit c2e67f9

Please sign in to comment.