Send server panics to Axiom
Co-Authored-By: Thorsten <thorsten@zed.dev> Co-Authored-By: Bennet <bennet@zed.dev> Co-Authored-By: Kirill <kirill@zed.dev>
This commit is contained in:
parent
3e7a2e5c30
commit
122b5b4e6c
1 changed files with 19 additions and 0 deletions
|
@ -84,6 +84,8 @@ async fn main() -> Result<()> {
|
||||||
|
|
||||||
let config = envy::from_env::<Config>().expect("error loading config");
|
let config = envy::from_env::<Config>().expect("error loading config");
|
||||||
init_tracing(&config);
|
init_tracing(&config);
|
||||||
|
init_panic_hook();
|
||||||
|
|
||||||
let mut app = Router::new()
|
let mut app = Router::new()
|
||||||
.route("/", get(handle_root))
|
.route("/", get(handle_root))
|
||||||
.route("/healthz", get(handle_liveness_probe))
|
.route("/healthz", get(handle_liveness_probe))
|
||||||
|
@ -378,3 +380,20 @@ pub fn init_tracing(config: &Config) -> Option<()> {
|
||||||
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn init_panic_hook() {
|
||||||
|
std::panic::set_hook(Box::new(move |panic_info| {
|
||||||
|
let panic_message = match panic_info.payload().downcast_ref::<&'static str>() {
|
||||||
|
Some(message) => *message,
|
||||||
|
None => match panic_info.payload().downcast_ref::<String>() {
|
||||||
|
Some(message) => message.as_str(),
|
||||||
|
None => "Box<Any>",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
let backtrace = std::backtrace::Backtrace::force_capture();
|
||||||
|
let location = panic_info
|
||||||
|
.location()
|
||||||
|
.map(|loc| format!("{}:{}", loc.file(), loc.line()));
|
||||||
|
tracing::error!(panic = true, ?location, %panic_message, %backtrace, "Server Panic");
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue