pub struct Traceparent {
pub trace_id: TraceId,
pub span_id: SpanId,
}
Expand description
A container for OpenTelemetry trace parent information used in testing.
This struct holds a trace ID and span ID pair that represents a trace context relationship. It’s commonly used for generating test trace headers and validating trace propagation in integration tests.
§Example
use telemetry_rust::test::{Traceparent, TracingHeaderKind};
// Generate a new trace parent for testing
let traceparent = Traceparent::generate();
// Create HTTP headers for trace propagation
let headers = traceparent.get_headers(TracingHeaderKind::Traceparent);
// Use in HTTP request testing
let mut req = hyper::Request::new(());
for (key, value) in headers {
if let Some(header_name) = key {
req.headers_mut().insert(header_name, value);
}
}
Fields§
§trace_id: TraceId
The OpenTelemetry trace ID
span_id: SpanId
The OpenTelemetry span ID
Implementations§
Source§impl Traceparent
impl Traceparent
Sourcepub fn generate() -> Self
pub fn generate() -> Self
Generates a new random trace parent with random trace and span IDs.
This method creates a new trace parent with randomly generated IDs, useful for creating test scenarios with unique trace contexts.
§Returns
A new Traceparent
with randomly generated trace and span IDs
§Examples
use telemetry_rust::test::Traceparent;
let traceparent = Traceparent::generate();
println!("Trace ID: {}", traceparent.trace_id);
Sourcepub fn get_headers(&self, kind: TracingHeaderKind) -> HeaderMap
pub fn get_headers(&self, kind: TracingHeaderKind) -> HeaderMap
Generates HTTP headers containing trace context in the specified format.
This method creates HTTP headers with trace context information formatted according to the specified tracing header kind. This is useful for testing trace propagation with different header formats.
§Arguments
kind
: The format to use for the trace headers
§Returns
A HeaderMap
containing the appropriately formatted trace headers
§Examples
use telemetry_rust::test::{Traceparent, TracingHeaderKind};
let traceparent = Traceparent::generate();
let headers = traceparent.get_headers(TracingHeaderKind::Traceparent);
§Panics
This function will panic if the trace ID or span ID cannot be converted to a valid HTTP header value format.
Auto Trait Implementations§
impl Freeze for Traceparent
impl RefUnwindSafe for Traceparent
impl Send for Traceparent
impl Sync for Traceparent
impl Unpin for Traceparent
impl UnwindSafe for Traceparent
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