From 0f7b798caec98e2ae53b551545e6fa59b1e4abc2 Mon Sep 17 00:00:00 2001 From: Thomas Durieux <5577568+tdurieux@users.noreply.github.com> Date: Sat, 14 Nov 2026 21:25:09 +0000 Subject: [PATCH] test: trace a real synthetic exception through logging --- deploy/logging/README.md | 2 +- scripts/test-admin-logs.js | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/deploy/logging/README.md b/deploy/logging/README.md index bdc48a9..94f9ed4 100644 --- a/deploy/logging/README.md +++ b/deploy/logging/README.md @@ -325,7 +325,7 @@ The fixture uses only synthetic counters and removes its container on exit. New application errors retain the normalized route template, HTTP method/status, a finite error type/code, and up to eight recognized application frames (1 KiB maximum per stack) for the -exception and a bounded cause chain (three levels, cycles stopped). Raw messages, +exception and the deepest inspected cause (at most three levels, cycles stopped). Raw messages, URLs, query strings, repository/file parameters, external frames and absolute filesystem roots are not stored. Unknown error types use `UnknownError`; unknown function names become ``. Source locations are build-relative for diff --git a/scripts/test-admin-logs.js b/scripts/test-admin-logs.js index f30f22c..8327010 100644 --- a/scripts/test-admin-logs.js +++ b/scripts/test-admin-logs.js @@ -65,16 +65,18 @@ const sleep = ms => new Promise(resolve=>setTimeout(resolve,ms)); const {serializeError}=require('../src/core/logger'); const {safeRedisLog}=require('../src/server/admin-log-investigation'); const {logContext}=require('../src/core/log-context'); - const path=require('node:path'); + const {requestRoute}=require('../src/core/request-monitoring'); const diagnosticId=randomUUID(), secret='SECRET_private_owner_token'; - const error=new TypeError('https://user:'+secret+'@example.test/private?token='+secret); - error.stack=error.message+'\n at printError ('+path.resolve('src/server/routes/route-utils.ts')+':200:7)\n at '+secret+' (/private/'+secret+':1:2)'; + let error; + try { requestRoute(null,'api'); } catch (failure) { error=failure; } // real synthetic TypeError in application code + assert(error instanceof TypeError); + error.message='https://user:'+secret+'@example.test/private?token='+secret; error.cause=new RangeError(secret);error.cause.stack=error.stack; const diagnostic=logContext.run({requestId:diagnosticId,route:'/api/repo/:repoId/file/:path',method:'GET'},()=>logRecord('error','route',['', {...serializeError(error),httpStatus:500}])); const rawSource={file:'/host/docker/fixture/log.json',message:JSON.stringify({attrs:{tag:'api'},log:JSON.stringify({...diagnostic,url:secret,stack:secret,errorStack:diagnostic.errorStack+'\n at '+secret+' (/private/'+secret+':1:2)'})})}; const projected=execFileSync('docker',['run','--rm','-i','--network','none','--memory','256m',vectorImage,'vrl','-i','/dev/stdin',fs.readFileSync('deploy/logging/sanitize.vrl','utf8')+'\nencode_json(.)'],{encoding:'utf8',input:JSON.stringify(rawSource)+'\n'}).trim().split('\n').map(line=>JSON.parse(JSON.parse(line)))[0]; assert.equal(projected.errorType,'TypeError');assert.equal(projected.causeType,'RangeError'); - assert.equal(projected.errorStack,'at printError (src/server/routes/route-utils.ts:200:7)'); + assert.match(projected.errorStack,/at requestRoute \(src\/core\/request-monitoring.ts:\d+:\d+\)/); assert(!JSON.stringify(projected).includes(secret)); const ingested=await fetch(process.env.ADMIN_LOG_URL+'/insert/jsonline?_time_field=timestamp',{method:'POST',body:JSON.stringify(projected),headers:{'Content-Type':'application/stream+json'}});assert(ingested.ok);await sleep(2000); const traced=await investigateLogs(logOptions({kind:'requestId',id:diagnosticId},true),true);