From f05fc904aa9e9292200d16ef266e3c0a847b02a4 Mon Sep 17 00:00:00 2001 From: peachisai <2581009893@qq.com> Date: Tue, 17 Mar 2026 09:17:54 +0800 Subject: [PATCH 1/4] fix the tag key of ttfr to align with OTLP semantic --- .../org/apache/skywalking/apm/agent/core/context/tag/Tags.java | 2 +- .../apm/plugin/spring/ai/v1/ChatModelStreamInterceptor.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 995b91f582..3f2fe78835 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 @@ -238,7 +238,7 @@ public static final class HTTP { /** * GEN_AI_STREAM_TTFR represents the time to first response (TTFR) for streaming operations. */ - public static final StringTag GEN_AI_STREAM_TTFR = new StringTag(40, "gen_ai.stream.ttfr"); + public static final StringTag GEN_AI_STREAM_TIME_TO_FIRST_TOKEN = new StringTag(40, "gen_ai.server.time_to_first_token"); /** * 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 e0c11c32ec..98020bf05d 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 @@ -150,7 +150,7 @@ private void recordTtfrIfFirstToken(AbstractSpan span, Generation generation, St return; } if (state.firstResponseReceived.compareAndSet(false, true)) { - Tags.GEN_AI_STREAM_TTFR.set(span, String.valueOf(System.currentTimeMillis() - state.startTime)); + Tags.GEN_AI_STREAM_TIME_TO_FIRST_TOKEN.set(span, String.valueOf(System.currentTimeMillis() - state.startTime)); } } From 0404604a534431fd2e3d301b514af171e2a50fc3 Mon Sep 17 00:00:00 2001 From: peachisai <2581009893@qq.com> Date: Tue, 17 Mar 2026 12:36:47 +0800 Subject: [PATCH 2/4] fix the tag sequence --- .../apache/skywalking/apm/agent/core/context/tag/Tags.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 3f2fe78835..cd1d2711fe 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 @@ -243,12 +243,12 @@ public static final class HTTP { /** * GEN_AI_INPUT_MESSAGES represents the chat history provided to the model as an input. */ - public static final StringTag GEN_AI_INPUT_MESSAGES = new StringTag(44, "gen_ai.input.messages"); + public static final StringTag GEN_AI_INPUT_MESSAGES = new StringTag(41, "gen_ai.input.messages"); /** * GEN_AI_OUTPUT_MESSAGES represents the messages returned by the model where each message represents a specific model response (choice, candidate). */ - public static final StringTag GEN_AI_OUTPUT_MESSAGES = new StringTag(45, "gen_ai.output.messages"); + public static final StringTag GEN_AI_OUTPUT_MESSAGES = new StringTag(42, "gen_ai.output.messages"); /** * Creates a {@code StringTag} with the given key and cache it, if it's created before, simply return it without From 47a24bcab94ed0546ea124f61b73c6abdb888493 Mon Sep 17 00:00:00 2001 From: peachisai <2581009893@qq.com> Date: Tue, 17 Mar 2026 12:48:54 +0800 Subject: [PATCH 3/4] fix --- .../org/apache/skywalking/apm/agent/core/context/tag/Tags.java | 2 +- .../apm/plugin/spring/ai/v1/ChatModelStreamInterceptor.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 cd1d2711fe..3d0b9f37cb 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 @@ -238,7 +238,7 @@ public static final class HTTP { /** * GEN_AI_STREAM_TTFR represents the time to first response (TTFR) for streaming operations. */ - public static final StringTag GEN_AI_STREAM_TIME_TO_FIRST_TOKEN = new StringTag(40, "gen_ai.server.time_to_first_token"); + public static final StringTag GEN_AI_SERVER_TIME_TO_FIRST_TOKEN = new StringTag(40, "gen_ai.server.time_to_first_token"); /** * 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 98020bf05d..1674e82011 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 @@ -150,7 +150,7 @@ private void recordTtfrIfFirstToken(AbstractSpan span, Generation generation, St return; } if (state.firstResponseReceived.compareAndSet(false, true)) { - Tags.GEN_AI_STREAM_TIME_TO_FIRST_TOKEN.set(span, String.valueOf(System.currentTimeMillis() - state.startTime)); + Tags.GEN_AI_SERVER_TIME_TO_FIRST_TOKEN.set(span, String.valueOf(System.currentTimeMillis() - state.startTime)); } } From 61ea51aeb02b9fdc9dd906665bbe07498ca8ba27 Mon Sep 17 00:00:00 2001 From: peachisai <2581009893@qq.com> Date: Tue, 17 Mar 2026 19:54:58 +0800 Subject: [PATCH 4/4] fix --- .../scenarios/spring-ai-1.x-scenario/config/expectedData.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 161eb6e2f2..5f40e79a48 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.stream.ttfr, value: not null } + - { key: gen_ai.server.time_to_first_token, 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 }