|
23 | 23 | XraySubsegment, |
24 | 24 | Headers, |
25 | 25 | ) |
26 | | -from datadog_lambda.metric import ( |
27 | | - flush_stats, |
28 | | - submit_invocations_metric, |
29 | | - submit_errors_metric, |
30 | | -) |
31 | 26 | from datadog_lambda.module_name import modify_module_name |
32 | 27 | from datadog_lambda.patch import patch_all |
33 | 28 | from datadog_lambda.span_pointers import calculate_span_pointers |
@@ -248,7 +243,10 @@ def __call__(self, event, context, **kwargs): |
248 | 243 | self.response = self.func(event, context, **kwargs) |
249 | 244 | return self.response |
250 | 245 | except Exception: |
251 | | - submit_errors_metric(context) |
| 246 | + if not should_use_extension: |
| 247 | + from datadog_lambda.metric import submit_invocations_metric |
| 248 | + submit_invocations_metric(context) |
| 249 | + |
252 | 250 | if self.span: |
253 | 251 | self.span.set_traceback() |
254 | 252 | raise |
@@ -284,7 +282,11 @@ def _before(self, event, context): |
284 | 282 | try: |
285 | 283 | self.response = None |
286 | 284 | set_cold_start(init_timestamp_ns) |
287 | | - submit_invocations_metric(context) |
| 285 | + |
| 286 | + if not should_use_extension: |
| 287 | + from datadog_lambda.metric import submit_invocations_metric |
| 288 | + submit_invocations_metric(context) |
| 289 | + |
288 | 290 | self.trigger_tags = extract_trigger_tags(event, context) |
289 | 291 | # Extract Datadog trace context and source from incoming requests |
290 | 292 | dd_context, trace_context_source, event_source = extract_dd_trace_context( |
@@ -383,6 +385,7 @@ def _after(self, event, context): |
383 | 385 | logger.debug("Failed to create cold start spans. %s", e) |
384 | 386 |
|
385 | 387 | if not self.flush_to_log or should_use_extension: |
| 388 | + from datadog_lambda.metric import flush_stats |
386 | 389 | flush_stats(context) |
387 | 390 | if should_use_extension and self.local_testing_mode: |
388 | 391 | # when testing locally, the extension does not know when an |
|
0 commit comments