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 span attributes to HTTP traces in both the API builder middleware and guard proxy service to improve observability. The changes add standard HTTP semantic attributes like method, path, route, and status code to spans.

Code Quality ✅

Strengths:

  • Clean implementation following OpenTelemetry patterns
  • Consistent approach across both middleware and proxy service
  • Proper use of structured attributes instead of embedding data in span names
  • Correctly added tracing-opentelemetry dependency to guard-core
  • Good span lifecycle management by storing current_span in a variable

Issues to Address:

  1. Non-standard attribute naming

    • Location: engine/packages/api-builder/src/middleware.rs:71, engine/packages/guard-core/src/proxy_service.rs:2039
    • Issue: Using http.path instead of standard OpenTelemetry semantic conventions
    • Recommendation: According to OpenTelemetry HTTP semantic conventions v1.23+, use:
      • url.path for the path component (e.g., /api/users)
      • url.full for the complete URI if needed
    • Impact: Non-standard attributes may not be recognized by observability tools and dashboards expecting standard conventions
  2. Redundant span data

    • Location: engine/packages/api-builder/src/middleware.rs:70-71
    • Issue: The span already records method and uri as tracing fields during span creation (lines 65-66), then sets them again as OpenTelemetry attributes
    • Analysis: While not incorrect, this duplicates data. Tracing fields and OTel attributes serve different purposes (fields for tracing display, attributes for OTel exporters)
    • Recommendation: This is acceptable if intentional for cross-tool compatibility, but consider documenting why both are needed
  3. Missing attribute validation

    • Location: All set_attribute calls
    • Issue: No length limits on string conversions that could result in very large trace payloads
    • Recommendation: Consider truncating extremely long URIs (e.g., those with large query strings) to prevent bloating trace data. Most observability backends have payload limits.

Best Practices 📋

Follows CLAUDE.md conventions:

  • ✅ Uses structured logging (tracing with separate fields)
  • ✅ Imports added at the top of files
  • ✅ No formatting changes made
  • ✅ Proper dependency management using workspace dependencies
  • ✅ Lowercase log messages

OpenTelemetry Semantic Convention Status:

  • http.request.method → ✅ Correct (stable in v1.23+)
  • http.path → ❌ Should be url.path (as of v1.23+)
  • http.route → ✅ Correct (stable in v1.23+)
  • http.response.status_code → ✅ Correct (stable in v1.23+)

Potential Bugs 🐛

None identified - The implementation is safe and straightforward. All attribute values are properly typed (strings and i64).

Performance Considerations ⚡

Current impact: Minimal

  • String allocations for attributes are small and infrequent (once per request)
  • No blocking operations introduced
  • Attribute setting is efficient in the tracing-opentelemetry layer

Potential concern:

  • Very long URIs (e.g., with large base64-encoded data in query params) could increase trace payload size
  • Consider adding length validation if this becomes an issue

Security Concerns 🔒

Low risk, but consider:

  • URIs may contain sensitive data (auth tokens, API keys in query params)
  • Ensure your OpenTelemetry collector/backend pipeline sanitizes sensitive data
  • Consider adding attribute value sanitization for known sensitive patterns

Test Coverage 🧪

Not included in PR:

  • No new tests added
  • Recommendation: Consider adding integration tests that verify:
    1. Span attributes are correctly set on successful requests
    2. Span attributes are correctly set on error responses
    3. Attributes follow expected format and types

Example test structure:

#[tokio::test]
async fn test_http_span_attributes() {
    // Setup tracing subscriber with in-memory exporter
    // Make HTTP request through middleware
    // Assert span contains expected attributes with correct values
}

Recommendations

High Priority:

  1. Update http.path to url.path to match OpenTelemetry semantic conventions v1.23+
  2. Consider updating the full URI attribute to url.full if needed

Medium Priority:
3. Add integration tests for span attribute verification
4. Consider adding URI sanitization for sensitive data

Low Priority:
5. Document why both tracing fields and OTel attributes are used (if intentional)
6. Consider adding length limits for URI attributes

Overall Assessment

Status:Approve with suggestions

This is a solid improvement to observability. The main issue is using non-standard attribute names (http.path instead of url.path), which should be corrected to ensure compatibility with standard OpenTelemetry tooling and dashboards. The implementation is otherwise clean and follows Rivet's conventions well.

@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: 116ea58

@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
@MasterPtato MasterPtato force-pushed the 01-12-fix_guard_clean_up_guard branch from 875a7a4 to 920b1d9 Compare January 14, 2026 23:07
@MasterPtato MasterPtato force-pushed the 01-13-fix_otel_enrich_http_traces branch from d8a0135 to 116ea58 Compare January 14, 2026 23:07
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