tessl install tessl/pypi-langsmith@0.6.1Python SDK for LangSmith Observability and Evaluation Platform
Global configuration for LangSmith tracing behavior using the configure() function and RunTree settings.
Global configuration for LangSmith tracing context.
def configure(
client: Optional[Client] = ...,
enabled: Optional[bool] = ...,
project_name: Optional[str] = ...,
tags: Optional[list[str]] = ...,
metadata: Optional[dict[str, Any]] = ...,
) -> None:
"""
Configure global LangSmith tracing context.
Call once at application startup to set global defaults for tracing.
These settings apply to all traced operations unless overridden locally.
Parameters:
- client: LangSmith Client instance to use globally (pass None to clear)
- enabled: Enable/disable tracing globally (True/False/'local'/None)
- True: Full tracing enabled
- False: Tracing disabled
- 'local': Trace locally without sending to server
- None: Clear the setting
- project_name: Default project name for all traces (pass None to clear)
- tags: Global tags to apply to all runs (pass None to clear)
- metadata: Global metadata to apply to all runs (pass None to clear)
"""import langsmith as ls
# Basic configuration
ls.configure(
enabled=True,
project_name="my-project"
)import langsmith as ls
from langsmith import Client
custom_client = Client(
api_key="custom-key",
api_url="https://custom.langsmith.com"
)
ls.configure(client=custom_client)import langsmith as ls
ls.configure(
project_name="production-app",
tags=["production", "v2.0"],
metadata={
"environment": "prod",
"region": "us-west",
"version": "2.0.1"
}
)import langsmith as ls
# Disable tracing globally
ls.configure(enabled=False)Trace locally without sending to server (useful for testing):
import langsmith as ls
ls.configure(enabled="local")import langsmith as ls
# Clear specific settings
ls.configure(
project_name=None, # Clear project name
tags=None, # Clear tags
metadata=None # Clear metadata
)Configure based on environment (inline or as a function):
import langsmith as ls
import os
# Option 1: Inline configuration
env = os.getenv("ENV", "development")
if env == "production":
ls.configure(
enabled=True,
project_name="prod-app",
tags=["production", "v1.0"],
metadata={
"environment": "production",
"region": os.getenv("REGION", "us-west")
}
)
elif env == "staging":
ls.configure(enabled=True, project_name="staging-app", tags=["staging"])
elif env == "development":
ls.configure(enabled="local", project_name="dev-app") # Local tracing
else:
ls.configure(enabled=False) # Disabled for tests
# Option 2: As a reusable function
def setup_tracing():
"""Setup tracing based on environment."""
env = os.getenv("ENVIRONMENT", "development")
if env == "production":
ls.configure(enabled=True, project_name="prod-app",
tags=["production", "v1.0"],
metadata={"environment": "production",
"region": os.getenv("REGION", "us-west")})
elif env == "staging":
ls.configure(enabled=True, project_name="staging-app", tags=["staging"])
elif env == "development":
ls.configure(enabled="local", project_name="dev-app")
else:
ls.configure(enabled=False)
setup_tracing() # Call at startupLater calls override earlier ones:
import langsmith as ls
ls.configure(enabled=True)
ls.configure(project_name="my-project")
ls.configure(tags=["v1"])
# Final state: enabled=True, project_name="my-project", tags=["v1"]@traceabletrace and RunTree