-
Notifications
You must be signed in to change notification settings - Fork 549
Open
Description
Summary
The SpanExporter
trait should be redesigned to use immutable references (&self
) for methods that don't need to mutate state, similar to how LogExporter
is already correctly implemented. This would remove the need for RwLock<E>
wrappers and simplify the API.
Background
As discussed here - #3028 (comment), Currently, the SpanExporter trait requires &mut self for several methods, forcing batch processors to wrap exporters in RwLock for concurrent access:
Current SpanExporter (problematic):
pub trait SpanExporter: Send + Sync + Debug {
fn export(&self, batch: Vec<SpanData>) -> impl Future<Output = OTelSdkResult> + Send;
fn shutdown_with_timeout(&mut self, _timeout: Duration) -> OTelSdkResult; // ❌ &mut self
fn shutdown(&mut self) -> OTelSdkResult; // ❌ &mut self
fn force_flush(&mut self) -> OTelSdkResult; // ❌ &mut self
fn set_resource(&mut self, _resource: &Resource); // ❌ &mut self
}
LogExporter (correctly implemented):
pub trait LogExporter: Send + Sync + Debug {
fn export(&self, batch: LogBatch<'_>) -> impl Future<Output = OTelSdkResult> + Send;
fn shutdown_with_timeout(&self, _timeout: Duration) -> OTelSdkResult; // ✅ &self
fn shutdown(&self) -> OTelSdkResult; // ✅ &self
fn set_resource(&mut self, _resource: &Resource); // Only this uses &mut
}
Proposed Solution:
Redesign SpanExporter to match LogExporter's pattern. And also modify the span processors to use exporters without wrapping in RwLock for concurrent access.
Also the core exporters implementation should also be modified to handle mutable state properly if needed.
cijothomasCopilot