Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(llmobs): toggle config when enabled/disabled programmatically #12089

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ddtrace/llmobs/_llmobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ def enable(
# override the default _instance with a new tracer
cls._instance = cls(tracer=_tracer)
cls.enabled = True
config._llmobs_enabled = True
Yun-Kim marked this conversation as resolved.
Show resolved Hide resolved
cls._instance.start()

# Register hooks for span events
Expand Down Expand Up @@ -391,6 +392,7 @@ def disable(cls) -> None:

cls._instance.stop()
cls.enabled = False
config._llmobs_enabled = False
telemetry_writer.product_activated(TELEMETRY_APM_PRODUCT.LLMOBS, False)

log.debug("%s disabled", cls.__name__)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
fixes:
- |
LLM Observability: Resolves an issue where explicitly only using ``LLMObs.enable()`` to configure LLM Observability
without environment variables would not automatically propagate distributed tracing headers.
27 changes: 27 additions & 0 deletions tests/llmobs/test_llmobs_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,33 @@ def test_service_enable_proxy_default():
llmobs_service.disable()


@pytest.mark.subprocess()
def test_service_enable_manually_updates_config():
from ddtrace import config
from ddtrace.llmobs import LLMObs

LLMObs.enable(api_key="<not-a-real-key>", agentless_enabled=True, ml_app="test_ml_app")
assert config._llmobs_enabled is True
LLMObs.disable()
assert config._llmobs_enabled is False


@pytest.mark.subprocess(
env={
"DD_API_KEY": "<not-a-real-key>",
"DD_LLMOBS_ML_APP": "test_ml_app",
"DD_LLMOBS_AGENTLESS_ENABLED": "true",
"DD_LLMOBS_ENABLED": "true",
"DD_TRACE_ENABLED": "false",
}
)
def test_service_enable_env_var_sets_config():
Yun-Kim marked this conversation as resolved.
Show resolved Hide resolved
from ddtrace import auto # noqa: F401
from ddtrace import config

assert config._llmobs_enabled is True


def test_enable_agentless():
with override_global_config(dict(_dd_api_key="<not-a-real-key>", _llmobs_ml_app="<ml-app-name>")):
dummy_tracer = DummyTracer()
Expand Down
Loading