Skip to content

Commit 2431cae

Browse files
committed
gate recording instances
1 parent e1590d0 commit 2431cae

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

ddtrace/llmobs/_integrations/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ def __init__(self, integration_config: IntegrationConfig) -> None:
6565
self.start_log_writer()
6666
self._llmobs_pc_sampler = RateSampler(sample_rate=config._llmobs_sample_rate)
6767

68+
@property
69+
def span_linking_enabled(self) -> bool:
70+
return asbool(os.getenv("_DD_LLMOBS_AUTO_SPAN_LINKING_ENABLED", "false"))
71+
6872
@property
6973
def metrics_enabled(self) -> bool:
7074
"""

ddtrace/llmobs/_integrations/langchain.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from collections import defaultdict
22
import json
3-
import os
43
from typing import Any
54
from typing import Dict
65
from typing import List
@@ -12,7 +11,6 @@
1211
from ddtrace.internal.logger import get_logger
1312
from ddtrace.internal.utils import ArgumentError
1413
from ddtrace.internal.utils import get_argument_value
15-
from ddtrace.internal.utils.formats import asbool
1614
from ddtrace.llmobs import LLMObs
1715
from ddtrace.llmobs._constants import INPUT_DOCUMENTS
1816
from ddtrace.llmobs._constants import INPUT_MESSAGES
@@ -107,7 +105,7 @@ class LangChainIntegration(BaseLLMIntegration):
107105
"""Maps spans to instances."""
108106

109107
def record_steps(self, instance, span):
110-
if not self.llmobs_enabled:
108+
if not self.llmobs_enabled or not self.span_linking_enabled:
111109
return
112110

113111
steps = getattr(instance, "steps", [])
@@ -117,7 +115,7 @@ def record_steps(self, instance, span):
117115
self.record_instance(instance, span)
118116

119117
def record_instance(self, instance, span):
120-
if not self.llmobs_enabled:
118+
if not self.llmobs_enabled or not self.span_linking_enabled:
121119
return
122120

123121
instance = _extract_bound(instance)
@@ -140,7 +138,7 @@ def _llmobs_set_tags(
140138
log.warning("Unsupported operation : %s", operation)
141139
return
142140

143-
if asbool(os.getenv("_DD_LLMOBS_AUTO_SPAN_LINKING_ENABLED")):
141+
if self.span_linking_enabled:
144142
self._set_links(span)
145143

146144
model_provider = span.get_tag(PROVIDER)

0 commit comments

Comments
 (0)