Skip to content

ai-gateway observability/add azure image moderation span - #74520

Open
alex-m-brown wants to merge 1 commit into
stagingfrom
ai-gateway-observability/add-azure-span
Open

ai-gateway observability/add azure image moderation span#74520
alex-m-brown wants to merge 1 commit into
stagingfrom
ai-gateway-observability/add-azure-span

Conversation

@alex-m-brown

@alex-m-brown alex-m-brown commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Adds a span around our Azure AI Content Safety image moderation call, so the time we spend waiting on moderation is visible in the client trace.

The span goes in runModeration, the shared choke point, so both entry points get it:

Entry point Span name Payload attributes
moderateImage image-moderation.moderateImage image.source: 'file', image.type, image.size_bytes
moderateImageUrl image-moderation.moderateImageUrl image.source: 'url'

Both use op image.moderate and carry feature, image.app_name, and image.uploader_type. Uploads send the whole image in the request body, hence image.size_bytes — without it a slow span is unreadable, since duration tracks payload size as much as it tracks Azure's analysis. The URL is deliberately left off the span: it can carry signed query parameters, and image.source is enough to tell the variants apart.

feature defaults to image-moderation and is threaded through both entry points, so a caller in a larger pipeline can attribute moderation time to itself. getImageModerationStatus passes ai-gateway when checking a model-generated image, which folds that moderation into the gateway pipeline's traces alongside ai-gateway.generateText and ai-gateway.turnstile.

The verdict is not a span attribute. It is only known after the response, and Observability.startSpan fixes attributes at creation; adding it would mean changing the shared observability plugin. It stays where it already is — the ModerateCustomImage.{Success,Flagged,Error} counters, which are sampled at 100% and are the right place for rates anyway, given only 0.5% of client traces are kept.

Testing story

Unit tested: safetyHelpersTest covers the ai-gateway attribution for generated images. Ran the consumer suites for every caller — aichat, lab2, sketchlab, p5lab, plus applab/commandsTest and ImageURLInputTest for the URL variant — all green, along with yarn run typecheck and lint.
Screenshot 2026-08-10 at 5 17 07 PM
Screenshot 2026-08-10 at 5 17 42 PM
Screenshot 2026-08-10 at 5 25 40 PM

Wraps the Azure AI Content Safety request in runModeration, so both
moderateImage and moderateImageUrl report their round trip in the client
trace. Callers in a larger pipeline can name it: the AI Gateway passes
feature 'ai-gateway' when moderating a generated image.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@alex-m-brown
alex-m-brown requested a review from a team August 10, 2026 21:26
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.

1 participant