Skip to content

Commit

Permalink
fix: bump opentelemetry dependencies to 0.27 (#596)
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswk authored Dec 11, 2024
1 parent 4cc054d commit 91750dd
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 56 deletions.
58 changes: 30 additions & 28 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ iter_tools = "0.24.0"
itertools = "0.13.0"
lazy_static = "1.4.0"
num_cpus = "1.16.0"
opentelemetry = { version = "0.24.0", features = ["trace", "metrics"] }
opentelemetry-prometheus = "0.17.0"
opentelemetry-semantic-conventions = "0.16.0"
opentelemetry_sdk = { version = "0.24.0", features = [
opentelemetry = { version = "0.27.0", features = ["trace", "metrics"] }
opentelemetry-prometheus = "0.27.0"
opentelemetry-semantic-conventions = "0.27.0"
opentelemetry_sdk = { version = "0.27.0", features = [
"metrics",
"serde",
"serde_json",
Expand All @@ -60,17 +60,17 @@ prometheus = { version = "0.13.4", features = ["process"] }
prometheus-reqwest-remote-write = { version = "0.2.1" }
prometheus-static-metric = "0.5.1"
rand = "0.8.5"
redis = { version = "0.27.5", features = [
redis = { version = "0.27.6", features = [
"tokio-comp",
"tokio-rustls-comp",
"cluster",
] }
reqwest = { version = "0.12.8", default-features = false, features = [
reqwest = { version = "0.12.9", default-features = false, features = [
"json",
"rustls-tls",
"native-tls",
] }
rustls = { version = "0.23.15", default-features = false, features = [
rustls = { version = "0.23.18", default-features = false, features = [
"logging",
"ring",
"std",
Expand All @@ -81,8 +81,8 @@ semver = "1.0.23"
serde = { version = "1.0.213", features = ["derive"] }
serde_json = "1.0.132"
serde_qs = { version = "0.13.0", features = ["actix4", "tracing"] }
shadow-rs = { version = "0.35.0" }
tokio = { version = "1.41.0", features = [
shadow-rs = { version = "0.36.0" }
tokio = { version = "1.42.0", features = [
"macros",
"rt-multi-thread",
"tracing",
Expand Down Expand Up @@ -112,4 +112,4 @@ testcontainers-modules = { version = "0.11.3", features = [
tracing-test = "0.2.5"

[build-dependencies]
shadow-rs = "0.35.0"
shadow-rs = "0.36.0"
31 changes: 13 additions & 18 deletions server/src/metrics/actix_web_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use actix_web::dev::ServiceRequest;
use actix_web::http::{Method, StatusCode, Version};
use futures::{future, FutureExt};
use futures_core::future::LocalBoxFuture;
use opentelemetry::metrics::{Histogram, Meter, MeterProvider, MetricsError, UpDownCounter};
use opentelemetry::{global, KeyValue, Value};
use opentelemetry::metrics::{Histogram, Meter, MeterProvider, UpDownCounter};
use opentelemetry::{InstrumentationScope, KeyValue, Value};
use opentelemetry_semantic_conventions::trace::{
CLIENT_ADDRESS, HTTP_REQUEST_METHOD, HTTP_RESPONSE_STATUS_CODE, NETWORK_PROTOCOL_NAME,
NETWORK_PROTOCOL_VERSION, SERVER_ADDRESS, SERVER_PORT, URL_PATH, URL_SCHEME,
Expand Down Expand Up @@ -115,25 +115,25 @@ impl Metrics {
let http_server_active_requests = meter
.i64_up_down_counter(HTTP_SERVER_ACTIVE_REQUESTS)
.with_description("HTTP concurrent in-flight requests per route")
.init();
.build();

let http_server_duration = meter
.f64_histogram(HTTP_SERVER_DURATION)
.with_description("HTTP inbound request duration per route")
.with_unit("ms")
.init();
.build();

let http_server_request_size = meter
.u64_histogram(HTTP_SERVER_REQUEST_SIZE)
.with_description("Measures the size of HTTP request messages (compressed).")
.with_unit("By")
.init();
.build();

let http_server_response_size = meter
.u64_histogram(HTTP_SERVER_RESPONSE_SIZE)
.with_description("Measures the size of HTTP request messages (compressed).")
.with_unit("By")
.init();
.build();

Metrics {
http_server_active_requests,
Expand Down Expand Up @@ -174,9 +174,7 @@ impl RequestMetricsBuilder {

/// Build the `RequestMetrics` middleware
pub fn build(self) -> RequestMetrics {
let meter = self
.meter
.unwrap_or_else(|| get_versioned_meter(global::meter_provider()));
let meter = self.meter.unwrap();

RequestMetrics {
route_formatter: self.route_formatter,
Expand All @@ -187,11 +185,11 @@ impl RequestMetricsBuilder {

/// construct meters for this crate
fn get_versioned_meter(meter_provider: impl MeterProvider) -> Meter {
meter_provider.versioned_meter(
"unleash_edge",
Some(env!("CARGO_PKG_VERSION")),
Some(opentelemetry_semantic_conventions::SCHEMA_URL),
None,
meter_provider.meter_with_scope(
InstrumentationScope::builder("unleash_edge")
.with_version(env!("CARGO_PKG_VERSION"))
.with_schema_url(opentelemetry_semantic_conventions::SCHEMA_URL)
.build(),
)
}

Expand Down Expand Up @@ -331,10 +329,7 @@ impl PrometheusMetricsHandler {
let encoder = TextEncoder::new();
let metric_families = self.registry.gather();
let mut buf = Vec::new();
if let Err(err) = encoder.encode(&metric_families[..], &mut buf) {
global::handle_error(MetricsError::Other(err.to_string()));
}

let _ = encoder.encode(&metric_families[..], &mut buf);
String::from_utf8(buf).unwrap_or_default()
}
}
Expand Down

0 comments on commit 91750dd

Please sign in to comment.