mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-08 22:21:35 +00:00
fix req changes
This commit is contained in:
parent
cd60e3d4e0
commit
94be31a816
5 changed files with 247 additions and 574 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -7,6 +7,12 @@ from typing import List, Optional, Union
|
|||
|
||||
from litellm._logging import verbose_logger
|
||||
from litellm.integrations.custom_batch_logger import CustomBatchLogger
|
||||
from litellm.integrations.datadog.datadog_handler import (
|
||||
get_datadog_env,
|
||||
get_datadog_hostname,
|
||||
get_datadog_pod_name,
|
||||
get_datadog_service,
|
||||
)
|
||||
from litellm.litellm_core_utils.safe_json_dumps import safe_dumps
|
||||
from litellm.llms.custom_httpx.http_handler import (
|
||||
get_async_httpx_client,
|
||||
|
|
@ -22,7 +28,7 @@ from litellm.types.utils import StandardLoggingPayload
|
|||
|
||||
|
||||
class DatadogMetricsLogger(CustomBatchLogger):
|
||||
def __init__(self, **kwargs):
|
||||
def __init__(self, start_periodic_flush: bool = True, **kwargs):
|
||||
self.dd_api_key = os.getenv("DD_API_KEY")
|
||||
self.dd_app_key = os.getenv("DD_APP_KEY")
|
||||
self.dd_site = os.getenv("DD_SITE", "datadoghq.com")
|
||||
|
|
@ -51,8 +57,9 @@ class DatadogMetricsLogger(CustomBatchLogger):
|
|||
|
||||
super().__init__(**kwargs)
|
||||
|
||||
# Start periodic flush task
|
||||
asyncio.create_task(self.periodic_flush())
|
||||
# Start periodic flush task only if instructed
|
||||
if start_periodic_flush:
|
||||
asyncio.create_task(self.periodic_flush())
|
||||
|
||||
def _extract_tags(
|
||||
self,
|
||||
|
|
@ -62,13 +69,6 @@ class DatadogMetricsLogger(CustomBatchLogger):
|
|||
"""
|
||||
Builds the list of tags for a Datadog metric point
|
||||
"""
|
||||
from litellm.integrations.datadog.datadog_handler import (
|
||||
get_datadog_env,
|
||||
get_datadog_hostname,
|
||||
get_datadog_pod_name,
|
||||
get_datadog_service,
|
||||
)
|
||||
|
||||
# Base tags
|
||||
tags = [
|
||||
f"env:{get_datadog_env()}",
|
||||
|
|
@ -188,8 +188,9 @@ class DatadogMetricsLogger(CustomBatchLogger):
|
|||
error_information = (
|
||||
standard_logging_object.get("error_information", {}) or {}
|
||||
)
|
||||
if "error_code" in error_information and error_information["error_code"] is not None: # type: ignore
|
||||
status_code = str(error_information["error_code"]) # type: ignore
|
||||
error_code = error_information.get("error_code") # type: ignore
|
||||
if error_code is not None:
|
||||
status_code = str(error_code)
|
||||
|
||||
self._add_metrics_from_log(
|
||||
log=standard_logging_object, kwargs=kwargs, status_code=status_code
|
||||
|
|
|
|||
|
|
@ -133,8 +133,8 @@ from ..integrations.azure_sentinel.azure_sentinel import AzureSentinelLogger
|
|||
from ..integrations.azure_storage.azure_storage import AzureBlobStorageLogger
|
||||
from ..integrations.custom_prompt_management import CustomPromptManagement
|
||||
from ..integrations.datadog.datadog import DataDogLogger
|
||||
from ..integrations.datadog.datadog_llm_obs import DataDogLLMObsLogger
|
||||
from ..integrations.datadog.datadog_metrics import DatadogMetricsLogger
|
||||
from ..integrations.datadog.datadog_llm_obs import DataDogLLMObsLogger
|
||||
from ..integrations.dotprompt import DotpromptManager
|
||||
from ..integrations.dynamodb import DyanmoDBLogger
|
||||
from ..integrations.galileo import GalileoObserve
|
||||
|
|
@ -1654,7 +1654,9 @@ class Logging(LiteLLMLoggingBaseClass):
|
|||
|
||||
self.model_call_details[
|
||||
"standard_logging_object"
|
||||
] = self._build_standard_logging_payload(logging_result, start_time, end_time)
|
||||
] = self._build_standard_logging_payload(
|
||||
logging_result, start_time, end_time
|
||||
)
|
||||
|
||||
if (
|
||||
standard_logging_payload := self.model_call_details.get(
|
||||
|
|
@ -2517,7 +2519,9 @@ class Logging(LiteLLMLoggingBaseClass):
|
|||
## STANDARDIZED LOGGING PAYLOAD
|
||||
self.model_call_details[
|
||||
"standard_logging_object"
|
||||
] = self._build_standard_logging_payload(result, start_time, end_time)
|
||||
] = self._build_standard_logging_payload(
|
||||
result, start_time, end_time
|
||||
)
|
||||
|
||||
# print standard logging payload
|
||||
if (
|
||||
|
|
@ -3658,10 +3662,6 @@ def _init_custom_logger_compatible_class( # noqa: PLR0915
|
|||
_datadog_logger = DataDogLogger()
|
||||
_in_memory_loggers.append(_datadog_logger)
|
||||
return _datadog_logger # type: ignore
|
||||
elif logging_integration == "datadog_llm_observability":
|
||||
_datadog_llm_obs_logger = DataDogLLMObsLogger()
|
||||
_in_memory_loggers.append(_datadog_llm_obs_logger)
|
||||
return _datadog_llm_obs_logger # type: ignore
|
||||
elif logging_integration == "datadog_metrics":
|
||||
for callback in _in_memory_loggers:
|
||||
if isinstance(callback, DatadogMetricsLogger):
|
||||
|
|
@ -3670,6 +3670,10 @@ def _init_custom_logger_compatible_class( # noqa: PLR0915
|
|||
_datadog_metrics_logger = DatadogMetricsLogger()
|
||||
_in_memory_loggers.append(_datadog_metrics_logger)
|
||||
return _datadog_metrics_logger # type: ignore
|
||||
elif logging_integration == "datadog_llm_observability":
|
||||
_datadog_llm_obs_logger = DataDogLLMObsLogger()
|
||||
_in_memory_loggers.append(_datadog_llm_obs_logger)
|
||||
return _datadog_llm_obs_logger # type: ignore
|
||||
elif logging_integration == "azure_sentinel":
|
||||
for callback in _in_memory_loggers:
|
||||
if isinstance(callback, AzureSentinelLogger):
|
||||
|
|
@ -4215,14 +4219,14 @@ def get_custom_logger_compatible_class( # noqa: PLR0915
|
|||
for callback in _in_memory_loggers:
|
||||
if isinstance(callback, DataDogLogger):
|
||||
return callback
|
||||
elif logging_integration == "datadog_llm_observability":
|
||||
for callback in _in_memory_loggers:
|
||||
if isinstance(callback, DataDogLLMObsLogger):
|
||||
return callback
|
||||
elif logging_integration == "datadog_metrics":
|
||||
for callback in _in_memory_loggers:
|
||||
if isinstance(callback, DatadogMetricsLogger):
|
||||
return callback
|
||||
elif logging_integration == "datadog_llm_observability":
|
||||
for callback in _in_memory_loggers:
|
||||
if isinstance(callback, DataDogLLMObsLogger):
|
||||
return callback
|
||||
elif logging_integration == "azure_sentinel":
|
||||
for callback in _in_memory_loggers:
|
||||
if isinstance(callback, AzureSentinelLogger):
|
||||
|
|
@ -4704,11 +4708,9 @@ class StandardLoggingPayloadSetup:
|
|||
).model_dump()
|
||||
if isinstance(_raw, dict):
|
||||
if ResponseAPILoggingUtils._is_response_api_usage(_raw):
|
||||
return (
|
||||
ResponseAPILoggingUtils._transform_response_api_usage_to_chat_usage(
|
||||
_raw
|
||||
).model_dump()
|
||||
)
|
||||
return ResponseAPILoggingUtils._transform_response_api_usage_to_chat_usage(
|
||||
_raw
|
||||
).model_dump()
|
||||
return _raw
|
||||
if isinstance(_raw, Usage):
|
||||
return _raw.model_dump()
|
||||
|
|
@ -5554,3 +5556,4 @@ def create_dummy_standard_logging_payload() -> StandardLoggingPayload:
|
|||
model_parameters={"stream": True},
|
||||
hidden_params=hidden_params,
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -286,7 +286,7 @@ async def health_services_endpoint( # noqa: PLR0915
|
|||
DatadogMetricsLogger,
|
||||
)
|
||||
|
||||
datadog_metrics_logger = DatadogMetricsLogger()
|
||||
datadog_metrics_logger = DatadogMetricsLogger(start_periodic_flush=False)
|
||||
response = await datadog_metrics_logger.async_health_check()
|
||||
return {
|
||||
"status": response["status"],
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ class DatadogMetricPoint(TypedDict):
|
|||
|
||||
class DatadogMetricSeries(TypedDict):
|
||||
metric: str
|
||||
type: int # 1=count, 2=rate, 3=gauge, distribution is submitted as type=3, but distributions use a different endpoint /api/v1/distribution_points, wait actually according to DD /api/v2/series: 0=unspecified, 1=count, 2=rate, 3=gauge. For histogram/distribution we use type 3 or 1.
|
||||
type: int # 0=unspecified, 1=count, 2=rate, 3=gauge
|
||||
points: List[DatadogMetricPoint]
|
||||
tags: List[str]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue