Skip to content

Commit

Permalink
build(deps): bump opentelemetry crates to 0.27 (#6774)
Browse files Browse the repository at this point in the history
  • Loading branch information
SanchithHegde authored Dec 10, 2024
1 parent b6cdb65 commit 873b18e
Show file tree
Hide file tree
Showing 86 changed files with 737 additions and 1,084 deletions.
273 changes: 76 additions & 197 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions config/loki.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ ingester:
schema_config:
configs:
- from: 2020-10-24
store: boltdb-shipper
store: tsdb
object_store: filesystem
schema: v11
schema: v13
index:
prefix: index_
period: 24h
Expand Down
7 changes: 4 additions & 3 deletions config/otel-collector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317

exporters:
otlp:
endpoint: tempo:4317
tls:
insecure: true

logging:
loglevel: debug
debug:
verbosity: detailed

prometheus:
endpoint: 0.0.0.0:8889
Expand All @@ -21,7 +22,7 @@ exporters:
service:
telemetry:
logs:
level: debug
level: DEBUG
metrics:
level: detailed
address: 0.0.0.0:8888
Expand Down
7 changes: 3 additions & 4 deletions crates/analytics/src/api_event/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use common_utils::errors::ReportSwitchExt;
use error_stack::ResultExt;
use router_env::{
instrument, logger,
metrics::add_attributes,
tracing::{self, Instrument},
};

Expand Down Expand Up @@ -136,14 +135,14 @@ pub async fn get_api_event_metrics(
.change_context(AnalyticsError::UnknownError)?
{
let data = data?;
let attributes = &add_attributes([
let attributes = router_env::metric_attributes!(
("metric_type", metric.to_string()),
("source", pool.to_string()),
]);
);

let value = u64::try_from(data.len());
if let Ok(val) = value {
metrics::BUCKETS_FETCHED.record(&metrics::CONTEXT, val, attributes);
metrics::BUCKETS_FETCHED.record(val, attributes);
logger::debug!("Attributes: {:?}, Buckets fetched: {}", attributes, val);
}
for (id, value) in data {
Expand Down
7 changes: 3 additions & 4 deletions crates/analytics/src/disputes/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use api_models::analytics::{
use error_stack::ResultExt;
use router_env::{
logger,
metrics::add_attributes,
tracing::{self, Instrument},
};

Expand Down Expand Up @@ -72,14 +71,14 @@ pub async fn get_metrics(
.change_context(AnalyticsError::UnknownError)?
{
let data = data?;
let attributes = &add_attributes([
let attributes = router_env::metric_attributes!(
("metric_type", metric.to_string()),
("source", pool.to_string()),
]);
);

let value = u64::try_from(data.len());
if let Ok(val) = value {
metrics::BUCKETS_FETCHED.record(&metrics::CONTEXT, val, attributes);
metrics::BUCKETS_FETCHED.record(val, attributes);
logger::debug!("Attributes: {:?}, Buckets fetched: {}", attributes, val);
}

Expand Down
7 changes: 3 additions & 4 deletions crates/analytics/src/frm/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use api_models::analytics::{
use error_stack::ResultExt;
use router_env::{
logger,
metrics::add_attributes,
tracing::{self, Instrument},
};

Expand Down Expand Up @@ -66,13 +65,13 @@ pub async fn get_metrics(
{
let data = data?;

let attributes = &add_attributes([
let attributes = router_env::metric_attributes!(
("metric_type", metric.to_string()),
("source", pool.to_string()),
]);
);
let value = u64::try_from(data.len());
if let Ok(val) = value {
metrics::BUCKETS_FETCHED.record(&metrics::CONTEXT, val, attributes);
metrics::BUCKETS_FETCHED.record(val, attributes);
logger::debug!("Attributes: {:?}, Buckets fetched: {}", attributes, val);
}

Expand Down
5 changes: 2 additions & 3 deletions crates/analytics/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use router_env::{global_meter, histogram_metric, histogram_metric_u64, metrics_context};
use router_env::{global_meter, histogram_metric_f64, histogram_metric_u64};

metrics_context!(CONTEXT);
global_meter!(GLOBAL_METER, "ROUTER_API");

histogram_metric!(METRIC_FETCH_TIME, GLOBAL_METER);
histogram_metric_f64!(METRIC_FETCH_TIME, GLOBAL_METER);
histogram_metric_u64!(BUCKETS_FETCHED, GLOBAL_METER);

pub mod request;
8 changes: 3 additions & 5 deletions crates/analytics/src/metrics/request.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use std::time;

use router_env::metrics::add_attributes;

#[inline]
pub async fn record_operation_time<F, R, T>(
future: F,
Expand All @@ -14,12 +12,12 @@ where
T: ToString,
{
let (result, time) = time_future(future).await;
let attributes = &add_attributes([
let attributes = router_env::metric_attributes!(
("metric_name", metric_name.to_string()),
("source", source.to_string()),
]);
);
let value = time.as_secs_f64();
metric.record(&super::CONTEXT, value, attributes);
metric.record(value, attributes);

router_env::logger::debug!("Attributes: {:?}, Time: {}", attributes, value);
result
Expand Down
7 changes: 3 additions & 4 deletions crates/analytics/src/payment_intents/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use currency_conversion::{conversion::convert, types::ExchangeRates};
use error_stack::ResultExt;
use router_env::{
instrument, logger,
metrics::add_attributes,
tracing::{self, Instrument},
};

Expand Down Expand Up @@ -118,14 +117,14 @@ pub async fn get_metrics(
match task_type {
TaskType::MetricTask(metric, data) => {
let data = data?;
let attributes = &add_attributes([
let attributes = router_env::metric_attributes!(
("metric_type", metric.to_string()),
("source", pool.to_string()),
]);
);

let value = u64::try_from(data.len());
if let Ok(val) = value {
metrics::BUCKETS_FETCHED.record(&metrics::CONTEXT, val, attributes);
metrics::BUCKETS_FETCHED.record(val, attributes);
logger::debug!("Attributes: {:?}, Buckets fetched: {}", attributes, val);
}

Expand Down
13 changes: 6 additions & 7 deletions crates/analytics/src/payments/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use currency_conversion::{conversion::convert, types::ExchangeRates};
use error_stack::ResultExt;
use router_env::{
instrument, logger,
metrics::add_attributes,
tracing::{self, Instrument},
};

Expand Down Expand Up @@ -126,14 +125,14 @@ pub async fn get_metrics(
match task_type {
TaskType::MetricTask(metric, data) => {
let data = data?;
let attributes = &add_attributes([
let attributes = router_env::metric_attributes!(
("metric_type", metric.to_string()),
("source", pool.to_string()),
]);
);

let value = u64::try_from(data.len());
if let Ok(val) = value {
metrics::BUCKETS_FETCHED.record(&metrics::CONTEXT, val, attributes);
metrics::BUCKETS_FETCHED.record(val, attributes);
logger::debug!("Attributes: {:?}, Buckets fetched: {}", attributes, val);
}

Expand Down Expand Up @@ -193,14 +192,14 @@ pub async fn get_metrics(
}
TaskType::DistributionTask(distribution, data) => {
let data = data?;
let attributes = &add_attributes([
let attributes = router_env::metric_attributes!(
("distribution_type", distribution.to_string()),
("source", pool.to_string()),
]);
);

let value = u64::try_from(data.len());
if let Ok(val) = value {
metrics::BUCKETS_FETCHED.record(&metrics::CONTEXT, val, attributes);
metrics::BUCKETS_FETCHED.record(val, attributes);
logger::debug!("Attributes: {:?}, Buckets fetched: {}", attributes, val);
}

Expand Down
13 changes: 6 additions & 7 deletions crates/analytics/src/refunds/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use currency_conversion::{conversion::convert, types::ExchangeRates};
use error_stack::ResultExt;
use router_env::{
logger,
metrics::add_attributes,
tracing::{self, Instrument},
};

Expand Down Expand Up @@ -121,14 +120,14 @@ pub async fn get_metrics(
match task_type {
TaskType::MetricTask(metric, data) => {
let data = data?;
let attributes = &add_attributes([
let attributes = router_env::metric_attributes!(
("metric_type", metric.to_string()),
("source", pool.to_string()),
]);
);

let value = u64::try_from(data.len());
if let Ok(val) = value {
metrics::BUCKETS_FETCHED.record(&metrics::CONTEXT, val, attributes);
metrics::BUCKETS_FETCHED.record(val, attributes);
logger::debug!("Attributes: {:?}, Buckets fetched: {}", attributes, val);
}

Expand Down Expand Up @@ -168,13 +167,13 @@ pub async fn get_metrics(
}
TaskType::DistributionTask(distribution, data) => {
let data = data?;
let attributes = &add_attributes([
let attributes = router_env::metric_attributes!(
("distribution_type", distribution.to_string()),
("source", pool.to_string()),
]);
);
let value = u64::try_from(data.len());
if let Ok(val) = value {
metrics::BUCKETS_FETCHED.record(&metrics::CONTEXT, val, attributes);
metrics::BUCKETS_FETCHED.record(val, attributes);
logger::debug!("Attributes: {:?}, Buckets fetched: {}", attributes, val);
}

Expand Down
5 changes: 2 additions & 3 deletions crates/common_utils/src/id_type/merchant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@ crate::impl_serializable_secret_id_type!(MerchantId);
crate::impl_queryable_id_type!(MerchantId);
crate::impl_to_sql_from_sql_id_type!(MerchantId);

// This is implemented so that we can use merchant id directly as attribute in metrics
#[cfg(feature = "metrics")]
/// This is implemented so that we can use merchant id directly as attribute in metrics
impl From<MerchantId> for router_env::opentelemetry::Value {
fn from(val: MerchantId) -> Self {
let string_value = val.0 .0 .0;
Self::String(router_env::opentelemetry::StringValue::from(string_value))
Self::from(val.0 .0 .0)
}
}

Expand Down
5 changes: 2 additions & 3 deletions crates/common_utils/src/id_type/payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,10 @@ crate::impl_try_from_cow_str_id_type!(PaymentReferenceId, "payment_reference_id"
crate::impl_queryable_id_type!(PaymentReferenceId);
crate::impl_to_sql_from_sql_id_type!(PaymentReferenceId);

// This is implemented so that we can use payment id directly as attribute in metrics
#[cfg(feature = "metrics")]
/// This is implemented so that we can use payment id directly as attribute in metrics
impl From<PaymentId> for router_env::opentelemetry::Value {
fn from(val: PaymentId) -> Self {
let string_value = val.0 .0 .0;
Self::String(router_env::opentelemetry::StringValue::from(string_value))
Self::from(val.0 .0 .0)
}
}
8 changes: 8 additions & 0 deletions crates/common_utils/src/id_type/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,11 @@ impl FromStr for ProfileId {
Self::try_from(cow_string)
}
}

// This is implemented so that we can use profile id directly as attribute in metrics
#[cfg(feature = "metrics")]
impl From<ProfileId> for router_env::opentelemetry::Value {
fn from(val: ProfileId) -> Self {
Self::from(val.0 .0 .0)
}
}
3 changes: 1 addition & 2 deletions crates/common_utils/src/metrics/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ where
pub async fn record_operation_time<F, R>(
future: F,
metric: &opentelemetry::metrics::Histogram<f64>,
metric_context: &opentelemetry::Context,
key_value: &[opentelemetry::KeyValue],
) -> R
where
F: futures::Future<Output = R>,
{
let (result, time) = time_future(future).await;
metric.record(metric_context, time.as_secs_f64(), key_value);
metric.record(time.as_secs_f64(), key_value);
result
}
5 changes: 2 additions & 3 deletions crates/diesel_models/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,10 @@ pub(crate) mod diesel_impl {
}

pub(crate) mod metrics {
use router_env::{counter_metric, global_meter, histogram_metric, metrics_context, once_cell};
use router_env::{counter_metric, global_meter, histogram_metric_f64, once_cell};

metrics_context!(CONTEXT);
global_meter!(GLOBAL_METER, "ROUTER_API");

counter_metric!(DATABASE_CALLS_COUNT, GLOBAL_METER);
histogram_metric!(DATABASE_CALL_TIME, GLOBAL_METER);
histogram_metric_f64!(DATABASE_CALL_TIME, GLOBAL_METER);
}
18 changes: 6 additions & 12 deletions crates/diesel_models/src/query/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ use router_env::logger;
use crate::{errors, PgPooledConn, StorageResult};

pub mod db_metrics {
use router_env::opentelemetry::KeyValue;

#[derive(Debug)]
pub enum DatabaseOperation {
FindOne,
Expand All @@ -51,18 +49,14 @@ pub mod db_metrics {

let table_name = std::any::type_name::<T>().rsplit("::").nth(1);

let attributes = [
KeyValue::new("table", table_name.unwrap_or("undefined")),
KeyValue::new("operation", format!("{:?}", operation)),
];

crate::metrics::DATABASE_CALLS_COUNT.add(&crate::metrics::CONTEXT, 1, &attributes);
crate::metrics::DATABASE_CALL_TIME.record(
&crate::metrics::CONTEXT,
time_elapsed.as_secs_f64(),
&attributes,
let attributes = router_env::metric_attributes!(
("table", table_name.unwrap_or("undefined")),
("operation", format!("{:?}", operation))
);

crate::metrics::DATABASE_CALLS_COUNT.add(1, attributes);
crate::metrics::DATABASE_CALL_TIME.record(time_elapsed.as_secs_f64(), attributes);

output
}
}
Expand Down
Loading

0 comments on commit 873b18e

Please sign in to comment.