greentic_runner_host/engine/glue/
telemetry_bridge.rs1use super::super::error::GResult;
2use super::super::host::{SpanContext, TelemetryHost};
3use async_trait::async_trait;
4use std::sync::Arc;
5
6type TelemetryFn = dyn Fn(&SpanContext, &[(&str, &str)]) -> GResult<()> + Send + Sync;
7
8pub struct FnTelemetryHost {
9 inner: Arc<TelemetryFn>,
10}
11
12impl FnTelemetryHost {
13 pub fn new<F>(func: F) -> Self
14 where
15 F: Send + Sync + 'static + Fn(&SpanContext, &[(&str, &str)]) -> GResult<()>,
16 {
17 Self {
18 inner: Arc::new(func),
19 }
20 }
21}
22
23#[async_trait]
24impl TelemetryHost for FnTelemetryHost {
25 async fn emit(&self, span: &SpanContext, fields: &[(&str, &str)]) -> GResult<()> {
26 (self.inner)(span, fields)
27 }
28}