Skip to content

Commit 754044e

Browse files
Yun-Kimgithub-actions[bot]
authored andcommitted
fix(llmobs): avoid missing ml app error if llmobs is disabled (#13717)
Our `_start_span()` method does a bunch of llmobs-instrumentation/modifications under the hood, even if LLMObs is disabled. Specifically our llm/task/tool/agent/retrieval/workflow/embeddings() methods only log a warning if ML_APP is missing, but still route to our `_start_span()` method, which then continues on to do a ML_APP check (and raises if this is missing), even if LLMObs is disabled. This means if ML_APP is missing, any manual instrumentation will break customer apps if they disable LLMObs. We need to make `_start_span()` a no-op wrapper around `tracer.trace(...)`. This fix ensures that if llmobs is disabled, we return the span immediately before we start doing llmobs-specific logic. ## Checklist - [x] PR author has checked that all the criteria below are met - The PR description includes an overview of the change - The PR description articulates the motivation for the change - The change includes tests OR the PR description describes a testing strategy - The PR description notes risks associated with the change, if any - Newly-added code is easy to change - The change follows the [library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) - The change includes or references documentation updates if necessary - Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Reviewer has checked that all the criteria below are met - Title is accurate - All changes are related to the pull request's stated goal - Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - Testing strategy adequately addresses listed risks - Newly-added code is easy to change - Release note makes sense to a user of the library - If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - 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) (cherry picked from commit 17ce936)
1 parent 03c93b7 commit 754044e

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

ddtrace/llmobs/_llmobs.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,10 @@ def _start_span(
800800
if name is None:
801801
name = operation_kind
802802
span = self.tracer.trace(name, resource=operation_kind, span_type=SpanTypes.LLM)
803+
804+
if not self.enabled:
805+
return span
806+
803807
span._set_ctx_item(SPAN_KIND, operation_kind)
804808
if model_name is not None:
805809
span._set_ctx_item(MODEL_NAME, model_name)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
fixes:
3+
- |
4+
LLM Observability: Resolved an issue where manual instrumentation would raise ``DD_LLMOBS_ML_APP`` missing errors when LLM Observability was disabled.

tests/llmobs/test_llmobs_service.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,11 @@ def test_start_span_with_no_ml_app_throws(llmobs_no_ml_app):
226226
pass
227227

228228

229+
def test_start_span_without_ml_app_does_noop():
230+
with llmobs_service.task():
231+
pass
232+
233+
229234
def test_ml_app_local_precedence(llmobs, tracer):
230235
with tracer.trace("apm") as apm_span:
231236
apm_span.context._meta[PROPAGATED_ML_APP_KEY] = "propagated-ml-app"

0 commit comments

Comments
 (0)