diff --git a/packages/traceloop-sdk/traceloop/sdk/__init__.py b/packages/traceloop-sdk/traceloop/sdk/__init__.py index 6663429d99..7f0c1fb0a0 100644 --- a/packages/traceloop-sdk/traceloop/sdk/__init__.py +++ b/packages/traceloop-sdk/traceloop/sdk/__init__.py @@ -73,6 +73,7 @@ def init( endpoint_is_traceloop: Optional[bool] = False, use_attributes: Optional[bool] = None, use_legacy_attributes: Optional[bool] = None, + trace_content: Optional[bool] = None, ) -> Optional[Client]: """Initialize Traceloop tracing, metrics, and instrumentation. @@ -88,6 +89,10 @@ def init( events have nowhere to go and no prompt/completion data will be recorded. use_legacy_attributes: Deprecated alias for ``use_attributes``. Will be removed in a future release. + trace_content: Whether to trace prompt/completion content. If not set, + uses the ``TRACELOOP_TRACE_CONTENT`` environment variable + (defaults to ``True``). Set to ``False`` to disable sending + sensitive content in traces. """ if use_attributes is not None and use_legacy_attributes is not None: raise TypeError( @@ -125,7 +130,7 @@ def init( print(Fore.YELLOW + "Tracing is disabled" + Fore.RESET) return - enable_content_tracing = is_content_tracing_enabled() + enable_content_tracing = is_content_tracing_enabled(trace_content) if exporter and processor: warnings.warn( diff --git a/packages/traceloop-sdk/traceloop/sdk/config/__init__.py b/packages/traceloop-sdk/traceloop/sdk/config/__init__.py index 8b57568ff4..204cbf2a7f 100644 --- a/packages/traceloop-sdk/traceloop/sdk/config/__init__.py +++ b/packages/traceloop-sdk/traceloop/sdk/config/__init__.py @@ -1,11 +1,14 @@ import os +from typing import Optional def is_tracing_enabled() -> bool: return (os.getenv("TRACELOOP_TRACING_ENABLED") or "true").lower() == "true" -def is_content_tracing_enabled() -> bool: +def is_content_tracing_enabled(trace_content: Optional[bool] = None) -> bool: + if trace_content is not None: + return trace_content return (os.getenv("TRACELOOP_TRACE_CONTENT") or "true").lower() == "true"