laminar_connectors/otel/mod.rs
1//! OpenTelemetry (OTLP/gRPC) source connector.
2//!
3//! Receives trace spans, metrics, or logs from OTel exporters and
4//! collectors via the standard OTLP/gRPC protocol. Each source handles
5//! one signal type on its own port.
6//!
7//! ```sql
8//! CREATE SOURCE traces FROM OTEL (port = '4317', signals = 'traces');
9//! CREATE SOURCE metrics FROM OTEL (port = '4318', signals = 'metrics');
10//! CREATE SOURCE logs FROM OTEL (port = '4319', signals = 'logs');
11//! ```
12
13#![allow(clippy::doc_markdown)] // "OTel" is a proper name, not code
14
15pub mod config;
16pub mod convert;
17pub mod schema;
18pub mod server;
19pub mod source;
20
21pub use config::{OtelSignal, OtelSourceConfig};
22pub use source::OtelSource;
23
24use std::sync::Arc;
25
26use crate::config::ConnectorInfo;
27use crate::registry::ConnectorRegistry;
28
29use self::config::otel_source_config_keys;
30use self::schema::traces_schema;
31
32/// Registers the OTel source connector with the given registry.
33///
34/// After registration, the runtime can instantiate `OtelSource` by
35/// name when processing `CREATE SOURCE ... FROM OTEL (...)`.
36///
37/// # Errors
38///
39/// Returns an error if the connector name is already registered or the registry is frozen.
40pub fn register_otel_source(
41 registry: &ConnectorRegistry,
42) -> Result<(), crate::error::ConnectorError> {
43 let info = ConnectorInfo {
44 name: "otel".to_string(),
45 display_name: "OpenTelemetry OTLP/gRPC Source".to_string(),
46 version: env!("CARGO_PKG_VERSION").to_string(),
47 is_source: true,
48 is_sink: false,
49 config_keys: otel_source_config_keys(),
50 };
51
52 registry.register_source(
53 "otel",
54 info,
55 Arc::new(|registry: Option<&Arc<prometheus::Registry>>| {
56 Ok(Box::new(OtelSource::new(
57 traces_schema(),
58 registry.map(Arc::as_ref),
59 )))
60 }),
61 )
62}