|
46 | 46 | extract_http_status_code_tag, |
47 | 47 | ) |
48 | 48 |
|
| 49 | +logger = logging.getLogger(__name__) |
| 50 | + |
49 | 51 | # ddtrace imports are also tested in |
50 | 52 | # dd-trace-py/tests/internal/test_serverless.py please update those tests when |
51 | 53 | # making changes to any ddtrace import. |
|
61 | 63 |
|
62 | 64 | start() |
63 | 65 |
|
| 66 | +profiler = None |
64 | 67 | if config.profiling_enabled: |
65 | | - from ddtrace.profiling import profiler |
| 68 | + try: |
| 69 | + from ddtrace.profiling import profiler |
| 70 | + except Exception as e: |
| 71 | + logger.error(f"Failed to initialize profiler: [{e.__class__.__name__})] {e}") |
66 | 72 |
|
67 | 73 | if config.llmobs_enabled: |
68 | 74 | from ddtrace.llmobs import LLMObs |
|
75 | 81 | except ImportError: |
76 | 82 | from ddtrace.debugging._uploader import LogsIntakeUploaderV1 as SignalUploader |
77 | 83 |
|
78 | | -logger = logging.getLogger(__name__) |
79 | | - |
80 | 84 | DD_REQUESTS_SERVICE_NAME = "DD_REQUESTS_SERVICE_NAME" |
81 | 85 | DD_SERVICE = "DD_SERVICE" |
82 | 86 |
|
@@ -141,7 +145,7 @@ def __init__(self, func): |
141 | 145 | self.response = None |
142 | 146 | self.blocking_response = None |
143 | 147 |
|
144 | | - if config.profiling_enabled: |
| 148 | + if config.profiling_enabled and profiler: |
145 | 149 | self.prof = profiler.Profiler(env=config.env, service=config.service) |
146 | 150 |
|
147 | 151 | if config.trace_extractor: |
@@ -283,7 +287,7 @@ def _before(self, event, context): |
283 | 287 | self.blocking_response = get_asm_blocked_response(self.event_source) |
284 | 288 | else: |
285 | 289 | set_correlation_ids() |
286 | | - if config.profiling_enabled and is_new_sandbox(): |
| 290 | + if config.profiling_enabled and profiler and is_new_sandbox(): |
287 | 291 | self.prof.start(stop_on_exit=False, profile_children=True) |
288 | 292 | logger.debug("datadog_lambda_wrapper _before() done") |
289 | 293 | except Exception as e: |
|
0 commit comments