-
-
Notifications
You must be signed in to change notification settings - Fork 591
Add Langfuse diagnostics and GiteeAI plugin #1196
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?
Conversation
System.Diagnostics combined with Microsoft.Extensions.Telemetry integrated into Langfuse via OpenTelemetry (OTEL)
Removed the BotSharp.Langfuse project and related files, migrating LangfuseSettings to BotSharp.ServiceDefaults. Added the BotSharp.Plugin.GiteeAI plugin with chat and embedding providers. Enhanced OpenTelemetry integration with Langfuse support and improved diagnostics tagging in core executors and controllers. Updated solution and project files to reflect these changes.
Replaces previous GPT-4.1 model entries with updated GPT-3.5-turbo and gpt-35-turbo-instruct configurations, including new endpoints, versioning, and cost structure. Sensitive API keys have been removed from the configuration.
Introduced OpenTelemetry-based model diagnostics with Langfuse integration, including new helper classes and activity tracing for agent and function execution. Added BotSharp.Plugin.GiteeAI with chat and embedding providers, and updated solution/project files to register the new plugin. Enhanced tracing in routing, executor, and controller logic for improved observability.
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
|||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||||||||||||
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.
Should this class be moved to the implementation project of BotSharp.Plugin.GiteeAI?
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.
this class is otel semantic conventions https://github.com/open-telemetry/semantic-conventions
Replaces previous GPT-4.1 model entries with updated GPT-3.5-turbo and gpt-35-turbo-instruct configurations, including new endpoints, versioning, and cost structure. Sensitive API keys have been removed from the configuration.
merge latest code
Langfuse
merge latest code
feat: add chatcompletion activity
High-Level Objectives
Architectural EvolutionPreviously, Langfuse integration appears to have been isolated (e.g., via a specialized diagnostics project). This PR consolidates diagnostic responsibilities into:
Core Added / Modified ComponentsDiagnostics & Tracing Foundation
Routing & Execution Instrumentation
Controller Layer
Provider EnhancementsInstrumentation added (or refactored) to:
GiteeAI Plugin Infrastructure
Configuration & Settings
Documentation
Formatting / Minor Adjustments
Mermaid Diagram Walkthrough1. High-Level Data & Trace Flowflowchart LR
Request["HTTP Request /conversation"] --> CC["ConversationController"]
CC --> RT["RoutingService"]
RT --> AGT["Agent Selection"]
AGT --> DEC{"Dispatch"}
DEC --> CHAT["ChatCompletion Provider (Azure/OpenAI/GiteeAI)"]
DEC --> FUNC["FunctionCallbackExecutor"]
DEC --> MCP["MCPToolExecutor"]
CHAT --> DIAG["ModelDiagnostics"]
FUNC --> DIAG
MCP --> DIAG
DIAG --> OTEL["OpenTelemetry ActivitySource"]
OTEL --> LANG["Langfuse Exporter"]
OTEL --> OTHER["Other OTEL Exporters (e.g., Console, OTLP)"]
2. Detailed Sequence (Conversation -> Agent -> Provider -> Trace)sequenceDiagram
participant User
participant Controller as ConversationController
participant Router as RoutingService
participant Agent as Agent/Policy
participant Provider as Model Provider (Azure/OpenAI/GiteeAI)
participant Exec as Function/MCP Executor
participant Diag as ModelDiagnostics
participant OTel as OpenTelemetry
participant Lang as Langfuse
User->>Controller: Chat/Task request
Controller->>Diag: Start root Activity (request span)
Controller->>Router: Route(message, context)
Router->>Agent: Evaluate agent(s)
Agent-->>Router: Selected agent + strategy
Router->>Diag: Start agent invocation span
Router->>Provider: Generate response (chat or embedding)
Provider->>Diag: Start model operation span
Provider-->>Diag: Emit attributes (model, tokens, latency, etc.)
Diag->>OTel: Activity emission
OTel->>Lang: Export spans (Langfuse sink)
alt Needs tool/function
Router->>Exec: Invoke function/MCP tool
Exec->>Diag: Start tool execution span
Exec-->>Diag: Output / error metadata
end
Provider-->>Router: Response
Router-->>Controller: Aggregated result
Controller-->>User: Final structured reply
File Walkthrough (Categorized)Configuration & Bootstrapping
Diagnostics Core
Routing & Execution
Providers
Documentation
Miscellaneous
Observability & Semantic ConventionsThe tracing layer appears to align with emerging GenAI semantic conventions:
Commit-Level Summary (Conceptual)While individual commit messages were not visible in the retrieved data, the 26 commits likely progressed through:
Key Benefits
|
| <PackageVersion Include="NCrontab" Version="3.3.3" /> | ||
| <PackageVersion Include="Azure.AI.OpenAI" Version="2.5.0-beta.1" /> | ||
| <PackageVersion Include="OpenAI" Version="2.6.0" /> | ||
| <PackageVersion Include="OpenAI" Version="2.5.0" /> |
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.
OpenAI怎么降级了?
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.
2.6.0 和 Azure.AI.OpenAI 2.5.0 冲突,有序列化 bug,要等Azure.AI.OpenAI 修复 53986
| RoleDialogModel responseMessage; | ||
|
|
||
| if (response.StopReason == "tool_use") | ||
| using (var activity = _telemetryService.StartCompletionActivity(null, _model, Provider, conversations, convService)) |
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.
如果不打开tracing,这块会影响执行效率吗
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.
不会对执行效率产生显著影响。即使 tracing 没有打开,OpenTelemetry 的设计也能保证很低的性能开销。
当 tracing 被禁用时,OpenTelemetry 会返回 "空活动" 或 "无操作活动":
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.
这个不影响效率的,这个是用的.NET 的Activity Source。
| RoleDialogModel responseMessage; | ||
|
|
||
| try | ||
| using (var activity = _telemetryService.StartCompletionActivity(null, _model, Provider, conversations, convService)) |
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.
不要硬编码进去,建议使用AOP来实现
在python 中已经有opentelemetry-instrumentation-openai的包,采用如下方式来实现会比较好一些
services.AddOpenTelemetry()
.WithTracing(tracing => tracing
.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation()
.AddRedisInstrumentation()
.AddMongoDBInstrumentation()
.AddMySqlDataInstrumentation()
.AddOtlpExporter())
.WithMetrics(metrics => metrics
.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation()
.AddRedisInstrumentation()
.AddMongoDBInstrumentation()
.AddMySqlDataInstrumentation()
.AddOtlpExporter());
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.
这个是用的.NET 的Activity Source ,Activity 是 .NET 中用于表示单个操作(如 HTTP 请求或数据库调用)的类,对应 OpenTelemetry 中的 Span 概念,他和Python的不一样。 这个在semantic kernel 和 microsoft agent framework 都是用这个实现的,他是从 Activity 到 OpenTelemetry 。
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.
OpenTelemetry(OTEL)的Semantic Conventions(语义约定)是一套标准化的属性命名规范,用于统一描述分布式系统中的监控数据(如 Traces、Metrics、Logs),确保不同工具生成的遥测数据具有一致的语义结构,从而提升可观测性系统的互操作性与分析效率。
https://github.com/open-telemetry/semantic-conventions
https://github.com/open-telemetry/semantic-conventions/tree/main/docs/gen-ai
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.
AOP来处理的是OpenTelemetry ,telemetryService 实现的是语义合约,并不是硬编码 ,具体参考semantic kernel的设计 https://github.com/microsoft/semantic-kernel/blob/main/docs/decisions/0044-OTel-semantic-convention.md
…harp into semantic-convention


