Skip to content

Commit bcfe604

Browse files
committed
fix all usages of logging, kill me please
1 parent 4ca9405 commit bcfe604

55 files changed

Lines changed: 670 additions & 365 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

bin/router/src/jwt/jwks_manager.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use hive_router_config::jwt_auth::{JwksProviderSourceConfig, JwtAuthConfig};
2-
use hive_router_internal::background_tasks::{BackgroundTask, BackgroundTasksManager};
2+
use hive_router_internal::{
3+
background_tasks::{BackgroundTask, BackgroundTasksManager},
4+
telemetry::logging::targets,
5+
};
36
use sonic_rs::from_str;
47
use std::sync::{Arc, RwLock};
58
use tokio::fs::read_to_string;
@@ -29,7 +32,7 @@ impl JwksManager {
2932
.filter_map(|v| match v.get_jwk_set() {
3033
Ok(set) => Some(set),
3134
Err(err) => {
32-
error!("Failed to use JWK set: {}, ignoring", err);
35+
error!(target: targets::JWT, error = ?err, "failed to use jwt set, ignoring this set");
3336

3437
None
3538
}
@@ -79,9 +82,10 @@ impl BackgroundTask for JwksSourceTask {
7982
..
8083
} = &self.0.config
8184
{
82-
debug!(
83-
"Starting remote jwks polling for source: {:?}",
84-
self.0.config
85+
info!(
86+
target: targets::JWT,
87+
source = ?self.0.config,
88+
"starting remote jwks polling for source",
8589
);
8690
let mut tokio_interval = tokio::time::interval(*interval);
8791

@@ -90,10 +94,10 @@ impl BackgroundTask for JwksSourceTask {
9094
_ = tokio_interval.tick() => { match self.0.load_and_store_jwks().await {
9195
Ok(_) => {}
9296
Err(err) => {
93-
error!("Failed to load remote jwks: {}", err);
97+
error!(target: targets::JWT, error = ?err, source = ?self.0.config, "failed to load remote jwks");
9498
}
9599
} }
96-
_ = token.cancelled() => { info!("Jwks source shutting down."); return; }
100+
_ = token.cancelled() => { info!(target: targets::JWT, "jwks source shutting down."); return; }
97101
}
98102
}
99103
}
@@ -117,7 +121,7 @@ impl JwksSource {
117121
let jwks_str = match &self.config {
118122
JwksProviderSourceConfig::Remote { url, .. } => {
119123
let client = reqwest::Client::new();
120-
debug!("loading jwks from a remote source: {}", url);
124+
debug!(target: targets::JWT, url = ?url, "loading jwks from a remote source");
121125

122126
let response_text = client
123127
.get(url)
@@ -131,7 +135,7 @@ impl JwksSource {
131135
response_text
132136
}
133137
JwksProviderSourceConfig::File { file, .. } => {
134-
debug!("loading jwks from a file source: {}", file.absolute);
138+
debug!(target: targets::JWT, path = ?file.absolute, "loading jwks from a file source");
135139

136140
let file_contents = read_to_string(&file.absolute)
137141
.await

bin/router/src/jwt/mod.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{str::FromStr, sync::Arc};
66

77
use cookie::Cookie;
88
use hive_router_config::jwt_auth::{JwtAuthConfig, JwtAuthPluginLookupLocation};
9-
use hive_router_internal::background_tasks::BackgroundTasksManager;
9+
use hive_router_internal::{background_tasks::BackgroundTasksManager, telemetry::logging::targets};
1010
use http::header::COOKIE;
1111
use jsonwebtoken::{
1212
decode, decode_header,
@@ -94,7 +94,7 @@ impl JwtAuthRuntime {
9494
let raw_cookies = match cookie_raw.to_str() {
9595
Ok(cookies) => cookies.split(';'),
9696
Err(e) => {
97-
warn!("jwt auth failed to convert cookie header to string, ignoring cookie. error: {}", e);
97+
warn!(target: targets::JWT, error = ?e, "jwt auth failed to convert cookie header to string, ignoring cookie");
9898
continue;
9999
}
100100
};
@@ -111,10 +111,7 @@ impl JwtAuthRuntime {
111111
Err(e) => {
112112
// Should we reject the entire request in case of invalid cookies?
113113
// I think it's better to consider this as a user error? maybe return 400?
114-
warn!(
115-
"jwt auth failed to parse cookie value, ignoring cookie. error: {}",
116-
e
117-
);
114+
warn!(target: targets::JWT, error = ?e, "jwt auth failed to parse cookie value, ignoring cookie");
118115
}
119116
}
120117
}
@@ -173,7 +170,7 @@ impl JwtAuthRuntime {
173170
.map(|token_data| (token_data, maybe_prefix, token))
174171
}
175172
Err(e) => {
176-
warn!("jwt plugin failed to lookup token. error: {}", e);
173+
warn!(target: targets::JWT, error = ?e, "jwt plugin failed to lookup token");
177174

178175
Err(JwtError::LookupFailed(e))
179176
}
@@ -311,7 +308,7 @@ impl JwtAuthRuntime {
311308
token_prefix: maybe_prefix,
312309
})),
313310
Err(err) => {
314-
warn!("jwt token error: {:?}", err);
311+
warn!(target: targets::JWT, error = ?err, "jwt token error");
315312
if self.config.require_authentication.is_some_and(|v| v) {
316313
Err((*err).clone())
317314
} else {

bin/router/src/lib.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ mod utils;
1414

1515
use std::ops::ControlFlow;
1616
use std::sync::Arc;
17-
use tracing::error;
17+
use tracing::{debug, error};
1818

1919
use crate::{
2020
consts::ROUTER_VERSION,
@@ -61,7 +61,7 @@ pub use hive_router_config::humantime_serde;
6161
use hive_router_config::{load_config, subscriptions::CallbackConfig, HiveRouterConfig};
6262
pub use hive_router_internal::background_tasks;
6363
use hive_router_internal::telemetry::{
64-
logging::{log_http_request_end, log_http_request_start},
64+
logging::{log_http_request_end, log_http_request_start, targets},
6565
otel::tracing_opentelemetry::OpenTelemetrySpanExt,
6666
traces::spans::http_request::HttpServerRequestSpan,
6767
TelemetryContext,
@@ -237,7 +237,7 @@ async fn graphql_endpoint_dispatch(
237237
.take()
238238
.modify_client_response_headers(response.headers_mut())
239239
{
240-
error!(error = %err, "Failed to apply response header rules to the outgoing client response");
240+
error!(target: targets::HEADER_MANIPULATION, error = %err, "failed to apply response header rules to the outgoing client response");
241241
}
242242

243243
// Apply CORS headers to the final response if CORS is configured.
@@ -260,7 +260,7 @@ async fn graphql_endpoint_dispatch(
260260
ControlFlow::Break(updated_response) | ControlFlow::Continue(updated_response),
261261
) => updated_response,
262262
Err(error) => {
263-
warn!(%error, "coprocessor graphql.response stage failed");
263+
warn!(target: targets::COPROCESSOR, error = ?error, "coprocessor graphql.response stage failed");
264264
write_graphql_response_metric_status(request, GraphQLResponseStatus::Error);
265265
handle_pipeline_error(error.into(), request, &app_state, &response_mode)
266266
}
@@ -291,7 +291,7 @@ pub async fn router_entrypoint(plugin_registry: PluginRegistry) -> Result<(), Ro
291291
.prometheus
292292
.as_ref()
293293
.and_then(|prom| prom.to_attached());
294-
info!("hive-router@{} starting...", ROUTER_VERSION);
294+
info!(target: targets::CORE, version = ROUTER_VERSION, "hive-router starting...");
295295
let addr = router_config.address();
296296
let graphql_path = router_config.graphql_path().to_string();
297297
let websocket_path = router_config.websocket_path().map(|p| p.to_string());
@@ -332,8 +332,9 @@ pub async fn router_entrypoint(plugin_registry: PluginRegistry) -> Result<(), Ro
332332
});
333333
if let Some(workers) = workers {
334334
info!(
335-
"configuring HTTP callback server with {} worker(s)",
336-
workers
335+
target: targets::CORE,
336+
workers_count = workers,
337+
"configuring HTTP callback server worker(s)",
337338
);
338339
cb_server_builder = cb_server_builder.workers(workers.get());
339340
}
@@ -386,7 +387,7 @@ pub async fn router_entrypoint(plugin_registry: PluginRegistry) -> Result<(), Ro
386387
});
387388

388389
if let Some(workers) = workers {
389-
info!("configuring HTTP server with {} worker(s)", workers);
390+
info!(target: targets::CORE, workers_count = workers, "configuring HTTP server worker(s)");
390391
server = server.workers(workers.get());
391392
}
392393

@@ -426,7 +427,7 @@ pub async fn router_entrypoint(plugin_registry: PluginRegistry) -> Result<(), Ro
426427
.await
427428
.map_err(RouterInitError::HttpServerStartError);
428429

429-
info!("server stopped, clearing background tasks");
430+
info!(target: targets::CORE, "router stopped, clearing background tasks");
430431
bg_tasks_manager.shutdown();
431432
telemetry.graceful_shutdown().await;
432433

@@ -437,7 +438,8 @@ pub async fn router_entrypoint(plugin_registry: PluginRegistry) -> Result<(), Ro
437438

438439
pub async fn invoke_shutdown_hooks(shared_state: &RouterSharedState) {
439440
if let Some(plugins) = &shared_state.plugins {
440-
info!("invoking plugin shutdown hooks");
441+
debug!(target: targets::CORE, "invoking plugin shutdown hooks");
442+
441443
for plugin in plugins.as_ref() {
442444
plugin.on_shutdown().await;
443445
}
@@ -676,7 +678,7 @@ pub fn init_rustls_crypto_provider() {
676678
.install_default()
677679
.is_err()
678680
{
679-
warn!("Rustls crypto provider already installed");
681+
error!(target: targets::TLS, "rustls crypto provider already installed, ignoring");
680682
}
681683
}
682684

bin/router/src/pipeline/active_subscriptions.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::sync::Arc;
22

33
use bytes::Bytes;
44
use dashmap::DashMap;
5+
use hive_router_internal::telemetry::logging::targets;
56
use hive_router_plan_executor::response::graphql_error::GraphQLError;
67
use tokio::sync::broadcast;
78
use tracing::trace;
@@ -54,7 +55,7 @@ impl ActiveSubscriptions {
5455
_guard: guard,
5556
};
5657

57-
trace!(subscription_id = %id, "registered new subscription");
58+
trace!(target: targets::SUBSCRIPTIONS, subscription_id = %id, "registered new subscription");
5859

5960
(handle, receiver)
6061
}
@@ -93,6 +94,6 @@ impl ProducerHandle {
9394
impl Drop for ProducerHandle {
9495
fn drop(&mut self) {
9596
self.map.remove(&self.id);
96-
trace!(subscription_id = %self.id, "producer dropped, upstream closed");
97+
trace!(target: targets::SUBSCRIPTIONS, subscription_id = %self.id, "producer dropped, upstream closed");
9798
}
9899
}

bin/router/src/pipeline/authorization/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use crate::pipeline::normalize::{hash_normalized_operation, GraphQLNormalization
2929
use hive_router_config::authorization::UnauthorizedMode;
3030
use hive_router_config::HiveRouterConfig;
3131
use hive_router_internal::authorization::metadata::AuthorizationMetadata;
32+
use hive_router_internal::telemetry::logging::targets;
3233
use hive_router_plan_executor::execution::client_request_details::JwtRequestDetails;
3334
use hive_router_plan_executor::execution::plan::CoerceVariablesPayload;
3435
use hive_router_plan_executor::introspection::schema::SchemaMetadata;
@@ -180,7 +181,8 @@ pub fn apply_authorization_to_operation(
180181
}
181182

182183
if reject_mode {
183-
tracing::debug!("Request rejected due to unauthorized fields and reject mode being set");
184+
tracing::warn!(target: targets::AUTHORIZATION, "request rejected due to unauthorized fields and reject mode being set");
185+
184186
return AuthorizationDecision::Reject {
185187
errors: collection_result.errors,
186188
};

bin/router/src/pipeline/coerce_variables.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
use std::collections::HashMap;
22

3+
use hive_router_internal::telemetry::logging::targets;
34
use hive_router_internal::telemetry::traces::spans::graphql::GraphQLVariableCoercionSpan;
45
use hive_router_plan_executor::execution::plan::CoerceVariablesPayload;
56
use hive_router_plan_executor::hooks::on_supergraph_load::SupergraphData;
67
use hive_router_plan_executor::variables::collect_variables;
78
use sonic_rs::Value;
8-
use tracing::{trace, warn};
9+
use tracing::{debug, warn};
910

1011
use crate::pipeline::error::PipelineError;
1112
use crate::pipeline::normalize::GraphQLNormalizationPayload;
@@ -24,9 +25,10 @@ pub fn coerce_request_variables(
2425
&supergraph.metadata,
2526
) {
2627
Ok(values) => {
27-
trace!(
28-
"sucessfully collected variables from incoming request: {:?}",
29-
values
28+
debug!(
29+
target: targets::COERCE_VARIABLES,
30+
variables = ?values,
31+
"sucessfully collected variables from incoming request",
3032
);
3133

3234
Ok(CoerceVariablesPayload {
@@ -35,8 +37,9 @@ pub fn coerce_request_variables(
3537
}
3638
Err(err_msg) => {
3739
warn!(
38-
"failed to collect variables from incoming request: {}",
39-
err_msg
40+
target: targets::COERCE_VARIABLES,
41+
error = ?err_msg,
42+
"failed to collect variables from incoming request",
4043
);
4144
Err(PipelineError::VariablesCoercionError(err_msg))
4245
}

bin/router/src/pipeline/demand_control/formula.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use ahash::{HashMap as AHashMap, HashMapExt, HashSet as AHashSet, HashSetExt};
22

3+
use hive_router_internal::telemetry::logging::targets;
34
use hive_router_plan_executor::execution::demand_control::demand_control_definition_cost;
45
use hive_router_plan_executor::execution::demand_control::CompiledActualCostPlan;
56
use hive_router_plan_executor::execution::demand_control::DemandControlEvaluation;
@@ -298,6 +299,7 @@ fn eval_cost_expr(
298299
Ok(only_value)
299300
} else {
300301
warn!(
302+
target: targets::DEMAND_CONTROL,
301303
field = field_name.as_str(),
302304
found = resolved_count,
303305
"rejecting operation: expected exactly one slicing argument for @listSize"

bin/router/src/pipeline/demand_control/runtime.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use hive_router_config::demand_control::{
66
DemandControlActualCostMode, DemandControlConfig, DemandControlExposeHeadersConfig,
77
DemandControlMode,
88
};
9+
use hive_router_internal::telemetry::logging::targets;
910
use hive_router_internal::telemetry::metrics::demand_control_metrics::DemandControlResultCode;
1011
use hive_router_internal::telemetry::metrics::Metrics;
1112
use hive_router_internal::telemetry::traces::spans::graphql::GraphQLSpanOperationIdentity;
@@ -44,12 +45,15 @@ impl DemandControlRuntime {
4445
metrics: Arc<Metrics>,
4546
) -> Option<Self> {
4647
let config = config?;
48+
4749
if !config.enabled {
48-
debug!("demand control is disabled");
50+
debug!(target: targets::DEMAND_CONTROL, "demand control is disabled");
51+
4952
return None;
5053
}
5154

5255
info!(
56+
target: targets::DEMAND_CONTROL,
5357
operation_mode = ?config.operation_cost.mode,
5458
operation_max_cost = config.operation_cost.max,
5559
subgraph_budget_mode = ?config.subgraphs_budget.mode,
@@ -61,6 +65,7 @@ impl DemandControlRuntime {
6165
if config.operation_cost.mode == DemandControlMode::Enforce {
6266
if config.operation_cost.max == 0 {
6367
warn!(
68+
target: targets::DEMAND_CONTROL,
6469
"demand control is in enforce mode with a max cost of 0; all operations with non-zero cost will be rejected"
6570
);
6671
}
@@ -69,6 +74,7 @@ impl DemandControlRuntime {
6974
&& config.default_list_size.subgraphs.is_none()
7075
{
7176
warn!(
77+
target: targets::DEMAND_CONTROL,
7278
"demand control is in enforce mode without a default list_size; list fields without an @listSize directive are estimated as 0 and may be under-counted"
7379
);
7480
}
@@ -141,6 +147,7 @@ impl DemandControlRuntime {
141147
match self.config.operation_cost.mode {
142148
DemandControlMode::Enforce => {
143149
warn!(
150+
target: targets::DEMAND_CONTROL,
144151
operation_name = ?operation_name,
145152
estimated_cost = evaluation.estimated_cost,
146153
max_cost,
@@ -166,6 +173,7 @@ impl DemandControlRuntime {
166173
}
167174
DemandControlMode::Measure => {
168175
info!(
176+
target: targets::DEMAND_CONTROL,
169177
operation_name = ?operation_name,
170178
estimated_cost = evaluation.estimated_cost,
171179
max_cost,
@@ -231,7 +239,13 @@ impl DemandControlRuntime {
231239

232240
if let Some(subgraph_max) = maybe_subgraph_max {
233241
if *estimated_cost > subgraph_max {
234-
debug!(subgraph_name = subgraph.as_str(), estimated_cost, subgraph_max, "subgraph call will be blocked dueing execution due to estimated cost exceeding limit");
242+
debug!(
243+
target: targets::DEMAND_CONTROL,
244+
subgraph_name = subgraph.as_str(),
245+
estimated_cost,
246+
subgraph_max,
247+
"subgraph call will be blocked during execution due to estimated cost exceeding limit"
248+
);
235249
over_limit.insert(subgraph.clone(), subgraph_max);
236250
}
237251
}

0 commit comments

Comments
 (0)