/* Sentry for the Site and the Kanban, used only when the DSN arrives from the API. It loads after web/vendor/sentry.min.js and never fetches anything itself; DSNs are public by design, so an empty one leaves everything off. beforeSend follows the server (app/observability.py): no cookies, credential headers, request bodies or signed/token query strings, and CPF/CNPJ and e-mails replaced by [removido]. */ (function () { const EMAIL = /[^\s@]+@[^\s@]+\.[A-Za-z]{2,}/g; const DOCUMENT = /(? String(value == null ? '' : value) .replace(EMAIL, REDACTED).replace(DOCUMENT, REDACTED); function scrubQuery(query) { if (!query) return query; return String(query).split('&').filter(part => { let key = part.split('=')[0] || ''; try { key = decodeURIComponent(key.replace(/\+/g, ' ')); } catch (error) { /* keep the raw key */ } return !SENSITIVE_PARAM.test(key); }).join('&'); } function scrubText(value) { if (typeof value !== 'string') return value; value = clean(value); const at = value.indexOf('?'); return at < 0 ? value : value.slice(0, at + 1) + scrubQuery(value.slice(at + 1)); } function scrubUrl(url) { if (typeof url !== 'string') return url; const at = url.indexOf('?'); return at < 0 ? url : url.slice(0, at + 1) + scrubQuery(url.slice(at + 1)); } function scrubValue(value) { if (typeof value === 'string') return scrubText(value); if (Array.isArray(value)) return value.map(scrubValue); if (value && typeof value === 'object') { const out = {}; for (const [key, item] of Object.entries(value)) out[key] = scrubValue(item); return out; } return value; } function scrubRequest(request) { if (!request || typeof request !== 'object') return; delete request.cookies; delete request.data; delete request.body; if (request.headers && typeof request.headers === 'object') { for (const key of Object.keys(request.headers)) { if (SENSITIVE_HEADER.test(key)) delete request.headers[key]; } } if (request.query_string) request.query_string = scrubQuery(request.query_string); if (request.url) request.url = scrubUrl(request.url); } function scrub(event) { if (!event || typeof event !== 'object') return event; scrubRequest(event.request); if (typeof event.message === 'string') event.message = scrubText(event.message); if (event.logentry && typeof event.logentry.message === 'string') event.logentry.message = scrubText(event.logentry.message); if (event.exception && Array.isArray(event.exception.values)) { for (const value of event.exception.values) { if (value && typeof value.value === 'string') value.value = scrubText(value.value); } } let breadcrumbs = event.breadcrumbs; if (breadcrumbs && !Array.isArray(breadcrumbs)) breadcrumbs = breadcrumbs.values; if (Array.isArray(breadcrumbs)) { for (const crumb of breadcrumbs) { if (!crumb || typeof crumb !== 'object') continue; if (typeof crumb.message === 'string') crumb.message = scrubText(crumb.message); if (crumb.data) crumb.data = scrubValue(crumb.data); } } if (event.extra) event.extra = scrubValue(event.extra); if (event.user) event.user = scrubValue(event.user); return event; } function start(dsn, component) { if (started || !dsn || typeof Sentry === 'undefined') return; started = true; app = component || ''; const options = {dsn, sendDefaultPii: false, beforeSend: scrub}; if (window.dtfEnvironment) options.environment = window.dtfEnvironment; if (window.dtfRelease) options.release = window.dtfRelease; try { Sentry.init(options); Sentry.setTag('app', app); } catch (error) { started = false; } } function apiError(path, status, message, detail) { if (!started || status === 401 || typeof Sentry === 'undefined') return; try { const extra = {path, status, page: location.pathname}; if (status === 422 && detail) extra.detail = detail; Sentry.captureMessage(clean('API ' + status + ' ' + path + ': ' + (message || '')), {level: 'error', tags: {app}, extra}); } catch (error) { // Reporting an error must never break the page. } } window.dtfObservability = {start, apiError, scrub}; })();