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:
1 parent
6ea0dce549
commit
ba7a971bc1
3 files changed
+49
-3
No files matched your search
@@ -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 || {}),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user