diff --git a/core-api/src/telemetry.rs b/core-api/src/telemetry.rs index 75597aa0c..14c029c20 100644 --- a/core-api/src/telemetry.rs +++ b/core-api/src/telemetry.rs @@ -71,6 +71,9 @@ pub struct OtelCollectorOptions { /// Overrides for histogram buckets. Units depend on the value of `use_seconds_for_durations`. #[builder(default)] pub histogram_bucket_overrides: HistogramBucketOverrides, + /// Protocol to use for communication with the collector + #[builder(default = "OtlpProtocl::Grpc")] + pub protocol: OtlpProtocl, } /// Options for exporting metrics to Prometheus @@ -143,6 +146,15 @@ pub enum MetricTemporality { Delta, } +/// Options for configuring telemetry +#[derive(Debug, Clone, Copy)] +pub enum OtlpProtocl { + /// Use gRPC to communicate with the collector + Grpc, + /// Use HTTP to communicate with the collector + Http, +} + impl Default for TelemetryOptions { fn default() -> Self { TelemetryOptionsBuilder::default().build().unwrap() diff --git a/core/Cargo.toml b/core/Cargo.toml index 562032468..caaf15122 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -44,7 +44,7 @@ lru = "0.12" mockall = "0.13" opentelemetry = { workspace = true, features = ["metrics"], optional = true } opentelemetry_sdk = { version = "0.26", features = ["rt-tokio", "metrics"], optional = true } -opentelemetry-otlp = { version = "0.26", features = ["tokio", "metrics", "tls"], optional = true } +opentelemetry-otlp = { version = "0.26", features = ["tokio", "metrics", "tls", "http-proto"], optional = true } opentelemetry-prometheus = { git = "https://github.com/open-telemetry/opentelemetry-rust.git", rev = "e911383", optional = true } parking_lot = { version = "0.12", features = ["send_guard"] } pid = "4.0" diff --git a/core/src/telemetry/otel.rs b/core/src/telemetry/otel.rs index c4bca1c52..e8cc70990 100644 --- a/core/src/telemetry/otel.rs +++ b/core/src/telemetry/otel.rs @@ -30,7 +30,8 @@ use temporal_sdk_core_api::telemetry::{ CoreMeter, Counter, Gauge, GaugeF64, Histogram, HistogramDuration, HistogramF64, MetricAttributes, MetricParameters, NewAttributes, }, - HistogramBucketOverrides, MetricTemporality, OtelCollectorOptions, PrometheusExporterOptions, + HistogramBucketOverrides, MetricTemporality, OtelCollectorOptions, OtlpProtocl, + PrometheusExporterOptions, }; use tokio::task::AbortHandle; use tonic::{metadata::MetadataMap, transport::ClientTlsConfig}; @@ -120,16 +121,26 @@ pub(super) fn augment_meter_provider_with_defaults( pub fn build_otlp_metric_exporter( opts: OtelCollectorOptions, ) -> Result { - let mut exporter = - opentelemetry_otlp::TonicExporterBuilder::default().with_endpoint(opts.url.to_string()); - if opts.url.scheme() == "https" || opts.url.scheme() == "grpcs" { - exporter = exporter.with_tls_config(ClientTlsConfig::new().with_native_roots()); - } - let exporter = exporter - .with_metadata(MetadataMap::from_headers((&opts.headers).try_into()?)) - .build_metrics_exporter(Box::new(metric_temporality_to_selector( - opts.metric_temporality, - )))?; + let exporter = match opts.protocol { + OtlpProtocl::Grpc => { + let mut exporter = opentelemetry_otlp::TonicExporterBuilder::default() + .with_endpoint(opts.url.to_string()); + if opts.url.scheme() == "https" || opts.url.scheme() == "grpcs" { + exporter = exporter.with_tls_config(ClientTlsConfig::new().with_native_roots()); + } + exporter + .with_metadata(MetadataMap::from_headers((&opts.headers).try_into()?)) + .build_metrics_exporter(Box::new(metric_temporality_to_selector( + opts.metric_temporality, + )))? + } + OtlpProtocl::Http => opentelemetry_otlp::HttpExporterBuilder::default() + .with_endpoint(opts.url.to_string()) + .with_headers(opts.headers) + .build_metrics_exporter(Box::new(metric_temporality_to_selector( + opts.metric_temporality, + )))?, + }; let reader = PeriodicReader::builder(exporter, runtime::Tokio) .with_interval(opts.metric_periodicity) .build();