feat(error-reporting): include routing metadata in bridge reporter

Add source metadata for deterministic news-platform routing.
This commit was merged in pull request #4.
This commit is contained in:
spark committed 2026-04-06 23:00:55 +01:00
commit 02c64f0ff9
1 file changed
+11 -2
+11 -2
View File
@@ -17,6 +17,9 @@
let _token = '';
let _endpoint = 'https://errors.bitreport.pt';
let _disabled = false;
let _projectName = process.env.ERROR_REPORTING_PROJECT_NAME || 'news-platform-bridge';
let _projectSlug = process.env.ERROR_REPORTING_PROJECT_SLUG || 'news-platform';
let _giteaRepo = process.env.ERROR_REPORTING_GITEA_REPO || 'BitReport.pt/news-platform';
const _queue = [];
let _flushTimer = null;
const BATCH_SIZE = 25;
@@ -25,12 +28,15 @@ const TIMEOUT_MS = 8000;
/**
* Initialise the reporter. Call once at startup.
* @param {{ token?: string, endpoint?: string, disabled?: boolean }} opts
* @param {{ token?: string, endpoint?: string, disabled?: boolean, projectName?: string, projectSlug?: string, giteaRepo?: string }} opts
*/
export function initReporter(opts = {}) {
_token = opts.token || process.env.ERROR_REPORTING_TOKEN || '';
_endpoint = (opts.endpoint || process.env.ERROR_REPORTING_ENDPOINT || 'https://errors.bitreport.pt').replace(/\/$/, '');
_disabled = opts.disabled ?? process.env.ERROR_REPORTING_DISABLED === '1';
_projectName = opts.projectName || process.env.ERROR_REPORTING_PROJECT_NAME || _projectName;
_projectSlug = opts.projectSlug || process.env.ERROR_REPORTING_PROJECT_SLUG || _projectSlug;
_giteaRepo = opts.giteaRepo || process.env.ERROR_REPORTING_GITEA_REPO || _giteaRepo;
if (!_disabled && _token) {
process.on('uncaughtException', (err) => {
@@ -69,6 +75,9 @@ export function reportError(err, context = {}) {
line_number: lineNumber || undefined,
error_type: err?.constructor?.name || 'Error',
error_code: err?.code || undefined,
project_name: _projectName,
project_slug: _projectSlug,
gitea_repo: _giteaRepo,
...context,
},
});
@@ -87,7 +96,7 @@ export function reportMessage(message, level = 'error', context = {}) {
occurred_at: new Date().toISOString(),
level,
message,
context,
context: { project_name: _projectName, project_slug: _projectSlug, gitea_repo: _giteaRepo, ...context },
});
}