Skip to content

Commit 121f38f

Browse files
authored
Send error message and stack to Lambda extension (#8417)
1 parent 10dc2ef commit 121f38f

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

dd-java-agent/instrumentation/aws-lambda-handler/src/main/java/datadog/trace/instrumentation/aws/v1/lambda/LambdaHandlerInstrumentation.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ static void exit(
112112

113113
try {
114114
final AgentSpan span = scope.span();
115+
if (throwable != null) {
116+
span.addThrowable(throwable);
117+
}
115118
span.finish();
116119
AgentTracer.get().notifyExtensionEnd(span, result, null != throwable);
117120
} finally {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import com.amazonaws.services.lambda.runtime.Context;
2+
import com.amazonaws.services.lambda.runtime.RequestStreamHandler;
3+
import java.io.InputStream;
4+
import java.io.OutputStream;
5+
6+
public class HandlerStreamingWithError implements RequestStreamHandler {
7+
@Override
8+
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) {
9+
throw new Error("Some error");
10+
}
11+
}

dd-java-agent/instrumentation/aws-lambda-handler/src/test/groovy/LambdaHandlerInstrumentationTest.groovy

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,40 @@ abstract class LambdaHandlerInstrumentationTest extends VersionedNamingTestBase
2424
}
2525
}
2626
}
27+
28+
def "test streaming handler with error"() {
29+
when:
30+
def input = new ByteArrayInputStream(StandardCharsets.UTF_8.encode("Hello").array())
31+
def output = new ByteArrayOutputStream()
32+
new HandlerStreamingWithError().handleRequest(input, output, null)
33+
34+
then:
35+
thrown(Error)
36+
assertTraces(1) {
37+
trace(1) {
38+
span {
39+
operationName operation()
40+
errored true
41+
tags {
42+
tag "error.type", "java.lang.Error"
43+
tag "error.message", "Some error"
44+
tag "error.stack", String
45+
tag "language", "jvm"
46+
tag "process_id", Long
47+
tag "runtime-id", String
48+
tag "thread.id", Long
49+
tag "thread.name", String
50+
tag "_dd.profiling.ctx", "test"
51+
tag "_dd.profiling.enabled", 0
52+
tag "_dd.agent_psr", 1.0
53+
tag "_dd.tracer_host", String
54+
tag "_sample_rate", 1
55+
tag "_dd.trace_span_attribute_schema", { it != null }
56+
}
57+
}
58+
}
59+
}
60+
}
2761
}
2862

2963

0 commit comments

Comments
 (0)