Skip to content

Commit 3d41a6b

Browse files
authored
[SLES-1357] set exception on the aws.lambda span (#5054)
1 parent ee340c7 commit 3d41a6b

File tree

5 files changed

+50
-4
lines changed

5 files changed

+50
-4
lines changed

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ services:
569569
args:
570570
- DOTNETSDK_VERSION=${dotnetCoreSdkLatestVersion:-8.0.100}
571571
image: dd-trace-dotnet/${baseImage:-debian}-tester:${dotnetCoreSdkLatestVersion:-8.0.100}
572-
command: dotnet /build/bin/Debug/_build.dll RunLinuxIntegrationTests --framework ${framework:-netcoreapp3.1} --filter Category=Lambda --code-coverage ${runCodeCoverage:-true}
572+
command: dotnet /build/bin/Debug/_build.dll RunLinuxIntegrationTests --framework ${framework:-net6.0} --filter Category=Lambda --code-coverage ${runCodeCoverage:-true}
573573
volumes:
574574
- ./:/project
575575
cap_add:

tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/AWS/Lambda/LambdaCommon.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ await Tracer.Instance.TracerManager.AgentWriter.FlushTracesAsync()
9595

9696
try
9797
{
98+
if (exception != null && scope is { Span: var span })
99+
{
100+
span.SetException(exception);
101+
}
102+
98103
SendEndInvocation(requestBuilder, scope, exception != null, returnValue);
99104
}
100105
catch (Exception ex)

tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AWS/AwsLambdaTests.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ await VerifyHelper.VerifySpans(allSpans, settings)
9797
private static MockSpan ToMockSpan(MockLambdaExtension.EndExtensionRequest endInvocation, DateTimeOffset? startTime)
9898
{
9999
var start = startTime ?? endInvocation.Created.AddMilliseconds(100);
100+
var tags = new Dictionary<string, string> { { "_sampling_priority_v1", endInvocation.SamplingPriority?.ToString("N1") } };
101+
if (endInvocation.IsError)
102+
{
103+
tags["error.msg"] = endInvocation.ErrorMsg ?? string.Empty;
104+
tags["error.type"] = endInvocation.ErrorType ?? string.Empty;
105+
tags["error.stack"] = endInvocation.ErrorStack ?? string.Empty;
106+
}
107+
100108
return new MockSpan
101109
{
102110
Duration = endInvocation.Created.Subtract(start).ToNanoseconds(),
@@ -107,7 +115,7 @@ private static MockSpan ToMockSpan(MockLambdaExtension.EndExtensionRequest endIn
107115
SpanId = endInvocation.SpanId ?? 0,
108116
Start = start.ToUnixTimeNanoseconds(),
109117
Error = endInvocation.IsError ? (byte)1 : (byte)0,
110-
Tags = new Dictionary<string, string> { { "_sampling_priority_v1", endInvocation.SamplingPriority?.ToString("N1") } }
118+
Tags = tags
111119
};
112120
}
113121
}

tracer/test/Datadog.Trace.TestHelpers/MockLambdaExtension.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,10 @@ protected virtual void HandleHttpRequest(HttpListenerContext ctx)
139139
ulong? spanId = ulong.TryParse(headers.Get("x-datadog-span-id"), out var s) ? s : null;
140140
int? samplingPriority = int.TryParse(headers.Get("x-datadog-sampling-priority"), out var p) ? p : null;
141141
bool isError = headers.Get("x-datadog-invocation-error") == "true";
142-
var invocation = new EndExtensionRequest(headers, body, traceId, spanId, samplingPriority, isError);
142+
string? errorMsg = headers.Get("x-datadog-invocation-error-msg") ?? null;
143+
string? errorType = headers.Get("x-datadog-invocation-error-type") ?? null;
144+
string? errorStack = headers.Get("x-datadog-invocation-error-stack") ?? null;
145+
var invocation = new EndExtensionRequest(headers, body, traceId, spanId, samplingPriority, isError, errorMsg, errorType, errorStack);
143146

144147
EndInvocations.Push(invocation);
145148
Output?.WriteLine($"[LambdaExtension]Received end-invocation. traceId:{traceId}, spanId:{spanId}");
@@ -226,14 +229,20 @@ public EndExtensionRequest(
226229
ulong? traceId,
227230
ulong? spanId,
228231
int? samplingPriority,
229-
bool isError)
232+
bool isError,
233+
string? errorMsg,
234+
string? errorType,
235+
string? errorStack)
230236
{
231237
Headers = headers;
232238
Body = body;
233239
TraceId = traceId;
234240
SpanId = spanId;
235241
SamplingPriority = samplingPriority;
236242
IsError = isError;
243+
ErrorMsg = errorMsg;
244+
ErrorType = errorType;
245+
ErrorStack = errorStack;
237246
}
238247

239248
public NameValueCollection Headers { get; }
@@ -248,6 +257,12 @@ public EndExtensionRequest(
248257

249258
public bool IsError { get; }
250259

260+
public string? ErrorMsg { get; }
261+
262+
public string? ErrorType { get; }
263+
264+
public string? ErrorStack { get; }
265+
251266
public DateTimeOffset Created { get; } = DateTimeOffset.UtcNow;
252267
}
253268
}

tracer/test/snapshots/AwsLambdaTests.verified.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@
237237
Service: LambdaExtension,
238238
Error: 1,
239239
Tags: {
240+
error.msg: Cannot assign requested address,
241+
error.stack: Cannot assign requested address (SocketException),
242+
error.type: System.Net.WebException,
240243
_sampling_priority_v1: 1.0
241244
}
242245
},
@@ -248,6 +251,9 @@
248251
Service: LambdaExtension,
249252
Error: 1,
250253
Tags: {
254+
error.msg: Cannot assign requested address,
255+
error.stack: Cannot assign requested address (SocketException),
256+
error.type: System.Net.WebException,
251257
_sampling_priority_v1: 1.0
252258
}
253259
},
@@ -259,6 +265,9 @@
259265
Service: LambdaExtension,
260266
Error: 1,
261267
Tags: {
268+
error.msg: Cannot assign requested address,
269+
error.stack: Cannot assign requested address (SocketException),
270+
error.type: System.Net.WebException,
262271
_sampling_priority_v1: 1.0
263272
}
264273
},
@@ -270,6 +279,9 @@
270279
Service: LambdaExtension,
271280
Error: 1,
272281
Tags: {
282+
error.msg: Cannot assign requested address,
283+
error.stack: Cannot assign requested address (SocketException),
284+
error.type: System.Net.WebException,
273285
_sampling_priority_v1: 1.0
274286
}
275287
},
@@ -281,6 +293,9 @@
281293
Service: LambdaExtension,
282294
Error: 1,
283295
Tags: {
296+
error.msg: Cannot assign requested address,
297+
error.stack: Cannot assign requested address (SocketException),
298+
error.type: System.Net.WebException,
284299
_sampling_priority_v1: 1.0
285300
}
286301
},
@@ -292,6 +307,9 @@
292307
Service: LambdaExtension,
293308
Error: 1,
294309
Tags: {
310+
error.msg: Cannot assign requested address,
311+
error.stack: Cannot assign requested address (SocketException),
312+
error.type: System.Net.WebException,
295313
_sampling_priority_v1: 1.0
296314
}
297315
},

0 commit comments

Comments
 (0)