relay_server/endpoints/
mod.rs

1//! Web server endpoints.
2//!
3//! This module contains implementations for all supported relay endpoints, as well as a generic
4//! `forward` endpoint that sends unknown requests to the upstream.
5
6mod attachments;
7mod autoscaling;
8mod batch_metrics;
9mod batch_outcomes;
10mod common;
11mod envelope;
12mod forward;
13mod health_check;
14mod integrations;
15mod minidump;
16mod monitor;
17mod nel;
18#[cfg(sentry)]
19mod playstation;
20mod project_configs;
21mod public_keys;
22mod security_report;
23mod statics;
24mod store;
25mod unreal;
26
27use axum::extract::DefaultBodyLimit;
28use axum::routing::{Router, any, get, post};
29use relay_config::Config;
30
31use crate::middlewares;
32use crate::service::ServiceState;
33
34/// Size limit for internal batch endpoints.
35const BATCH_JSON_BODY_LIMIT: usize = 50_000_000; // 50 MB
36
37#[rustfmt::skip]
38pub fn routes(config: &Config) -> Router<ServiceState>{
39    // Relay-internal routes pointing to /api/relay/
40    let internal_routes = Router::new()
41        .route("/api/relay/healthcheck/{kind}/", get(health_check::handle))
42        .route("/api/relay/autoscaling/", get(autoscaling::handle))
43        // Fallback route, but with a name, and just on `/api/relay/*`.
44        .route("/api/relay/{*not_found}", any(statics::not_found));
45
46    // Sentry Web API routes pointing to /api/0/relays/
47    let web_routes = Router::new()
48        .route("/api/0/relays/projectconfigs/", post(project_configs::handle))
49        .route("/api/0/relays/publickeys/", post(public_keys::handle))
50        // Network connectivity check for downstream Relays, same as the internal health check.
51        .route("/api/0/relays/live/", get(health_check::handle_live))
52        .route_layer(DefaultBodyLimit::max(crate::constants::MAX_JSON_SIZE));
53
54    let batch_routes = Router::new()
55        .route("/api/0/relays/outcomes/", post(batch_outcomes::handle))
56        .route("/api/0/relays/metrics/", post(batch_metrics::handle))
57        .route_layer(DefaultBodyLimit::max(BATCH_JSON_BODY_LIMIT));
58
59    // Ingestion routes pointing to /api/:project_id/
60    let store_routes = Router::new()
61        // Legacy store path that is missing the project parameter.
62        .route("/api/store/", store::route(config))
63        // cron monitor level routes.  These are user facing APIs and as such support trailing slashes.
64        .route("/api/{project_id}/cron/{monitor_slug}/{sentry_key}", monitor::route(config))
65        .route("/api/{project_id}/cron/{monitor_slug}/{sentry_key}/", monitor::route(config))
66        .route("/api/{project_id}/cron/{monitor_slug}", monitor::route(config))
67        .route("/api/{project_id}/cron/{monitor_slug}/", monitor::route(config))
68
69        .route("/api/{project_id}/store/", store::route(config))
70        .route("/api/{project_id}/envelope/", envelope::route(config))
71        .route("/api/{project_id}/security/", security_report::route(config))
72        .route("/api/{project_id}/csp-report/", security_report::route(config))
73        .route("/api/{project_id}/nel/", nel::route(config))
74        // No mandatory trailing slash here because people already use it like this.
75        .route("/api/{project_id}/minidump", minidump::route(config))
76        .route("/api/{project_id}/minidump/", minidump::route(config))
77        .route("/api/{project_id}/events/{event_id}/attachments/", post(attachments::handle))
78        .route("/api/{project_id}/unreal/{sentry_key}/", unreal::route(config));
79
80    #[cfg(sentry)]
81    let store_routes = store_routes.route("/api/{project_id}/playstation/", playstation::route(config));
82    let store_routes = store_routes.route_layer(middlewares::cors());
83
84    // Integration routes.
85    //
86    // For integrations we want to be lenient on trailing `/`, as they are often manually
87    // configured by users or protocols may force a specific variant.
88    let integration_routes = Router::new()
89        .nest("/api/{project_id}/integration/otlp", integrations::otlp::routes(config))
90        .nest("/api/{project_id}/integration/vercel", integrations::vercel::routes(config))
91        .route_layer(middlewares::cors());
92
93    // NOTE: If you add a new (non-experimental) route here, please also list it in
94    // https://github.com/getsentry/sentry-docs/blob/master/docs/product/relay/operating-guidelines.mdx
95
96    Router::new().merge(internal_routes)
97        .merge(web_routes)
98        .merge(batch_routes)
99        .merge(store_routes)
100        .merge(integration_routes)
101        // Forward all other API routes to the upstream. This will 404 for non-API routes.
102        .fallback(forward::forward)
103}