sentry-rust icon indicating copy to clipboard operation
sentry-rust copied to clipboard

Issues and trace not working

Open ghmendonca opened this issue 1 year ago • 0 comments
trafficstars

I'm trying to configure sentry for my application and doesn't seem to work. I've read all the issues related and I couldn't find a single example to make this work.

My application is very small, I have just 2 endpoints, and one of them is just a health check. The other one is an endpoint to process images, it downloads files from s3, process them and then uploads back to s3. The tracing is working because I can see a bunch of logs, but it's not being sent to sentry.

Here is my code:

fn main() {
    let _ = sentry::init((
        "***",
        sentry::ClientOptions {
            release: sentry::release_name!(),
            traces_sample_rate: 0.2,
            environment: Some(
                std::env::var("STAGE")
                    .unwrap_or(String::from("local"))
                    .into(),
            ),
            ..Default::default()
        },
    ));

    tokio::runtime::Builder::new_multi_thread()
        .enable_all()
        .build()
        .unwrap()
        .block_on(async {
            tracing_subscriber::registry()
                .with(tracing_subscriber::fmt::layer())
                .with(sentry_tracing::layer())
                .init();

            dotenv().ok();

            let config = load_defaults(BehaviorVersion::latest())
                .await
                .to_builder()
                .stalled_stream_protection(StalledStreamProtectionConfig::disabled())
                .build();
            let client = aws_sdk_s3::Client::new(&config);
            let aws = AWSService::new(client);

            let state = AppState { aws };

            let app = Router::new()
                .route("/images", post(process_images))
                .route("/health", get(health))
                .layer(sentry_tower::NewSentryLayer::new_from_top())
                .layer(sentry_tower::SentryHttpLayer::with_transaction())
                .with_state(state);

            let stage = std::env::var("STAGE");

            if stage.is_ok() && stage.unwrap() == String::from("local") {
                let listener = TcpListener::bind("0.0.0.0:8080").await?;

                println!("Server started on {}", listener.local_addr()?);

                serve(listener, app).await?;

                return Ok(());
            } else {
                return run(app).await;
            }
        })
        .unwrap();
}

This is not working local or when I deploy. Not sure if makes any difference, but I'm deploying my application to AWS Lambda using the serverless framework.

ghmendonca avatar Sep 14 '24 01:09 ghmendonca