-
Notifications
You must be signed in to change notification settings - Fork 948
feat: adding telemetry-trace-sample-rate cli arg and set default to 1%
#8561
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: unstable
Are you sure you want to change the base?
Changes from all commits
d3b16dc
5b8494f
f3f343c
93aaca2
20d7332
e039381
97e06e1
3cf9c1a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -294,6 +294,23 @@ fn main() { | |
| .global(true) | ||
| .display_order(0) | ||
| ) | ||
| .arg( | ||
| Arg::new("telemetry-trace-sample-rate") | ||
| .long("telemetry-trace-sample-rate") | ||
| .value_name("PERCENT") | ||
| .help( | ||
| "OpenTelemetry trace sampling rate as a percentage (0-100). \ | ||
| A value of 1 means 1% of traces are sampled. \ | ||
| Lower values reduce resource consumption. \ | ||
| For more info see https://opentelemetry.io/docs/concepts/sampling/#why-sampling" | ||
| ) | ||
| .requires("telemetry-collector-url") | ||
| .value_parser(clap::value_parser!(u8).range(0..=100)) | ||
| .default_value("1") | ||
| .action(ArgAction::Set) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lets set the default here explicitly via
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can also set a min and max value explicitly at the flag level
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure and we can use the range of value parser for min and max |
||
| .global(true) | ||
| .display_order(0) | ||
| ) | ||
| .arg( | ||
| Arg::new("datadir") | ||
| .long("datadir") | ||
|
|
@@ -657,6 +674,7 @@ fn run<E: EthSpec>( | |
| .eth2_network_config(eth2_network_config)? | ||
| .build()?; | ||
|
|
||
| let mut telemetry_sample_ratio = None; | ||
| if let Some(telemetry_collector_url) = matches.get_one::<String>("telemetry-collector-url") { | ||
| let telemetry_layer = environment.runtime().block_on(async { | ||
| let exporter = opentelemetry_otlp::SpanExporter::builder() | ||
|
|
@@ -675,8 +693,18 @@ fn run<E: EthSpec>( | |
| _ => "lighthouse".to_string(), | ||
| }); | ||
|
|
||
| // Calculate sample percent as a ratio (percentage / 100) | ||
| telemetry_sample_ratio = Some(matches | ||
| .get_one::<u8>("telemetry-trace-sample-rate") | ||
| .copied() | ||
| .unwrap_or(1) as f64 / 100.0); | ||
| let sampler = opentelemetry_sdk::trace::Sampler::ParentBased(Box::new( | ||
| opentelemetry_sdk::trace::Sampler::TraceIdRatioBased(telemetry_sample_ratio.unwrap()), | ||
| )); | ||
|
|
||
| let provider = opentelemetry_sdk::trace::SdkTracerProvider::builder() | ||
| .with_batch_exporter(exporter) | ||
| .with_sampler(sampler) | ||
| .with_resource( | ||
| opentelemetry_sdk::Resource::builder() | ||
| .with_service_name(service_name) | ||
|
|
@@ -823,6 +851,7 @@ fn run<E: EthSpec>( | |
| let executor = context.executor.clone(); | ||
| let mut config = beacon_node::get_config::<E>(matches, &context)?; | ||
| config.logger_config = logger_config; | ||
| config.telemetry_sample_ratio = telemetry_sample_ratio; | ||
| // Dump configs if `dump-config` or `dump-chain-config` flags are set | ||
| clap_utils::check_dump_configs::<_, E>(matches, &config, &context.eth2_config.spec)?; | ||
|
|
||
|
|
@@ -868,4 +897,4 @@ fn run<E: EthSpec>( | |
| ShutdownReason::Success(_) => Ok(()), | ||
| ShutdownReason::Failure(msg) => Err(msg.to_string()), | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please write a test case for this flag. we have some example flag specific tests you can use as an example