mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-11 08:38:24 +00:00
Merge ccf02ad73e into add7dea9aa
This commit is contained in:
commit
bc51d6c742
2 changed files with 42 additions and 0 deletions
|
|
@ -36,6 +36,7 @@ from litellm.integrations.otel.model.semconv import LiteLLM, Metric
|
|||
from litellm.integrations.otel.plumbing.otlp_tls import resolve_otlp_http_tls
|
||||
from litellm.integrations.otel.routing import routing_decision_attributes
|
||||
from litellm.litellm_core_utils.internal_call_metadata import is_unbilled_non_inference_call_from_params
|
||||
from litellm.litellm_core_utils.redact_messages import should_redact_message_logging
|
||||
from litellm.litellm_core_utils.safe_json_dumps import safe_dumps
|
||||
from litellm.litellm_core_utils.secret_redaction import redact_string
|
||||
from litellm.litellm_core_utils.service_tier_utils import (
|
||||
|
|
@ -1518,6 +1519,9 @@ class OpenTelemetry(OTELGenAISemconvMixin, CustomLogger):
|
|||
if not self._capture_in_span():
|
||||
return
|
||||
|
||||
if should_redact_message_logging(kwargs):
|
||||
return
|
||||
|
||||
litellm_params: Final = kwargs.get("litellm_params", {})
|
||||
metadata: Final = litellm_params.get("metadata") or {}
|
||||
generation_name: Final = metadata.get("generation_name")
|
||||
|
|
|
|||
|
|
@ -1945,6 +1945,44 @@ class TestOpenTelemetry(unittest.TestCase):
|
|||
|
||||
mock_tracer.start_span.assert_not_called()
|
||||
|
||||
@patch.dict(os.environ, {"OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT": ""})
|
||||
@patch("litellm.turn_off_message_logging", False)
|
||||
def test_maybe_log_raw_request_exports_span_only_without_redaction_header(self):
|
||||
from opentelemetry.sdk.trace import TracerProvider
|
||||
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
|
||||
from opentelemetry.sdk.trace.export.in_memory_span_exporter import (
|
||||
InMemorySpanExporter,
|
||||
)
|
||||
|
||||
from litellm.integrations.opentelemetry import RAW_REQUEST_SPAN_NAME
|
||||
|
||||
exporter = InMemorySpanExporter()
|
||||
provider = TracerProvider()
|
||||
provider.add_span_processor(SimpleSpanProcessor(exporter))
|
||||
tracer = provider.get_tracer("test")
|
||||
otel = OpenTelemetry()
|
||||
otel.message_logging = True
|
||||
otel.get_tracer_to_use_for_request = MagicMock(return_value=tracer)
|
||||
|
||||
def exported_raw_spans(headers):
|
||||
exporter.clear()
|
||||
kwargs = {"litellm_params": {"metadata": {"headers": headers}}}
|
||||
otel._maybe_log_raw_request(
|
||||
kwargs, {}, datetime.now(), datetime.now(), tracer.start_span("parent")
|
||||
)
|
||||
return [
|
||||
span
|
||||
for span in exporter.get_finished_spans()
|
||||
if span.name == RAW_REQUEST_SPAN_NAME
|
||||
]
|
||||
|
||||
self.assertEqual(len(exported_raw_spans({})), 1)
|
||||
for header in (
|
||||
"x-litellm-enable-message-redaction",
|
||||
"litellm-enable-message-redaction",
|
||||
):
|
||||
self.assertEqual(exported_raw_spans({header: "true"}), [])
|
||||
|
||||
|
||||
class TestOpenTelemetryToNs(unittest.TestCase):
|
||||
"""``_to_ns`` converts a span boundary to epoch nanoseconds. Service spans now
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue