From 3975d31b9170ec2bd6af8199e22487a36193dfbc Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Wed, 7 Oct 2026 19:13:06 +0100 Subject: [PATCH] refactor: Delegate otlp_protocol to standard OTLP env variables --- conduwuit-example.toml | 13 +++++-------- docs/guides/metrics.mdx | 4 ++-- src/core/config/check.rs | 8 -------- src/core/config/mod.rs | 18 ++++++------------ src/main/logging.rs | 28 +++------------------------- src/main/metrics.rs | 13 ++++--------- 6 files changed, 20 insertions(+), 64 deletions(-) diff --git a/conduwuit-example.toml b/conduwuit-example.toml index 6d83e5a2d..ca4e1611f 100644 --- a/conduwuit-example.toml +++ b/conduwuit-example.toml @@ -823,7 +823,7 @@ # Jaeger) that supports the OpenTelemetry Protocol. # # Configure your OTLP endpoint using the OTEL_EXPORTER_OTLP_ENDPOINT -# environment variable (defaults to http://localhost:4318). +# environment variable, or OTEL_EXPORTER_OTLP_TRACES_ENDPOINT (defaults to http://localhost:4318), and OTEL_EXPORTER_OTLP_PROTOCOL for the protocol. # #allow_otlp = false @@ -832,13 +832,10 @@ # #otlp_filter = "info" -# Protocol to use for OTLP tracing export. Options are "http" or "grpc". -# The HTTP protocol uses port 4318 by default, while gRPC uses port 4317. -# -#otlp_protocol = "http" - -# Enable OpenTelemetry OTLP metrics export, using the same endpoint and -# `otlp_protocol` as traces. +# Enable OpenTelemetry OTLP metrics export. Configure your OTLP endpoint +# and protocol using standard OpenTelemetry environment variables +# (such as OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_PROTOCOL and +# OTEL_EXPORTER_OTLP_METRICS_PROTOCOL). # # The export interval can be changed with the # OTEL_METRIC_EXPORT_INTERVAL environment variable (milliseconds, diff --git a/docs/guides/metrics.mdx b/docs/guides/metrics.mdx index f807fd80a..cb5df8c70 100644 --- a/docs/guides/metrics.mdx +++ b/docs/guides/metrics.mdx @@ -33,13 +33,13 @@ ## OTLP ```toml [global] allow_otlp_metrics = true -otlp_protocol = "http" # or "grpc" ``` -Configure the exporter with the standard OpenTelemetry environment variables: +Configure the exporter with standard OpenTelemetry environment variables: ```sh OTEL_EXPORTER_OTLP_ENDPOINT=http://collector:4318 +OTEL_EXPORTER_OTLP_METRICS_PROTOCOL=http/protobuf # or "grpc" OTEL_METRIC_EXPORT_INTERVAL=15000 ``` diff --git a/src/core/config/check.rs b/src/core/config/check.rs index 8aad111a2..1e3efdb5e 100644 --- a/src/core/config/check.rs +++ b/src/core/config/check.rs @@ -194,14 +194,6 @@ pub fn check(config: &Config) -> Result { ); } - if !matches!(config.otlp_protocol.as_str(), "http" | "grpc") { - warn!( - "Invalid OTLP protocol '{}', falling back to HTTP. Valid options are 'http' or \ - 'grpc'.", - config.otlp_protocol - ); - } - if config.allow_prometheus_metrics && config.prometheus_metrics_token.is_none() { warn!( "The Prometheus metrics endpoint is enabled without `prometheus_metrics_token`. \ diff --git a/src/core/config/mod.rs b/src/core/config/mod.rs index 0962d7a88..98c74a116 100644 --- a/src/core/config/mod.rs +++ b/src/core/config/mod.rs @@ -1008,7 +1008,7 @@ pub struct Config { /// Jaeger) that supports the OpenTelemetry Protocol. /// /// Configure your OTLP endpoint using the OTEL_EXPORTER_OTLP_ENDPOINT - /// environment variable (defaults to http://localhost:4318). + /// environment variable, or OTEL_EXPORTER_OTLP_TRACES_ENDPOINT (defaults to http://localhost:4318), and OTEL_EXPORTER_OTLP_PROTOCOL for the protocol. #[serde(default, alias = "allow_jaeger")] pub allow_otlp: bool, @@ -1019,15 +1019,10 @@ pub struct Config { #[serde(default = "default_otlp_filter", alias = "jaeger_filter")] pub otlp_filter: String, - /// Protocol to use for OTLP tracing export. Options are "http" or "grpc". - /// The HTTP protocol uses port 4318 by default, while gRPC uses port 4317. - /// - /// default: "http" - #[serde(default = "default_otlp_protocol")] - pub otlp_protocol: String, - - /// Enable OpenTelemetry OTLP metrics export, using the same endpoint and - /// `otlp_protocol` as traces. + /// Enable OpenTelemetry OTLP metrics export. Configure your OTLP endpoint + /// and protocol using standard OpenTelemetry environment variables + /// (such as OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_PROTOCOL and + /// OTEL_EXPORTER_OTLP_METRICS_PROTOCOL). /// /// The export interval can be changed with the /// OTEL_METRIC_EXPORT_INTERVAL environment variable (milliseconds, @@ -2965,6 +2960,7 @@ pub fn new(server_name: OwnedServerName) -> Self { "cache_capacity", "conduit_cache_capacity_modifier", "max_concurrent_requests", + "otlp_protocol", "roomid_spacehierarchy_cache_capacity", "well_known_client", "well_known_server", @@ -3211,8 +3207,6 @@ fn default_otlp_filter() -> String { .to_owned() } -fn default_otlp_protocol() -> String { "http".to_owned() } - fn default_tracing_flame_output_path() -> String { "./tracing.folded".to_owned() } fn default_trusted_servers() -> Vec { diff --git a/src/main/logging.rs b/src/main/logging.rs index 79ff3c51e..c882fcb7f 100644 --- a/src/main/logging.rs +++ b/src/main/logging.rs @@ -6,12 +6,9 @@ debug_warn, err, log::{ConsoleFormat, ConsoleWriter, LogLevelReloadHandles, capture, fmt_span}, result::UnwrapOrErr, - warn, }; #[cfg(feature = "otlp_telemetry")] use opentelemetry::trace::TracerProvider; -#[cfg(feature = "otlp_telemetry")] -use opentelemetry_otlp::WithExportConfig; use tracing_subscriber::{EnvFilter, Layer, Registry, fmt, layer::SubscriberExt, reload}; #[cfg(feature = "perf_measurements")] @@ -83,28 +80,9 @@ pub(crate) fn init( opentelemetry_sdk::propagation::TraceContextPropagator::new(), ); - let exporter = match config.otlp_protocol.as_str() { - | "grpc" => opentelemetry_otlp::SpanExporter::builder() - .with_tonic() - .with_protocol(opentelemetry_otlp::Protocol::Grpc) // TODO: build from env when 0.32 is released - .build() - .expect("Failed to create OTLP gRPC exporter"), - | "http" => opentelemetry_otlp::SpanExporter::builder() - .with_http() - .build() - .expect("Failed to create OTLP HTTP exporter"), - | protocol => { - warn!( - "Invalid OTLP protocol '{}', falling back to HTTP. Valid options are \ - 'http' or 'grpc'.", - protocol - ); - opentelemetry_otlp::SpanExporter::builder() - .with_http() - .build() - .expect("Failed to create OTLP HTTP exporter") - }, - }; + let exporter = opentelemetry_otlp::SpanExporter::builder() + .build() + .expect("Failed to create OTLP span exporter"); let provider = opentelemetry_sdk::trace::SdkTracerProvider::builder() .with_resource(crate::metrics::resource(config)) diff --git a/src/main/metrics.rs b/src/main/metrics.rs index 929a7ff80..0e818c32c 100644 --- a/src/main/metrics.rs +++ b/src/main/metrics.rs @@ -56,16 +56,11 @@ pub(crate) fn init( #[cfg(feature = "otlp_telemetry")] if config.allow_otlp_metrics { - use opentelemetry_otlp::{MetricExporter, Protocol, WithExportConfig}; + use opentelemetry_otlp::MetricExporter; - let exporter = match config.otlp_protocol.as_str() { - | "grpc" => MetricExporter::builder() - .with_tonic() - .with_protocol(Protocol::Grpc) - .build(), - | _ => MetricExporter::builder().with_http().build(), - } - .map_err(|e| err!(Config("allow_otlp_metrics", "{e}")))?; + let exporter = MetricExporter::builder() + .build() + .map_err(|e| err!(Config("allow_otlp_metrics", "{e}")))?; builder = builder.with_periodic_exporter(exporter); readers = true;