or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/langsmith@0.6.x

docs

index.md
tile.json

tessl/pypi-langsmith

tessl install tessl/pypi-langsmith@0.6.1

Python SDK for LangSmith Observability and Evaluation Platform

configuration.mddocs/tracing/

Tracing Configuration

Global configuration for LangSmith tracing behavior using the configure() function and RunTree settings.

configure Function

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)
    """

Basic Configuration

import langsmith as ls

# Basic configuration
ls.configure(
    enabled=True,
    project_name="my-project"
)

With Custom Client

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)

With Tags and Metadata

import langsmith as ls

ls.configure(
    project_name="production-app",
    tags=["production", "v2.0"],
    metadata={
        "environment": "prod",
        "region": "us-west",
        "version": "2.0.1"
    }
)

Disable Tracing

import langsmith as ls

# Disable tracing globally
ls.configure(enabled=False)

Local-Only Tracing

Trace locally without sending to server (useful for testing):

import langsmith as ls

ls.configure(enabled="local")

Clear Settings

import langsmith as ls

# Clear specific settings
ls.configure(
    project_name=None,  # Clear project name
    tags=None,  # Clear tags
    metadata=None  # Clear metadata
)

Environment-Based Configuration

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 startup

Multiple Configuration Calls

Later 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"]

Related Documentation

  • Decorators - Automatic tracing with @traceable
  • Manual Tracing - Manual control with trace and RunTree
  • Client API - Client initialization options