Skip to content

Fix instrumentation support for OpenAI client 0.14+#531

Merged
JonasKunz merged 9 commits into
elastic:mainfrom
JonasKunz:openai-upgrade
Feb 5, 2025
Merged

Fix instrumentation support for OpenAI client 0.14+#531
JonasKunz merged 9 commits into
elastic:mainfrom
JonasKunz:openai-upgrade

Conversation

@JonasKunz

@JonasKunz JonasKunz commented Feb 5, 2025

Copy link
Copy Markdown
Contributor

The OpenAI java client 0.14 had several breaking changes due to some methods we used being renamed.
The other logic is still all the same, that's why I decided to simply encapsulate those methods in an ApiAdapter and provide implementations for each the pre and post 0.14.0 versions.

For on how to install the instrumentation I considered two alternatives:

  • Stay with a single instrumentation module and simply load the correct adapter at runtime after inspecting via reflection which OpenAI client version is present
  • Use two instrumentations modules, each loading a specific adapter

While the second option introduces slightly more code, it has the benefit of muzzle working correctly: For each module, muzzle will pick up the OpenAI client methods used in the ApiAdapterImpls and will therefore ensure that future breaking changes to those are correctly detected. That's why I went for two instrumentation modules here.

@JonasKunz
JonasKunz marked this pull request as ready for review February 5, 2025 11:05
@JonasKunz
JonasKunz requested a review from SylvainJuge February 5, 2025 11:05
@JonasKunz JonasKunz self-assigned this Feb 5, 2025
Comment thread custom/build.gradle.kts Outdated
id("elastic-otel.instrumentation-conventions")
}

val openAiVersion = "0.13.0"; // DO NOT UPGRADE

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it something that renovate/dependabot would attempt to upgrade ? If so I think there are ways like splitting the string in parts to prevent this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good idea. I don't know if renovate is smart enough for this. We can just keep it like this for now and see if renovate detects it and attempts an upgrade

Comment thread settings.gradle.kts Outdated
@JonasKunz
JonasKunz requested a review from SylvainJuge February 5, 2025 13:39
@JonasKunz
JonasKunz merged commit 1ebb1ff into elastic:main Feb 5, 2025
@JonasKunz
JonasKunz deleted the openai-upgrade branch February 5, 2025 14:58
@SylvainJuge SylvainJuge added the enhancement New feature or request label Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-java enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants