-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Support Virtual-GenAI monitoring #13745
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 4 commits
e29c3a9
3642ce3
37708a2
0de57e7
45d255f
f15e579
d2c2165
f417ea5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # Virtual GenAI | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need to update the demo to point to here. I think from
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not just this. menu.yml is not updated in the /docs/en |
||
|
|
||
| Virtual cache represent the Generative AI service nodes detected by [server agents' plugins](server-agents.md). The performance | ||
| metrics of the GenAI operations are also from the GenAI client-side perspective. | ||
|
|
||
| For example, an Spring-ai plugin in the Java agent could detect the latency of a chat completion request. | ||
| As a result, SkyWalking would show traffic, latency, success rate, and token usage (input/output) powered by backend analysis capabilities in this dashboard. | ||
|
|
||
| The GenAI operation span should have | ||
| - It is an **Exit** span | ||
| - **Span's layer == GENAI** | ||
| - Tag key = `gen_ai.provider.name`, value = The Generative AI provider, e.g. openai, anthropic, ollama | ||
| - Tag key = `gen_ai.response.model`, value = The name of the GenAI model a response is being made to, e.g. gpt-4o, claude-3-5-sonnet | ||
| - Tag key = `gen_ai.usage.input_tokens`, value = The number of tokens used in the GenAI input (prompt) | ||
| - Tag key = `gen_ai.usage.output_tokens`, value = The number of tokens used in the GenAI response (completion) | ||
| - If the GenAI service is a remote API (e.g. OpenAI), the span's peer would be the network address (IP or domain) of the GenAI server. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.skywalking.oap.server.analyzer.provider.trace.parser.listener.vservice; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import org.apache.skywalking.apm.network.language.agent.v3.SegmentObject; | ||
| import org.apache.skywalking.apm.network.language.agent.v3.SpanLayer; | ||
| import org.apache.skywalking.apm.network.language.agent.v3.SpanObject; | ||
| import org.apache.skywalking.oap.meter.analyzer.service.IGenAIMeterAnalyzerService; | ||
| import org.apache.skywalking.oap.server.core.analysis.Layer; | ||
| import org.apache.skywalking.oap.server.core.source.GenAIMetrics; | ||
| import org.apache.skywalking.oap.server.core.source.GenAIModelAccess; | ||
| import org.apache.skywalking.oap.server.core.source.GenAIProviderAccess; | ||
| import org.apache.skywalking.oap.server.core.source.ServiceMeta; | ||
| import org.apache.skywalking.oap.server.core.source.Source; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.function.Consumer; | ||
|
|
||
| @RequiredArgsConstructor | ||
| public class VirtualGenAIProcessor implements VirtualServiceProcessor { | ||
|
|
||
| private final IGenAIMeterAnalyzerService meterAnalyzerService; | ||
|
|
||
| private List<Source> recordList = new ArrayList<>(); | ||
|
|
||
| @Override | ||
| public void prepareVSIfNecessary(SpanObject span, SegmentObject segmentObject) { | ||
| if (span.getSpanLayer() != SpanLayer.GenAI) { | ||
| return; | ||
| } | ||
|
|
||
| GenAIMetrics metrics = meterAnalyzerService.extractMetricsFromSWSpan(span, segmentObject); | ||
| if (metrics == null) { | ||
| return; | ||
| } | ||
|
|
||
| recordList.add(toServiceMeta(metrics)); | ||
| recordList.add(toProviderAccess(metrics)); | ||
| recordList.add(toModelAccess(metrics)); | ||
| } | ||
|
|
||
| private ServiceMeta toServiceMeta(GenAIMetrics metrics) { | ||
| ServiceMeta service = new ServiceMeta(); | ||
| service.setName(metrics.getProviderName()); | ||
| service.setLayer(Layer.VIRTUAL_GENAI); | ||
| service.setTimeBucket(metrics.getTimeBucket()); | ||
| return service; | ||
| } | ||
|
|
||
| private GenAIProviderAccess toProviderAccess(GenAIMetrics metrics) { | ||
| GenAIProviderAccess source = new GenAIProviderAccess(); | ||
| source.setName(metrics.getProviderName()); | ||
| source.setInputTokens(metrics.getInputTokens()); | ||
| source.setOutputTokens(metrics.getOutputTokens()); | ||
| source.setTotalCost(metrics.getTotalCost()); | ||
| source.setLatency(metrics.getLatency()); | ||
| source.setStatus(metrics.isStatus()); | ||
| source.setTimeBucket(metrics.getTimeBucket()); | ||
| return source; | ||
| } | ||
|
|
||
| private GenAIModelAccess toModelAccess(GenAIMetrics metrics) { | ||
| GenAIModelAccess source = new GenAIModelAccess(); | ||
| source.setServiceName(metrics.getProviderName()); | ||
| source.setModelName(metrics.getModelName()); | ||
| source.setInputTokens(metrics.getInputTokens()); | ||
| source.setOutputTokens(metrics.getOutputTokens()); | ||
| source.setTotalCost(metrics.getTotalCost()); | ||
| source.setTimeToFirstToken(metrics.getTimeToFirstToken()); | ||
| source.setLatency(metrics.getLatency()); | ||
| source.setStatus(metrics.isStatus()); | ||
| source.setTimeBucket(metrics.getTimeBucket()); | ||
| return source; | ||
| } | ||
|
|
||
| @Override | ||
| public void emitTo(Consumer<Source> consumer) { | ||
| for (Source source : recordList) { | ||
| if (source != null) { | ||
| consumer.accept(source); | ||
| } | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!-- | ||
| ~ Licensed to the Apache Software Foundation (ASF) under one or more | ||
| ~ contributor license agreements. See the NOTICE file distributed with | ||
| ~ this work for additional information regarding copyright ownership. | ||
| ~ The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| ~ (the "License"); you may not use this file except in compliance with | ||
| ~ the License. You may obtain a copy of the License at | ||
| ~ | ||
| ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
| ~ | ||
| ~ Unless required by applicable law or agreed to in writing, software | ||
| ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
| ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| ~ See the License for the specific language governing permissions and | ||
| ~ limitations under the License. | ||
| ~ | ||
| --> | ||
|
|
||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <parent> | ||
| <artifactId>analyzer</artifactId> | ||
| <groupId>org.apache.skywalking</groupId> | ||
| <version>${revision}</version> | ||
| </parent> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <artifactId>genAI-analyzer</artifactId> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.apache.skywalking</groupId> | ||
| <artifactId>server-core</artifactId> | ||
| <version>${project.version}</version> | ||
| </dependency> | ||
| </dependencies> | ||
| </project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| */ | ||
|
|
||
| package org.apache.skywalking.oap.meter.analyzer; | ||
|
|
||
| import org.apache.skywalking.oap.meter.analyzer.config.GenAIConfig; | ||
| import org.apache.skywalking.oap.meter.analyzer.config.GenAIConfigLoader; | ||
| import org.apache.skywalking.oap.meter.analyzer.config.GenAIOALDefine; | ||
| import org.apache.skywalking.oap.meter.analyzer.matcher.GenAIProviderPrefixMatcher; | ||
| import org.apache.skywalking.oap.meter.analyzer.module.GenAIAnalyzerModule; | ||
| import org.apache.skywalking.oap.meter.analyzer.service.GenAIMeterAnalyzer; | ||
| import org.apache.skywalking.oap.meter.analyzer.service.IGenAIMeterAnalyzerService; | ||
| import org.apache.skywalking.oap.server.core.CoreModule; | ||
| import org.apache.skywalking.oap.server.core.oal.rt.OALEngineLoaderService; | ||
| import org.apache.skywalking.oap.server.library.module.ModuleConfig; | ||
| import org.apache.skywalking.oap.server.library.module.ModuleDefine; | ||
| import org.apache.skywalking.oap.server.library.module.ModuleProvider; | ||
| import org.apache.skywalking.oap.server.library.module.ModuleStartException; | ||
| import org.apache.skywalking.oap.server.library.module.ServiceNotProvidedException; | ||
| import org.yaml.snakeyaml.Yaml; | ||
|
|
||
| public class GenAIAnalyzerModuleProvider extends ModuleProvider { | ||
|
|
||
| private GenAIConfig config; | ||
|
|
||
| @Override | ||
| public String name() { | ||
| return "default"; | ||
| } | ||
|
|
||
| @Override | ||
| public Class<? extends ModuleDefine> module() { | ||
| return GenAIAnalyzerModule.class; | ||
| } | ||
|
|
||
| @Override | ||
| public ConfigCreator<? extends ModuleConfig> newConfigCreator() { | ||
| return new ConfigCreator<GenAIConfig>() { | ||
| @Override | ||
| public Class<GenAIConfig> type() { | ||
| return GenAIConfig.class; | ||
| } | ||
|
|
||
| @Override | ||
| public void onInitialized(final GenAIConfig initialized) { | ||
| config = initialized; | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| @Override | ||
| public void prepare() throws ServiceNotProvidedException, ModuleStartException { | ||
| GenAIConfigLoader loader = new GenAIConfigLoader(config, new Yaml()); | ||
| config = loader.loadConfig(); | ||
| GenAIProviderPrefixMatcher matcher = GenAIProviderPrefixMatcher.build(config); | ||
| this.registerServiceImplementation( | ||
| IGenAIMeterAnalyzerService.class, | ||
| new GenAIMeterAnalyzer(matcher) | ||
| ); | ||
| } | ||
|
|
||
| @Override | ||
| public void start() throws ServiceNotProvidedException, ModuleStartException { | ||
| getManager().find(CoreModule.NAME) | ||
| .provider() | ||
| .getService(OALEngineLoaderService.class) | ||
| .load(GenAIOALDefine.INSTANCE); | ||
| } | ||
|
|
||
| @Override | ||
| public void notifyAfterCompleted() throws ServiceNotProvidedException, ModuleStartException { | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public String[] requiredModules() { | ||
| return new String[0]; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| */ | ||
|
|
||
| package org.apache.skywalking.oap.meter.analyzer.config; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.Setter; | ||
| import org.apache.skywalking.oap.server.library.module.ModuleConfig; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class GenAIConfig extends ModuleConfig { | ||
|
|
||
| @Getter | ||
| @Setter | ||
| private List<Provider> providers = new ArrayList<>(); | ||
|
|
||
| @Getter | ||
| @Setter | ||
| public static class Provider { | ||
| private String provider; | ||
| private String baseUrl; | ||
| private List<String> prefixMatch = new ArrayList<>(); | ||
| private List<Model> models = new ArrayList<>(); | ||
| } | ||
|
|
||
| @Getter | ||
| @Setter | ||
| public static class Model { | ||
| private String name; | ||
| private double inputCostPerM; | ||
| private double outputCostPerM; | ||
| } | ||
| } |

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.