diff --git a/CHANGES.md b/CHANGES.md index 5916165bd5..bbd0b768ed 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -37,6 +37,11 @@ Release Notes. carry macOS extended attributes, which made GNU tar print `Ignoring unknown extended header keyword 'LIBARCHIVE.xattr.com.apple.provenance'` for every entry (apache/skywalking#14271). +* Report the time to first token of a streaming call of the `spring-ai-1.x` plugin in the + `gen_ai.response.time_to_first_chunk` tag, in seconds, the span attribute the OpenTelemetry GenAI semantic conventions + define for it, instead of in `gen_ai.server.time_to_first_token`, in milliseconds, a name the conventions give to a + metric. `Tags.GEN_AI_SERVER_TIME_TO_FIRST_TOKEN` is renamed to `Tags.GEN_AI_RESPONSE_TIME_TO_FIRST_CHUNK`. An OAP that + reads only the previous tag shows no time to first token for the calls this agent traces. All issues and pull requests are [here](https://github.com/apache/skywalking/milestone/267?closed=1) diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/tag/Tags.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/tag/Tags.java index 8acb2b9879..6deea4011d 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/tag/Tags.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/tag/Tags.java @@ -236,9 +236,10 @@ public static final class HTTP { public static final StringTag GEN_AI_RESPONSE_FINISH_REASONS = new StringTag(39, "gen_ai.response.finish_reasons"); /** - * GEN_AI_STREAM_TTFR represents the time to first response (TTFR) for streaming operations. + * GEN_AI_RESPONSE_TIME_TO_FIRST_CHUNK represents the time from the start of the call to the first chunk of a + * streaming response, in seconds. */ - public static final StringTag GEN_AI_SERVER_TIME_TO_FIRST_TOKEN = new StringTag(40, "gen_ai.server.time_to_first_token"); + public static final StringTag GEN_AI_RESPONSE_TIME_TO_FIRST_CHUNK = new StringTag(40, "gen_ai.response.time_to_first_chunk"); /** * GEN_AI_INPUT_MESSAGES represents the chat history provided to the model as an input. diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-ai-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/ai/v1/ChatModelStreamInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-ai-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/ai/v1/ChatModelStreamInterceptor.java index 981c90f74b..f1d1a99898 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-ai-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/ai/v1/ChatModelStreamInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-ai-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/ai/v1/ChatModelStreamInterceptor.java @@ -161,7 +161,8 @@ private void recordTtfrIfFirstToken(AbstractSpan span, Generation generation, St return; } if (state.firstResponseReceived.compareAndSet(false, true)) { - Tags.GEN_AI_SERVER_TIME_TO_FIRST_TOKEN.set(span, String.valueOf(System.currentTimeMillis() - state.startTime)); + Tags.GEN_AI_RESPONSE_TIME_TO_FIRST_CHUNK.set( + span, String.valueOf((System.currentTimeMillis() - state.startTime) / 1000.0)); } } diff --git a/test/plugin/scenarios/spring-ai-1.x-scenario/config/expectedData.yaml b/test/plugin/scenarios/spring-ai-1.x-scenario/config/expectedData.yaml index d714ae2542..8a9f4e4a76 100644 --- a/test/plugin/scenarios/spring-ai-1.x-scenario/config/expectedData.yaml +++ b/test/plugin/scenarios/spring-ai-1.x-scenario/config/expectedData.yaml @@ -116,7 +116,7 @@ segmentItems: - { 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.server.time_to_first_token, value: not null } + - { key: gen_ai.response.time_to_first_chunk, value: not null } - { key: gen_ai.response.id, value: 'chatcmpl-fc1b64d3' } - { key: gen_ai.response.model, value: gpt-4.1-2025-04-14 } - { key: gen_ai.response.finish_reasons, value: STOP }