Skip to content

Conversation

@MasterPtato
Copy link
Contributor

No description provided.

Copy link
Contributor Author

MasterPtato commented Jan 13, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more


How to use the Graphite Merge Queue

Add the label merge-queue to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@claude
Copy link

claude bot commented Jan 13, 2026

PR Review: fix(otel): enrich http traces

Summary

This PR adds OpenTelemetry attributes to HTTP traces in both the API builder middleware and guard proxy service to improve observability. The changes add standard HTTP semantic conventions attributes to spans.

Code Quality ✅

Strengths:

  • Clean implementation following OpenTelemetry semantic conventions
  • Consistent pattern applied across both middleware and proxy service
  • Properly uses the tracing-opentelemetry extension trait
  • Adds the dependency correctly to workspace dependencies

Observations:

  1. Redundant attribute setting in api-builder/middleware.rs (lines 70-71):
    The span is already created with method and uri fields (lines 65-66), and then immediately sets attributes for the same values (lines 70-71). While this provides both structured logging fields and OTEL attributes, it's redundant. The http.path attribute is set to the full URI string rather than just the path.

  2. Inconsistent attribute naming:

    • Uses http.path but the value is actually the full URI (from req.uri().to_string())
    • Should either use url.full or http.target for the full URI, and url.path for just the path component
    • See OpenTelemetry HTTP semantic conventions
  3. Missing standard HTTP attributes:
    While adding attributes is good, consider including other standard HTTP semantic convention attributes for better observability:

    • http.request.body.size
    • http.response.body.size
    • user_agent.original (already extracted in the code)
    • server.address and server.port
    • network.peer.address (the remote_addr already extracted)

Potential Issues ⚠️

  1. String allocation on every request (performance):
    Each request creates multiple string allocations via .to_string() calls. For high-throughput services, consider if these allocations are necessary or if there's a more efficient way.

    • Line 70-71 in middleware.rs: 2 string allocations
    • Line 73: 1 string allocation
    • Line 2038-2039 in proxy_service.rs: 2 string allocations

    However, this is likely acceptable for the observability benefit, but worth noting.

  2. MatchedPath extraction timing (api-builder/middleware.rs:72-74):
    The MatchedPath extension is checked before the request is processed by the router. Depending on when Axum populates this extension, it might not be available yet. Verify this works as expected - if the matched path isn't available at this point in the middleware chain, this code won't have any effect.

Security ✅

No security concerns identified. The changes only add observability attributes and don't modify request/response handling logic.

Test Coverage ⚠️

Missing tests:

  • No new tests added to verify that the OTEL attributes are correctly set
  • Existing test files in both packages don't appear to cover trace attribute verification

Recommendation:
Add integration tests that verify the expected attributes are present on spans. Example test structure:

  • Create a test request
  • Capture the span
  • Assert expected attributes are set (http.request.method, http.path, http.response.status_code, etc.)

Performance Considerations ⚠️

Minor performance impact from:

  1. String allocations on each request (discussed above)
  2. Additional hash map insertions for span attributes

The overhead should be minimal and acceptable for the observability benefits, but should be monitored in production.

Suggestions for Improvement

  1. Use OpenTelemetry HTTP semantic conventions consistently:

    // Instead of:
    req_span.set_attribute("http.path", req.uri().to_string());
    
    // Consider:
    req_span.set_attribute("url.full", req.uri().to_string());
    req_span.set_attribute("url.path", req.uri().path());
  2. Add more standard attributes in a follow-up PR:

    • User agent, content lengths, network peer info, etc.
  3. Add tests for trace enrichment:
    Verify spans contain expected attributes in integration tests.

  4. Consider caching current_span in proxy_service.rs:
    You already extract it to a variable (line 2013), which is good for avoiding repeated Span::current() calls.

Verdict: ✅ Approve with Suggestions

