Skip to content

Phase 4: Sentry SDK integration in Rungu + CIRA #234

Description

@ajianaz

Goal

Integrate Sentry Rust SDK into Rungu and CIRA backends, pointing DSN to self-hosted TrapFall instead of Sentry SaaS. Enable error capture, performance tracing, session tracking, and attachment support.

Context

Both Rungu and CIRA share identical stack: Rust/Axum 0.8, tracing + tracing-subscriber, custom ApiError (IntoResponse), SQLite/Postgres dual DB. The Sentry Rust SDK is MIT-licensed and works as a drop-in dependency.

Critical: #[tokio::main] Incompatibility

sentry::init() requires the Sentry client to exist before the tokio runtime is created. #[tokio::main] macro hides runtime construction — we must replace it with manual tokio::runtime::Builder:

// BEFORE (won't work with sentry::init)
#[tokio::main]
async fn main() { ... }

// AFTER (required for sentry::init)
fn main() {
    let _guard = sentry::init((...));
    let rt = tokio::runtime::Builder::new_multi_thread()
        .enable_all()
        .build()
        .unwrap();
    rt.block_on(async { ... });
}

Tasks

4a. Dependencies

  • Add sentry crate with features: tower, tower-http, tower-axum-matched-path, tracing, panic, anyhow, release-health
  • Add config fields: sentry_dsn: Option<String>, sentry_environment: Option<String>, sentry_traces_sample_rate: f64
  • Support DSN from env var: SENTRY_DSN

4b. Runtime refactor

  • Replace #[tokio::main] with manual runtime in main entry point
  • Ensure _guard (sentry init guard) lives for the entire process lifetime

4c. Tower middleware

  • Add NewSentryLayer::<Request<Body>>::new_from_top() layer
  • Add SentryHttpLayer::new() (error capture)
  • Add .enable_transaction() for performance tracing (Phase 1 dependent)
  • Configure traces_sample_rate from config

4d. Testing

  • Integration test: trigger error → verify received in TrapFall
  • Integration test: trigger slow request → verify transaction in TrapFall
  • Integration test: verify session emitted with correct release
  • Verify prod vs dev separate projects (different DSNs)

4e. Separate projects for dual-env

  • Rungu prod: https://key@trapfall:9090/rungu-prod
  • Rungu dev: https://key@trapfall:9090/rungu-dev
  • CIRA prod: https://key@trapfall:9090/cira-prod
  • CIRA dev: https://key@trapfall:9090/cira-dev

Depends On

Repos Affected

  • codecoradev/rungu
  • codecoradev/cira (or relevant repo)

Effort

~3-5 hours (mostly config + middleware wiring)


Sub-issues:

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestpriority:highP1 - Fix soonscope: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