-
Notifications
You must be signed in to change notification settings - Fork 46
Prototype OpenTelemetry Traces in MCP Server #274
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
Changes from 4 commits
9fb0c95
967ef38
08f6dcf
9ce28d3
7f2ee83
b0542bf
86a38e0
b6166d2
ec0fef4
9478d0c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
DaleSeo marked this conversation as resolved.
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,109 @@ | ||||||||||
| use opentelemetry::{KeyValue, global, trace::TracerProvider as _}; | ||||||||||
| use opentelemetry_sdk::{ | ||||||||||
| Resource, | ||||||||||
| metrics::{MeterProviderBuilder, PeriodicReader, SdkMeterProvider}, | ||||||||||
| trace::{RandomIdGenerator, SdkTracerProvider}, | ||||||||||
| }; | ||||||||||
| use opentelemetry_semantic_conventions::{ | ||||||||||
| SCHEMA_URL, | ||||||||||
| attribute::{DEPLOYMENT_ENVIRONMENT_NAME, SERVICE_VERSION}, | ||||||||||
| }; | ||||||||||
| use tracing_opentelemetry::{MetricsLayer, OpenTelemetryLayer}; | ||||||||||
| use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; | ||||||||||
|
|
||||||||||
| use crate::runtime::{Config, logging::Logging}; | ||||||||||
DaleSeo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||
|
|
||||||||||
| // Create a Resource that captures information about the entity for which telemetry is recorded. | ||||||||||
| fn resource() -> Resource { | ||||||||||
| Resource::builder() | ||||||||||
| .with_service_name(env!("CARGO_PKG_NAME")) | ||||||||||
|
||||||||||
| .with_service_name(env!("CARGO_PKG_NAME")) | |
| fn resource(service_name: &str) -> Resource { | |
| Resource::builder() | |
| .with_service_name(service_name) |
swcollard marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
swcollard marked this conversation as resolved.
Show resolved
Hide resolved
DaleSeo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
Copilot
AI
Aug 20, 2025
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.
The logging setup logic is split between this module and the Logging module, creating tight coupling. Consider consolidating all tracing setup logic in one place or making the dependency more explicit through better separation of concerns.
| let (logging_layer, logging_guard) = Logging::logging_layer(config)?; | |
| let env_filter = build_env_filter(config)?; | |
| let (logging_layer, logging_guard) = build_logging_layer(config)?; |
DaleSeo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
Copilot
AI
Aug 20, 2025
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.
Taking the logging_guard without dropping it explicitly may not properly clean up the logging worker. The guard should be allowed to drop naturally or explicitly dropped to ensure proper cleanup.
| self.logging_guard.take(); | |
| drop(self.logging_guard.take()); |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3,6 +3,8 @@ use std::sync::Arc; | |||||
|
|
||||||
| use apollo_compiler::{Schema, validation::Valid}; | ||||||
| use headers::HeaderMapExt as _; | ||||||
| use opentelemetry::Context; | ||||||
| use opentelemetry::trace::FutureExt; | ||||||
| use reqwest::header::HeaderMap; | ||||||
| use rmcp::model::Implementation; | ||||||
| use rmcp::{ | ||||||
|
|
@@ -169,6 +171,7 @@ impl Running { | |||||
| } | ||||||
|
|
||||||
| impl ServerHandler for Running { | ||||||
| #[tracing::instrument(skip(self))] | ||||||
| async fn initialize( | ||||||
| &self, | ||||||
| _request: InitializeRequestParam, | ||||||
|
|
@@ -180,6 +183,7 @@ impl ServerHandler for Running { | |||||
| Ok(self.get_info()) | ||||||
| } | ||||||
|
|
||||||
| #[tracing::instrument(skip(self, context), fields(tool_name = request.name.as_ref(), request_id = %context.id.clone()))] | ||||||
|
||||||
| #[tracing::instrument(skip(self, context), fields(tool_name = request.name.as_ref(), request_id = %context.id.clone()))] | |
| #[tracing::instrument(skip(self, context), fields(tool_name = request.name.as_ref(), request_id = %context.id))] |
Uh oh!
There was an error while loading. Please reload this page.