|
2 | 2 | # under the Apache License Version 2.0. |
3 | 3 | # This product includes software developed at Datadog (https://www.datadoghq.com/). |
4 | 4 | # Copyright 2019 Datadog, Inc. |
5 | | -import os |
6 | 5 | import logging |
| 6 | +import os |
7 | 7 | import traceback |
8 | | -import ujson as json |
9 | 8 | from importlib import import_module |
10 | 9 | from time import time_ns |
11 | 10 |
|
12 | | -from datadog_lambda.extension import should_use_extension, flush_extension |
| 11 | +import ujson as json |
| 12 | + |
13 | 13 | from datadog_lambda.cold_start import ( |
14 | | - set_cold_start, |
| 14 | + ColdStartTracer, |
15 | 15 | is_cold_start, |
16 | | - is_proactive_init, |
17 | | - is_new_sandbox, |
18 | 16 | is_managed_instances_mode, |
19 | | - ColdStartTracer, |
| 17 | + is_new_sandbox, |
| 18 | + is_proactive_init, |
| 19 | + set_cold_start, |
20 | 20 | ) |
21 | 21 | from datadog_lambda.config import config |
22 | 22 | from datadog_lambda.constants import ( |
| 23 | + Headers, |
23 | 24 | TraceContextSource, |
24 | 25 | XraySubsegment, |
25 | | - Headers, |
26 | 26 | ) |
| 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 |
27 | 32 | from datadog_lambda.module_name import modify_module_name |
28 | 33 | from datadog_lambda.span_pointers import calculate_span_pointers |
29 | 34 | from datadog_lambda.tag_object import tag_object |
30 | 35 | from datadog_lambda.tracing import ( |
31 | | - extract_dd_trace_context, |
| 36 | + InferredSpanInfo, |
32 | 37 | create_dd_dummy_metadata_subsegment, |
| 38 | + create_function_execution_span, |
| 39 | + create_inferred_span, |
| 40 | + extract_dd_trace_context, |
33 | 41 | inject_correlation_ids, |
| 42 | + is_authorizer_response, |
34 | 43 | mark_trace_as_error_for_5xx_responses, |
| 44 | + propagator, |
35 | 45 | set_correlation_ids, |
36 | 46 | set_dd_trace_py_root, |
37 | | - create_function_execution_span, |
38 | | - create_inferred_span, |
39 | | - InferredSpanInfo, |
40 | | - is_authorizer_response, |
41 | 47 | tracer, |
42 | | - propagator, |
43 | | -) |
44 | | -from datadog_lambda.durable import ( |
45 | | - extract_durable_function_tags, |
46 | | - extract_durable_execution_status, |
47 | 48 | ) |
48 | 49 | from datadog_lambda.trigger import ( |
49 | | - extract_trigger_tags, |
50 | 50 | extract_http_status_code_tag, |
| 51 | + extract_trigger_tags, |
51 | 52 | ) |
52 | 53 |
|
53 | 54 | logger = logging.getLogger(__name__) |
|
57 | 58 | # making changes to any ddtrace import. |
58 | 59 |
|
59 | 60 | if config.appsec_enabled: |
| 61 | + from ddtrace.internal.appsec.product import start |
| 62 | + |
60 | 63 | from datadog_lambda.asm import ( |
61 | 64 | asm_set_context, |
62 | | - asm_start_response, |
63 | 65 | asm_start_request, |
| 66 | + asm_start_response, |
64 | 67 | get_asm_blocked_response, |
65 | 68 | ) |
66 | | - from ddtrace.internal.appsec.product import start |
67 | 69 |
|
68 | 70 | start() |
69 | 71 |
|
@@ -190,17 +192,17 @@ def __call__(self, event, context, **kwargs): |
190 | 192 | if self.blocking_response: |
191 | 193 | return self.blocking_response |
192 | 194 | 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 |
198 | 197 |
|
199 | | - submit_errors_metric(context) |
| 198 | + submit_errors_metric(context) |
200 | 199 |
|
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) |
204 | 206 | finally: |
205 | 207 | self._after(event, context) |
206 | 208 | if self.blocking_response: |
|
0 commit comments