All checks were successful
Build and deploy / Validate source (push) Successful in 8s
Build and deploy / Integration suite on a real stack (push) Successful in 8m14s
Build and deploy / Secret scan and release gate (push) Successful in 7s
Build and deploy / Publish images (push) Successful in 1m22s
The same Android 10 phone failed three times on 2026-12-02 reading a file seven seconds after picking it: not a permission lost over time, but a file the phone does not have yet (Google Drive or WhatsApp). "Escolha o arquivo de novo" sent the customer back to the same file. The message now says "Se ele está no Google Drive ou no WhatsApp, salve no aparelho e escolha de novo". The Sentry notice carries the browser's error name, the file's type, extension and size in MB, never its name, so the next one says which case it is. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
168 lines
7.4 KiB
JavaScript
168 lines
7.4 KiB
JavaScript
/* 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 = /(?<!\d)(?:\d{2}\.?\d{3}\.?\d{3}\/?\d{4}-?\d{2}|\d{3}\.?\d{3}\.?\d{3}-?\d{2})(?!\d)/g;
|
|
// What changes from one API error to the next of the same kind: the ids of
|
|
// the files, quotes and orders, the numbers and the file names.
|
|
const UUID = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi;
|
|
const FILE_NAME = /[^\s"'<>:,;()[\]{}]+\.(?:png|jpe?g|pdf|tiff?|psd|psb|ai|cdr|webp|zip)\b/gi;
|
|
const NUMBER = /\d+/g;
|
|
const SENSITIVE_PARAM = /token|signature|x-amz/i;
|
|
const SENSITIVE_HEADER = /^(cookie|authorization|x-.*token.*)$/i;
|
|
const REDACTED = '[removido]';
|
|
let started = false;
|
|
let app = '';
|
|
|
|
const clean = value => 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;
|
|
}
|
|
}
|
|
|
|
const normalizedPath = value => clean(String(value == null ? '' : value)
|
|
.replace(UUID, ':id').replace(NUMBER, ':id'));
|
|
const normalizedMessage = value => clean(String(value == null ? '' : value)
|
|
.replace(UUID, ':id').replace(FILE_NAME, ':arquivo').replace(NUMBER, ':id'));
|
|
|
|
// What apiError already sent, so the same text shown in red is not sent twice.
|
|
const recent = new Map();
|
|
function apiError(path, status, message, detail) {
|
|
// Recorded first: a skipped 401 or restart 503 stays out of uiError too.
|
|
recent.set(String(message), Date.now());
|
|
if (!started || status === 401 || typeof Sentry === 'undefined') return;
|
|
// A restart's few seconds without the database (app/app.py): not a bug.
|
|
if (status === 503 && /reiniciando/.test(String(message))) return;
|
|
// A refusal the server explains to the person (a rule, a check, a limit:
|
|
// a 4xx with a sentence for them) is the system working, not a bug: on
|
|
// the Kanban it stays, as a warning, since a refusal the team keeps
|
|
// meeting says a screen confuses; on the Site the customer reads it and
|
|
// nothing is sent (2026-11-30). A 4xx without a sentence (a list of
|
|
// fields: what the page sent was wrong) and a 5xx stay errors.
|
|
const refusal = status >= 400 && status < 500 && typeof detail === 'string';
|
|
if (refusal && app !== 'kanban') return;
|
|
try {
|
|
// One issue per kind of API error: without this Sentry groups them all
|
|
// by apiError and DTF-WEB-1 mixes a 422 for 66 files with a 422 for
|
|
// 96 DPI. The title names the same kind as the fingerprint.
|
|
const kindPath = normalizedPath(path);
|
|
const kindMessage = normalizedMessage(message);
|
|
const extra = {path, status, page: location.pathname};
|
|
if (status === 422 && detail) extra.detail = detail;
|
|
Sentry.captureMessage('API ' + status + ' ' + kindPath + ': ' + kindMessage,
|
|
{level: refusal ? 'warning' : 'error', tags: {app, ...(refusal ? {recusa: 'sim'} : {})}, extra,
|
|
fingerprint: ['api-error', String(status), kindPath, kindMessage]});
|
|
} catch (error) {
|
|
// Reporting an error must never break the page.
|
|
}
|
|
}
|
|
|
|
// Every error the page shows the user in red, also the ones it caught and
|
|
// handled itself (a folder it could not write, an upload that failed): the
|
|
// team sees them in Sentry before anyone sends a screenshot.
|
|
function uiError(text, where, detail) {
|
|
if (!started || !text || typeof Sentry === 'undefined') return;
|
|
const said = recent.get(String(text));
|
|
if (said && Date.now() - said < 15000) return;
|
|
try {
|
|
const kind = normalizedMessage(text);
|
|
Sentry.captureMessage('Aviso ' + (where || app) + ': ' + kind,
|
|
{level: 'error', tags: {app, aviso: where || app}, extra: {page: location.pathname, ...(detail || {})},
|
|
fingerprint: ['ui-error', where || app, kind]});
|
|
} catch (error) {
|
|
// Reporting an error must never break the page.
|
|
}
|
|
}
|
|
|
|
window.dtfObservability = {start, apiError, uiError, scrub};
|
|
})();
|