Skip to content

Commit 2713470

Browse files
committed
Do not call flush extension after each invocation.
1 parent 8d38aa9 commit 2713470

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

datadog_lambda/wrapper.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
DD_LOGS_INJECTION = "DD_LOGS_INJECTION"
6161
DD_MERGE_XRAY_TRACES = "DD_MERGE_XRAY_TRACES"
6262
AWS_LAMBDA_FUNCTION_NAME = "AWS_LAMBDA_FUNCTION_NAME"
63+
DD_LOCAL_TEST = "DD_LOCAL_TEST"
6364
DD_TRACE_EXTRACTOR = "DD_TRACE_EXTRACTOR"
6465
DD_TRACE_MANAGED_SERVICES = "DD_TRACE_MANAGED_SERVICES"
6566
DD_ENCODE_AUTHORIZER_CONTEXT = "DD_ENCODE_AUTHORIZER_CONTEXT"
@@ -183,6 +184,9 @@ def __init__(self, func):
183184
self.min_cold_start_trace_duration = get_env_as_int(
184185
DD_MIN_COLD_START_DURATION, 3
185186
)
187+
self.local_testing_mode = (
188+
os.environ.get(DD_LOCAL_TEST, "false").lower() in ("true", "1")
189+
)
186190
self.cold_start_trace_skip_lib = [
187191
"ddtrace.internal.compat",
188192
"ddtrace.filters",
@@ -367,7 +371,10 @@ def _after(self, event, context):
367371

368372
if not self.flush_to_log or should_use_extension:
369373
flush_stats()
370-
if should_use_extension:
374+
if should_use_extension and self.local_testing_mode:
375+
# when testing locally, the extension does not know when an
376+
# invocation completes because it does not have access to the
377+
# logs api
371378
flush_extension()
372379

373380
if self.encode_authorizer_context and is_authorizer_response(self.response):

0 commit comments

Comments
 (0)