Skip to content

Commit bf17e03

Browse files
fix(profiling): import protobuf only if needed [backport 1.20] (#7156)
Backport f4503a8 from #7124 to 1.20. Importing protobuf when this is a shared dependency with the tracer might cause issues. We make sure to import it only if necessary. This means that we can avoid importing the protobuf Python module when exporting exclusively via libdatadog. ## Checklist - [x] Change(s) are motivated and described in the PR description. - [x] Testing strategy is described if automated tests are not included in the PR. - [x] Risk is outlined (performance impact, potential for breakage, maintainability, etc). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) are followed. If no release note is required, add label `changelog/no-changelog`. - [x] Documentation is included (in-code, generated user docs, [public corp docs](https://github.com/DataDog/documentation/)). - [x] Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Title is accurate. - [x] No unnecessary changes are introduced. - [x] Description motivates each change. - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [x] Testing strategy adequately addresses listed risk(s). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] Release note makes sense to a user of the library. - [x] Reviewer has explicitly acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment. - [x] Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting) - [x] If this PR touches code that signs or publishes builds or packages, or handles credentials of any kind, I've requested a review from `@DataDog/security-design-and-guidance`. - [x] This PR doesn't touch any of that. Co-authored-by: Gabriele N. Tornetta <[email protected]>
1 parent a7c3396 commit bf17e03

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

ddtrace/profiling/profiler.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
from ddtrace.profiling.collector import stack
2828
from ddtrace.profiling.collector import stack_event
2929
from ddtrace.profiling.collector import threading
30-
from ddtrace.profiling.exporter import file
31-
from ddtrace.profiling.exporter import http
3230
from ddtrace.settings.profiling import config
3331

3432
from . import _asyncio
@@ -138,6 +136,10 @@ def _build_default_exporters(self):
138136
# type: (...) -> List[exporter.Exporter]
139137
_OUTPUT_PPROF = config.output_pprof
140138
if _OUTPUT_PPROF:
139+
# DEV: Import this only if needed to avoid importing protobuf
140+
# unnecessarily
141+
from ddtrace.profiling.exporter import file
142+
141143
return [
142144
file.PprofFileExporter(prefix=_OUTPUT_PPROF),
143145
]
@@ -187,6 +189,10 @@ def _build_default_exporters(self):
187189
)
188190

189191
if self._export_py_enabled:
192+
# DEV: Import this only if needed to avoid importing protobuf
193+
# unnecessarily
194+
from ddtrace.profiling.exporter import http
195+
190196
return [
191197
http.PprofHTTPExporter(
192198
service=self.service,

docs/spelling_wordlist.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,3 +264,4 @@ Gitlab
264264
Enablement
265265
hotspot
266266
CMake
267+
libdatadog
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
fixes:
3+
- |
4+
profiling: Load the protobuf module only if needed to avoid interfering with
5+
the module state for applications that also make use of it. The protobuf
6+
module is used in file and classic Python HTTP export. It is not needed for
7+
the libdatadog-based exporter.

0 commit comments

Comments
 (0)