Skip to content
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

Fix instrumentation support for OpenAI client 0.14+ #531

Merged
merged 9 commits into from
Feb 5, 2025

Conversation

JonasKunz
Copy link
Contributor

@JonasKunz JonasKunz commented Feb 5, 2025

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
custom/build.gradle.kts Outdated Show resolved Hide resolved
id("elastic-otel.instrumentation-conventions")
}

val openAiVersion = "0.13.0"; // DO NOT UPGRADE
Copy link
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
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

settings.gradle.kts Outdated Show resolved Hide resolved
@JonasKunz JonasKunz requested a review from SylvainJuge February 5, 2025 13:39
@JonasKunz JonasKunz merged commit 1ebb1ff into elastic:main Feb 5, 2025
18 checks passed
@JonasKunz JonasKunz deleted the openai-upgrade branch February 5, 2025 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants