Skip to main content

start_span

Function start_span 

Source
pub fn start_span<B>(request: &Request<B>) -> Context
Expand description

Start a server span and return the context to use for the handler.

Run the handler future with FutureExt::with_context and end the span when the request finishes. Only deployed policy can supply URL and header attributes. Without a policy route, the span is named by method alone (HTTP for an unrecognized method).

use encore::opentelemetry::trace::{FutureExt, TraceContextExt};
use encore::telemetry::http::start_span;

async fn handle(request: http::Request<()>) {
    let ctx = start_span(&request);
    async { /* handle the original request */ }.with_context(ctx.clone()).await;
    ctx.span().end();
}