Skip to content

feat: improve metrics - #1033

Open
tipogi wants to merge 5 commits into
mainfrom
feat/missing-metrics
Open

feat: improve metrics#1033
tipogi wants to merge 5 commits into
mainfrom
feat/missing-metrics

Conversation

@tipogi

@tipogi tipogi commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

Summary

Essential request/error totals were missing or hard to find: HTTP had traces only, Neo4j had errors but no first-class request counter, and reach-scoped graph queries lumped WoT with following under one label.

  • HTTP: http.server.requests, http.server.errors (5xx + 408), and http.server.request.duration (semconv seconds). Routes use the matched template (unmatched otherwise); unknown methods collapse to _OTHER. Incoming traceparent is ignored on this public API. Query strings are not recorded.
  • Neo4j: neo4j.query.requests next to the existing neo4j.query.errors, same query label, so error rate is errors / requests without using histogram _count.
  • WoT: post-stream wot.post_stream.requests / errors already existed. Trusted-network tag queries were already distinct Neo4j labels. get_*_by_reach labels are now split by reach and WoT depth (…_following, …_wot_3, …) because those queries have no companion meter — depth cannot live as an attribute the way it does on post_stream_wot.

Pre-submission Checklist

  • I manually reviewed the PR
  • I asked one or more LLMs to review the PR
  • I asked one or more LLMs to check if this PR can be simplified 1
  • If appropriate, I added tests for the changes in this PR
  • If appropriate, I added performance benchmarks for the APIs added in this PR 2

Footnotes

  1. Sample prompt: "Can this be simplified? Can the code, comments, or logic introduced by these changes be simplfied, clarified or otherwise made more terse, concise and understandable, without affecting functionality?"

  2. cargo bench -p nexus-webapi

@tipogi tipogi added this to the 2026-Lugano milestone Aug 20, 2026
@tipogi tipogi self-assigned this Aug 20, 2026
@tipogi tipogi added 🌐 service Nexus API endpoint related 📡 observability labels Aug 20, 2026
METRICS.duration.record(elapsed_secs, &attrs);
if is_failed_request(status) {
METRICS.errors.add(1, &attrs);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

delete error counter, we have response code in labels that's enough

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@tipogi
tipogi marked this pull request as ready for review August 21, 2026 07:38
@tipogi
tipogi requested a review from aintnostressin August 21, 2026 07:38
@greptile-apps

greptile-apps Bot commented Aug 21, 2026

Copy link
Copy Markdown

Greptile Summary

The PR adds HTTP request and duration telemetry, introduces a Neo4j request counter, and splits reach-sensitive graph-query labels by reach and WoT depth.

  • Records bounded-cardinality HTTP method, matched-route, status, and duration attributes while excluding query strings.
  • Adds neo4j.query.requests at the same completion sites as existing query-duration measurements.
  • Assigns distinct query labels for followers, following, friends, and each supported WoT depth.
  • The advertised HTTP error counter is missing from the implementation.

Confidence Score: 4/5

The missing HTTP error instrument should be restored or the stated telemetry contract revised before merging.

Failed HTTP responses are classified by the middleware, but the implementation exports no http.server.errors counter despite advertising that metric as an essential error-rate signal.

Files Needing Attention: nexus-webapi/src/routes/middlewares/tracing.rs

Important Files Changed

Filename Overview
nexus-webapi/src/routes/middlewares/tracing.rs Adds bounded HTTP request telemetry and safer trace attributes, but omits the promised http.server.errors counter.
nexus-webapi/src/routes/mod.rs Places tracing outside timeout, body-limit, CORS, and compression layers so short-circuit responses remain observable.
nexus-common/src/db/graph/instrumented.rs Adds a Neo4j request denominator consistently across run completion, execute failure, and stream finalization.
nexus-common/src/db/graph/queries/get.rs Splits three reach-scoped query families into stable labels for each reach mode and validated WoT depth.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Client[HTTP client] --> MW[Tracing middleware]
  MW --> Router[Matched Axum route]
  Router --> Graph[Instrumented Neo4j graph]
  MW --> HTTPMetrics[HTTP request and duration metrics]
  Graph --> NeoMetrics[Neo4j request, error, duration, and row metrics]
  HTTPMetrics --> OTLP[OTLP metrics exporter]
  NeoMetrics --> OTLP
Loading

Reviews (1): Last reviewed commit: "chore: drop http.server.errors; status o..." | Re-trigger Greptile

Comment on lines +23 to +26
struct HttpMetrics {
requests: Counter<u64>,
duration: Histogram<f64>,
}

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 HTTP error counter is missing

When a request returns 408 or 5xx, the middleware classifies it as failed but records only http.server.requests and duration, so the promised http.server.errors series is never exported and dashboards cannot calculate errors / requests using that instrument.

Knowledge Base Used: Nexus observability stack

@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: dd58930995

ℹ️ 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".

Comment on lines +89 to +90
METRICS.requests.add(1, &attrs);
METRICS.duration.record(elapsed_secs, &attrs);

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 Record the HTTP error counter

When a request returns 408 or 5xx, is_failed_request only marks the tracing span as failed, while this function records only http.server.requests and the duration histogram. Consequently, the advertised http.server.errors metric is never created or incremented, so operators cannot use the intended first-class error total without reconstructing it from status-labeled request series.

Useful? React with 👍 / 👎.

@tipogi
tipogi force-pushed the feat/missing-metrics branch from 8c484c2 to e435f2e Compare August 25, 2026 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📡 observability 🌐 service Nexus API endpoint related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants