Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions instrumented-object-store/src/instrumented_object_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,28 @@ pub fn instrument_object_store(

/// A wrapper around an `ObjectStore` that instruments all public methods with tracing.
#[derive(Clone, Debug)]
struct InstrumentedObjectStore {
inner: Arc<dyn ObjectStore>,
pub struct InstrumentedObjectStore<T: ObjectStore> {
inner: T,
name: String,
}

impl InstrumentedObjectStore {
impl<T: ObjectStore> InstrumentedObjectStore<T> {
/// Creates a new `InstrumentedObjectStore` wrapping the provided `ObjectStore`.
///
/// # Arguments
///
/// * `store` - An `Arc`-wrapped `dyn ObjectStore` to be instrumented.
pub fn new(store: Arc<dyn ObjectStore>, name: &str) -> Self {
/// * `store` - An `ObjectStore` to be instrumented.
pub fn new(store: T, name: impl Into<String>) -> Self {
Self {
inner: store,
name: name.to_owned(),
name: name.into(),
}
}

/// Returns a reference to the inner `ObjectStore`.
pub fn inner(&self) -> &T {
&self.inner
}
}

trait Instrumentable {
Expand Down Expand Up @@ -128,14 +133,14 @@ where
result
}

impl Display for InstrumentedObjectStore {
impl<T: ObjectStore> Display for InstrumentedObjectStore<T> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
Display::fmt(&self.inner, f)
}
}

#[async_trait]
impl ObjectStore for InstrumentedObjectStore {
impl<T: ObjectStore> ObjectStore for InstrumentedObjectStore<T> {
/// Save the provided bytes to the specified location with tracing.
#[instrument(
skip_all,
Expand Down
2 changes: 1 addition & 1 deletion instrumented-object-store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@

mod instrumented_object_store;

pub use instrumented_object_store::instrument_object_store;
pub use instrumented_object_store::{instrument_object_store, InstrumentedObjectStore};