-
Notifications
You must be signed in to change notification settings - Fork 45
Send errors metrics for 5xx response from API Gateway, Lambda Function URL, or ALB #229
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
Changes from 6 commits
de5aba0
ad09cc9
f5e80a8
29f4117
59b1f69
d60572b
d02855a
a7cb6ef
f71679c
9730be5
43fad9d
abcf63c
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 |
---|---|---|
|
@@ -8,11 +8,14 @@ | |
import traceback | ||
from importlib import import_module | ||
|
||
from ddtrace.constants import ERROR_MSG, ERROR_STACK, ERROR_TYPE | ||
|
||
from datadog_lambda.extension import should_use_extension, flush_extension | ||
from datadog_lambda.cold_start import set_cold_start, is_cold_start | ||
from datadog_lambda.constants import ( | ||
XraySubsegment, | ||
SERVER_ERRORS_STATUS_CODES, | ||
TraceContextSource, | ||
XraySubsegment, | ||
) | ||
from datadog_lambda.metric import ( | ||
flush_stats, | ||
|
@@ -150,6 +153,7 @@ def __call__(self, event, context, **kwargs): | |
self._after(event, context) | ||
|
||
def _before(self, event, context): | ||
self.response = None | ||
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. let's put this line inside the |
||
try: | ||
|
||
set_cold_start() | ||
|
@@ -190,6 +194,19 @@ def _after(self, event, context): | |
status_code = extract_http_status_code_tag(self.trigger_tags, self.response) | ||
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. Replied to the original conversation, but want to point out, in case of invocation fails, |
||
if status_code: | ||
self.trigger_tags["http.status_code"] = status_code | ||
if len(status_code) == 3 and status_code.startswith("5"): | ||
submit_errors_metric(context) | ||
if self.span: | ||
self.span.set_traceback() | ||
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'm not sure you have a valid stacktrace in this case, since there isn't a real python exception being thrown. I suspect you need to directly set the error message and type fields https://github.com/DataDog/dd-trace-py/blob/fb8dfa2f33fff37d21df9728d8386c0260df9744/ddtrace/contrib/grpc/server_interceptor.py#L41-L42 We should set both fields to something meaningful that can help users understand the problem when seeing it. For error.type, we can use @brettlangdon we are trying to mark Lambda invocations returning statusCode 5xx as errors in trace, is what I mentioned above the best way to do it? 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 is what we do in the tracer: https://github.com/DataDog/dd-trace-py/blob/3b91b0da8/ddtrace/contrib/trace_utils.py#L274-L282 tl;dr; you just need to do |
||
self.span.error = 1 | ||
self.span.set_tags( | ||
{ | ||
ERROR_TYPE: "5xx Server Errors", | ||
ERROR_MSG: SERVER_ERRORS_STATUS_CODES.get( | ||
status_code, "5xx Server Errors" | ||
), | ||
} | ||
) | ||
# Create a new dummy Datadog subsegment for function trigger tags so we | ||
# can attach them to X-Ray spans when hybrid tracing is used | ||
if self.trigger_tags: | ||
|
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.
you probably don't need them any longer.