The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(langsmith.py): support sampling langsmith traces (#5577)
Krish Dholakia4371aa199591
diff --git a/litellm/integrations/langsmith.py b/litellm/integrations/langsmith.pyindex c14a6bacc94..d245a6e2ce2 100644--- a/litellm/integrations/langsmith.py+++ b/litellm/integrations/langsmith.py@@ -2,6 +2,7 @@# On success, logs events to Langsmithimport asyncioimport os+import randomimport tracebackimport typesfrom datetime import datetime@@ -171,6 +172,20 @@ class LangsmithLogger(CustomLogger):async def async_log_success_event(self, kwargs, response_obj, start_time, end_time):try:+ sampling_rate = (+ float(os.getenv("LANGSMITH_SAMPLING_RATE"))+ if os.getenv("LANGSMITH_SAMPLING_RATE") is not None+ and os.getenv("LANGSMITH_SAMPLING_RATE").strip().isdigit()+ else 1.0+ )+ random_sample = random.random()+ if random_sample > sampling_rate:+ verbose_logger.info(+ "Skipping Langsmith logging. Sampling rate={}, random_sample={}".format(+ sampling_rate, random_sample+ )+ )+ return # Skip loggingverbose_logger.debug("Langsmith Async Layer Logging - kwargs: %s, response_obj: %s",kwargs,@@ -201,6 +216,20 @@ class LangsmithLogger(CustomLogger):def log_success_event(self, kwargs, response_obj, start_time, end_time):try:+ sampling_rate = (+ float(os.getenv("LANGSMITH_SAMPLING_RATE"))+ if os.getenv("LANGSMITH_SAMPLING_RATE") is not None+ and os.getenv("LANGSMITH_SAMPLING_RATE").strip().isdigit()+ else 1.0+ )+ random_sample = random.random()+ if random_sample > sampling_rate:+ verbose_logger.info(+ "Skipping Langsmith logging. Sampling rate={}, random_sample={}".format(+ sampling_rate, random_sample+ )+ )+ return # Skip loggingverbose_logger.debug("Langsmith Sync Layer Logging - kwargs: %s, response_obj: %s",kwargs,