Skip to content

Commit 7f9b089

Browse files
committed
fix: add logger to /:id/events
1 parent a4aa100 commit 7f9b089

File tree

4 files changed

+12
-14
lines changed

4 files changed

+12
-14
lines changed

sentry/src/db/event_aggregate.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::db::DbPool;
22
use bb8::RunError;
3-
// use bb8_postgres::tokio_postgres::types::{ToSql, FromSql};
43
use bb8_postgres::tokio_postgres::binary_copy::BinaryCopyInWriter;
54
use bb8_postgres::tokio_postgres::types::Type;
65
use bb8_postgres::tokio_postgres::Error;

sentry/src/event_aggregator.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ use std::collections::HashMap;
1414
use std::sync::Arc;
1515
use std::time::Duration;
1616
use tokio::time::delay_for;
17+
use slog::{error, Logger};
18+
1719

1820
#[derive(Default, Clone)]
1921
pub struct EventAggregator {
@@ -31,17 +33,18 @@ pub fn new_aggr(channel_id: &ChannelId) -> EventAggregate {
3133
async fn store(
3234
db: &DbPool,
3335
channel_id: &ChannelId,
36+
logger: &Logger,
3437
aggr: Arc<RwLock<HashMap<String, EventAggregate>>>,
3538
) {
3639
let mut recorder = aggr.write().await;
3740
let ev_aggr: Option<&EventAggregate> = recorder.get(&channel_id.to_string());
3841
if let Some(data) = ev_aggr {
3942
if let Err(e) = insert_event_aggregate(&db, &channel_id, data).await {
40-
eprintln!("{}", e);
41-
return;
43+
error!(&logger, "event-aggregates store error {}", e);
44+
} else {
45+
// reset aggr
46+
recorder.insert(channel_id.to_string(), new_aggr(&channel_id));
4247
};
43-
// reset aggr
44-
recorder.insert(channel_id.to_string(), new_aggr(&channel_id));
4548
}
4649
}
4750

@@ -71,6 +74,7 @@ impl EventAggregator {
7174
let aggregate = self.aggregate.clone();
7275
let withdraw_period_start = channel.spec.withdraw_period_start;
7376
let channel_id = channel.id;
77+
let logger = app.logger.clone();
7478

7579
let mut aggr: &mut EventAggregate = match recorder.get_mut(&channel.id.to_string()) {
7680
Some(aggr) => aggr,
@@ -93,7 +97,7 @@ impl EventAggregator {
9397
}
9498

9599
delay_for(Duration::from_secs(aggr_throttle as u64)).await;
96-
store(&dbpool, &channel_id, aggregate.clone()).await;
100+
store(&dbpool, &channel_id, &logger, aggregate.clone()).await;
97101
}
98102
});
99103
}
@@ -113,12 +117,9 @@ impl EventAggregator {
113117
drop(recorder);
114118

115119
if aggr_throttle == 0 {
116-
println!("storing data in ");
117-
store(&app.pool, &channel.id, self.aggregate.clone()).await;
120+
store(&app.pool, &channel.id, &app.logger.clone(), self.aggregate.clone()).await;
118121
}
119122

120-
println!("finished succesfully");
121-
122123
Ok(())
123124
}
124125
}

sentry/src/middleware/auth.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ fn get_request_ip(req: &Request<Body>) -> Option<String> {
7575
.get("true-client-ip")
7676
.or_else(|| req.headers().get("x-forwarded-for"))
7777
.and_then(|hv| hv.to_str().map(ToString::to_string).ok())
78-
.map(|token| token.split(',').collect::<Vec<&str>>()[0].to_string())
78+
.map(|token| token.split(',').nth(0).map(ToString::to_string).expect("should have ip"))
7979
}
8080

8181
#[cfg(test)]

sentry/src/routes/channel.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,7 @@ pub async fn insert_events<A: Adapter + 'static>(
126126
let events = request_body
127127
.get("events")
128128
.ok_or_else(|| ResponseError::BadRequest("invalid request".to_string()))?;
129-
130-
println!("working on something");
131-
129+
132130
app.event_aggregator
133131
.record(app, &channel, &session, &events.as_slice())
134132
.await?;

0 commit comments

Comments
 (0)