Skip to content

fix(anthropic): upgrade supported version of anthropic SDK#604

Merged
nirga merged 1 commit intotraceloop:mainfrom
gadget-inc:newer-anthropic
Jun 10, 2025
Merged

fix(anthropic): upgrade supported version of anthropic SDK#604
nirga merged 1 commit intotraceloop:mainfrom
gadget-inc:newer-anthropic

Conversation

@airhorns
Copy link
Copy Markdown
Contributor

@airhorns airhorns commented Jun 4, 2025

  • enables the mostly-finished streaming chat completion support in the implementation and tests
  • supports newer series of Anthropic SDKs which use overriden Promise classes and Stream classes, which break the current version of the instrumentation's approach to wrapping streaming

Important

Upgrade Anthropic SDK to v0.50.4 and update instrumentation for new streaming capabilities.

  • SDK Update:
    • Upgrades @anthropic-ai/sdk from ^0.32.1 to ^0.50.4 in package.json.
  • Instrumentation Changes:
    • Updates patchAnthropic() in instrumentation.ts to handle new APIPromise and Stream classes.
    • Modifies _streamingWrapPromise() to support new streaming chat completion.
    • Adjusts patch() and unpatch() methods to accommodate SDK changes.
  • Testing:
    • Enables previously skipped test for streaming messages in instrumentation.test.ts.
    • Updates test cases to reflect new model names and streaming behavior.

This description was created by Ellipsis for 8322a20. You can customize this summary. It will automatically update as commits are pushed.

@airhorns airhorns marked this pull request as ready for review June 4, 2025 16:47
Copy link
Copy Markdown
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

Caution

Changes requested ❌

Reviewed everything up to 8322a20 in 2 minutes and 8 seconds. Click for details.
  • Reviewed 504 lines of code in 3 files
  • Skipped 1 files when reviewing.
  • Skipped posting 4 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. packages/instrumentation-anthropic/package.json:48
  • Draft comment:
    Dependency upgrade to '@anthropic-ai/sdk' (^0.50.4) looks good. Please ensure that any breaking changes in the new SDK version are fully compatible with the instrumentation.
  • Reason this comment was not posted:
    Comment did not seem useful. Confidence is useful = 0% <= threshold 50% This comment is asking the PR author to ensure compatibility with a dependency upgrade, which violates the rule against asking for confirmation or verification of intentions. It does not provide a specific suggestion or point out a specific issue.
2. packages/instrumentation-anthropic/src/instrumentation.ts:64
  • Draft comment:
    Passing the moduleExports parameter to patchAnthropic improves compatibility with the new SDK. Verify that all call sites now supply the correct module reference.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
3. packages/instrumentation-anthropic/src/instrumentation.ts:380
  • Draft comment:
    The use of 'any' casts (e.g. for promise.responsePromise and promise.parseResponse) might hide potential type safety issues. Consider using proper typings if available.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 20% vs. threshold = 50% The comment identifies a real issue with type safety. However, looking at the code more carefully, these any casts appear to be necessary to work with the Anthropic SDK's internal API. The properties being accessed (responsePromise and parseResponse) seem to be internal implementation details of the SDK that aren't exposed in the public types. This suggests the casts may be unavoidable without changes to the SDK itself. I could be wrong about whether proper types exist in the SDK - there might be a way to access these properties in a type-safe way that I'm missing. Even if better types exist, the comment doesn't provide specific guidance on how to fix it. And if the types don't exist in the SDK, this isn't something the PR author can easily fix. The comment should be deleted because it points out an issue that likely can't be fixed without SDK changes, and doesn't provide actionable guidance.
4. packages/instrumentation-anthropic/test/instrumentation.test.ts:234
  • Draft comment:
    The previously skipped streaming test for messages is now enabled with an updated model. Confirm that the test expectations match the new SDK behavior.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None

Workflow ID: wflow_umYvvyBjEAmtJIdF

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

completion: "",
stop_reason: null,
};
for await (const chunk of await promise) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In the _streamingWrapPromise iterateStream function, the completion branch uses for await (const chunk of await promise) while the chat branch iterates over stream. This inconsistency may lead to unexpected behavior. Consider replacing it with for await (const chunk of stream) for consistency.

@airhorns airhorns force-pushed the newer-anthropic branch 2 times, most recently from f01aee3 to 2c71715 Compare June 5, 2025 19:58
Copy link
Copy Markdown
Member

@nirga nirga left a comment

Choose a reason for hiding this comment

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

Thanks @airhorns! You need to bump anthropic on the traceloop-sdk as well

 - supports newer series of Anthropic SDKs which use overriden Promise classes and Stream classes
 - enables the mostly-finished streaming chat completion support in the implementation and tests
@nirga nirga changed the title Upgrade supported version of anthropic SDK fix(anthropix): upgrade supported version of anthropic SDK Jun 10, 2025
@nirga nirga changed the title fix(anthropix): upgrade supported version of anthropic SDK fix(anthropic): upgrade supported version of anthropic SDK Jun 10, 2025
Copy link
Copy Markdown
Member

@nirga nirga left a comment

Choose a reason for hiding this comment

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

Nice work, thank you @airhorns!

@nirga nirga merged commit 1ac8678 into traceloop:main Jun 10, 2025
4 checks passed
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.

2 participants