use std::{pin::Pin, task::Poll};
use futures::Stream;
#[doc(hidden)]
#[non_exhaustive]
pub struct QueryTelemetryStream<S> {
inner: Pin<Box<S>>,
span: tracing::Span,
}
impl<S> Stream for QueryTelemetryStream<S>
where
S: Stream,
{
type Item = S::Item;
fn poll_next(
self: Pin<&mut Self>,
context: &mut std::task::Context<'_>,
) -> Poll<Option<Self::Item>> {
let this = self.get_mut();
let _guard = this.span.enter();
this.inner.as_mut().poll_next(context)
}
}
#[doc(hidden)]
pub fn instrument_query_stream<S>(
stream: S,
model: &'static str,
table: &'static str,
operation: &'static str,
) -> QueryTelemetryStream<S>
where
S: Stream,
{
QueryTelemetryStream {
inner: Box::pin(stream),
span: tracing::info_span!(
target: "rullst_orm",
"rullst.orm.query",
orm.model = model,
orm.table = table,
orm.operation = operation,
),
}
}