-
Notifications
You must be signed in to change notification settings - Fork 155
feat(portkey): Support instrumentation of portkey_ai.AsyncPortkey
#2407
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
base: main
Are you sure you want to change the base?
Conversation
|
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
| portkey_module.Completions.create = self._original_completions_create | ||
|
|
||
| if self._original_async_completions_create is not None: | ||
| portkey_module.AsyncCompletions.create = self._original_async_completions_create |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Incomplete uninstrumentation leaves generation wrap active
The _uninstrument method does not properly restore AsyncCompletions.create from the generation module. During instrumentation (lines 64-68), AsyncCompletions.create is wrapped in both portkey_ai.api_resources.apis.chat_complete and portkey_ai.api_resources.apis.generation modules. However, the uninstrument method only imports and restores from the chat_complete module (lines 71-76), leaving the generation module's AsyncCompletions.create method wrapped even after uninstrumentation. This will cause the instrumentation to remain active for async completions called through the generation module even after calling uninstrument().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is true, we would need to restore the sync function, in addition to the async function.
Add support for instrumentation of
portkey_ai.AsyncPortkeyNote
Adds async instrumentation for
portkey_ai.AsyncPortkeyby wrappingAsyncCompletions.create, plus tests and cassettes.AsyncCompletions.createinportkey_ai.api_resources.apis.{chat_complete,generation}with_AsyncCompletionsWrapperand track original for uninstrumentation._AsyncCompletionsWrapperto handle async spans, request/response attribute extraction, and span nameAsyncCompletions._original_async_completions_create.test_async_chat_completionandtest_async_prompt_templateasserting span name/attributes.tests/cassettes/test_async_chat_completion.yamlandtest_async_prompt_template.yaml.Written by Cursor Bugbot for commit fac30e1. This will update automatically on new commits. Configure here.