User description
Introduced OpenTelemetry-based model diagnostics with Langfuse integration, including new helper classes and activity tracing for agent and function execution. Added BotSharp.Plugin.GiteeAI with chat and embedding providers, and updated solution/project files to register the new plugin. Enhanced tracing in routing, executor, and controller logic for improved observability.
PR Type
Enhancement, Documentation
Description
Implemented OpenTelemetry-based model diagnostics with Langfuse integration for improved observability
Added GiteeAI plugin with chat completion and text embedding providers
Enhanced tracing in routing, executor, and controller logic for agent and function execution
Integrated activity tracking with semantic conventions for GenAI operations
Diagram Walkthrough
File Walkthrough
6 files
Configure OpenTelemetry with Langfuse exporterCreate GiteeAI plugin project fileRegister GiteeAI plugin in solutionAdd GiteeAI plugin project referenceAdd Langfuse and GiteeAI model configurationsComment out MCP service configuration17 files
Add Langfuse configuration settings modelImplement model diagnostics with semantic conventionsAdd activity extension methods for tracingHelper to read app context switch valuesAdd activity tracing to function executionAdd activity tracing to MCP tool executionAdd agent invocation activity tracingImport diagnostics for function invocationAdd System.Diagnostics import for tracingAdd activity tracing to conversation endpointsIntegrate model diagnostics into chat completionIntegrate model diagnostics into chat completionCreate GiteeAI plugin with DI registrationImplement GiteeAI chat completion providerImplement GiteeAI text embedding providerAdd helper to create GiteeAI client instancesAdd global using statements for GiteeAI plugin1 files
Add GiteeAI plugin documentation1 files
Reorder using statements for clarity