mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-11-17 17:44:09 +01:00
test: trace a real synthetic exception through logging
This commit is contained in:
1 parent
f6574069da
commit
0f7b798cae
2 files changed
+7
-5
No files matched your search
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user