Skip to content

feat: populate metric labels from span context using metrics-tracing-context - #2634

Open
carneiro-cw wants to merge 11 commits into
mainfrom
feat_metrics
Open

feat: populate metric labels from span context using metrics-tracing-context#2634
carneiro-cw wants to merge 11 commits into
mainfrom
feat_metrics

Conversation

@carneiro-cw

Copy link
Copy Markdown
Contributor

No description provided.

@carneiro-cw
carneiro-cw requested a review from a team as a code owner August 25, 2026 20:04

@cloudwalk-review-agent cloudwalk-review-agent Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Good direction overall: wiring tracing span fields into metrics labels is useful, and moving metrics init into the Tokio runtime context is necessary for the spawned exporter task. I found one blocking correctness issue in the span field population that can prevent the intended label from ever being attached to eth_call metrics.

Blocking

  1. eth_call creates a point_in_time span field, but the value is recorded in rpc_call before that method span exists, so the field is never set on the eth_call span. As implemented, Span::with(...) in rpc_call records on the current span at that point in execution (middleware/no method span yet), so metrics labels for point_in_time on eth_call can be missing/empty despite being declared.

Please ensure the point_in_time recording happens after entering the eth_call method span (or pass/record via explicit span handle) so the metrics-tracing-context layer can observe it consistently.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ad93bf7b66

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

let (recorder, exporter) = builder.build()?;
tokio::spawn(exporter);

let recorder = MetricsTracingContextLayer::only_allow(["rpc_client", "rpc_method", "point_in_time"]).layer(recorder);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep the active-request gauge out of per-request context

When metrics are enabled and an RPC arrives, this recorder adds rpc_client and rpc_method to every metric recorded in the request span, including set_rpc_requests_active in rpc_middleware.rs. That gauge is set to the server-wide active connection count, so the change creates a separate series for each client/method whose last global value remains stale; consumers can no longer obtain the current active total from this metric and sums will overcount. Exclude this gauge from context enrichment or change it to maintain genuinely per-label counts.

Useful? React with 👍 / 👎.

Comment thread src/eth/rpc/server.rs

// execute
let point_in_time = ctx.server.storage.translate_to_point_in_time(filter)?;
Span::with(|s| s.rec_str("point_in_time", &point_in_time));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Declare point_in_time on the stratus_call span

When rpc_call is reached through the stratus_call handler, this recording is a no-op because that handler's rpc::stratus_call span declares only tx_from, tx_to, and filter; tracing cannot dynamically add an undeclared field. Consequently metrics emitted while executing stratus_call lack the new point_in_time label even though the same helper supplies it for eth_call. Add the empty field to the stratus_call span as well.

Useful? React with 👍 / 👎.

@stratus-benchmark

Copy link
Copy Markdown

Benchmark:
Run ID: bench-28580c8f

Git Info:

Leader Stats:
RPS Stats: Max: 9827.00, Min: 1403.00, Avg: 1623.89, StdDev: 501.51
TPS Stats: Max: 1938.00, Min: 357.00, Avg: 1573.77, StdDev: 116.58

Follower Stats:
Imported Blocks/s: Max: 16.00, Min: 4.00, Avg: 11.37, StdDev: 3.07
Imported Transactions/s: Max: 24945.00, Min: 6285.00, Avg: 17894.33, StdDev: 4801.45

Plots:

@stratus-benchmark

Copy link
Copy Markdown

Benchmark:
Run ID: bench-41bcf034

Git Info:

Leader Stats:
RPS Stats: Max: 10188.00, Min: 1349.00, Avg: 1601.85, StdDev: 521.89
TPS Stats: Max: 1912.00, Min: 457.00, Avg: 1554.90, StdDev: 110.43

Follower Stats:
Imported Blocks/s: Max: 15.00, Min: 5.00, Avg: 10.96, StdDev: 2.08
Imported Transactions/s: Max: 23505.00, Min: 5583.00, Avg: 17048.36, StdDev: 3451.56

Plots:

@carneiro-cw carneiro-cw linked an issue Aug 26, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add point-in-time to more metrics

2 participants