feat(clients): support project_slug and gitea_repo routing metadata

Extend official Node/PHP reporter clients to attach optional project routing metadata (`project_name`, `project_slug`, `gitea_repo`) via env/options so product repos can emit deterministic ERRSIG routing context at source.
This commit is contained in:
David Santos committed 2026-04-06 21:59:01 +00:00
1 parent 6ea0dce549
commit ba7a971bc1
3 files changed
+49 -3

No files matched your search

+14 -1
View File
@@ -7,6 +7,9 @@
let _token = '';
let _endpoint = 'https://errors.bitreport.pt';
let _disabled = false;
let _projectName = process.env.ERROR_REPORTING_PROJECT_NAME || '';
let _projectSlug = process.env.ERROR_REPORTING_PROJECT_SLUG || '';
let _giteaRepo = process.env.ERROR_REPORTING_GITEA_REPO || '';
const _queue = [];
let _flushTimer = null;
const BATCH_SIZE = 25;
@@ -18,6 +21,9 @@ 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 != null ? 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', function (err) {
@@ -51,6 +57,9 @@ function reportError(err, context) {
line_number: lineNumber || undefined,
error_type: (err && err.constructor && err.constructor.name) || 'Error',
error_code: (err && err.code) || undefined,
project_name: _projectName || undefined,
project_slug: _projectSlug || undefined,
gitea_repo: _giteaRepo || undefined,
}, context),
});
}
@@ -62,7 +71,11 @@ function reportMessage(message, level, context) {
occurred_at: new Date().toISOString(),
level: level || 'error',
message: message,
context: context || {},
context: Object.assign({
project_name: _projectName || undefined,
project_slug: _projectSlug || undefined,
gitea_repo: _giteaRepo || undefined,
}, context || {}),
});
}
+16 -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 || '';
let _projectSlug = process.env.ERROR_REPORTING_PROJECT_SLUG || '';
let _giteaRepo = process.env.ERROR_REPORTING_GITEA_REPO || '';
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 || undefined,
project_slug: _projectSlug || undefined,
gitea_repo: _giteaRepo || undefined,
...context,
},
});
@@ -87,7 +96,12 @@ export function reportMessage(message, level = 'error', context = {}) {
occurred_at: new Date().toISOString(),
level,
message,
context,
context: {
project_name: _projectName || undefined,
project_slug: _projectSlug || undefined,
gitea_repo: _giteaRepo || undefined,
...context,
},
});
}
+19
View File
@@ -44,6 +44,22 @@ final class ErrorReporter
return self::env('ERROR_REPORTING_TOKEN');
}
private static function projectName(): string
{
return self::env('ERROR_REPORTING_PROJECT_NAME');
}
private static function projectSlug(): string
{
return self::env('ERROR_REPORTING_PROJECT_SLUG');
}
private static function giteaRepo(): string
{
return self::env('ERROR_REPORTING_GITEA_REPO');
}
private static function env(string $key): string
{
$v = getenv($key);
@@ -130,6 +146,9 @@ final class ErrorReporter
'request_uri' => $_SERVER['REQUEST_URI'] ?? null,
'http_method' => $_SERVER['REQUEST_METHOD'] ?? null,
'ip_address' => $_SERVER['REMOTE_ADDR'] ?? null,
'project_name' => self::projectName() !== '' ? self::projectName() : null,
'project_slug' => self::projectSlug() !== '' ? self::projectSlug() : null,
'gitea_repo' => self::giteaRepo() !== '' ? self::giteaRepo() : null,
], $context);
// Remove null values