From 8af51099548f61f698267a02a88af66b4e8d5788 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Wed, 12 Apr 2023 09:37:12 +0200 Subject: [PATCH] feat: Add deterministic debug IDs for minified JS files (#1570) --- src/utils/sourcemaps/inject.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/utils/sourcemaps/inject.rs b/src/utils/sourcemaps/inject.rs index 23cbb65ed4..d497a0b1ac 100644 --- a/src/utils/sourcemaps/inject.rs +++ b/src/utils/sourcemaps/inject.rs @@ -10,7 +10,6 @@ use anyhow::{bail, Result}; use log::debug; use sentry::types::DebugId; use serde_json::Value; -use uuid::Uuid; const CODE_SNIPPET_TEMPLATE: &str = r#"!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="__SENTRY_DEBUG_ID__")}catch(e){}}()"#; const DEBUGID_PLACEHOLDER: &str = "__SENTRY_DEBUG_ID__"; @@ -158,7 +157,13 @@ pub fn fixup_sourcemap(sourcemap_contents: &mut Vec) -> Result<(DebugId, boo } None => { - let debug_id = DebugId::from_uuid(Uuid::new_v4()); + let mut hash = sha1_smol::Sha1::new(); + hash.update(sourcemap_contents); + let mut sha1_bytes = [0u8; 16]; + sha1_bytes.copy_from_slice(&hash.digest().bytes()[..16]); + let debug_id = + DebugId::from_uuid(uuid::Builder::from_sha1_bytes(sha1_bytes).into_uuid()); + let id = serde_json::to_value(debug_id)?; map.insert(SOURCEMAP_DEBUGID_KEY.to_string(), id);