Skip to content

feat(llmobs): [MLOB-2681] instrument openai responses with llm #13310

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

Open
wants to merge 108 commits into
base: main
Choose a base branch
from

Conversation

XG-xin
Copy link
Contributor

@XG-xin XG-xin commented May 1, 2025

This PR add LLM tracing/instrumentation for the OpenAI Responses endpoint.

For stream response, we will only get the response.completed chunk because it includes all metadata. Since there's only one response object that is present in each stream chunk, we append it as the first item in streamed_chunks.

This PR only handles function tool, and we might want to support other type of tools (i.e file search) in the furture.

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 May 1, 2025

CODEOWNERS have been resolved as:

.riot/requirements/1458d7e.txt                                          @DataDog/apm-python
.riot/requirements/164ce6e.txt                                          @DataDog/apm-python
.riot/requirements/1a18a5a.txt                                          @DataDog/apm-python
.riot/requirements/1dd6795.txt                                          @DataDog/apm-python
.riot/requirements/41b0f95.txt                                          @DataDog/apm-python
.riot/requirements/77994b3.txt                                          @DataDog/apm-python
.riot/requirements/c050b53.txt                                          @DataDog/apm-python
.riot/requirements/e3b63a1.txt                                          @DataDog/apm-python
releasenotes/notes/openai-responses-llm-2194499974f7324e.yaml           @DataDog/apm-python
tests/contrib/openai/cassettes/v1/response_error.yaml                   @DataDog/ml-observability
tests/contrib/openai/cassettes/v1/response_function_call.yaml           @DataDog/ml-observability
tests/contrib/openai/cassettes/v1/response_function_call_streamed.yaml  @DataDog/ml-observability
ddtrace/contrib/integration_registry/registry.yaml                      @DataDog/apm-core-python @DataDog/apm-idm-python
ddtrace/contrib/internal/openai/_endpoint_hooks.py                      @DataDog/ml-observability
ddtrace/contrib/internal/openai/utils.py                                @DataDog/ml-observability
ddtrace/llmobs/_integrations/openai.py                                  @DataDog/ml-observability
ddtrace/llmobs/_integrations/utils.py                                   @DataDog/ml-observability
riotfile.py                                                             @DataDog/apm-python
supported_versions_output.json                                          @DataDog/apm-core-python
supported_versions_table.csv                                            @DataDog/apm-core-python
tests/contrib/openai/test_openai_llmobs.py                              @DataDog/ml-observability
tests/contrib/openai/utils.py                                           @DataDog/ml-observability
tests/snapshots/tests.contrib.openai.test_openai.test_response_error.json  @DataDog/apm-python
tests/snapshots/tests.contrib.openai.test_openai.test_response_stream.json  @DataDog/apm-python
tests/snapshots/tests.contrib.openai.test_openai.test_response_tools_stream.json  @DataDog/apm-python
.riot/requirements/109d638.txt                                          @DataDog/apm-python
.riot/requirements/13c42e3.txt                                          @DataDog/apm-python
.riot/requirements/1ce4e3f.txt                                          @DataDog/apm-python
.riot/requirements/1e8124b.txt                                          @DataDog/apm-python
.riot/requirements/35f0cba.txt                                          @DataDog/apm-python
.riot/requirements/5301b11.txt                                          @DataDog/apm-python

Copy link
Contributor

github-actions bot commented May 1, 2025

Bootstrap import analysis

Comparison of import times between this PR and base.

Summary

The average import time from this PR is: 274 ± 2 ms.

The average import time from base is: 276 ± 2 ms.

The import time difference between this PR and base is: -2.2 ± 0.1 ms.

Import time breakdown

The following import paths have shrunk:

ddtrace.auto 2.067 ms (0.76%)
ddtrace.bootstrap.sitecustomize 1.398 ms (0.51%)
ddtrace.bootstrap.preload 1.398 ms (0.51%)
ddtrace.internal.remoteconfig.client 0.664 ms (0.24%)
ddtrace 0.669 ms (0.24%)
ddtrace.internal._unpatched 0.030 ms (0.01%)
json 0.030 ms (0.01%)
json.decoder 0.030 ms (0.01%)
re 0.030 ms (0.01%)
enum 0.030 ms (0.01%)
types 0.030 ms (0.01%)

@pr-commenter
Copy link

pr-commenter bot commented May 1, 2025

Benchmarks

Benchmark execution time: 2025-06-17 01:58:38

Comparing candidate commit 37aa590 in PR branch xinyuan/openai-responses-llm with baseline commit d30bcd7 in branch main.

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

scenario:iastaspects-replace_aspect

  • 🟥 execution_time [+428.760ns; +550.212ns] or [+9.095%; +11.671%]

scenario:telemetryaddmetric-1-distribution-metric-1-times

  • 🟥 execution_time [+226.052ns; +314.762ns] or [+7.721%; +10.751%]

Copy link
Contributor

@Yun-Kim Yun-Kim left a comment

Choose a reason for hiding this comment

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

Minor nits but good to merge once addressed!

XG-xin and others added 7 commits June 16, 2025 16:33
Co-authored-by: Yun Kim <35776586+Yun-Kim@users.noreply.github.com>
Co-authored-by: Yun Kim <35776586+Yun-Kim@users.noreply.github.com>
…trace-py into xinyuan/openai-responses-llm

Merge remote changes
XG-xin and others added 5 commits June 16, 2025 17:36
Co-authored-by: Yun Kim <35776586+Yun-Kim@users.noreply.github.com>
Co-authored-by: Yun Kim <35776586+Yun-Kim@users.noreply.github.com>
Co-authored-by: Yun Kim <35776586+Yun-Kim@users.noreply.github.com>
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.

5 participants