Skip to content

[MLOB-3112] make shared base classes for llmobs traced streams #13736

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

Conversation

ncybul
Copy link
Contributor

@ncybul ncybul commented Jun 20, 2025

This PR attempts to create shared base classes for tracing streams in our LLMObs integrations. The Anthropic, Gemini, Langchain, LiteLLM, Open AI / Azure Open AI, and Vertex AI integrations were all refactored to use this new standardized interface.

How it works

todo

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

Copy link
Contributor

github-actions bot commented Jun 20, 2025

CODEOWNERS have been resolved as:

ddtrace/llmobs/_integrations/base_stream_handler.py                     @DataDog/ml-observability
ddtrace/contrib/internal/anthropic/_streaming.py                        @DataDog/ml-observability
ddtrace/contrib/internal/google_generativeai/_utils.py                  @DataDog/ml-observability
ddtrace/contrib/internal/google_generativeai/patch.py                   @DataDog/ml-observability
ddtrace/contrib/internal/langchain/utils.py                             @DataDog/ml-observability
ddtrace/contrib/internal/litellm/patch.py                               @DataDog/ml-observability
ddtrace/contrib/internal/litellm/utils.py                               @DataDog/ml-observability
ddtrace/contrib/internal/openai/_endpoint_hooks.py                      @DataDog/ml-observability
ddtrace/contrib/internal/openai/utils.py                                @DataDog/ml-observability
ddtrace/contrib/internal/vertexai/_utils.py                             @DataDog/ml-observability
ddtrace/contrib/internal/vertexai/patch.py                              @DataDog/ml-observability

Copy link
Contributor

github-actions bot commented Jun 20, 2025

Bootstrap import analysis

Comparison of import times between this PR and base.

Summary

The average import time from this PR is: 286 ± 4 ms.

The average import time from base is: 293 ± 7 ms.

The import time difference between this PR and base is: -7.3 ± 0.3 ms.

Import time breakdown

The following import paths have shrunk:

ddtrace.auto 2.532 ms (0.89%)
ddtrace.bootstrap.sitecustomize 1.710 ms (0.60%)
ddtrace.bootstrap.preload 1.710 ms (0.60%)
ddtrace.internal.remoteconfig.client 0.740 ms (0.26%)
ddtrace 0.822 ms (0.29%)
ddtrace.internal._unpatched 0.162 ms (0.06%)
subprocess 0.126 ms (0.04%)
contextlib 0.126 ms (0.04%)
json 0.036 ms (0.01%)
json.decoder 0.036 ms (0.01%)
re 0.036 ms (0.01%)
enum 0.036 ms (0.01%)
types 0.036 ms (0.01%)


def __exit__(self, exc_type, exc_val, exc_tb):
self.__wrapped__.__exit__(exc_type, exc_val, exc_tb)
class BaseOpenAIStreamHandler:
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

Class BaseOpenAIStreamHandler should have an init method (...read more)

Ensure that a class has an __init__ method. This check is bypassed when the class is a data class (annotated with @dataclass).

View in Datadog  Leave us feedback  Documentation

@pr-commenter
Copy link

pr-commenter bot commented Jun 23, 2025

Benchmarks

Benchmark execution time: 2025-06-23 20:03:58

Comparing candidate commit 7626f40 in PR branch nicole-cybul/streaming-handler-consistency with baseline commit 3e54c5c in branch main.

Found 0 performance improvements and 2 performance regressions! Performance is the same for 499 metrics, 3 unstable metrics.

scenario:iastaspects-lower_aspect

  • 🟥 execution_time [+184.374ns; +230.116ns] or [+8.158%; +10.182%]

scenario:iastaspects-upper_aspect

  • 🟥 execution_time [+182.167ns; +223.256ns] or [+8.056%; +9.873%]

)
self._dd_span.finish()

class BaseVertexAIStreamHandler:
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

Class BaseVertexAIStreamHandler should have an init method (...read more)

Ensure that a class has an __init__ method. This check is bypassed when the class is a data class (annotated with @dataclass).

View in Datadog  Leave us feedback  Documentation

from ddtrace.llmobs._integrations.utils import get_generation_config_google
from ddtrace.llmobs._integrations.utils import get_system_instructions_from_google_model
from ddtrace.llmobs._integrations.utils import tag_request_content_part_google
from ddtrace.llmobs._integrations.utils import tag_response_part_google

class BaseGoogleGenerativeAIStramHandler:
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

Class BaseGoogleGenerativeAIStramHandler should have an init method (...read more)

Ensure that a class has an __init__ method. This check is bypassed when the class is a data class (annotated with @dataclass).

View in Datadog  Leave us feedback  Documentation

return traced_stream

async def __aexit__(self, exc_type, exc_val, exc_tb):
await self.__wrapped__.__aexit__(exc_type, exc_val, exc_tb)
class BaseAnthropicStreamHandler:
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

Class BaseAnthropicStreamHandler should have an init method (...read more)

Ensure that a class has an __init__ method. This check is bypassed when the class is a data class (annotated with @dataclass).

View in Datadog  Leave us feedback  Documentation

@ncybul ncybul changed the title wip; make shared base classes for llmobs traced streams [MLOB-2880] make shared base classes for llmobs traced streams Jun 23, 2025
from ddtrace.llmobs._integrations.base_stream_handler import make_traced_stream
from ddtrace.llmobs._integrations.base_stream_handler import StreamHandler

class BaseLangchainStreamHandler:
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

Class BaseLangchainStreamHandler should have an init method (...read more)

Ensure that a class has an __init__ method. This check is bypassed when the class is a data class (annotated with @dataclass).

View in Datadog  Leave us feedback  Documentation

@ncybul ncybul changed the title [MLOB-2880] make shared base classes for llmobs traced streams [MLOB-3112] make shared base classes for llmobs traced streams Jun 23, 2025
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