bump otel to v0.24.0

Someone contributed opentelemetry-prometheus support for v0.24 and this
version also doesn't put stupid requirements on the tokio version. This
version of the OTel ecosystem also fixes an apparent bug with some hacks
I plan on doing in the future...
This commit is contained in:
Charles Hall 2024-09-22 20:04:01 -07:00
parent c24f79b79b
commit b0d1cc1b63
No known key found for this signature in database
GPG key ID: 7B8E0645816E07CF
3 changed files with 110 additions and 218 deletions

View file

@ -10,10 +10,7 @@ use axum::{
};
use http::Method;
use once_cell::sync::Lazy;
use opentelemetry::{
metrics::{MeterProvider, Unit},
KeyValue,
};
use opentelemetry::{metrics::MeterProvider, trace::TracerProvider, KeyValue};
use opentelemetry_otlp::WithExportConfig;
use opentelemetry_sdk::{
metrics::{new_view, Aggregation, Instrument, SdkMeterProvider, Stream},
@ -168,10 +165,10 @@ pub(crate) fn init(
if let Some(endpoint) = &config.observability.traces.endpoint {
exporter = exporter.with_endpoint(endpoint);
}
let tracer = opentelemetry_otlp::new_pipeline()
let tracer_provider = opentelemetry_otlp::new_pipeline()
.tracing()
.with_trace_config(
opentelemetry_sdk::trace::config().with_resource(
opentelemetry_sdk::trace::Config::default().with_resource(
standard_resource(
config.observability.traces.service_name.clone(),
),
@ -179,6 +176,18 @@ pub(crate) fn init(
)
.with_exporter(exporter)
.install_batch(opentelemetry_sdk::runtime::Tokio)?;
// The passed value sets the library name, and `""` seems to be
// morally equivalent to passing `None`, which is probably fine
// because what other library is there to use for this anyway?
//
// Prior to opentelemetry v0.24, this value was set for us by the
// opentelemetry-otlp crate. Trying to automate getting the right
// values doesn't seem worth it, as alluded to above.
let tracer = tracer_provider.tracer("");
opentelemetry::global::set_tracer_provider(tracer_provider);
Ok((tracing_opentelemetry::layer().with_tracer(tracer), ()))
},
)?;
@ -315,7 +324,7 @@ impl Metrics {
let http_requests_histogram = meter
.f64_histogram(http_requests_histogram_name)
.with_unit(Unit::new("seconds"))
.with_unit("seconds")
.with_description("Histogram of HTTP requests")
.init();