Skip to content

Commit 3cbd588

Browse files
committed
exception types
1 parent ea58e9b commit 3cbd588

2 files changed

Lines changed: 33 additions & 31 deletions

File tree

datadog_lambda/wrapper.py

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,53 @@
22
# under the Apache License Version 2.0.
33
# This product includes software developed at Datadog (https://www.datadoghq.com/).
44
# Copyright 2019 Datadog, Inc.
5-
import os
65
import logging
6+
import os
77
import traceback
8-
import ujson as json
98
from importlib import import_module
109
from time import time_ns
1110

12-
from datadog_lambda.extension import should_use_extension, flush_extension
11+
import ujson as json
12+
1313
from datadog_lambda.cold_start import (
14-
set_cold_start,
14+
ColdStartTracer,
1515
is_cold_start,
16-
is_proactive_init,
17-
is_new_sandbox,
1816
is_managed_instances_mode,
19-
ColdStartTracer,
17+
is_new_sandbox,
18+
is_proactive_init,
19+
set_cold_start,
2020
)
2121
from datadog_lambda.config import config
2222
from datadog_lambda.constants import (
23+
Headers,
2324
TraceContextSource,
2425
XraySubsegment,
25-
Headers,
2626
)
27+
from datadog_lambda.durable import (
28+
extract_durable_execution_status,
29+
extract_durable_function_tags,
30+
)
31+
from datadog_lambda.extension import flush_extension, should_use_extension
2732
from datadog_lambda.module_name import modify_module_name
2833
from datadog_lambda.span_pointers import calculate_span_pointers
2934
from datadog_lambda.tag_object import tag_object
3035
from datadog_lambda.tracing import (
31-
extract_dd_trace_context,
36+
InferredSpanInfo,
3237
create_dd_dummy_metadata_subsegment,
38+
create_function_execution_span,
39+
create_inferred_span,
40+
extract_dd_trace_context,
3341
inject_correlation_ids,
42+
is_authorizer_response,
3443
mark_trace_as_error_for_5xx_responses,
44+
propagator,
3545
set_correlation_ids,
3646
set_dd_trace_py_root,
37-
create_function_execution_span,
38-
create_inferred_span,
39-
InferredSpanInfo,
40-
is_authorizer_response,
4147
tracer,
42-
propagator,
43-
)
44-
from datadog_lambda.durable import (
45-
extract_durable_function_tags,
46-
extract_durable_execution_status,
4748
)
4849
from datadog_lambda.trigger import (
49-
extract_trigger_tags,
5050
extract_http_status_code_tag,
51+
extract_trigger_tags,
5152
)
5253

5354
logger = logging.getLogger(__name__)
@@ -57,13 +58,14 @@
5758
# making changes to any ddtrace import.
5859

5960
if config.appsec_enabled:
61+
from ddtrace.internal.appsec.product import start
62+
6063
from datadog_lambda.asm import (
6164
asm_set_context,
62-
asm_start_response,
6365
asm_start_request,
66+
asm_start_response,
6467
get_asm_blocked_response,
6568
)
66-
from ddtrace.internal.appsec.product import start
6769

6870
start()
6971

@@ -190,17 +192,17 @@ def __call__(self, event, context, **kwargs):
190192
if self.blocking_response:
191193
return self.blocking_response
192194
self.response = self.func(event, context, **kwargs)
193-
except Exception as e:
194-
if "BlockingException" in type(e).__name__:
195-
self.blocking_response = get_asm_blocked_response(self.event_source)
196-
else:
197-
from datadog_lambda.metric import submit_errors_metric
195+
except Exception:
196+
from datadog_lambda.metric import submit_errors_metric
198197

199-
submit_errors_metric(context)
198+
submit_errors_metric(context)
200199

201-
if self.span:
202-
self.span.set_traceback()
203-
raise
200+
if self.span:
201+
self.span.set_traceback()
202+
raise
203+
except BaseException as e:
204+
if "BlockingException" in type(e).__name__:
205+
self.blocking_response = get_asm_blocked_response(self.event_source)
204206
finally:
205207
self._after(event, context)
206208
if self.blocking_response:

tests/test_wrapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ def test_blocking_before(self):
724724
def test_blocking_during(self):
725725
self.mock_get_asm_blocking_response.return_value = None
726726

727-
class BlockingException(Exception):
727+
class BlockingException(BaseException):
728728
pass
729729

730730
def lambda_handler(event, context):

0 commit comments

Comments
 (0)