Skip to content

Commit 7e3b0f0

Browse files
committed
wip: integrating tracer into object lifecycles
1 parent 7ba3a5e commit 7e3b0f0

File tree

6 files changed

+37
-11
lines changed

6 files changed

+37
-11
lines changed

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<!-- Span Visualiser Code -->

npmDepsHash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sha256-4fkSE29rEC53aecV/DYYwP5Xmd2wDjw6sBwGGaaDjF0=
1+
sha256-lV+4/1+pJp1IpSxd31F3FzHPqsp6AK5pFhfWzdo0orM=

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
},
138138
"devDependencies": {
139139
"@matrixai/errors": "^2.1.3",
140-
"@matrixai/logger": "^4.0.3",
140+
"@matrixai/logger": "^4.0.4-alpha.3",
141141
"@matrixai/exec": "^1.0.3",
142142
"@fast-check/jest": "^2.1.1",
143143
"@swc/core": "1.3.82",
@@ -171,5 +171,8 @@
171171
"tsx": "^3.12.7",
172172
"typedoc": "^0.24.8",
173173
"typescript": "^5.1.6"
174+
},
175+
"overrides": {
176+
"@matrixai/logger": "^4.0.4-alpha.3"
174177
}
175178
}

span.jsonl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{"type":"start","id":"mBoGCDYHzcACZ3oKGxhzU+A","spanId":"mBoGCDYHvcACR1sYwXQq3jg","name":"ss-Status"}
2+
{"type":"end","id":"mBoGCDYIIcACNVjBw1zDc6Q","spanId":"mBoGCDYHvcACR1sYwXQq3jg","name":"ss-Status"}

src/polykey.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type { PolykeyAgent } from 'polykey';
88
import fs from 'node:fs';
99
import process from 'node:process';
1010
import { fileURLToPath } from 'node:url';
11+
import { tracer } from '@matrixai/logger';
1112
/**
1213
* Hack for wiping out the threads signal handlers
1314
* See: https://github.com/andywer/threads.js/issues/388
@@ -245,14 +246,33 @@ async function polykeyMain(argv: Array<string>): Promise<number> {
245246
}
246247

247248
async function main(argv = process.argv): Promise<number> {
249+
const fs = await import('node:fs');
250+
const p = (async () => {
251+
const spanFile = await fs.promises.open('span.jsonl', 'w');
252+
const gen = tracer.streamEvents();
253+
for await (const event of gen) {
254+
await spanFile.write(JSON.stringify(event) + '\n');
255+
}
256+
await spanFile.close();
257+
})();
248258
if (argv[argv.length - 1] === '--agent-mode') {
249259
// This is an internal mode for running `PolykeyAgent` as a child process
250260
// This is not supposed to be used directly by the user
251261
process.title = 'polykey-agent';
252-
return polykeyAgentMain();
262+
return (async () => {
263+
const retval = await polykeyAgentMain();
264+
// tracer.endTracing();
265+
await p;
266+
return retval;
267+
})();
253268
} else {
254269
process.title = 'polykey';
255-
return polykeyMain(argv);
270+
return (async () => {
271+
const retval = await polykeyMain(argv);
272+
// tracer.endTracing();
273+
await p;
274+
return retval;
275+
})();
256276
}
257277
}
258278

0 commit comments

Comments
 (0)