This is a solid improvement to observability. The code is clean and follows good patterns. The main suggestions are:

  • Use correct OpenTelemetry semantic convention attribute names
  • Verify MatchedPath timing works as expected
  • Consider adding tests for trace attributes
  • Consider adding more standard HTTP attributes in follow-up work

The PR is ready to merge as-is, but the suggestions would make it even better.


Review generated by Claude Code

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 13, 2026

More templates

@rivetkit/cloudflare-workers

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/cloudflare-workers@3878

@rivetkit/db

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/db@3878

@rivetkit/framework-base

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/framework-base@3878

@rivetkit/next-js

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/next-js@3878

@rivetkit/react

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/react@3878

rivetkit

pnpm add https://pkg.pr.new/rivet-dev/rivet/rivetkit@3878

@rivetkit/sql-loader

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/sql-loader@3878

@rivetkit/virtual-websocket

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/virtual-websocket@3878

@rivetkit/engine-runner

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/engine-runner@3878

@rivetkit/engine-runner-protocol

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/engine-runner-protocol@3878

commit: e8bbcf8

@MasterPtato MasterPtato force-pushed the 01-13-fix_otel_enrich_http_traces branch from c6bf57a to 5f2275d Compare January 13, 2026 20:07
@MasterPtato MasterPtato force-pushed the 01-13-fix_otel_enrich_http_traces branch from 5f2275d to a35f0d9 Compare January 14, 2026 02:05
@MasterPtato MasterPtato force-pushed the 01-12-fix_guard_clean_up_guard branch from c079c96 to 9e8cf3d Compare January 14, 2026 02:05
@MasterPtato MasterPtato force-pushed the 01-13-fix_otel_enrich_http_traces branch from a35f0d9 to e88b75c Compare January 14, 2026 02:53
@MasterPtato MasterPtato force-pushed the 01-12-fix_guard_clean_up_guard branch from 9e8cf3d to 3008b28 Compare January 14, 2026 02:53
@MasterPtato MasterPtato force-pushed the 01-13-fix_otel_enrich_http_traces branch from e88b75c to 74129c7 Compare January 14, 2026 03:06
@MasterPtato MasterPtato force-pushed the 01-12-fix_guard_clean_up_guard branch from 3008b28 to 70900c0 Compare January 14, 2026 03:06
@MasterPtato MasterPtato force-pushed the 01-13-fix_otel_enrich_http_traces branch from 74129c7 to c3c6740 Compare January 14, 2026 19:47
@MasterPtato MasterPtato force-pushed the 01-12-fix_guard_clean_up_guard branch from 70900c0 to 5f50433 Compare January 14, 2026 19:47
@MasterPtato MasterPtato force-pushed the 01-13-fix_otel_enrich_http_traces branch from c3c6740 to cdb8231 Compare January 14, 2026 20:01
@MasterPtato MasterPtato force-pushed the 01-12-fix_guard_clean_up_guard branch from 5f50433 to d4e5e20 Compare January 14, 2026 20:01
@MasterPtato MasterPtato force-pushed the 01-12-fix_guard_clean_up_guard branch from d4e5e20 to f831199 Compare January 14, 2026 22:45
@MasterPtato MasterPtato force-pushed the 01-13-fix_otel_enrich_http_traces branch from cdb8231 to 1353291 Compare January 14, 2026 22:45
@MasterPtato MasterPtato force-pushed the 01-12-fix_guard_clean_up_guard branch from f831199 to c90f0b8 Compare January 14, 2026 22:47
@MasterPtato MasterPtato force-pushed the 01-13-fix_otel_enrich_http_traces branch 2 times, most recently from 921ccb3 to e8bbcf8 Compare January 14, 2026 22:52
@MasterPtato MasterPtato force-pushed the 01-12-fix_guard_clean_up_guard branch from c90f0b8 to 9d72300 Compare January 14, 2026 22:52
@MasterPtato MasterPtato force-pushed the 01-13-fix_otel_enrich_http_traces branch from e8bbcf8 to d8a0135 Compare January 14, 2026 23:02
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.

3 participants