refactor: Delegate otlp_protocol to standard OTLP env variables

This commit is contained in:
Jade Ellis
2026-10-12 10:03:16 +01:00
parent fd4cb4a306
commit 3975d31b91
6 changed files with 20 additions and 64 deletions
+5 -8
View File
@@ -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,
+2 -2
View File
@@ -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
```
-8
View File
@@ -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`. \
+6 -12
View File
@@ -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<TrustedServer> {
+3 -25
View File
@@ -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))
+4 -9
View File
@@ -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;