mas_axum_utils/
sentry.rs

1// Copyright 2024 New Vector Ltd.
2// Copyright 2023, 2024 The Matrix.org Foundation C.I.C.
3//
4// SPDX-License-Identifier: AGPL-3.0-only
5// Please see LICENSE in the repository root for full details.
6
7use std::convert::Infallible;
8
9use axum::response::{IntoResponseParts, ResponseParts};
10use sentry::types::Uuid;
11
12/// A wrapper to include a Sentry event ID in the response headers.
13#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
14pub struct SentryEventID(Uuid);
15
16impl From<Uuid> for SentryEventID {
17    fn from(uuid: Uuid) -> Self {
18        Self(uuid)
19    }
20}
21
22impl IntoResponseParts for SentryEventID {
23    type Error = Infallible;
24    fn into_response_parts(self, mut res: ResponseParts) -> Result<ResponseParts, Self::Error> {
25        res.headers_mut()
26            .insert("X-Sentry-Event-ID", self.0.to_string().parse().unwrap());
27
28        Ok(res)
29    }
30}