Skip to content

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]

Native Webhook Integration Sumologic (#17630)

Chetan Choudharyd8ac213c6a1e
diff --git a/litellm/integrations/generic_api/generic_api_compatible_callbacks.json b/litellm/integrations/generic_api/generic_api_compatible_callbacks.json
index 1e88a39e0a7..6c8e5fd1b2a 100644
--- a/litellm/integrations/generic_api/generic_api_compatible_callbacks.json
+++ b/litellm/integrations/generic_api/generic_api_compatible_callbacks.json
@@ -16,5 +16,12 @@
"Authorization": "Bearer {{environment_variables.RUBRIK_API_KEY}}"
},
"environment_variables": ["RUBRIK_API_KEY", "RUBRIK_WEBHOOK_URL"]
+ },
+ "sumologic": {
+ "endpoint": "{{environment_variables.SUMOLOGIC_WEBHOOK_URL}}",
+ "headers": {
+ "Content-Type": "application/json"
+ },
+ "environment_variables": ["SUMOLOGIC_WEBHOOK_URL"]
}
}
\ No newline at end of file
diff --git a/litellm/litellm_core_utils/logging_callback_manager.py b/litellm/litellm_core_utils/logging_callback_manager.py
index 349cb6f3ceb..b78484816da 100644
--- a/litellm/litellm_core_utils/logging_callback_manager.py
+++ b/litellm/litellm_core_utils/logging_callback_manager.py
@@ -158,39 +158,57 @@ class LoggingCallbackManager:
"""
callback_config = litellm.callback_settings.get(callback)
- if not isinstance(callback_config, dict):
- return callback
-
- if callback_config.get("callback_type") != "generic_api":
- return callback
+ # Check if callback is in callback_settings with callback_type: generic_api
+ if (
+ isinstance(callback_config, dict)
+ and callback_config.get("callback_type") == "generic_api"
+ ):
+ endpoint = callback_config.get("endpoint")
+ headers = callback_config.get("headers")
+ event_types = callback_config.get("event_types")
+
+ if endpoint is None or headers is None:
+ verbose_logger.warning(
+ "generic_api callback '%s' is missing endpoint or headers, skipping.",
+ callback,
+ )
+ return callback
- endpoint = callback_config.get("endpoint")
- headers = callback_config.get("headers")
- event_types = callback_config.get("event_types")
+ cached_logger = _generic_api_logger_cache.get(callback)
+ if (
+ isinstance(cached_logger, GenericAPILogger)
+ and cached_logger.endpoint == endpoint
+ and cached_logger.headers == headers
+ and cached_logger.event_types == event_types
+ ):
+ return cached_logger
- if endpoint is None or headers is None:
- verbose_logger.warning(
- "generic_api callback '%s' is missing endpoint or headers, skipping.",
- callback,
+ new_logger = GenericAPILogger(
+ endpoint=endpoint,
+ headers=headers,
+ event_types=event_types,
)
- return callback
-
- cached_logger = _generic_api_logger_cache.get(callback)
- if (
- isinstance(cached_logger, GenericAPILogger)
- and cached_logger.endpoint == endpoint
- and cached_logger.headers == headers
- and cached_logger.event_types == event_types
- ):
- return cached_logger
+ _generic_api_logger_cache[callback] = new_logger
+ return new_logger
- new_logger = GenericAPILogger(
- endpoint=endpoint,
- headers=headers,
- event_types=event_types,
+ # Check if callback is in generic_api_compatible_callbacks.json
+ from litellm.integrations.generic_api.generic_api_callback import (
+ is_callback_compatible,
)
- _generic_api_logger_cache[callback] = new_logger
- return new_logger
+
+ if is_callback_compatible(callback):
+ # Check if we already have a cached logger for this callback
+ cached_logger = _generic_api_logger_cache.get(callback)
+ if isinstance(cached_logger, GenericAPILogger):
+ return cached_logger
+
+ # Create new GenericAPILogger with callback_name parameter
+ # This will load config from generic_api_compatible_callbacks.json
+ new_logger = GenericAPILogger(callback_name=callback)
+ _generic_api_logger_cache[callback] = new_logger
+ return new_logger
+
+ return callback
def _safe_add_callback_to_list(
self,
@@ -218,7 +236,6 @@ class LoggingCallbackManager:
callback=callback, parent_list=parent_list
)
elif isinstance(callback, CustomLogger):
-
self._add_custom_logger_to_list(
custom_logger=callback,
parent_list=parent_list,
diff --git a/tests/litellm_utils_tests/test_logging_callback_manager.py b/tests/litellm_utils_tests/test_logging_callback_manager.py
index d6abbd4b105..39bda158cb8 100644
--- a/tests/litellm_utils_tests/test_logging_callback_manager.py
+++ b/tests/litellm_utils_tests/test_logging_callback_manager.py
@@ -277,3 +277,97 @@ async def test_slack_alerting_callback_registration(callback_manager):
# Cleanup
callback_manager._reset_all_callbacks()
+
+async def test_generic_api_compatible_callbacks_json():
+ """
+ Test that callbacks defined in generic_api_compatible_callbacks.json
+ are properly loaded and initialized by _add_custom_callback_generic_api_str
+ """
+ from litellm.integrations.generic_api.generic_api_callback import GenericAPILogger
+
+ # Mock environment variable for SumoLogic webhook URL
+ test_sumologic_url = "https://collectors.sumologic.com/receiver/v1/http/test123"
+
+ with patch.dict(os.environ, {"SUMOLOGIC_WEBHOOK_URL": test_sumologic_url}):
+ # Test that sumologic callback is recognized from JSON file
+ result = LoggingCallbackManager._add_custom_callback_generic_api_str(
+ "sumologic"
+ )
+
+ # Verify a GenericAPILogger instance is returned
+ assert isinstance(
+ result, GenericAPILogger
+ ), "Should return GenericAPILogger instance for sumologic callback"
+
+ # Verify the endpoint is correctly loaded from environment variable
+ assert (
+ result.endpoint == test_sumologic_url
+ ), f"Endpoint should be {test_sumologic_url}"
+
+ # Verify headers only contain Content-Type (no Authorization for SumoLogic)
+ assert "Content-Type" in result.headers, "Should have Content-Type header"
+ assert (
+ result.headers["Content-Type"] == "application/json"
+ ), "Content-Type should be application/json"
+ assert (
+ "Authorization" not in result.headers
+ ), "Should not have Authorization header for SumoLogic"
+
+
+async def test_generic_api_compatible_callbacks_json_rubrik():
+ """
+ Test the rubrik callback from generic_api_compatible_callbacks.json
+ which requires both API key and webhook URL
+ """
+ from litellm.integrations.generic_api.generic_api_callback import GenericAPILogger
+
+ # Mock environment variables for Rubrik
+ test_rubrik_url = "https://webhook.site/test-rubrik"
+ test_rubrik_api_key = "sk-rubrik-test-key"
+
+ with patch.dict(
+ os.environ,
+ {"RUBRIK_WEBHOOK_URL": test_rubrik_url, "RUBRIK_API_KEY": test_rubrik_api_key},
+ ):
+ # Test that rubrik callback is recognized from JSON file
+ result = LoggingCallbackManager._add_custom_callback_generic_api_str("rubrik")
+
+ # Verify a GenericAPILogger instance is returned
+ assert isinstance(
+ result, GenericAPILogger
+ ), "Should return GenericAPILogger instance for rubrik callback"
+
+ # Verify the endpoint is correctly loaded
+ assert (
+ result.endpoint == test_rubrik_url
+ ), f"Endpoint should be {test_rubrik_url}"
+
+ # Verify headers include Authorization with Bearer token
+ assert "Content-Type" in result.headers, "Should have Content-Type header"
+ assert (
+ "Authorization" in result.headers
+ ), "Should have Authorization header for Rubrik"
+ assert (
+ result.headers["Authorization"] == f"Bearer {test_rubrik_api_key}"
+ ), "Authorization should have correct API key"
+
+ # Verify event_types filter (rubrik only logs success events)
+ assert result.event_types == [
+ "llm_api_success"
+ ], "Rubrik should only log success events"
+
+def test_generic_api_compatible_callbacks_json_unknown_callback():
+ """
+ Test that unknown callbacks (not in JSON or callback_settings) are returned unchanged
+ """
+ # Test with a callback that doesn't exist in the JSON file
+ result = LoggingCallbackManager._add_custom_callback_generic_api_str(
+ "unknown_callback"
+ )
+
+ # Should return the string unchanged
+ assert result == "unknown_callback", "Unknown callback should be returned as-is"
+ assert isinstance(result, str), "Unknown callback should remain a string"
+