pub struct TracedResponse<T = Incoming> {
pub trace_id: TraceId,
pub span_id: SpanId,
/* private fields */
}
Expand description
HTTP response wrapper that includes OpenTelemetry trace information.
This struct wraps an HTTP response and provides easy access to the associated trace ID and span ID for testing and debugging purposes. It’s particularly useful in integration tests where you need to verify trace propagation.
§Example
use telemetry_rust::test::{TracedResponse, Traceparent};
async fn send_traced_request() -> TracedResponse<&'static str> {
let traceparent = Traceparent::generate();
// Send request and get response
let resp = hyper::Response::new("Hello world!");
TracedResponse::new(resp, traceparent)
}
Fields§
§trace_id: TraceId
The OpenTelemetry trace ID associated with this response
span_id: SpanId
The OpenTelemetry span ID associated with this response
Implementations§
Source§impl<T> TracedResponse<T>
impl<T> TracedResponse<T>
Sourcepub fn new(resp: Response<T>, traceparent: Traceparent) -> Self
pub fn new(resp: Response<T>, traceparent: Traceparent) -> Self
Creates a new traced response from an HTTP response and trace parent information.
§Arguments
resp
: The HTTP response to wraptraceparent
: The trace parent containing trace and span IDs
§Returns
A new TracedResponse
instance
Sourcepub async fn into_inner(self) -> Response<T>
pub async fn into_inner(self) -> Response<T>
Consumes the traced response and returns the inner HTTP response.
§Returns
The wrapped hyper::Response
instance.
Source§impl<E, T: Body<Data = Bytes, Error = E>> TracedResponse<T>
impl<E, T: Body<Data = Bytes, Error = E>> TracedResponse<T>
Sourcepub async fn into_bytes(self) -> Result<Bytes, E>
pub async fn into_bytes(self) -> Result<Bytes, E>
Consumes the response and returns the body as bytes.
§Returns
A future that resolves to the response body as bytes::Bytes
§Errors
Returns an error if the response body cannot be read
Methods from Deref<Target = Response<T>>§
Sourcepub fn status(&self) -> StatusCode
pub fn status(&self) -> StatusCode
Returns the StatusCode
.
§Examples
let response: Response<()> = Response::default();
assert_eq!(response.status(), StatusCode::OK);
Sourcepub fn status_mut(&mut self) -> &mut StatusCode
pub fn status_mut(&mut self) -> &mut StatusCode
Returns a mutable reference to the associated StatusCode
.
§Examples
let mut response: Response<()> = Response::default();
*response.status_mut() = StatusCode::CREATED;
assert_eq!(response.status(), StatusCode::CREATED);
Sourcepub fn version(&self) -> Version
pub fn version(&self) -> Version
Returns a reference to the associated version.
§Examples
let response: Response<()> = Response::default();
assert_eq!(response.version(), Version::HTTP_11);
Sourcepub fn version_mut(&mut self) -> &mut Version
pub fn version_mut(&mut self) -> &mut Version
Returns a mutable reference to the associated version.
§Examples
let mut response: Response<()> = Response::default();
*response.version_mut() = Version::HTTP_2;
assert_eq!(response.version(), Version::HTTP_2);
Sourcepub fn headers(&self) -> &HeaderMap
pub fn headers(&self) -> &HeaderMap
Returns a reference to the associated header field map.
§Examples
let response: Response<()> = Response::default();
assert!(response.headers().is_empty());
Sourcepub fn headers_mut(&mut self) -> &mut HeaderMap
pub fn headers_mut(&mut self) -> &mut HeaderMap
Returns a mutable reference to the associated header field map.
§Examples
let mut response: Response<()> = Response::default();
response.headers_mut().insert(HOST, HeaderValue::from_static("world"));
assert!(!response.headers().is_empty());
Sourcepub fn extensions(&self) -> &Extensions
pub fn extensions(&self) -> &Extensions
Returns a reference to the associated extensions.
§Examples
let response: Response<()> = Response::default();
assert!(response.extensions().get::<i32>().is_none());
Sourcepub fn extensions_mut(&mut self) -> &mut Extensions
pub fn extensions_mut(&mut self) -> &mut Extensions
Returns a mutable reference to the associated extensions.
§Examples
let mut response: Response<()> = Response::default();
response.extensions_mut().insert("hello");
assert_eq!(response.extensions().get(), Some(&"hello"));
Trait Implementations§
Source§impl<T: Debug> Debug for TracedResponse<T>
impl<T: Debug> Debug for TracedResponse<T>
Source§impl<T> Deref for TracedResponse<T>
impl<T> Deref for TracedResponse<T>
Auto Trait Implementations§
impl<T> Freeze for TracedResponse<T>where
T: Freeze,
impl<T = Incoming> !RefUnwindSafe for TracedResponse<T>
impl<T> Send for TracedResponse<T>where
T: Send,
impl<T> Sync for TracedResponse<T>where
T: Sync,
impl<T> Unpin for TracedResponse<T>where
T: Unpin,
impl<T = Incoming> !UnwindSafe for TracedResponse<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request