mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-27 11:43:54 +00:00
fix(langsmith.py): support sampling langsmith traces (#5577)
This commit is contained in:
parent
501b6f5bac
commit
8d5cad0c39
1 changed files with 29 additions and 0 deletions
|
@ -2,6 +2,7 @@
|
||||||
# On success, logs events to Langsmith
|
# On success, logs events to Langsmith
|
||||||
import asyncio
|
import asyncio
|
||||||
import os
|
import os
|
||||||
|
import random
|
||||||
import traceback
|
import traceback
|
||||||
import types
|
import types
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
@ -171,6 +172,20 @@ class LangsmithLogger(CustomLogger):
|
||||||
|
|
||||||
async def async_log_success_event(self, kwargs, response_obj, start_time, end_time):
|
async def async_log_success_event(self, kwargs, response_obj, start_time, end_time):
|
||||||
try:
|
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 logging
|
||||||
verbose_logger.debug(
|
verbose_logger.debug(
|
||||||
"Langsmith Async Layer Logging - kwargs: %s, response_obj: %s",
|
"Langsmith Async Layer Logging - kwargs: %s, response_obj: %s",
|
||||||
kwargs,
|
kwargs,
|
||||||
|
@ -201,6 +216,20 @@ class LangsmithLogger(CustomLogger):
|
||||||
|
|
||||||
def log_success_event(self, kwargs, response_obj, start_time, end_time):
|
def log_success_event(self, kwargs, response_obj, start_time, end_time):
|
||||||
try:
|
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 logging
|
||||||
verbose_logger.debug(
|
verbose_logger.debug(
|
||||||
"Langsmith Sync Layer Logging - kwargs: %s, response_obj: %s",
|
"Langsmith Sync Layer Logging - kwargs: %s, response_obj: %s",
|
||||||
kwargs,
|
kwargs,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue