Skip to content

Conversation

@ygree
Copy link
Contributor

@ygree ygree commented Nov 13, 2025

What Does This Do

Adds openai-java v3.0+ instrumentation for completions, chat completions, embeddings, and responses.

image
image

APM shared tests:

test_openai.py::TestOpenAiApm::test_chat_completion[java-test-ml-app-tcp-True] PASSED [ 12%]
test_openai.py::TestOpenAiApm::test_chat_completion[java-test-ml-app-tcp-False] PASSED [ 25%]
test_openai.py::TestOpenAiApm::test_completion[java-test-ml-app-tcp] PASSED [ 37%]
test_openai.py::TestOpenAiApm::test_embedding[java-test-ml-app-tcp] PASSED [ 50%]
test_openai.py::TestOpenAiApm::test_chat_completion_tool_call[java-test-ml-app-tcp-True] PASSED [ 62%]
test_openai.py::TestOpenAiApm::test_chat_completion_tool_call[java-test-ml-app-tcp-False] PASSED [ 75%]
test_openai.py::TestOpenAiApm::test_responses_create[java-test-ml-app-tcp-True] PASSED [ 87%]
test_openai.py::TestOpenAiApm::test_responses_create[java-test-ml-app-tcp-False] PASSED [100%]

LLMObs shared tests 14*/15:

test_openai.py::TestOpenAiLlmObs::test_chat_completion[java-test-ml-app-tcp-True] PASSED [  6%]
test_openai.py::TestOpenAiLlmObs::test_chat_completion[java-test-ml-app-tcp-False] PASSED [ 13%]
test_openai.py::TestOpenAiLlmObs::test_completion[java-test-ml-app-tcp] PASSED [ 20%]
test_openai.py::TestOpenAiLlmObs::test_embedding[java-test-ml-app-tcp] PASSED [ 26%]
test_openai.py::TestOpenAiLlmObs::test_chat_completion_tool_call[java-test-ml-app-tcp-True] PASSED [ 33%]
test_openai.py::TestOpenAiLlmObs::test_chat_completion_tool_call[java-test-ml-app-tcp-False] PASSED [ 40%]

test_openai.py::TestOpenAiLlmObs::test_chat_completion_telemetry[java-test-ml-app-tcp] FAILED* [ 46%]

test_openai.py::TestOpenAiLlmObs::test_responses_create[java-test-ml-app-tcp-True] PASSED [ 53%]
test_openai.py::TestOpenAiLlmObs::test_responses_create[java-test-ml-app-tcp-False] PASSED [ 60%]
test_openai.py::TestOpenAiLlmObs::test_responses_create_tool_call[java-test-ml-app-tcp-True] PASSED [ 66%]
test_openai.py::TestOpenAiLlmObs::test_responses_create_tool_call[java-test-ml-app-tcp-False] PASSED [ 73%]
test_openai.py::TestOpenAiLlmObs::test_responses_create_reasoning[java-test-ml-app-tcp-True] PASSED [ 80%]
test_openai.py::TestOpenAiLlmObs::test_responses_create_reasoning[java-test-ml-app-tcp-False] PASSED [ 86%]
test_openai.py::TestOpenAiLlmObs::test_responses_create_tool_input[java-test-ml-app-tcp-True] PASSED [ 93%]
test_openai.py::TestOpenAiLlmObs::test_responses_create_tool_input[java-test-ml-app-tcp-False] PASSED [100%]
    • test_chat_completion_telemetry FAILED because the shared test expects a namespace for the entire batch, but it should allow the namespace to be part of the metric data. Since Java batches telemetry data across subsystems and cannot guarantee that all the data belongs to the same namespace.

Motivation

Additional Notes

Contributor Checklist

Jira ticket: AIDM-163

ygree added 30 commits October 24, 2025 18:03
…d "streamed async request completion test with withRawResponse"
Call decorateWithResponse from the wrappers
Rename span resources to be aligned with trace-py
Add http.client resource assertion
Test case renaming
Reorder tests by synch, async
Fix Embeddings fixture for the latestDepTest when base64
@ygree ygree requested review from a team as code owners December 23, 2025 21:39
@ygree ygree requested review from dougqh and removed request for a team December 23, 2025 21:39
@github-actions
Copy link
Contributor

Hi! 👋 Thanks for your pull request! 🎉

To help us review it, please make sure to:

  • Add at least one type, and one component or instrumentation label to the pull request

If you need help, please check our contributing guidelines.

Copy link
Contributor

@PerfectSlayer PerfectSlayer left a comment

Choose a reason for hiding this comment

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

First round of comments for the core part. I will let IDM review the instrumentation part.

@ygree ygree force-pushed the ygree/openai-java branch from da72f90 to 3468137 Compare January 21, 2026 20:12
@ygree ygree force-pushed the ygree/openai-java branch from 6fa5b22 to aea89e3 Compare January 21, 2026 20:24
@ygree ygree requested a review from PerfectSlayer January 21, 2026 22:12
@ygree ygree force-pushed the ygree/openai-java branch from c1b0c81 to 37a8fd1 Compare January 22, 2026 02:02
@vandonr
Copy link
Contributor

vandonr commented Jan 22, 2026

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 37a8fd12f8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link
Contributor

@PerfectSlayer PerfectSlayer left a comment

Choose a reason for hiding this comment

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

Looking for for LP. I left aside the instrumentation part.
Thanks for the follow up changes 👍

@PerfectSlayer PerfectSlayer changed the title feat: openai-java v3.0+ instrumentation Add openai-java v3.0+ instrumentation Jan 22, 2026
@ygree ygree force-pushed the ygree/openai-java branch from 96ac8e8 to d9a6fcf Compare January 23, 2026 00:27
@ygree ygree added this to the 1.59.0 milestone Jan 26, 2026
@ygree ygree requested a review from vandonr January 26, 2026 19:55
@vandonr
Copy link
Contributor

vandonr commented Jan 27, 2026

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d9a6fcfbce

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +25 to +31
public static <T> CompletableFuture<HttpResponseFor<T>> wrapFuture(
CompletableFuture<HttpResponseFor<T>> future,
AgentSpan span,
BiConsumer<AgentSpan, T> decorate) {
return future
.thenApply(response -> wrap(response, span, decorate))
.whenComplete((_r, t) -> DECORATE.finishSpan(span, t));

Choose a reason for hiding this comment

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

P2 Badge Avoid finishing async spans before response parsing

The wrapFuture path finishes the span as soon as the CompletableFuture completes successfully, but the OpenAI async APIs return a response that is parsed later; the output decorators run in parse(). That means for any async create call (chat/completions/responses) where the future resolves before parse() is invoked—which is the normal usage—the span is already finished and the output tags/metrics set in parse() can be dropped or ignored. This effectively loses LLMObs output data for async calls. Consider only finishing on error in whenComplete and letting parse()/close() finish the span on success.

Useful? React with 👍 / 👎.

Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 we have tests on async requests though, which seem to be asserting the correct tags are applied. Is it that we do all the operations in a row in the test, which is not representative of a "real world" use case ?
Or maybe chatgpt's concerns are unfounded

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: mlobs ML Observability (LLMObs) inst: others All other instrumentations type: feature request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants