Skip to content

Record gen_ai.request.max_tokens, frequency_penalty and presence_penalty in the spring-ai-1.x plugin - #853

Merged
wu-sheng merged 1 commit into
apache:mainfrom
1chengfengyu:spring-ai-genai-request-params
Dec 3, 2026
Merged

wu-sheng merged 1 commit into
apache:mainfrom
1chengfengyu:spring-ai-genai-request-params

Conversation

@1chengfengyu

Copy link
Copy Markdown
Contributor

The OpenTelemetry GenAI semantic conventions list gen_ai.request.max_tokens, gen_ai.request.frequency_penalty and gen_ai.request.presence_penalty as recommended attributes of the client inference span. The ChatOptions of a Spring AI request carries all three, but the plugin recorded only the model name and the sampling settings (temperature, top_k, top_p).

Tags gets GEN_AI_REQUEST_MAX_TOKENS, GEN_AI_REQUEST_FREQUENCY_PENALTY and GEN_AI_REQUEST_PRESENCE_PENALTY, and both ChatModelCallInterceptor and ChatModelStreamInterceptor set them after GEN_AI_TOP_P. The three are optional in ChatOptions, so each is guarded by a null check: an option the caller left unset leaves no tag on the span, instead of writing the string null as the value.

The spring-ai-1.x-scenario sets frequency-penalty and presence-penalty so that the values differ from the defaults, and asserts the three tags on the two call spans and on the stream span.

gen_ai.request.stop_sequences is left out. The conventions type it as a string array while a span tag holds one string, so the format of the join needs a decision first.

Verified with bash test/plugin/run.sh spring-ai-1.x-scenario: spring-ai-1.x-scenario-1.0.1 and spring-ai-1.x-scenario-1.1.1 both passed.

…lty in the spring-ai-1.x plugin

The OpenTelemetry GenAI semantic conventions list gen_ai.request.max_tokens,
gen_ai.request.frequency_penalty and gen_ai.request.presence_penalty as recommended attributes of
the client inference span. The ChatOptions of a Spring AI request carries all three, but the plugin
recorded only the model name and the sampling settings (temperature, top_k, top_p).

Tags gets GEN_AI_REQUEST_MAX_TOKENS, GEN_AI_REQUEST_FREQUENCY_PENALTY and
GEN_AI_REQUEST_PRESENCE_PENALTY, and both ChatModelCallInterceptor and ChatModelStreamInterceptor
set them after GEN_AI_TOP_P. The three are optional in ChatOptions, so each is guarded by a null
check: an option the caller left unset leaves no tag on the span, instead of writing the string
null as the value.

gen_ai.request.stop_sequences is left out. The conventions type it as a string array while a span
tag holds one string, so the format of the join needs a decision first.
@wu-sheng
wu-sheng requested a review from peachisai December 2, 2026 14:47
@wu-sheng wu-sheng added this to the 9.9.0 milestone Dec 3, 2026
@wu-sheng
wu-sheng merged commit 6974276 into apache:main Dec 3, 2026
223 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants