Skip to content

Commit de5aba0

Browse files
committed
Send errors metrics for 5xx reponse from API Gateway, Lambda Function URL, or ALB
1 parent 3dca6e1 commit de5aba0

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

datadog_lambda/wrapper.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def __init__(self, func):
110110
os.environ.get("DD_TRACE_MANAGED_SERVICES", "true").lower() == "true"
111111
)
112112
self.response = None
113+
self.already_submitted_errors_metric_before = False
113114

114115
if self.extractor_env:
115116
extractor_parts = self.extractor_env.rsplit(".", 1)
@@ -143,6 +144,7 @@ def __call__(self, event, context, **kwargs):
143144
return self.response
144145
except Exception:
145146
submit_errors_metric(context)
147+
self.already_submitted_errors_metric_before = True
146148
if self.span:
147149
self.span.set_traceback()
148150
raise
@@ -190,6 +192,9 @@ def _after(self, event, context):
190192
status_code = extract_http_status_code_tag(self.trigger_tags, self.response)
191193
if status_code:
192194
self.trigger_tags["http.status_code"] = status_code
195+
if not self.already_submitted_errors_metric_before:
196+
if len(status_code) == 3 and status_code.startswith("5"):
197+
submit_errors_metric(context)
193198
# Create a new dummy Datadog subsegment for function trigger tags so we
194199
# can attach them to X-Ray spans when hybrid tracing is used
195200
if self.trigger_tags:

0 commit comments

Comments
 (0)