Spaces:
Sleeping
Sleeping
File size: 1,649 Bytes
71c1ad2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | # app/observability/langsmith.py
# LangSmith tracing integration for pipeline observability
import os
from app.config import get_settings
from app.observability.logging import get_logger
logger = get_logger(__name__)
def setup_langsmith() -> bool:
"""
Configure LangSmith tracing via environment variables.
LangChain/LangGraph automatically pick up these env vars.
Returns:
True if LangSmith is configured, False otherwise.
"""
settings = get_settings()
if not settings.langsmith_api_key:
logger.info("langsmith_disabled", reason="No API key provided")
return False
os.environ["LANGCHAIN_TRACING_V2"] = str(settings.langsmith_tracing_v2).lower()
os.environ["LANGCHAIN_API_KEY"] = settings.langsmith_api_key
os.environ["LANGCHAIN_PROJECT"] = settings.langsmith_project
logger.info(
"langsmith_enabled",
project=settings.langsmith_project,
)
return True
def get_trace_config(
run_name: str,
input_type: str,
metadata: dict | None = None,
) -> dict:
"""
Build configuration dict for LangGraph invoke calls.
This attaches metadata and tags to the LangSmith trace.
Args:
run_name: Human-readable name for this trace run.
input_type: The content type being analyzed (text/image/video).
metadata: Additional key-value metadata.
Returns:
Config dict to pass to workflow.invoke().
"""
tags = [f"input:{input_type}", "hubble-moderation"]
config = {
"run_name": run_name,
"tags": tags,
"metadata": metadata or {},
}
return {"configurable": config}
|