From c43146519bcaa5ee0b4f0574a9969c0753d6ff7b Mon Sep 17 00:00:00 2001 From: sanchda <838104+sanchda@users.noreply.github.com> Date: Wed, 25 Sep 2024 12:34:15 +0000 Subject: [PATCH 1/2] Try to scrape additional context for why libdd failed to load --- ddtrace/profiling/profiler.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ddtrace/profiling/profiler.py b/ddtrace/profiling/profiler.py index 8bff96066cb..3ee9d070fdd 100644 --- a/ddtrace/profiling/profiler.py +++ b/ddtrace/profiling/profiler.py @@ -247,7 +247,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 initialize libdd collector (%s) (%s), falling back to the legacy collector", e, ddup.failure_msg) + except Exception as ee: + LOG.error("Failed to initialize libdd collector (%s) (%s), falling back to the legacy collector", e, ee) self._export_libdd_enabled = False profiling_config.export.libdd_enabled = False From 624fe575e18f1640118630c0ef86a2a50b63a3e9 Mon Sep 17 00:00:00 2001 From: sanchda <838104+sanchda@users.noreply.github.com> Date: Wed, 25 Sep 2024 13:22:58 +0000 Subject: [PATCH 2/2] Release note and formatting --- ddtrace/profiling/profiler.py | 10 ++++++++-- ...filing-fix-autoinject-failure-48cc7d9a18cd70b9.yaml | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 releasenotes/notes/profiling-fix-autoinject-failure-48cc7d9a18cd70b9.yaml diff --git a/ddtrace/profiling/profiler.py b/ddtrace/profiling/profiler.py index 3ee9d070fdd..6feaab3eba1 100644 --- a/ddtrace/profiling/profiler.py +++ b/ddtrace/profiling/profiler.py @@ -248,9 +248,9 @@ def _build_default_exporters(self): return [] except Exception as e: try: - LOG.error("Failed to initialize libdd collector (%s) (%s), falling back to the legacy collector", e, ddup.failure_msg) + 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 initialize libdd collector (%s) (%s), falling back to the legacy collector", e, 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 @@ -260,6 +260,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 00000000000..6b533e614c5 --- /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.