Export a single trace span to an OTLP collector using the shared `reqwest::Client` held on `SharedState`. Call this from the request tracker when a bridge round-trip completes.
(
client: &reqwest::Client,
timeout: std::time::Duration,
params: &SpanExport<'_>,
)
| 216 | /// |
| 217 | /// Call this from the request tracker when a bridge round-trip completes. |
| 218 | pub async fn export_span( |
| 219 | client: &reqwest::Client, |
| 220 | timeout: std::time::Duration, |
| 221 | params: &SpanExport<'_>, |
| 222 | ) { |
| 223 | let SpanExport { |
| 224 | endpoint, |
| 225 | trace_id, |
| 226 | span_name, |
| 227 | start_ns, |
| 228 | end_ns, |
| 229 | tenant_id, |
| 230 | vshard_id, |
| 231 | status_ok, |
| 232 | } = params; |
| 233 | if endpoint.is_empty() { |
| 234 | return; |
| 235 | } |
| 236 | |
| 237 | let span_id_bytes = rand_span_id(); |
| 238 | |
| 239 | let span = Span { |
| 240 | trace_id: trace_id.0.to_vec(), |
| 241 | span_id: span_id_bytes.to_vec(), |
| 242 | name: (*span_name).into(), |
| 243 | kind: SpanKind::Server as i32, |
| 244 | start_time_unix_nano: *start_ns, |
| 245 | end_time_unix_nano: *end_ns, |
| 246 | attributes: vec![ |
| 247 | kv("nodedb.tenant_id", &tenant_id.to_string()), |
| 248 | kv("nodedb.vshard_id", &vshard_id.to_string()), |
| 249 | ], |
| 250 | status: Some(SpanStatus { |
| 251 | message: String::new(), |
| 252 | code: if *status_ok { |
| 253 | OtelStatusCode::Ok as i32 |
| 254 | } else { |
| 255 | OtelStatusCode::Error as i32 |
| 256 | }, |
| 257 | }), |
| 258 | }; |
| 259 | |
| 260 | let request = ExportTraceServiceRequest { |
| 261 | resource_spans: vec![ResourceSpans { |
| 262 | resource: Some(Resource { |
| 263 | attributes: vec![kv("service.name", "nodedb")], |
| 264 | }), |
| 265 | scope_spans: vec![ScopeSpans { |
| 266 | scope: Some(proto::InstrumentationScope { |
| 267 | name: "nodedb".into(), |
| 268 | version: env!("CARGO_PKG_VERSION").into(), |
| 269 | }), |
| 270 | spans: vec![span], |
| 271 | }], |
| 272 | }], |
| 273 | }; |
| 274 | |
| 275 | let mut buf = Vec::new(); |
no test coverage detected