Skip to content

Commit af71828

Browse files
refactor(config): add independent toggles for enabling traces and metrics (#1020)
1 parent 0df2244 commit af71828

File tree

14 files changed

+73
-69
lines changed

14 files changed

+73
-69
lines changed

config/config.example.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ filtering_directive = "WARN,router=INFO,reqwest=INFO"
8686

8787
# Telemetry configuration for metrics and traces
8888
[log.telemetry]
89-
enabled = false # boolean [true or false]
89+
traces_enabled = false # boolean [true or false], whether traces are enabled
90+
metrics_enabled = false # boolean [true or false], whether metrics are enabled
91+
ignore_errors = false # boolean [true or false], whether to ignore errors during traces or metrics pipeline setup
9092
sampling_rate = 0.1 # decimal rate between 0.0 - 1.0
9193
otel_exporter_otlp_endpoint = "http://localhost:4317" # endpoint to send metrics and traces to, can include port number
9294
otel_exporter_otlp_timeout = 5000 # timeout (in milliseconds) for sending metrics and traces

config/development.toml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ level = "DEBUG"
77
log_format = "default"
88

99
[log.telemetry]
10-
enabled = false
10+
traces_enabled = false
11+
metrics_enabled = false
1112

1213
# TODO: Update database credentials before running application
1314
[master_database]
@@ -31,8 +32,6 @@ connection_timeout = 10
3132
[secrets]
3233
admin_api_key = "test_admin"
3334

34-
[proxy]
35-
3635
[locker]
3736
host = ""
3837
mock_locker = true
@@ -148,10 +147,10 @@ stripe = { banks = "abn_amro,asn_bank,bunq,handelsbanken,ing,knab,moneyou,raboba
148147
adyen = { banks = "abn_amro,asn_bank,bunq,handelsbanken,ing,knab,moneyou,rabobank,regiobank,revolut,sns_bank,triodos_bank,van_lanschot" }
149148

150149
[bank_config.online_banking_czech_republic]
151-
adyen = { banks = "ceska_sporitelna,komercni_banka,platnosc_online_karta_platnicza"}
150+
adyen = { banks = "ceska_sporitelna,komercni_banka,platnosc_online_karta_platnicza" }
152151

153152
[bank_config.online_banking_slovakia]
154-
adyen = { banks = "e_platby_v_u_b,postova_banka,sporo_pay,tatra_pay,viamo,volksbank_gruppe,volkskredit_bank_ag,vr_bank_braunau"}
153+
adyen = { banks = "e_platby_v_u_b,postova_banka,sporo_pay,tatra_pay,viamo,volksbank_gruppe,volkskredit_bank_ag,vr_bank_braunau" }
155154

156155
[pm_filters.stripe]
157156
google_pay = { country = "AL,DZ,AS,AO,AG,AR,AU,AT,AZ,BH,BY,BE,BR,BG,CA,CL,CO,HR,CZ,DK,DO,EG,EE,FI,FR,DE,GR,HK,HU,IN,ID,IE,IL,IT,JP,JO,KZ,KE,KW,LV,LB,LT,LU,MY,MX,NL,NZ,NO,OM,PK,PA,PE,PH,PL,PT,QA,RO,RU,SA,SG,SK,ZA,ES,LK,SE,CH,TW,TH,TR,UA,AE,GB,US,UY,VN" }
@@ -195,5 +194,5 @@ bucket_name = ""
195194
region = ""
196195

197196
[tokenization]
198-
stripe = { long_lived_token = false, payment_method = "wallet"}
199-
checkout = { long_lived_token = false, payment_method = "wallet"}
197+
stripe = { long_lived_token = false, payment_method = "wallet" }
198+
checkout = { long_lived_token = false, payment_method = "wallet" }

config/docker_compose.toml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ enabled = true # Whether you want to see log in your terminal.
1414
level = "DEBUG" # What you see in your terminal.
1515

1616
[log.telemetry]
17-
enabled = false # Whether tracing/telemetry is enabled.
17+
traces_enabled = false # Whether traces are enabled.
18+
metrics_enabled = false # Whether metrics are enabled.
19+
ignore_errors = false # Whether to ignore errors during traces or metrics pipeline setup.
20+
otel_exporter_otlp_endpoint = "https://otel-collector:4317" # Endpoint to send metrics and traces to.
1821

1922
[master_database]
2023
username = "db_user"
@@ -32,10 +35,6 @@ port = 5432
3235
dbname = "hyperswitch_db"
3336
pool_size = 5
3437

35-
[proxy]
36-
# http_url = "http proxy URL"
37-
# https_url = "https proxy URL"
38-
3938
[secrets]
4039
admin_api_key = "test_admin"
4140
jwt_secret = "secret"

crates/drainer/src/env.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ pub mod logger {
66
pub use router_env::{log, logger::*};
77

88
/// Setup logging sub-system
9-
pub fn setup(
10-
conf: &config::Log,
11-
) -> error_stack::Result<TelemetryGuard, router_env::opentelemetry::metrics::MetricsError> {
12-
Ok(router_env::setup(conf, router_env::service_name!(), [])?)
9+
pub fn setup(conf: &config::Log) -> TelemetryGuard {
10+
router_env::setup(conf, router_env::service_name!(), [])
1311
}
1412
}

crates/drainer/src/errors.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ pub enum DrainerError {
99
RedisError(error_stack::Report<redis::errors::RedisError>),
1010
#[error("Application configuration error: {0}")]
1111
ConfigurationError(config::ConfigError),
12-
#[error("Metrics initialization error")]
13-
MetricsError,
1412
#[error("Error while configuring signals: {0}")]
1513
SignalError(String),
1614
#[error("Unexpected error occurred: {0}")]

crates/drainer/src/main.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use drainer::{errors, errors::DrainerResult, logger::logger, services, settings, start_drainer};
2-
use error_stack::ResultExt;
1+
use drainer::{errors::DrainerResult, logger::logger, services, settings, start_drainer};
32

43
#[tokio::main]
54
async fn main() -> DrainerResult<()> {
@@ -21,7 +20,7 @@ async fn main() -> DrainerResult<()> {
2120
let shutdown_intervals = conf.drainer.shutdown_interval;
2221
let loop_interval = conf.drainer.loop_interval;
2322

24-
let _guard = logger::setup(&conf.log).change_context(errors::DrainerError::MetricsError)?;
23+
let _guard = logger::setup(&conf.log);
2524

2625
logger::info!("Drainer started [{:?}] [{:?}]", conf.drainer, conf.log);
2726

crates/router/src/bin/router.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ async fn main() -> ApplicationResult<()> {
3434
conf.validate()
3535
.expect("Failed to validate router configuration");
3636

37-
let _guard = logger::setup(&conf.log)?;
37+
let _guard = logger::setup(&conf.log);
3838

3939
logger::info!("Application started [{:?}] [{:?}]", conf.server, conf.log);
4040

crates/router/src/bin/scheduler.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ async fn main() -> CustomResult<(), errors::ProcessTrackerError> {
2828
redis_shutdown_signal_rx,
2929
tx.clone(),
3030
));
31-
let _guard =
32-
logger::setup(&state.conf.log).map_err(|_| errors::ProcessTrackerError::UnexpectedFlow)?;
31+
let _guard = logger::setup(&state.conf.log);
3332

3433
logger::debug!(startup_config=?state.conf);
3534

crates/router/src/env.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,8 @@ pub mod logger {
44
#[doc(inline)]
55
pub use router_env::{log, logger::*};
66

7-
// TODO (prom-monitoring): Ideally tracing/opentelemetry structs shouldn't be pushed out.
8-
// Return a custom error type instead of `opentelemetry::metrics::MetricsError`.
97
/// Setup logging sub-system.
10-
pub fn setup(
11-
conf: &config::Log,
12-
) -> Result<TelemetryGuard, router_env::opentelemetry::metrics::MetricsError> {
8+
pub fn setup(conf: &config::Log) -> TelemetryGuard {
139
router_env::setup(conf, router_env::service_name!(), ["actix_server"])
1410
}
1511
}

crates/router_env/src/logger/config.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,12 @@ pub struct LogConsole {
8787
#[derive(Debug, Deserialize, Clone, Default)]
8888
#[serde(default)]
8989
pub struct LogTelemetry {
90-
/// Whether tracing/telemetry is enabled.
91-
pub enabled: bool,
90+
/// Whether the traces pipeline is enabled.
91+
pub traces_enabled: bool,
92+
/// Whether the metrics pipeline is enabled.
93+
pub metrics_enabled: bool,
94+
/// Whether errors in setting up traces or metrics pipelines must be ignored.
95+
pub ignore_errors: bool,
9296
/// Sampling rate for traces
9397
pub sampling_rate: Option<f64>,
9498
/// Base endpoint URL to send metrics and traces to. Can optionally include the port number.

0 commit comments

Comments
 (0)