ai-gateway observability/add azure image moderation span - #74520
Open
alex-m-brown wants to merge 1 commit into
Open
ai-gateway observability/add azure image moderation span#74520alex-m-brown wants to merge 1 commit into
alex-m-brown wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:moderateImageimage-moderation.moderateImageimage.source: 'file',image.type,image.size_bytesmoderateImageUrlimage-moderation.moderateImageUrlimage.source: 'url'Both use op
image.moderateand carryfeature,image.app_name, andimage.uploader_type. Uploads send the whole image in the request body, henceimage.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, andimage.sourceis enough to tell the variants apart.featuredefaults toimage-moderationand is threaded through both entry points, so a caller in a larger pipeline can attribute moderation time to itself.getImageModerationStatuspassesai-gatewaywhen checking a model-generated image, which folds that moderation into the gateway pipeline's traces alongsideai-gateway.generateTextandai-gateway.turnstile.The verdict is not a span attribute. It is only known after the response, and
Observability.startSpanfixes attributes at creation; adding it would mean changing the shared observability plugin. It stays where it already is — theModerateCustomImage.{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:



safetyHelpersTestcovers theai-gatewayattribution for generated images. Ran the consumer suites for every caller —aichat,lab2,sketchlab,p5lab, plusapplab/commandsTestandImageURLInputTestfor the URL variant — all green, along withyarn run typecheckand lint.