-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extract Upper64 bit trace ID from extension response #6041
Changes from all commits
69b6163
42c242a
94d9f24
00c5475
55245cd
ad19246
cee09c0
ddd0fb6
b300797
7b9bb9f
3fd8cd6
357f279
9fb8fcd
ad30105
a56874d
d2a6d92
274d538
83362d6
ed98cb1
52ccc64
60ccc82
bf5a010
7376508
c0c88f4
1bf0873
758301f
6e7966a
2b5c0dc
6f1be32
587426a
0ec8f01
a1838fa
43b2292
a4b1301
992259d
ce40a26
f710538
1d962d7
2363539
c6377c1
f6ef838
a898b31
83201d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
using System.Net; | ||
using System.Threading.Tasks; | ||
using Datadog.Trace.ClrProfiler.AutoInstrumentation.AWS.Lambda; | ||
using Datadog.Trace.ExtensionMethods; | ||
using Datadog.Trace.TestHelpers; | ||
|
||
using FluentAssertions; | ||
|
@@ -17,6 +18,8 @@ | |
|
||
namespace Datadog.Trace.Tests | ||
{ | ||
extern alias DatadogTraceManual; | ||
|
||
public class LambdaCommonTests | ||
{ | ||
private readonly Mock<ILambdaExtensionRequest> _lambdaRequestMock = new(); | ||
|
@@ -25,36 +28,38 @@ public class LambdaCommonTests | |
public async Task TestCreatePlaceholderScopeSuccessWithTraceIdOnly() | ||
{ | ||
await using var tracer = TracerHelper.CreateWithFakeAgent(); | ||
var scope = LambdaCommon.CreatePlaceholderScope(tracer, "1234", null); | ||
|
||
var headers = new WebHeaderCollection { { HttpHeaderNames.TraceId, "1234" } }.Wrap(); | ||
var scope = LambdaCommon.CreatePlaceholderScope(tracer, headers); | ||
scope.Should().NotBeNull(); | ||
scope.Span.TraceId128.Should().Be((TraceId)1234); | ||
((ISpan)scope.Span).TraceId.Should().Be(1234); | ||
scope.Span.SpanId.Should().BeGreaterThan(0); | ||
} | ||
|
||
[Fact] | ||
public async Task TestCreatePlaceholderScopeSuccessWithSamplingPriorityOnly() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wound up removing this test since dd-trace doesn't seem to allow a distributed trace with no trace ID. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's right. A trace id is required when extracting trace context from headers, otherwise we ignore all the other data. But what changed here? Are we now trying to propagate trace context without a trace id? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Oh, I see. The |
||
public async Task TestCreatePlaceholderScopeSuccessWith64BitTraceIdContext() | ||
{ | ||
await using var tracer = TracerHelper.CreateWithFakeAgent(); | ||
var scope = LambdaCommon.CreatePlaceholderScope(tracer, null, "-1"); | ||
var headers = new WebHeaderCollection { { HttpHeaderNames.TraceId, "1234" }, { HttpHeaderNames.SamplingPriority, "-1" } }.Wrap(); | ||
var scope = LambdaCommon.CreatePlaceholderScope(tracer, headers); | ||
|
||
scope.Should().NotBeNull(); | ||
scope.Span.TraceId128.Should().BeGreaterThan(TraceId.Zero); | ||
((ISpan)scope.Span).TraceId.Should().BeGreaterThan(0); | ||
scope.Span.TraceId128.Should().Be((TraceId)1234); | ||
((ISpan)scope.Span).TraceId.Should().Be(1234); | ||
scope.Span.SpanId.Should().BeGreaterThan(0); | ||
scope.Span.Context.TraceContext.SamplingPriority.Should().Be(-1); | ||
} | ||
|
||
[Fact] | ||
public async Task TestCreatePlaceholderScopeSuccessWithFullContext() | ||
public async Task TestCreatePlaceholderScopeSuccessWith128BitTraceIdContext() | ||
{ | ||
await using var tracer = TracerHelper.CreateWithFakeAgent(); | ||
var scope = LambdaCommon.CreatePlaceholderScope(tracer, "1234", "-1"); | ||
var headers = new WebHeaderCollection { { HttpHeaderNames.TraceId, "5744042798732701615" }, { HttpHeaderNames.SamplingPriority, "-1" }, { HttpHeaderNames.PropagatedTags, "_dd.p.tid=1914fe7789eb32be" } }.Wrap(); | ||
var scope = LambdaCommon.CreatePlaceholderScope(tracer, headers); | ||
|
||
scope.Should().NotBeNull(); | ||
scope.Span.TraceId128.Should().Be((TraceId)1234); | ||
((ISpan)scope.Span).TraceId.Should().Be(1234); | ||
scope.Span.TraceId128.ToString().Should().Be("1914fe7789eb32be4fb6f07e011a6faf"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This value agrees with dd-trace-java There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Confirmed that
|
||
scope.Span.SpanId.Should().BeGreaterThan(0); | ||
scope.Span.Context.TraceContext.SamplingPriority.Should().Be(-1); | ||
} | ||
|
@@ -64,28 +69,14 @@ public async Task TestCreatePlaceholderScopeSuccessWithFullContext() | |
public async Task TestCreatePlaceholderScopeSuccessWithoutContext() | ||
{ | ||
await using var tracer = TracerHelper.CreateWithFakeAgent(); | ||
var scope = LambdaCommon.CreatePlaceholderScope(tracer, null, null); | ||
var scope = LambdaCommon.CreatePlaceholderScope(tracer, new WebHeaderCollection().Wrap()); | ||
|
||
scope.Should().NotBeNull(); | ||
scope.Span.TraceId128.Should().BeGreaterThan((TraceId.Zero)); | ||
((ISpan)scope.Span).TraceId.Should().BeGreaterThan(0); | ||
scope.Span.SpanId.Should().BeGreaterThan(0); | ||
} | ||
|
||
[Fact] | ||
public async Task TestCreatePlaceholderScopeInvalidTraceId() | ||
{ | ||
await using var tracer = TracerHelper.CreateWithFakeAgent(); | ||
Assert.Throws<FormatException>(() => LambdaCommon.CreatePlaceholderScope(tracer, "invalid-trace-id", "-1")); | ||
} | ||
|
||
[Fact] | ||
public async Task TestCreatePlaceholderScopeInvalidSamplingPriority() | ||
{ | ||
await using var tracer = TracerHelper.CreateWithFakeAgent(); | ||
Assert.Throws<FormatException>(() => LambdaCommon.CreatePlaceholderScope(tracer, "1234", "invalid-sampling-priority")); | ||
} | ||
|
||
[Fact] | ||
[Trait("Category", "ArmUnsupported")] | ||
public void TestSendStartInvocationThrow() | ||
|
@@ -146,7 +137,8 @@ public void TestSendStartInvocationSuccess() | |
public async Task TestSendEndInvocationFailure() | ||
{ | ||
await using var tracer = TracerHelper.CreateWithFakeAgent(); | ||
var scope = LambdaCommon.CreatePlaceholderScope(tracer, "1234", "-1"); | ||
var headers = new WebHeaderCollection { { HttpHeaderNames.TraceId, "1234" }, { HttpHeaderNames.SamplingPriority, "-1" } }.Wrap(); | ||
var scope = LambdaCommon.CreatePlaceholderScope(tracer, headers); | ||
|
||
var response = new Mock<HttpWebResponse>(MockBehavior.Loose); | ||
var responseStream = new Mock<Stream>(MockBehavior.Loose); | ||
|
@@ -166,7 +158,8 @@ public async Task TestSendEndInvocationFailure() | |
public async Task TestSendEndInvocationSuccess() | ||
{ | ||
await using var tracer = TracerHelper.CreateWithFakeAgent(); | ||
var scope = LambdaCommon.CreatePlaceholderScope(tracer, "1234", "-1"); | ||
var headers = new WebHeaderCollection { { HttpHeaderNames.TraceId, "1234" }, { HttpHeaderNames.SamplingPriority, "-1" } }.Wrap(); | ||
var scope = LambdaCommon.CreatePlaceholderScope(tracer, headers); | ||
|
||
var response = new Mock<HttpWebResponse>(MockBehavior.Loose); | ||
var responseStream = new Mock<Stream>(MockBehavior.Loose); | ||
|
@@ -189,7 +182,8 @@ public async Task TestSendEndInvocationSuccess() | |
public async Task TestSendEndInvocationFalse() | ||
{ | ||
await using var tracer = TracerHelper.CreateWithFakeAgent(); | ||
var scope = LambdaCommon.CreatePlaceholderScope(tracer, "1234", "-1"); | ||
var headers = new WebHeaderCollection { { HttpHeaderNames.TraceId, "1234" }, { HttpHeaderNames.SamplingPriority, "-1" } }.Wrap(); | ||
var scope = LambdaCommon.CreatePlaceholderScope(tracer, headers); | ||
|
||
var response = new Mock<HttpWebResponse>(MockBehavior.Loose); | ||
var responseStream = new Mock<Stream>(MockBehavior.Loose); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick
I don't think the
spanContext != null
is necessary as we'll always be calling the sameStartSpan
function andparent
can be set tonull
- that is the default value.