Repository navigation
Do not record the unset options of a spring-ai-1.x streaming chat request as the string null - #854
Open
1chengfengyu wants to merge 1 commit into
Open
1chengfengyu wants to merge 1 commit into
1chengfengyu wants to merge 1 commit into
Conversation
…uest as the string null
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.
Fix the
spring-ai-1.xplugin recording the stringnullas the value of a request option a streaming call leaves unsetWhy the bug exists
ChatModelStreamInterceptorwrites four request options without checking them first(
apm-spring-ai-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/ai/v1/ChatModelStreamInterceptor.java,lines 74-77 as of
6974276):ChatOptionsreturnsnullfor every sampling setting a request does not carry, andString.valueOfturns thatnullinto the four-character stringnull. The collector has no way to tell it from a value the application reallyset, so the tag is stored as is.
gen_ai.request.top_kis the one that fires in practice. The OpenAI API has notop_kparameter, soOpenAiChatOptions.getTopK()isnullunless the application sets it explicitly, which means the span of everyOpenAI streaming call carries
gen_ai.request.top_k=null.The non-streaming interceptor guards all four with
!= nullalready, so one request recorded two different tag setsdepending on whether the application called
call()orstream(). For the same prompt with onlymodel,temperatureandtop-pconfigured, the E2E scenario shows:Why the E2E scenario did not catch it
The expected tags of the streaming span contained
- { key: gen_ai.request.top_k, value: null }The validator reads that as a YAML
null, andExpressParser.parse(null)returnsNoopAssertor, so the value wasnever compared. The line only required that a tag with that key exists at that position, and
"null"satisfied it.How it is fixed
Each of the four options is written only when the request carries it, which is what the non-streaming interceptor and
the OpenTelemetry GenAI conventions both do. The expected tag is removed with it, because
SegmentAssert.tagsEqualscompares the two tag lists by size and position: the expected list now has 17 entries, so a
gen_ai.request.top_kthat comes back fails the scenario instead of passing silently.
Verification
bash test/plugin/run.sh --debug spring-ai-1.x-scenarioon both supported versions:Tag lists of
Spring-ai/openai/streamfromworkspace/spring-ai-1.x-scenario/1.1.1/data/actualData.yaml, before andafter the change:
tags: - {key: gen_ai.operation.name, value: chat} - {key: gen_ai.provider.name, value: openai} - {key: gen_ai.request.model, value: gpt-4.1-2025-04-14} - {key: gen_ai.request.temperature, value: '0.7'} - - {key: gen_ai.request.top_k, value: 'null'} - {key: gen_ai.request.top_p, value: '0.9'} - {key: gen_ai.request.max_tokens, value: '1000'} - {key: gen_ai.request.frequency_penalty, value: '0.5'} - {key: gen_ai.request.presence_penalty, value: '0.3'}No
value: 'null'is left in eitheractualData.yaml.