MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / export_span

Function export_span

nodedb/src/control/otel/exporter.rs:218–282  ·  view source on GitHub ↗

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<'_>,
)

Source from the content-addressed store, hash-verified

216///
217/// Call this from the request tracker when a bridge round-trip completes.
218pub 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();

Callers 1

emitMethod · 0.85

Calls 5

rand_span_idFunction · 0.85
export_trace_with_clientFunction · 0.85
encodeFunction · 0.70
is_emptyMethod · 0.45
to_vecMethod · 0.45

Tested by

no test coverage detected