fix(common): re-enable observability module and fix type errors
Fix three compilation errors in the observability module that had been commented out due to type errors with tracing_subscriber: - Fix lifetime issue in set_correlation_id by cloning Arc before async - Fix Option<CorrelationId> vs CorrelationId type mismatch in get_correlation_id - Update deprecated opentelemetry_sdk::trace::Config API to builder methods - Remove unused imports across all observability submodules Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -11690,6 +11690,7 @@ dependencies = [
|
||||
"lazy_static",
|
||||
"nom",
|
||||
"oid-registry",
|
||||
"ring",
|
||||
"rusticata-macros",
|
||||
"thiserror 1.0.69",
|
||||
"time",
|
||||
|
||||
@@ -31,8 +31,7 @@ pub mod features; // Wave D: Shared feature extraction (225 features)
|
||||
pub mod market_data;
|
||||
pub mod metrics; // Wave 5: Prometheus metrics infrastructure (W5-3)
|
||||
pub mod ml_strategy;
|
||||
// TODO: Fix observability module - type errors with tracing_subscriber
|
||||
// pub mod observability; // Wave 5: Structured logging and observability
|
||||
pub mod observability; // Wave 5: Structured logging and observability
|
||||
pub mod regime_persistence;
|
||||
pub mod resilience; // Wave 5: Circuit breaker and retry patterns
|
||||
pub mod thresholds;
|
||||
@@ -103,17 +102,16 @@ pub use resilience::{
|
||||
RetryError,
|
||||
};
|
||||
|
||||
// TODO: Re-enable when observability module is fixed
|
||||
// Re-export observability infrastructure (Wave 5: Structured logging and observability)
|
||||
// pub use crate::observability::{
|
||||
// init_observability,
|
||||
// CorrelationId,
|
||||
// CorrelationIdExt,
|
||||
// JsonLoggerConfig,
|
||||
// LogLevel,
|
||||
// TracingConfig,
|
||||
// CORRELATION_ID_HEADER,
|
||||
// };
|
||||
pub use crate::observability::{
|
||||
init_observability,
|
||||
CorrelationId,
|
||||
CorrelationIdExt,
|
||||
JsonLoggerConfig,
|
||||
LogLevel,
|
||||
TracingConfig,
|
||||
CORRELATION_ID_HEADER,
|
||||
};
|
||||
|
||||
// Test utilities module (available for all tests)
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -33,10 +33,10 @@ use uuid::Uuid;
|
||||
/// The gRPC metadata header key for correlation IDs.
|
||||
pub const CORRELATION_ID_HEADER: &str = "x-correlation-id";
|
||||
|
||||
/// Thread-local storage for the current correlation ID.
|
||||
///
|
||||
/// This allows correlation IDs to be automatically available in any function
|
||||
/// within the current async task context without explicit parameter passing.
|
||||
// Thread-local storage for the current correlation ID.
|
||||
//
|
||||
// This allows correlation IDs to be automatically available in any function
|
||||
// within the current async task context without explicit parameter passing.
|
||||
tokio::task_local! {
|
||||
pub static CURRENT_CORRELATION_ID: Arc<RwLock<Option<CorrelationId>>>;
|
||||
}
|
||||
@@ -231,14 +231,13 @@ impl CorrelationIdExt for tonic::metadata::MetadataMap {
|
||||
/// }
|
||||
/// ```
|
||||
pub async fn set_correlation_id(correlation_id: CorrelationId) {
|
||||
CURRENT_CORRELATION_ID
|
||||
.try_with(|id| -> std::pin::Pin<Box<dyn std::future::Future<Output = ()> + '_>> {
|
||||
Box::pin(async move {
|
||||
let mut guard = id.write().await;
|
||||
*guard = Some(correlation_id);
|
||||
})
|
||||
})
|
||||
let maybe_lock = CURRENT_CORRELATION_ID
|
||||
.try_with(|id| Arc::clone(id))
|
||||
.ok();
|
||||
if let Some(lock) = maybe_lock {
|
||||
let mut guard = lock.write().await;
|
||||
*guard = Some(correlation_id);
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the current correlation ID from the async task context.
|
||||
@@ -261,15 +260,11 @@ pub async fn set_correlation_id(correlation_id: CorrelationId) {
|
||||
/// }
|
||||
/// ```
|
||||
pub async fn get_correlation_id() -> Option<CorrelationId> {
|
||||
CURRENT_CORRELATION_ID
|
||||
.try_with(|id| -> std::pin::Pin<Box<dyn std::future::Future<Output = CorrelationId> + Send + '_>> {
|
||||
Box::pin(async move {
|
||||
let guard = id.read().await;
|
||||
guard.clone()
|
||||
})
|
||||
})
|
||||
.ok()?
|
||||
.await
|
||||
let lock = CURRENT_CORRELATION_ID
|
||||
.try_with(|id| Arc::clone(id))
|
||||
.ok()?;
|
||||
let guard = lock.read().await;
|
||||
guard.clone()
|
||||
}
|
||||
|
||||
/// Create a new metadata map with the correlation ID header set.
|
||||
|
||||
@@ -30,15 +30,11 @@
|
||||
//! ```
|
||||
|
||||
use crate::error::{CommonError, CommonResult};
|
||||
use serde_json::json;
|
||||
use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
use tracing::{Level, Subscriber};
|
||||
use tracing::Level;
|
||||
use tracing_subscriber::{
|
||||
fmt::Layer as FmtLayer,
|
||||
layer::SubscriberExt,
|
||||
registry::LookupSpan,
|
||||
EnvFilter, Layer, Registry,
|
||||
EnvFilter, Registry,
|
||||
};
|
||||
|
||||
/// Log rotation strategy.
|
||||
|
||||
@@ -75,7 +75,7 @@ pub use correlation::{CorrelationId, CorrelationIdExt, CORRELATION_ID_HEADER};
|
||||
pub use logger::{init_json_logger, JsonLoggerConfig, LogLevel};
|
||||
pub use tracing_config::{init_tracing, TracingConfig};
|
||||
|
||||
use crate::error::{CommonError, CommonResult};
|
||||
use crate::error::CommonResult;
|
||||
|
||||
/// Initialize the complete observability stack for a service.
|
||||
///
|
||||
|
||||
@@ -19,14 +19,12 @@
|
||||
//! across multiple services. Trace context is propagated via gRPC metadata
|
||||
//! using the W3C Trace Context specification.
|
||||
|
||||
use crate::error::{CommonError, CommonResult};
|
||||
use crate::error::CommonResult;
|
||||
use opentelemetry::{global, KeyValue};
|
||||
use opentelemetry_sdk::{
|
||||
trace::{Sampler, TracerProvider},
|
||||
Resource,
|
||||
};
|
||||
use tracing::Subscriber;
|
||||
use tracing_subscriber::{layer::SubscriberExt, registry::LookupSpan, EnvFilter, Layer, Registry};
|
||||
|
||||
/// Configuration for OpenTelemetry tracing.
|
||||
///
|
||||
@@ -99,14 +97,11 @@ pub async fn init_tracing(config: TracingConfig) -> CommonResult<()> {
|
||||
|
||||
// Create a basic tracer provider with console export for development
|
||||
let provider = TracerProvider::builder()
|
||||
.with_config(
|
||||
opentelemetry_sdk::trace::Config::default()
|
||||
.with_sampler(Sampler::AlwaysOn)
|
||||
.with_resource(Resource::new(vec![
|
||||
KeyValue::new("service.name", config.service_name.clone()),
|
||||
KeyValue::new("service.version", env!("CARGO_PKG_VERSION")),
|
||||
])),
|
||||
)
|
||||
.with_sampler(Sampler::AlwaysOn)
|
||||
.with_resource(Resource::new(vec![
|
||||
KeyValue::new("service.name", config.service_name.clone()),
|
||||
KeyValue::new("service.version", env!("CARGO_PKG_VERSION")),
|
||||
]))
|
||||
.build();
|
||||
|
||||
// Set as global tracer provider
|
||||
|
||||
Reference in New Issue
Block a user