Skip to content

feat: Add Message Batches API instrumentation#1698

Closed
Stephen Belanger (Qard) wants to merge 3 commits intomainfrom
feat/anthropic-message-batches-instrumentation
Closed

feat: Add Message Batches API instrumentation#1698
Stephen Belanger (Qard) wants to merge 3 commits intomainfrom
feat/anthropic-message-batches-instrumentation

Conversation

@Qard
Copy link
Copy Markdown
Contributor

Summary

Changes

  • vendor-sdk-types/anthropic.ts: Added AnthropicBatches, AnthropicMessageBatch, AnthropicBatchCreateParams, AnthropicBatchRequest, AnthropicBatchListParams types; added batches field to AnthropicMessages
  • anthropic-channels.ts: Added 5 new diagnostic channels (messages.batches.create/retrieve/list/cancel/delete)
  • wrappers/anthropic.ts: Added batchesProxy() and wired it into messagesProxy() to intercept the batches property
  • anthropic-plugin.ts: Added traceAsyncChannel subscriptions for all 5 batch channels
  • configs/anthropic.ts: Added auto-instrumentation configs targeting Batches class methods in resources/messages/batches.mjs (>=0.39.0)

Test plan

  • Unit tests pass (pnpm run test:checks in js/)
  • No lint errors (pnpm run lint)
  • Formatting applied (pnpm run fix:formatting)
  • CI checks pass

🤖 Generated with Claude Code

Copy link
Copy Markdown
Member

@lforst Luca Forstner (lforst) left a comment

Choose a reason for hiding this comment

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

Generally looks good but some e2e test assertions would be beneficial I think.

@lforst
Copy link
Copy Markdown
Member

Luca Forstner (lforst) commented Mar 28, 2026

Actually, coming back to my senses... Should we really be instrumenting create, retrieve, list, cancel, delete? Those seem more like CRUD operations and less like AI relevant things that we would like to instrument no?

create makes sense to some degree, but even there it's more an input thing and less an output thing.

Luca Forstner (lforst) pushed a commit that referenced this pull request Mar 31, 2026
…ropic timeout (#1707)

## Summary

- **Langchain canary**: Newer versions of `@langchain/openai` removed
`max_tokens`, `model`, `stream`, and `temperature` from the `ls_*`
metadata block (they're already captured in the standardized
`ls_max_tokens`, `ls_model_name`, etc. fields). Added normalization in
`assertions.ts` to delete these volatile keys from any metadata object
that contains `ls_` keys, making the `wrap-langchain-js-traces` snapshot
stable across both the locked (1.3.0) and latest langchain versions.
- **Anthropic timeout**: Increase the `anthropic-instrumentation`
scenario timeout from 90s to 150s to accommodate the additional
`messages.batches` API calls (create, retrieve, list, cancel) that will
land when #1698 merges.

## Test plan

- [ ] `wrap-langchain-js-traces` canary test passes with both locked and
latest `@langchain/openai`
- [ ] Anthropic instrumentation tests unaffected (timeout increase is
headroom only)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Stephen Belanger (Qard) and others added 3 commits March 31, 2026 16:34
- Add vendor types for AnthropicBatches, AnthropicMessageBatch, and batch params
- Add diagnostic channels for create, retrieve, list, cancel, and delete batch ops
- Add batchesProxy() in wrapAnthropic() to intercept all Batches methods
- Add AnthropicPlugin subscriptions for batch channels via traceAsyncChannel
- Add auto-instrumentation configs targeting Batches class methods (>=0.39.0)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ractInput

The destructured parameter type annotations (e.g. `([params]: [T])`) were
stricter than the expected `(args: [T, ...any[]], event, span) => ...` type,
causing assignability errors. Removing the annotations lets TypeScript infer
the correct types from the channel's generic parameters.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds scenario coverage and snapshot assertions for the Anthropic Message
Batches API (create, retrieve, list, cancel) across all supported SDK
versions (v0.39.0+). Normalizes volatile batch response fields
(timestamps, batch IDs, list bodies) for stable snapshots.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Qard Stephen Belanger (Qard) force-pushed the feat/anthropic-message-batches-instrumentation branch from 5adc7f4 to e60aacd Compare March 31, 2026 08:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Anthropic Message Batches API (client.messages.batches.*) not instrumented

2 participants