-
Notifications
You must be signed in to change notification settings - Fork 15
feat: populate metric labels from span context using metrics-tracing-context #2634
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: main
Are you sure you want to change the base?
Changes from all commits
f202755
1825ab9
c83e13c
496a875
8d11927
2edfb07
8f21dd9
65c5509
9b2af46
4178a45
ad93bf7
7412249
1a03caf
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 |
|---|---|---|
|
|
@@ -2,6 +2,12 @@ use std::net::SocketAddr; | |
|
|
||
| use clap::Parser; | ||
| use display_json::DebugAsJson; | ||
| #[cfg(feature = "metrics")] | ||
| use metrics_exporter_prometheus::PrometheusBuilder; | ||
| #[cfg(feature = "metrics")] | ||
| use metrics_tracing_context::TracingContextLayer as MetricsTracingContextLayer; | ||
| #[cfg(feature = "metrics")] | ||
| use metrics_util::layers::Layer as MetricsLayerExt; | ||
|
|
||
| use crate::infra::metrics::metrics_for_consensus; | ||
| use crate::infra::metrics::metrics_for_executor; | ||
|
|
@@ -36,7 +42,7 @@ impl MetricsConfig { | |
| metrics.extend(metrics_for_kafka()); | ||
|
|
||
| // init metric exporter | ||
| init_metrics_exporter(self.metrics_exporter_address); | ||
| init_metrics_exporter(self.metrics_exporter_address)?; | ||
|
|
||
| // init metric description (always after provider started) | ||
| for metric in &metrics { | ||
|
|
@@ -48,19 +54,32 @@ impl MetricsConfig { | |
| } | ||
|
|
||
| #[cfg(feature = "metrics")] | ||
| fn init_metrics_exporter(address: SocketAddr) { | ||
| fn init_metrics_exporter(address: SocketAddr) -> anyhow::Result<()> { | ||
| tracing::info!(%address, "creating prometheus metrics exporter"); | ||
| if let Err(e) = metrics_exporter_prometheus::PrometheusBuilder::new() | ||
|
|
||
| let builder = PrometheusBuilder::new() | ||
| .add_global_label("service", crate::infra::build_info::service_name()) | ||
| .add_global_label("version", crate::infra::build_info::version()) | ||
| .with_http_listener(address) | ||
| .install() | ||
| { | ||
| tracing::error!(reason = ?e, %address, "failed to create metrics exporter"); | ||
| } | ||
| .with_http_listener(address); | ||
|
|
||
| install_metrics_tracing_recorder(builder)?; | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| #[cfg(feature = "metrics")] | ||
| fn install_metrics_tracing_recorder(builder: PrometheusBuilder) -> anyhow::Result<()> { | ||
| let (recorder, exporter) = builder.build()?; | ||
| tokio::spawn(exporter); | ||
|
|
||
| let recorder = MetricsTracingContextLayer::only_allow(["rpc_client", "rpc_method", "point_in_time"]).layer(recorder); | ||
|
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.
When metrics are enabled and an RPC arrives, this recorder adds Useful? React with 👍 / 👎. |
||
| metrics::set_global_recorder(recorder)?; | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| #[cfg(not(feature = "metrics"))] | ||
| fn init_metrics_exporter(_: SocketAddr) { | ||
| fn init_metrics_exporter(_: SocketAddr) -> anyhow::Result<()> { | ||
| tracing::info!("creating noop metrics exporter"); | ||
| Ok(()) | ||
| } | ||
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.
When
rpc_callis reached through thestratus_callhandler, this recording is a no-op because that handler'srpc::stratus_callspan declares onlytx_from,tx_to, andfilter; tracing cannot dynamically add an undeclared field. Consequently metrics emitted while executingstratus_calllack the newpoint_in_timelabel even though the same helper supplies it foreth_call. Add the empty field to thestratus_callspan as well.Useful? React with 👍 / 👎.