ITADN

[python][anthropic] Use BlobUploader for oversized images in input.value

#3538Opencaroger 创建于 9 天前
enhancementlanguage: pythoninstrumentationinstrumentation: anthropicpython
C
carogercommented
## Context Provider-specific child of [Arize-ai/arize#81885](https://github.com/Arize-ai/arize/issues/81885), following [#3409](https://github.com/Arize-ai/openinference/pull/3409) and the shared deferred-upload work in [#3537](https://github.com/Arize-ai/openinference/issues/3537). The Anthropic instrumentor eagerly serializes request kwargs into `input.value`. Add upload-or-redact handling for image blocks in regular and beta `Messages.create`, `parse`, and `stream` paths, including nested tool-result content. ## Acceptance criteria - For `{type: "image", source: {type: "base64", media_type, data}}`, each over-budget bare-base64 image is decoded and passed to the shared helper with its MIME type and `attribute_key="input.value"`; a valid URI replaces the telemetry copy's entire source with `{type: "url", url: URI}` rather than leaving an invalid base64 source. - Caller requests and requests sent to Anthropic are not mutated. Non-image fields and supported SDK-normalized base64 values are preserved. - `hide_inputs` redacts the whole input with no traversal/upload. `hide_input_images` redacts base64 `source.data` and URL `source.url` leaves with no upload. At-or-below-budget base64 and remote URL sources remain unchanged when not hidden. - Missing/rejected uploads, malformed base64, exceptions, and invalid returned URIs redact only the affected base64 leaf and never affect the Anthropic call. - Use the shared deferred seam rather than invoking the uploader while building initial attributes. Suppressed and sampled-out spans perform zero uploads, and the sampler remains side-effect free. - Tests cover direct/nested image blocks, regular/beta sync/async/streaming routes, both source types, budget/privacy/fallback behavior, non-mutation, and suppression/sampling. - Raise the package's `openinference-instrumentation` lower bound to the release containing the shared helper. ## Out of scope `output.value`, documents/audio, and uploading remote URL sources.
0 条评论