Skip to content

feat(anthropic): instrument Messages Batch API#127

Merged
Abhijeet Prasad (AbhiPrasad) merged 1 commit intomainfrom
abhi-test-anthropic-cleanup-vcr-mocks
Mar 24, 2026
Merged

feat(anthropic): instrument Messages Batch API#127
Abhijeet Prasad (AbhiPrasad) merged 1 commit intomainfrom
abhi-test-anthropic-cleanup-vcr-mocks

Conversation

@AbhiPrasad
Copy link
Member

resolves #108

Add tracing for client.messages.batches.create() and
client.messages.batches.results(), covering both sync/async clients
and the beta namespace. Batch operations now produce spans with
batch ID, request count, model, and processing status metadata.

The Messages and AsyncMessages wrapper classes gain a batches property
that returns a traced Batches/AsyncBatches resource instead of falling
through to the unwrapped original via Wrapper.__getattr__.

Also clean up the test file: remove tests that asserted on wrapping
internals (already covered by wrapper compat subprocess tests), convert
batch create tests to VCR cassettes, and keep mocks only for
batches.results() which requires a completed batch (up to 24 hours).

Add tracing for client.messages.batches.create() and
client.messages.batches.results(), covering both sync/async clients
and the beta namespace. Batch operations now produce spans with
batch ID, request count, model, and processing status metadata.

The Messages and AsyncMessages wrapper classes gain a batches property
that returns a traced Batches/AsyncBatches resource instead of falling
through to the unwrapped original via Wrapper.__getattr__.

Also clean up the test file: remove tests that asserted on wrapping
internals (already covered by wrapper compat subprocess tests), convert
batch create tests to VCR cassettes, and keep mocks only for
batches.results() which requires a completed batch (up to 24 hours).

Closes #108
Copy link
Contributor

Choose a reason for hiding this comment

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

Otherwise looks good, assuming the CI passes.


import inspect
import time
import unittest.mock

Choose a reason for hiding this comment

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

I think VCR are usually preferred in this repo, were they too hard to record/use for this use-case?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes unfortunately I couldn't make it work. I left the reasoning as a docstring on the test but:

Mocked because the batch results API requires a completed batch, and batches
can take up to 24 hours to finish processing.

@AbhiPrasad Abhijeet Prasad (AbhiPrasad) merged commit 92165c3 into main Mar 24, 2026
33 checks passed
@AbhiPrasad Abhijeet Prasad (AbhiPrasad) deleted the abhi-test-anthropic-cleanup-vcr-mocks branch March 24, 2026 17:09
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.

Anthropic: Messages Batch API not instrumented

2 participants