GH-1608: Add observability support to Stability AI image model#5876
Open
Gaurav1112 wants to merge 1 commit intospring-projects:mainfrom
Open
GH-1608: Add observability support to Stability AI image model#5876Gaurav1112 wants to merge 1 commit intospring-projects:mainfrom
Gaurav1112 wants to merge 1 commit intospring-projects:mainfrom
Conversation
…ge model
Instrument StabilityAiImageModel with Micrometer observations using the
portable ImageModelObservationConvention, matching the pattern already in
place for OpenAiImageModel.
- Add STABILITY_AI ("stability_ai") to AiProvider enum.
- Add 3-arg StabilityAiImageModel constructor accepting an
ObservationRegistry; existing constructors default to
ObservationRegistry.NOOP for backwards compatibility.
- Wrap call() with IMAGE_MODEL_OPERATION.observation(...).observe(...)
using DefaultImageModelObservationConvention. Pass the raw ImagePrompt
to the observation context for consistency with OpenAiImageModel.
- Expose setObservationConvention(...) for custom conventions.
- Wire ObjectProvider<ObservationRegistry> and
ObjectProvider<ImageModelObservationConvention> in
StabilityAiImageAutoConfiguration.
- Add unit tests (happy path, no-options path, API-error path, custom
convention, null-convention guard, null-registry fallback, backwards-
compatible constructors) plus auto-configuration wiring tests.
- Update observability reference docs to list Stability AI alongside
OpenAI for ImageModel observability.
Fixes spring-projectsGH-1608
Signed-off-by: CodeItWithKG <17354977+Gaurav1112@users.noreply.github.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.
GH-1608: Add observability support to Stability AI image model
Fixes #1608
Problem
StabilityAiImageModelwas the last remainingImageModelin the project without observability. Calls toimageModel.call(...)for Stability AI produced nogen_ai.client.operationobservation, so they were invisible in the Actuator metrics endpoint and in any attached tracer — while equivalent calls againstOpenAiImageModelhave been fully instrumented for some time.What this PR does
Instruments
StabilityAiImageModelwith Micrometer observations using the portableImageModelObservationConventioninfrastructure, mirroringOpenAiImageModelso the resulting tags are consistent across providers.Production code
AiProvider— addedSTABILITY_AI("stability_ai")enum value (placed alphabetically, inside the existing@formatter:offregion).StabilityAiImageModel:StabilityAiImageModel(StabilityAiApi, StabilityAiImageOptions, ObservationRegistry). Anullregistry is defensively swapped forObservationRegistry.NOOP.ObservationRegistry.NOOP, preserving source and binary compatibility.call(ImagePrompt)is wrapped withImageModelObservationDocumentation.IMAGE_MODEL_OPERATION.observation(...).observe(...)using the sharedDefaultImageModelObservationConvention. The rawImagePromptis passed to the observation context (matchingOpenAiImageModel) so observation tags reflect what the user actually sent rather than post-merge defaults.setObservationConvention(ImageModelObservationConvention)accessor; guards againstnull.StabilityAiImageAutoConfiguration— acceptsObjectProvider<ObservationRegistry>andObjectProvider<ImageModelObservationConvention>and wires them into the model bean, identical toOpenAiImageAutoConfiguration.Tests
All mocked — no network access and no API keys required.
StabilityAiImageModelObservationTests(7 cases):gen_ai.client.operationname, contextual name, provider =stability_ai, model tag, size/style high-cardinality tags.ImagePromptwith no options — observation still emitted with provider + operation type.ImageModelObservationConventionis honoured (custom name + custom tags).setObservationConvention(null)→IllegalArgumentException.ObservationRegistryconstructor arg falls back toObservationRegistry.NOOP.StabilityAiImageAutoConfigurationObservabilityTests(3 cases):ObservationRegistrybean is picked up viagetIfUnique.ImageModelObservationConventionbean is applied to the model.Documentation
spring-ai-docs/.../observability/index.adoc— the Image Model note previously said "supported only for … OpenAI". Updated to list both "OpenAI, Stability AI".How I verified
spring-ai-stability-ai: 10 tests, 0 failures (3 existing options tests + 7 new observation tests).spring-ai-autoconfigure-model-stability-ai: 5 tests, 0 failures (2 existing properties tests + 3 new observability wiring tests).Compatibility
ObservationRegistrybean getObservationRegistry.NOOPand see no new overhead. Users who do configure one now get agen_ai.client.operationobservation percall(...)automatically.OTel semantic conventions
The
STABILITY_AIprovider value (stability_ai) follows the snake-case convention used by the other provider enum values (e.g.mistral_ai,oci_genai,openai_sdk) and is compatible with OpenTelemetry'sgen_ai.systemattribute as documented in the OTel GenAI semantic conventions.Checklist
GH-1608perCONTRIBUTING.adoc.@author/@sincetags added.