commonware_runtime/telemetry/traces/status.rs
1//! Record the OTLP status of a span.
2
3use opentelemetry::trace::Status;
4use std::fmt::Debug;
5use tracing::Span;
6use tracing_opentelemetry::OpenTelemetrySpanExt;
7
8/// Set the status of a span to `Ok`.
9pub fn ok(span: &Span) {
10 span.set_status(Status::Ok);
11}
12
13/// Set the status of a span to `Error`.
14///
15/// If `error` is provided, it will be recorded as an attribute on the span.
16pub fn error(span: &Span, status: &str, error: Option<&dyn Debug>) {
17 if let Some(error) = error {
18 span.record("error", format!("{error:?}"));
19 }
20 span.set_status(Status::error(status.to_string()));
21}