|
6 | 6 | use num::bigint::{BigInt, Sign}; |
7 | 7 | use std::cell::Cell; |
8 | 8 | use std::collections::HashMap; |
9 | | -use std::sync::OnceLock; |
10 | 9 |
|
11 | 10 | use serde_json::Value; |
12 | 11 | use sha1::{Digest, Sha1}; |
@@ -345,61 +344,6 @@ fn eval_equals(ctx_val: &Value, condition_val: &Value) -> bool { |
345 | 344 | } |
346 | 345 | } |
347 | 346 |
|
348 | | -#[derive(Debug, PartialEq)] |
349 | | -enum DebugLogLevel { |
350 | | - None, |
351 | | - Parse, |
352 | | - Match, |
353 | | - All, |
354 | | -} |
355 | | - |
356 | | -static DEBUG_LOG_LEVEL: OnceLock<DebugLogLevel> = OnceLock::new(); |
357 | | -static DEBUG_MATCH_SAMPLE_RATE: OnceLock<u64> = OnceLock::new(); |
358 | | - |
359 | | -fn debug_log_level() -> &'static DebugLogLevel { |
360 | | - DEBUG_LOG_LEVEL.get_or_init(|| { |
361 | | - match std::env::var("SENTRY_OPTIONS_FEATURE_DEBUG_LOG") |
362 | | - .as_deref() |
363 | | - .unwrap_or("") |
364 | | - { |
365 | | - "all" => DebugLogLevel::All, |
366 | | - "parse" => DebugLogLevel::Parse, |
367 | | - "match" => DebugLogLevel::Match, |
368 | | - _ => DebugLogLevel::None, |
369 | | - } |
370 | | - }) |
371 | | -} |
372 | | - |
373 | | -fn debug_match_sample_rate() -> u64 { |
374 | | - *DEBUG_MATCH_SAMPLE_RATE.get_or_init(|| { |
375 | | - std::env::var("SENTRY_OPTIONS_FEATURE_DEBUG_LOG_SAMPLE_RATE") |
376 | | - .ok() |
377 | | - .and_then(|v| v.parse::<f64>().ok()) |
378 | | - .map(|r| (r.clamp(0.0, 1.0) * 1000.0) as u64) |
379 | | - .unwrap_or(1000) |
380 | | - }) |
381 | | -} |
382 | | - |
383 | | -fn debug_log_parse(msg: &str) { |
384 | | - match debug_log_level() { |
385 | | - DebugLogLevel::Parse | DebugLogLevel::All => eprintln!("[sentry-options/parse] {msg}"), |
386 | | - _ => {} |
387 | | - } |
388 | | -} |
389 | | - |
390 | | -fn debug_log_match(feature: &str, result: bool, context_id: u64) { |
391 | | - match debug_log_level() { |
392 | | - DebugLogLevel::Match | DebugLogLevel::All => { |
393 | | - if context_id % 1000 < debug_match_sample_rate() { |
394 | | - eprintln!( |
395 | | - "[sentry-options/match] feature='{feature}' result={result} context_id={context_id}" |
396 | | - ); |
397 | | - } |
398 | | - } |
399 | | - _ => {} |
400 | | - } |
401 | | -} |
402 | | - |
403 | 347 | /// A handle for checking feature flags within a specific namespace. |
404 | 348 | pub struct FeatureChecker { |
405 | 349 | namespace: String, |
@@ -427,24 +371,29 @@ impl FeatureChecker { |
427 | 371 | let feature_val = match opts.get(&self.namespace, &key) { |
428 | 372 | Ok(v) => v, |
429 | 373 | Err(e) => { |
430 | | - debug_log_parse(&format!("Failed to get feature '{key}': {e}")); |
| 374 | + tracing::debug!(key = %key, error = %e, "Failed to get feature"); |
431 | 375 | return false; |
432 | 376 | } |
433 | 377 | }; |
434 | 378 |
|
435 | 379 | let feature = match Feature::from_json(&feature_val) { |
436 | 380 | Some(f) => { |
437 | | - debug_log_parse(&format!("Parsed feature '{key}'")); |
| 381 | + tracing::debug!(key = %key, "Parsed feature"); |
438 | 382 | f |
439 | 383 | } |
440 | 384 | None => { |
441 | | - debug_log_parse(&format!("Failed to parse feature '{key}'")); |
| 385 | + tracing::debug!(key = %key, "Failed to parse feature"); |
442 | 386 | return false; |
443 | 387 | } |
444 | 388 | }; |
445 | 389 |
|
446 | 390 | let result = feature.matches(context); |
447 | | - debug_log_match(feature_name, result, context.id()); |
| 391 | + tracing::debug!( |
| 392 | + feature = feature_name, |
| 393 | + result, |
| 394 | + context_id = context.id(), |
| 395 | + "Feature match result" |
| 396 | + ); |
448 | 397 | result |
449 | 398 | } |
450 | 399 | } |
|
0 commit comments