From d5d9ed73af70a7e813cfd65b3def50a049ae4e55 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Sat, 27 Jul 2024 11:14:06 -0700 Subject: [PATCH] use _get_parent_otel_span_from_kwargs --- litellm/proxy/proxy_config.yaml | 8 +------- litellm/proxy/utils.py | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/litellm/proxy/proxy_config.yaml b/litellm/proxy/proxy_config.yaml index 4df510399..c0045e40c 100644 --- a/litellm/proxy/proxy_config.yaml +++ b/litellm/proxy/proxy_config.yaml @@ -27,12 +27,6 @@ model_list: mode: audio_speech general_settings: master_key: sk-1234 - alerting: ["slack"] - alerting_threshold: 0.0001 - alert_to_webhook_url: { - "llm_too_slow": "https://hooks.slack.com/services/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", - "llm_requests_hanging": "https://hooks.slack.com/services/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", - } litellm_settings: - success_callback: ["langfuse"] \ No newline at end of file + callbacks: ["otel"] \ No newline at end of file diff --git a/litellm/proxy/utils.py b/litellm/proxy/utils.py index fc47abf9c..682d85539 100644 --- a/litellm/proxy/utils.py +++ b/litellm/proxy/utils.py @@ -31,6 +31,7 @@ from litellm._service_logger import ServiceLogging, ServiceTypes from litellm.caching import DualCache, RedisCache from litellm.exceptions import RejectedRequestError from litellm.integrations.custom_logger import CustomLogger +from litellm.integrations.opentelemetry import _get_parent_otel_span_from_kwargs from litellm.integrations.slack_alerting import SlackAlerting from litellm.litellm_core_utils.litellm_logging import Logging from litellm.llms.custom_httpx.httpx_handler import HTTPHandler @@ -125,6 +126,27 @@ def log_to_opentelemetry(func): start_time=start_time, end_time=end_time, ) + elif ( + # in litellm custom callbacks kwargs is passed as arg[0] + # https://docs.litellm.ai/docs/observability/custom_callback#callback-functions + args is not None + and len(args) > 0 + ): + passed_kwargs = args[0] + parent_otel_span = _get_parent_otel_span_from_kwargs( + kwargs=passed_kwargs + ) + if parent_otel_span is not None: + from litellm.proxy.proxy_server import proxy_logging_obj + + await proxy_logging_obj.service_logging_obj.async_service_success_hook( + service=ServiceTypes.DB, + call_type=func.__name__, + parent_otel_span=parent_otel_span, + duration=0.0, + start_time=start_time, + end_time=end_time, + ) # end of logging to otel return result except Exception as e: