9
9
using System . Linq ;
10
10
using System . Text . RegularExpressions ;
11
11
using System . Threading . Tasks ;
12
- using Datadog . Trace . Configuration ;
13
12
using Datadog . Trace . ExtensionMethods ;
14
13
using Datadog . Trace . TestHelpers ;
15
14
using FluentAssertions ;
@@ -24,16 +23,6 @@ namespace Datadog.Trace.ClrProfiler.IntegrationTests.AWS
24
23
[ Trait ( "RequiresDockerDependency" , "true" ) ]
25
24
public class AwsLambdaTests : TestHelper
26
25
{
27
- private const int ExpectedRequests =
28
- 9 // param tests
29
- + 3 // param with context
30
- + 5 // base instrumentation
31
- + 6 // other parameter types
32
- + 3 // throwing (manual only)
33
- + 3 // throwing with context
34
- + 8 // Generic types
35
- + 1 ; // Toplevel Statement
36
-
37
26
private static readonly Regex StackRegex = new ( @"( error.stack:)(?:\n|\r){1,2}(?:[^,]*(?:\n|\r){1,2})+.*(,(?:\r|\n){1,2})" ) ;
38
27
private static readonly Regex ErrorMsgRegex = new ( @"( error.msg:).*(,(\r|\n){1,2})" ) ;
39
28
@@ -60,17 +49,39 @@ public async Task SubmitsTraces()
60
49
agent . Output = Output ;
61
50
using ( await RunSampleAndWaitForExit ( agent ) )
62
51
{
63
- // we manually instrument each request too
64
- var expectedSpans = ExpectedRequests * 2 ;
52
+ var requests = 9 // param tests
53
+ + 3 // param with context
54
+ + 5 // base instrumentation
55
+ + 6 // other parameter types
56
+ + 3 // throwing (manual only)
57
+ + 3 // throwing with context
58
+ + 8 // Generic types
59
+ + 1 ; // Toplevel Statement
60
+
61
+ var expectedSpans = requests * 2 ; // we manually instrument each request too
65
62
66
63
var spans = agent . WaitForSpans ( expectedSpans , 15_000 ) . ToArray ( ) ;
67
64
68
65
// Verify all the "with context" end invocations have a corresponding start context
69
66
using var s = new AssertionScope ( ) ;
70
- var allExtensionSpans = GetExtensionSpans ( extensionWithContext , extensionNoContext ) ;
67
+ var startWithContext = extensionWithContext . StartInvocations . ToList ( ) ;
68
+ var endWithContext = extensionWithContext . EndInvocations . ToList ( ) ;
69
+ startWithContext . Should ( ) . OnlyContain ( x => x . TraceId . HasValue ) ;
70
+ endWithContext . Should ( ) . OnlyContain ( x => x . TraceId . HasValue ) ;
71
+ var contextPairs = extensionWithContext . EndInvocations
72
+ . Select ( x => ( start : startWithContext . SingleOrDefault ( y => y . TraceId == x . TraceId ) , end : x ) )
73
+ . ToList ( ) ;
74
+ contextPairs . Should ( ) . OnlyContain ( x => x . start != null ) ;
75
+ var withContextSpans = contextPairs . Select ( x => ToMockSpan ( x . end , x . start . Created ) ) ;
76
+
77
+ // We can't match no-context start invocations with the end invocations, so just use the end ones
78
+ var noContextSpans = extensionNoContext . EndInvocations . Select ( x => ToMockSpan ( x , startTime : null ) ) ;
71
79
72
80
// Create the complete traces
73
- var allSpans = allExtensionSpans . Concat ( spans ) . ToList ( ) ;
81
+ var allSpans = withContextSpans
82
+ . Concat ( noContextSpans )
83
+ . Concat ( spans )
84
+ . ToList ( ) ;
74
85
75
86
var settings = VerifyHelper . GetSpanVerifierSettings ( ) ;
76
87
@@ -83,25 +94,6 @@ await VerifyHelper.VerifySpans(allSpans, settings)
83
94
}
84
95
}
85
96
86
- private static IEnumerable < MockSpan > GetExtensionSpans ( MockLambdaExtension extensionWithContext , MockLambdaExtension extensionNoContext )
87
- {
88
- var startWithContext = extensionWithContext . StartInvocations . ToList ( ) ;
89
- var endWithContext = extensionWithContext . EndInvocations . ToList ( ) ;
90
- startWithContext . Should ( ) . OnlyContain ( x => x . TraceId . HasValue ) ;
91
- endWithContext . Should ( ) . OnlyContain ( x => x . TraceId . HasValue ) ;
92
- var contextPairs = extensionWithContext . EndInvocations
93
- . Select ( x => ( start : startWithContext . SingleOrDefault ( y => y . TraceId == x . TraceId ) , end : x ) )
94
- . ToList ( ) ;
95
- contextPairs . Should ( ) . OnlyContain ( x => x . start != null ) ;
96
- var withContextSpans = contextPairs . Select ( x => ToMockSpan ( x . end , x . start . Created ) ) ;
97
-
98
- // We can't match no-context start invocations with the end invocations, so just use the end ones
99
- var noContextSpans = extensionNoContext . EndInvocations . Select ( x => ToMockSpan ( x , startTime : null ) ) ;
100
-
101
- var allExtensionSpans = withContextSpans . Concat ( noContextSpans ) ;
102
- return allExtensionSpans ;
103
- }
104
-
105
97
private static MockSpan ToMockSpan ( MockLambdaExtension . EndExtensionRequest endInvocation , DateTimeOffset ? startTime )
106
98
{
107
99
var start = startTime ?? endInvocation . Created . AddMilliseconds ( 100 ) ;
0 commit comments