Skip to content

Nicole cybul/litellm proxy instrumentation2 #13286

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 65 commits into
base: main
Choose a base branch
from

Conversation

ncybul
Copy link
Contributor

@ncybul ncybul commented Apr 28, 2025

Checklist

  • PR author has checked that all the criteria below are met
  • The PR description includes an overview of the change
  • The PR description articulates the motivation for the change
  • The change includes tests OR the PR description describes a testing strategy
  • The PR description notes risks associated with the change, if any
  • Newly-added code is easy to change
  • The change follows the library release note guidelines
  • The change includes or references documentation updates if necessary
  • Backport labels are set (if applicable)

Reviewer Checklist

  • Reviewer has checked that all the criteria below are met
  • Title is accurate
  • All changes are related to the pull request's stated goal
  • Avoids breaking API changes
  • Testing strategy adequately addresses listed risks
  • Newly-added code is easy to change
  • Release note makes sense to a user of the library
  • If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment
  • Backport labels are set in a manner that is consistent with the release branch maintenance policy

)

@staticmethod
def _extract_llmobs_metrics(resp: Any) -> Dict[str, Any]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 Code Quality Violation

do not use Any, use a concrete type (...read more)

Use the Any type very carefully. Most of the time, the Any type is used because we do not know exactly what type is being used. If you want to specify that a value can be of any type, use object instead of Any.

Learn More

View in Datadog  Leave us feedback  Documentation

@@ -284,6 +292,187 @@ def get_messages_from_converse_content(role: str, content: list):
return messages


def openai_set_meta_tags_from_completion(span: Span, kwargs: Dict[str, Any], completions: Any) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 Code Quality Violation

do not use Any, use a concrete type (...read more)

Use the Any type very carefully. Most of the time, the Any type is used because we do not know exactly what type is being used. If you want to specify that a value can be of any type, use object instead of Any.

Learn More

View in Datadog  Leave us feedback  Documentation

if data:
model = data.get("model", None)
except Exception:
pass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Code Quality Violation

silent exception (...read more)

Using the pass statement in an exception block ignores the exception. Exceptions should never be ignored. Instead, the user must add code to notify an exception occurred and attempt to handle it or recover from it.

The exception to this rule is the use of StopIteration or StopAsyncIteration when implementing a custom iterator (as those errors are used to acknowledge the end of a successful iteration).

View in Datadog  Leave us feedback  Documentation

Copy link
Contributor

CODEOWNERS have been resolved as:

.riot/requirements/10c8b6a.txt                                          @DataDog/apm-python
.riot/requirements/147ef17.txt                                          @DataDog/apm-python
.riot/requirements/14d3539.txt                                          @DataDog/apm-python
.riot/requirements/1534895.txt                                          @DataDog/apm-python
.riot/requirements/1c3ffc3.txt                                          @DataDog/apm-python
.riot/requirements/1e283d9.txt                                          @DataDog/apm-python
ddtrace/contrib/internal/litellm/utils.py                               @DataDog/apm-core-python @DataDog/apm-idm-python
releasenotes/notes/feat-llmobs-litellm-7fc73fd28ab88fac.yaml            @DataDog/apm-python
tests/contrib/litellm/cassettes/completion_multiple_choices_proxy.yaml  @DataDog/apm-core-python @DataDog/apm-idm-python
tests/contrib/litellm/cassettes/completion_multiple_choices_with_tools.yaml  @DataDog/apm-core-python @DataDog/apm-idm-python
tests/contrib/litellm/cassettes/completion_proxy.yaml                   @DataDog/apm-core-python @DataDog/apm-idm-python
tests/contrib/litellm/cassettes/completion_stream_exclude_usage.yaml    @DataDog/apm-core-python @DataDog/apm-idm-python
tests/contrib/litellm/cassettes/completion_stream_multiple_choices_exclude_usage.yaml  @DataDog/apm-core-python @DataDog/apm-idm-python
tests/contrib/litellm/cassettes/completion_stream_multiple_choices_proxy.yaml  @DataDog/apm-core-python @DataDog/apm-idm-python
tests/contrib/litellm/cassettes/completion_stream_multiple_choices_with_tools.yaml  @DataDog/apm-core-python @DataDog/apm-idm-python
tests/contrib/litellm/cassettes/completion_stream_proxy.yaml            @DataDog/apm-core-python @DataDog/apm-idm-python
tests/contrib/litellm/cassettes/completion_stream_with_tools.yaml       @DataDog/apm-core-python @DataDog/apm-idm-python
tests/contrib/litellm/cassettes/completion_with_tools.yaml              @DataDog/apm-core-python @DataDog/apm-idm-python
tests/contrib/litellm/test_litellm_llmobs.py                            @DataDog/apm-core-python @DataDog/apm-idm-python
tests/snapshots/tests.contrib.litellm.test_litellm.test_litellm_base_process_llm_request.json  @DataDog/apm-python
ddtrace/contrib/internal/litellm/patch.py                               @DataDog/apm-core-python @DataDog/apm-idm-python
ddtrace/contrib/internal/openai/utils.py                                @DataDog/ml-observability
ddtrace/llmobs/_integrations/litellm.py                                 @DataDog/ml-observability
ddtrace/llmobs/_integrations/openai.py                                  @DataDog/ml-observability
ddtrace/llmobs/_integrations/utils.py                                   @DataDog/ml-observability
ddtrace/llmobs/_llmobs.py                                               @DataDog/ml-observability
riotfile.py                                                             @DataDog/apm-python
tests/contrib/litellm/conftest.py                                       @DataDog/apm-core-python @DataDog/apm-idm-python
tests/contrib/litellm/test_litellm.py                                   @DataDog/apm-core-python @DataDog/apm-idm-python
tests/contrib/litellm/utils.py                                          @DataDog/apm-core-python @DataDog/apm-idm-python

Copy link
Contributor

Bootstrap import analysis

Comparison of import times between this PR and base.

Summary

The average import time from this PR is: 256 ± 5 ms.

The average import time from base is: 256 ± 4 ms.

The import time difference between this PR and base is: 0.9 ± 0.2 ms.

Import time breakdown

The following import paths have grown:

ddtrace.auto 0.020 ms (0.01%)
ddtrace 0.020 ms (0.01%)
ddtrace.settings._config 0.020 ms (0.01%)
ddtrace.settings.endpoint_config 0.020 ms (0.01%)

The following import paths have shrunk:

ddtrace.auto 1.819 ms (0.71%)
ddtrace.bootstrap.sitecustomize 1.140 ms (0.44%)
ddtrace.bootstrap.preload 1.140 ms (0.44%)
ddtrace.internal.products 1.140 ms (0.44%)
ddtrace.internal.remoteconfig.client 0.584 ms (0.23%)
ddtrace 0.679 ms (0.26%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant