diff --git a/ddtrace/profiling/profiler.py b/ddtrace/profiling/profiler.py index fd059fee62..dc106b17de 100644 --- a/ddtrace/profiling/profiler.py +++ b/ddtrace/profiling/profiler.py @@ -248,7 +248,10 @@ def _build_default_exporters(self): return [] except Exception as e: - LOG.error("Failed to initialize libdd collector (%s), falling back to the legacy collector", e) + try: + LOG.error("Failed to load libdd (%s) (%s), falling back to legacy mode", e, ddup.failure_msg) + except Exception as ee: + LOG.error("Failed to load libdd (%s) (%s), falling back to legacy mode", e, ee) self._export_libdd_enabled = False profiling_config.export.libdd_enabled = False @@ -258,6 +261,12 @@ def _build_default_exporters(self): self._stack_v2_enabled = False profiling_config.stack.v2_enabled = False + # If this instance of ddtrace was injected, then do not enable profiling, since that will load + # protobuf, breaking some environments. + if profiling_config._injected: + LOG.error("Profiling failures occurred in an injected instance of ddtrace, disabling profiling") + return [] + # DEV: Import this only if needed to avoid importing protobuf # unnecessarily from ddtrace.profiling.exporter import http diff --git a/releasenotes/notes/profiling-fix-autoinject-failure-48cc7d9a18cd70b9.yaml b/releasenotes/notes/profiling-fix-autoinject-failure-48cc7d9a18cd70b9.yaml new file mode 100644 index 0000000000..6b533e614c --- /dev/null +++ b/releasenotes/notes/profiling-fix-autoinject-failure-48cc7d9a18cd70b9.yaml @@ -0,0 +1,4 @@ +fixes: + - | + profiling: Improves the error message when the native exporter fails to load and stops profiling from starting + if ddtrace is also being injected.