Skip to main content

systemprompt_runtime/
span.rs

1//! Tracing span construction for inbound requests.
2//!
3//! Copyright (c) systemprompt.io — Business Source License 1.1.
4//! See <https://systemprompt.io> for licensing details.
5
6use systemprompt_logging::{RequestSpan, RequestSpanBuilder};
7use systemprompt_models::RequestContext;
8
9pub fn create_request_span(ctx: &RequestContext) -> RequestSpan {
10    let mut builder = RequestSpanBuilder::new(
11        &ctx.auth.actor.user_id,
12        &ctx.request.session_id,
13        &ctx.execution.trace_id,
14    );
15
16    if !ctx.execution.context_id.as_str().is_empty() {
17        builder = builder.with_context_id(&ctx.execution.context_id);
18    }
19
20    if let Some(ref task_id) = ctx.execution.task_id {
21        builder = builder.with_task_id(task_id);
22    }
23
24    if let Some(ref client_id) = ctx.request.client_id {
25        builder = builder.with_client_id(client_id);
26    }
27
28    builder.build()
29}