Fix sentry http request info
Add async bot running with semaphore
This commit is contained in:
+21
-6
@@ -1,3 +1,4 @@
|
||||
use anyhow::anyhow;
|
||||
use axum::body::{Body, Bytes, to_bytes};
|
||||
use axum::extract::{FromRef, FromRequest, State};
|
||||
use axum::http::Request;
|
||||
@@ -6,10 +7,11 @@ use axum::routing::{get, post};
|
||||
use axum::{Json, Router};
|
||||
use hmac::{Hmac, KeyInit, Mac};
|
||||
use reqwest::StatusCode;
|
||||
use sentry::integrations::tower::NewSentryLayer;
|
||||
use sentry::integrations::tower::{NewSentryLayer, SentryHttpLayer};
|
||||
use serde_json::Value;
|
||||
use sha2::Sha256;
|
||||
use subtle::ConstantTimeEq;
|
||||
use tower::ServiceBuilder;
|
||||
use tower_http::trace::TraceLayer;
|
||||
use tracing::{info, instrument};
|
||||
|
||||
@@ -22,10 +24,14 @@ pub async fn start(app_state: AppState) -> anyhow::Result<()> {
|
||||
let http_port = app_state.config.http_port;
|
||||
|
||||
let app = Router::new()
|
||||
.layer(NewSentryLayer::<Request<Body>>::new_from_top())
|
||||
.layer(TraceLayer::new_for_http())
|
||||
.route("/", get(root))
|
||||
.route("/webhook", post(webhook))
|
||||
.layer(
|
||||
ServiceBuilder::new()
|
||||
.layer(NewSentryLayer::<Request<_>>::new_from_top())
|
||||
.layer(SentryHttpLayer::new())
|
||||
.layer(TraceLayer::new_for_http()),
|
||||
)
|
||||
.with_state(app_state);
|
||||
|
||||
let listener = tokio::net::TcpListener::bind(format!("0.0.0.0:{}", http_port)).await?;
|
||||
@@ -49,9 +55,8 @@ async fn webhook(
|
||||
|
||||
app_state
|
||||
.bot_tx
|
||||
.send(wb)
|
||||
.await
|
||||
.map_err(anyhow::Error::from)?;
|
||||
.try_send(wb)
|
||||
.map_err(|_| AppError::ChannelFullErr)?;
|
||||
|
||||
Ok((StatusCode::CREATED, "Task started"))
|
||||
}
|
||||
@@ -74,6 +79,16 @@ where
|
||||
let type_header = extract_header(GITEA_EVENT_TYPE_HEADER_NAME, headers)?;
|
||||
let body_bytes = read_body(req.into_body()).await?;
|
||||
|
||||
let body_str = String::from_utf8_lossy(&body_bytes).into_owned();
|
||||
sentry::configure_scope(|scope| {
|
||||
scope.add_event_processor(move |mut event| {
|
||||
let mut request = event.request.take().unwrap_or_default();
|
||||
request.data = Some(body_str.clone());
|
||||
event.request = Some(request);
|
||||
Some(event)
|
||||
});
|
||||
});
|
||||
|
||||
verify_signature(
|
||||
app_state.config.webhook_secret.as_bytes(),
|
||||
&sig_header,
|
||||
|
||||
Reference in New Issue
Block a user