Skip to content

Commit 1e4ecf9

Browse files
github-actions[bot]Yun-Kimerikayasudabrettlangdon
authored
chore(llmobs): deprecate name of ML app env var [backport 2.9] (#9466)
Backport 0795fd6 from #9459 to 2.9. This PR changes the environment variable name for the user's ML application name from `DD_LLMOBS_APP_NAME` to `DD_LLMOBS_ML_APP` to better reflect LLM Observability's corp docs and guides. We are deprecating the old name instead of removing it outright so that users won't break their apps. ## 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] Risks are described (performance impact, potential for breakage, maintainability) - [x] Change is maintainable (easy to change, telemetry, documentation) - [x] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) are followed or label `changelog/no-changelog` is set - [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)) - [x] If this PR changes the public interface, I've notified `@DataDog/apm-tees`. ## Reviewer Checklist - [x] Title is accurate - [x] All changes are related to the pull request's stated goal - [x] Description motivates each change - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - [x] Testing strategy adequately addresses listed risks - [x] Change is maintainable (easy to change, telemetry, documentation) - [x] Release note makes sense to a user of the library - [x] Author has 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) Co-authored-by: Yun Kim <[email protected]> Co-authored-by: erikayasuda <[email protected]> Co-authored-by: Brett Langdon <[email protected]>
1 parent 1ef3be1 commit 1e4ecf9

File tree

6 files changed

+35
-14
lines changed

6 files changed

+35
-14
lines changed

ddtrace/llmobs/_llmobs.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,12 @@ def enable(
133133
# grab required values for LLMObs
134134
config._dd_site = site or config._dd_site
135135
config._dd_api_key = api_key or config._dd_api_key
136-
config._llmobs_ml_app = ml_app or config._llmobs_ml_app
137136
config.env = env or config.env
138137
config.service = service or config.service
138+
if os.getenv("DD_LLMOBS_APP_NAME"):
139+
log.warning("`DD_LLMOBS_APP_NAME` is deprecated. Use `DD_LLMOBS_ML_APP` instead.")
140+
config._llmobs_ml_app = ml_app or os.getenv("DD_LLMOBS_APP_NAME")
141+
config._llmobs_ml_app = ml_app or config._llmobs_ml_app
139142

140143
# validate required values for LLMObs
141144
if not config._dd_api_key:
@@ -150,7 +153,7 @@ def enable(
150153
)
151154
if not config._llmobs_ml_app:
152155
raise ValueError(
153-
"DD_LLMOBS_APP_NAME is required for sending LLMObs data. "
156+
"DD_LLMOBS_ML_APP is required for sending LLMObs data. "
154157
"Ensure this configuration is set before running your application."
155158
)
156159

@@ -288,7 +291,7 @@ def llm(
288291
If not provided, a default value of "custom" will be set.
289292
:param str session_id: The ID of the underlying user session. Required for tracking sessions.
290293
:param str ml_app: The name of the ML application that the agent is orchestrating. If not provided, the default
291-
value DD_LLMOBS_APP_NAME will be set.
294+
value will be set to the value of `DD_LLMOBS_ML_APP`.
292295
293296
:returns: The Span object representing the traced operation.
294297
"""
@@ -314,7 +317,7 @@ def tool(
314317
:param str name: The name of the traced operation. If not provided, a default value of "tool" will be set.
315318
:param str session_id: The ID of the underlying user session. Required for tracking sessions.
316319
:param str ml_app: The name of the ML application that the agent is orchestrating. If not provided, the default
317-
value DD_LLMOBS_APP_NAME will be set.
320+
value will be set to the value of `DD_LLMOBS_ML_APP`.
318321
319322
:returns: The Span object representing the traced operation.
320323
"""
@@ -332,7 +335,7 @@ def task(
332335
:param str name: The name of the traced operation. If not provided, a default value of "task" will be set.
333336
:param str session_id: The ID of the underlying user session. Required for tracking sessions.
334337
:param str ml_app: The name of the ML application that the agent is orchestrating. If not provided, the default
335-
value DD_LLMOBS_APP_NAME will be set.
338+
value will be set to the value of `DD_LLMOBS_ML_APP`.
336339
337340
:returns: The Span object representing the traced operation.
338341
"""
@@ -350,7 +353,7 @@ def agent(
350353
:param str name: The name of the traced operation. If not provided, a default value of "agent" will be set.
351354
:param str session_id: The ID of the underlying user session. Required for tracking sessions.
352355
:param str ml_app: The name of the ML application that the agent is orchestrating. If not provided, the default
353-
value DD_LLMOBS_APP_NAME will be set.
356+
value will be set to the value of `DD_LLMOBS_ML_APP`.
354357
355358
:returns: The Span object representing the traced operation.
356359
"""
@@ -368,7 +371,7 @@ def workflow(
368371
:param str name: The name of the traced operation. If not provided, a default value of "workflow" will be set.
369372
:param str session_id: The ID of the underlying user session. Required for tracking sessions.
370373
:param str ml_app: The name of the ML application that the agent is orchestrating. If not provided, the default
371-
value DD_LLMOBS_APP_NAME will be set.
374+
value will be set to the value of `DD_LLMOBS_ML_APP`.
372375
373376
:returns: The Span object representing the traced operation.
374377
"""
@@ -394,7 +397,7 @@ def embedding(
394397
If not provided, a default value of "custom" will be set.
395398
:param str session_id: The ID of the underlying user session. Required for tracking sessions.
396399
:param str ml_app: The name of the ML application that the agent is orchestrating. If not provided, the default
397-
value DD_LLMOBS_APP_NAME will be set.
400+
value will be set to the value of `DD_LLMOBS_ML_APP`.
398401
399402
:returns: The Span object representing the traced operation.
400403
"""
@@ -425,7 +428,7 @@ def retrieval(
425428
:param str name: The name of the traced operation. If not provided, a default value of "workflow" will be set.
426429
:param str session_id: The ID of the underlying user session. Required for tracking sessions.
427430
:param str ml_app: The name of the ML application that the agent is orchestrating. If not provided, the default
428-
value DD_LLMOBS_APP_NAME will be set.
431+
value will be set to the value of `DD_LLMOBS_ML_APP`.
429432
430433
:returns: The Span object representing the traced operation.
431434
"""
@@ -698,7 +701,7 @@ def submit_evaluation(
698701
# initialize tags with default values that will be overridden by user-provided tags
699702
evaluation_tags = {
700703
"ddtrace.version": ddtrace.__version__,
701-
"ml_app": config._llmobs_ml_app if config._llmobs_ml_app else "unknown",
704+
"ml_app": config._llmobs_ml_app or "unknown",
702705
}
703706

704707
if tags:

ddtrace/settings/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ def __init__(self):
565565

566566
self._llmobs_enabled = asbool(os.getenv("DD_LLMOBS_ENABLED", False))
567567
self._llmobs_sample_rate = float(os.getenv("DD_LLMOBS_SAMPLE_RATE", 1.0))
568-
self._llmobs_ml_app = os.getenv("DD_LLMOBS_APP_NAME")
568+
self._llmobs_ml_app = os.getenv("DD_LLMOBS_ML_APP")
569569

570570
def __getattr__(self, name) -> Any:
571571
if name in self._config:
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
deprecations:
3+
- |
4+
LLM Observability: ``DD_LLMOBS_APP_NAME`` is deprecated and will be removed in the next major version of ddtrace.
5+
As an alternative to ``DD_LLMOBS_APP_NAME``, you can use ``DD_LLMOBS_ML_APP`` instead. See the
6+
`SDK setup documentation <https://docs.datadoghq.com/tracing/llm_observability/sdk/#setup>`_ for more details on how to configure the LLM Observability SDK.

tests/llmobs/test_llmobs_decorators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ def f():
367367

368368

369369
def test_ml_app_override(LLMObs, mock_llmobs_span_writer):
370-
"""Test that setting ml_app kwarg on the LLMObs decorators will override the DD_LLMOBS_APP_NAME value."""
370+
"""Test that setting ml_app kwarg on the LLMObs decorators will override the DD_LLMOBS_ML_APP value."""
371371
for decorator_name, decorator in [("task", task), ("workflow", workflow), ("tool", tool)]:
372372

373373
@decorator(ml_app="test_ml_app")

tests/llmobs/test_llmobs_service.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,18 @@ def test_service_enable_no_ml_app_specified():
110110
assert llmobs_service._instance._llmobs_span_writer.status.value == "stopped"
111111

112112

113+
def test_service_enable_deprecated_ml_app_name(monkeypatch, mock_logs):
114+
with override_global_config(dict(_dd_api_key="<not-a-real-key>", _llmobs_ml_app="")):
115+
dummy_tracer = DummyTracer()
116+
monkeypatch.setenv("DD_LLMOBS_APP_NAME", "test_ml_app")
117+
llmobs_service.enable(_tracer=dummy_tracer)
118+
assert llmobs_service.enabled is True
119+
assert llmobs_service._instance._llmobs_eval_metric_writer.status.value == "running"
120+
assert llmobs_service._instance._llmobs_span_writer.status.value == "running"
121+
mock_logs.warning.assert_called_once_with("`DD_LLMOBS_APP_NAME` is deprecated. Use `DD_LLMOBS_ML_APP` instead.")
122+
llmobs_service.disable()
123+
124+
113125
def test_service_enable_already_enabled(mock_logs):
114126
with override_global_config(dict(_dd_api_key="<not-a-real-api-key>", _llmobs_ml_app="<ml-app-name>")):
115127
dummy_tracer = DummyTracer()

tests/llmobs/test_llmobs_trace_processor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def test_session_id_propagates_ignore_non_llmobs_spans():
172172

173173

174174
def test_ml_app_tag_defaults_to_env_var():
175-
"""Test that no ml_app defaults to the environment variable DD_LLMOBS_APP_NAME."""
175+
"""Test that no ml_app defaults to the environment variable DD_LLMOBS_ML_APP."""
176176
dummy_tracer = DummyTracer()
177177
with override_global_config(dict(_llmobs_ml_app="<not-a-real-app-name>")):
178178
with dummy_tracer.trace("root_llm_span", span_type=SpanTypes.LLM) as llm_span:
@@ -184,7 +184,7 @@ def test_ml_app_tag_defaults_to_env_var():
184184

185185

186186
def test_ml_app_tag_overrides_env_var():
187-
"""Test that when ml_app is set on the span, it overrides the environment variable DD_LLMOBS_APP_NAME."""
187+
"""Test that when ml_app is set on the span, it overrides the environment variable DD_LLMOBS_ML_APP."""
188188
dummy_tracer = DummyTracer()
189189
with override_global_config(dict(_llmobs_ml_app="<not-a-real-app-name>")):
190190
with dummy_tracer.trace("root_llm_span", span_type=SpanTypes.LLM) as llm_span:

0 commit comments

Comments
 (0)