Skip to content

litellm proxy instrumentation #13148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: nicole-cybul/litellm-llmobs-tracing
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions ddtrace/contrib/internal/litellm/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,25 @@ def get_version() -> str:
return getattr(version_module, "version", "")


@with_traced_module
async def traced_run_endpoint_function(litellm, pin, func, instance, args, kwargs):
name = getattr(getattr(kwargs.get("dependant", None), "call", None), "__name__", "")
if name != "chat_completion":
return await func(*args, **kwargs)
integration = litellm._datadog_integration
span = integration.trace(
pin,
"chat_completion",
submit_to_llmobs=False,
)
try:
return await func(*args, **kwargs)
except Exception:
span.set_exc_info(*sys.exc_info())
raise
finally:
span.finish()

@with_traced_module
def traced_completion(litellm, pin, func, instance, args, kwargs):
return _traced_completion(litellm, pin, func, instance, args, kwargs, False)
Expand Down Expand Up @@ -140,6 +159,7 @@ def patch():
wrap("litellm", "atext_completion", traced_atext_completion(litellm))
wrap("litellm", "get_llm_provider", traced_get_llm_provider(litellm))
wrap("litellm", "litellm.main.get_llm_provider", traced_get_llm_provider(litellm))
wrap("fastapi.routing", "run_endpoint_function", traced_run_endpoint_function(litellm))


def unpatch():
Expand Down
Loading