Skip to content

4c: Tower middleware — Sentry layer + tracing integration #250

Description

@ajianaz

Parent: #234 · Blocked by: #248, #249

Scope

Wire Sentry tower middleware into the Axum router for both Rungu and CIRA. Phase 1: errors only (no transactions — TrapFall doesn't support them yet).

Middleware Stack (bottom to top)

[SentryTracingLayer]     ← bridge tracing events → Sentry
  [SentryHttpLayer]       ← capture HTTP errors + context
    [app router]          ← existing Axum routes

Implementation

Rungu (rungud/src/server.rs)

use sentry_tower::NewSentryLayer;
use sentry_tower::SentryHttpLayer;

let app = Router::new()
    .route("/", get(index))
    // ... existing routes
    .layer(
        ServiceBuilder::new()
            .layer(NewSentryLayer::<Request<Body>>::new_from_top())
            .layer(SentryHttpLayer::new())  // errors only (no .enable_transaction())
    );

CIRA

Same pattern — insert in the main router builder.

Tracing Bridge (optional but recommended)

// In the tracing-subscriber setup, BEFORE Sentry init:
let sentry_layer = sentry_tracing::layer();
let subscriber = tracing_subscriber::Registry::default()
    .with(tracing_subscriber::EnvFilter::new(
        std::env::var("RUST_LOG").unwrap_or_else(|_| "info".into())
    ))
    .with(sentry_layer);  // bridges tracing::error! → Sentry events
tracing::subscriber::set_global_default(subscriber)?;

What Gets Auto-Captured

Event Type Source Captured By
HTTP 5xx responses Axum error responses SentryHttpLayer
panic!() / unwrap failures Rust panics sentry::init(panic) feature
tracing::error!() App logging sentry_tracing bridge
Request context (URL, method, headers) HTTP layer SentryHttpLayer
User context (if set) App code sentry::configure_scope()

Tasks

  • Add sentry_tower + sentry_tracing tower layers to Rungu router
  • Add same to CIRA router
  • Wire tracing subscriber bridge (optional: behind cfg flag)
  • Set user context from auth middleware (if user is authenticated)
  • Set tags from request: project, route, method
  • Test: trigger 500 error → verify event arrives at TrapFall
  • Test: trigger panic!() → verify captured
  • Test: tracing::error!("test") → verify captured
  • Test: normal 200 response → NO event sent (not an error)
  • Verify transaction envelopes NOT sent (TrapFall ignores them in Phase 1)

Important Notes

  • Do NOT call .enable_transaction() on SentryHttpLayer — TrapFall silently drops transaction envelopes in Phase 1. Adding transactions would waste bandwidth.
  • Once Phase 1 (TrapFall transaction support) is implemented, flip the flag.

Effort: ~1.5 hours

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestscope:sdkSentry SDK integration in client apps (Rungu/CIRA)type:envelopeSentry envelope item type expansion

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions