feat: add request ID and stack snippet to error reports; update scheduling documentation

This commit is contained in:
2025-12-06 13:38:02 +01:00
parent 0c8fcfc597
commit eda43ff7d9
2 changed files with 14 additions and 2 deletions

View File

@@ -1,6 +1,9 @@
const { randomUUID } = require('crypto')
const MAX_BODY_SIZE = 10000 const MAX_BODY_SIZE = 10000
const MAX_TEXT = 900 const MAX_TEXT = 900
const MAX_FIELD = 120 const MAX_FIELD = 120
const MAX_STACK_LINES = 8
const AUTH_HEADER = 'x-error-report-token' const AUTH_HEADER = 'x-error-report-token'
function isPlainObject(value) { function isPlainObject(value) {
@@ -96,6 +99,10 @@ module.exports = async function handler(req, res) {
const errorType = trimAndLimit(body.type || 'unspecified', 80) const errorType = trimAndLimit(body.type || 'unspecified', 80)
const environment = trimAndLimit((body.environment && (body.environment.name || body.environment)) || process.env.VERCEL_ENV || process.env.NODE_ENV || 'unspecified', 80) const environment = trimAndLimit((body.environment && (body.environment.name || body.environment)) || process.env.VERCEL_ENV || process.env.NODE_ENV || 'unspecified', 80)
const metadata = formatMetadata(body.metadata) const metadata = formatMetadata(body.metadata)
const stackSnippet = Array.isArray(body.stack)
? body.stack.slice(0, MAX_STACK_LINES).join('\n')
: trimAndLimit(typeof body.stack === 'string' ? body.stack.split('\n').slice(0, MAX_STACK_LINES).join('\n') : '', MAX_TEXT)
const requestId = randomUUID()
const embed = { const embed = {
title: 'Error Report', title: 'Error Report',
@@ -104,7 +111,8 @@ module.exports = async function handler(req, res) {
fields: [ fields: [
{ name: 'Error', value: errorText, inline: false }, { name: 'Error', value: errorText, inline: false },
{ name: 'Type', value: errorType, inline: true }, { name: 'Type', value: errorType, inline: true },
{ name: 'Environment', value: environment, inline: true } { name: 'Environment', value: environment, inline: true },
{ name: 'Request ID', value: requestId, inline: true }
], ],
footer: { text: 'Microsoft Rewards Bot' }, footer: { text: 'Microsoft Rewards Bot' },
timestamp: new Date().toISOString() timestamp: new Date().toISOString()
@@ -114,6 +122,10 @@ module.exports = async function handler(req, res) {
embed.fields.push({ name: 'Metadata', value: metadata, inline: false }) embed.fields.push({ name: 'Metadata', value: metadata, inline: false })
} }
if (stackSnippet) {
embed.fields.push({ name: 'Stack (truncated)', value: stackSnippet })
}
const payload = { embeds: [embed] } const payload = { embeds: [embed] }
try { try {

View File

@@ -8,7 +8,7 @@ Runs the bot automatically at set times.
- Choose a time using the cron or Task Scheduler fields already in the config. - Choose a time using the cron or Task Scheduler fields already in the config.
- Leave the machine or container running so the schedule can trigger. - Leave the machine or container running so the schedule can trigger.
- Check the console after start: it prints the next run time. If you close the window or stop the container, the scheduler stops. - Check the console after start: it prints the next run time. If you close the window or stop the container, the scheduler stops.
- Serverless hosts (e.g., Vercel) will not keep the scheduler alive; run on a machine or container that stays on. - Serverless hosts (e.g., Vercel) will not keep the scheduler alive; run on a machine or container that stays on. Use Vercel only for the API endpoints (like error reporting), not for scheduled runs.
## Example ## Example
```jsonc ```jsonc