Skip to content

Commit

Permalink
gate recording instances
Browse files Browse the repository at this point in the history
  • Loading branch information
sabrenner committed Feb 6, 2025
1 parent e1590d0 commit 2431cae
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 4 additions & 0 deletions ddtrace/llmobs/_integrations/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ def __init__(self, integration_config: IntegrationConfig) -> None:
self.start_log_writer()
self._llmobs_pc_sampler = RateSampler(sample_rate=config._llmobs_sample_rate)

@property
def span_linking_enabled(self) -> bool:
return asbool(os.getenv("_DD_LLMOBS_AUTO_SPAN_LINKING_ENABLED", "false"))

@property
def metrics_enabled(self) -> bool:
"""
Expand Down
8 changes: 3 additions & 5 deletions ddtrace/llmobs/_integrations/langchain.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from collections import defaultdict
import json
import os
from typing import Any
from typing import Dict
from typing import List
Expand All @@ -12,7 +11,6 @@
from ddtrace.internal.logger import get_logger
from ddtrace.internal.utils import ArgumentError
from ddtrace.internal.utils import get_argument_value
from ddtrace.internal.utils.formats import asbool
from ddtrace.llmobs import LLMObs
from ddtrace.llmobs._constants import INPUT_DOCUMENTS
from ddtrace.llmobs._constants import INPUT_MESSAGES
Expand Down Expand Up @@ -107,7 +105,7 @@ class LangChainIntegration(BaseLLMIntegration):
"""Maps spans to instances."""

def record_steps(self, instance, span):
if not self.llmobs_enabled:
if not self.llmobs_enabled or not self.span_linking_enabled:
return

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

def record_instance(self, instance, span):
if not self.llmobs_enabled:
if not self.llmobs_enabled or not self.span_linking_enabled:
return

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

if asbool(os.getenv("_DD_LLMOBS_AUTO_SPAN_LINKING_ENABLED")):
if self.span_linking_enabled:
self._set_links(span)

model_provider = span.get_tag(PROVIDER)
Expand Down

0 comments on commit 2431cae

Please sign in to comment.