@spotlightjs/spotlight 2.7.0 → 2.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,38 @@
1
+ import { init } from '@sentry/node';
2
+
3
+ init({
4
+ dsn: 'https://51bcd92dba1128934afd1c5726c84442@o1.ingest.us.sentry.io/4508404727283713',
5
+ environment: process.env.NODE_ENV || 'development',
6
+ release: process.env.npm_package_version,
7
+ debug: Boolean(process.env.SENTRY_DEBUG),
8
+
9
+ tracesSampleRate: 1,
10
+
11
+ beforeSendTransaction: event => {
12
+ event.server_name = undefined; // Server name might contain PII
13
+ return event;
14
+ },
15
+
16
+ beforeSend: event => {
17
+ const exceptions = event.exception?.values;
18
+ if (!exceptions) {
19
+ return event;
20
+ }
21
+ for (const exception of exceptions) {
22
+ if (!exception.stacktrace) {
23
+ continue;
24
+ }
25
+
26
+ for (const frame of exception.stacktrace.frames) {
27
+ if (!frame.filename) {
28
+ continue;
29
+ }
30
+
31
+ frame.filename = frame.filename?.replace(process.env.HOME, '~');
32
+ }
33
+ }
34
+
35
+ event.server_name = undefined; // Server name might contain PII
36
+ return event;
37
+ },
38
+ });
package/bin/run.js CHANGED
@@ -1,10 +1,12 @@
1
1
  #!/usr/bin/env node
2
+ import { setContext, startSpan } from '@sentry/node';
2
3
  import { setupSidecar } from '@spotlightjs/sidecar';
3
- import { inflateRawSync } from 'node:zlib';
4
4
  import { readFileSync } from 'node:fs';
5
+ import Module from 'node:module';
5
6
  import { join } from 'node:path';
6
7
  import { fileURLToPath } from 'node:url';
7
- import Module from 'node:module';
8
+ import { inflateRawSync } from 'node:zlib';
9
+ import './instrument.js';
8
10
  const require = Module.createRequire(import.meta.url);
9
11
  let sea = null;
10
12
  try {
@@ -15,75 +17,102 @@ try {
15
17
  sea = { isSea: () => false };
16
18
  }
17
19
 
18
- const readAsset = sea.isSea()
19
- ? name => Buffer.from(sea.getRawAsset(name))
20
- : (() => {
21
- const ASSET_DIR = join(fileURLToPath(import.meta.url), '../../dist/overlay/');
20
+ setContext('CLI', {
21
+ sea: sea.isSea(),
22
+ // TODO: Be less naive with path obscuring
23
+ argv: process.argv.map(arg => arg.replace(process.env.HOME, '~')),
24
+ });
25
+
26
+ const withTracing =
27
+ (fn, spanArgs = {}) =>
28
+ (...args) =>
29
+ startSpan({ name: fn.name, attributes: { args }, ...spanArgs }, () => fn(...args));
30
+
31
+ const readAsset = withTracing(
32
+ sea.isSea()
33
+ ? name => Buffer.from(sea.getRawAsset(name))
34
+ : (() => {
35
+ const ASSET_DIR = join(fileURLToPath(import.meta.url), '../../dist/overlay/');
36
+
37
+ return name => readFileSync(join(ASSET_DIR, name));
38
+ })(),
39
+ { name: 'readAsset', op: 'cli.asset.read' },
40
+ );
22
41
 
23
- return name => readFileSync(join(ASSET_DIR, name));
24
- })();
42
+ startSpan({ name: 'Spotlight CLI', op: 'cli' }, () => {
43
+ startSpan({ name: 'ASCII Art', op: 'cli.art.ascii' }, () => {
44
+ const MAX_COLS = process.stdout.columns;
45
+ if (!process.stdout.isTTY || MAX_COLS < 35) return;
46
+ let stdoutBuffer = '';
25
47
 
26
- const MAX_COLS = process.stdout.columns;
27
- if (process.stdout.isTTY && MAX_COLS > 34) {
28
- const data = Uint8Array.from(
29
- inflateRawSync(
30
- Buffer.from(
31
- 'bY7LCgMxFEK9L5MwDDSL9P//1DJMKGXowoUcUaFZOk8dU2Op9+qZVkYQoFsaEqA6PZxxma1AoMG+TiONTgcfAd741YxxVf8gCzCgWcYB7OSj9sjW7t2/eKxKAxkIYv8NqL3FpVY25CmjrBSuDw==',
32
- 'base64',
48
+ const data = startSpan({ name: 'Inflate ASCII Art Data', op: 'cli.art.ascii.inflate' }, () =>
49
+ Uint8Array.from(
50
+ inflateRawSync(
51
+ Buffer.from(
52
+ 'bY7LCgMxFEK9L5MwDDSL9P//1DJMKGXowoUcUaFZOk8dU2Op9+qZVkYQoFsaEqA6PZxxma1AoMG+TiONTgcfAd741YxxVf8gCzCgWcYB7OSj9sjW7t2/eKxKAxkIYv8NqL3FpVY25CmjrBSuDw==',
53
+ 'base64',
54
+ ),
55
+ ),
33
56
  ),
34
- ),
35
- );
36
- const E = '\x1b[';
37
- const C = `${E}38;5;`;
38
- const M_COL = `${C}96m`;
39
- const F_COL = `${C}61m`;
40
- const BOLD = `${E}1m`;
41
- const RESET = `${E}0m`;
42
- const NL = `${RESET}\n`;
43
- let factor = 0.22;
44
- let c = 0;
45
- let col = 0;
46
- let line = 0;
47
- let lim = 26;
48
- let r = 0;
49
- for (let p of data) {
50
- if (p === 255) {
51
- process.stdout.write(NL);
52
- c = col = 0;
53
- if (line++ === 5) {
54
- factor = factor / -3;
55
- }
56
- lim = Math.round(lim * (1 + factor));
57
- r = Math.round(Math.random() * 18);
58
- } else {
59
- while (p-- >= 0 && col < MAX_COLS) {
60
- if (col < lim - 1) {
61
- process.stdout.write(M_COL);
62
- } else if (col === lim - 1) {
63
- process.stdout.write(F_COL);
64
- } else if (col === lim + r) {
65
- process.stdout.write(`${RESET}${BOLD}`);
57
+ );
58
+ const E = '\x1b[';
59
+ const C = `${E}38;5;`;
60
+ const M_COL = `${C}96m`;
61
+ const F_COL = `${C}61m`;
62
+ const BOLD = `${E}1m`;
63
+ const RESET = `${E}0m`;
64
+ const NL = `${RESET}\n`;
65
+ let factor = 0.22;
66
+ let c = 0;
67
+ let col = 0;
68
+ let line = 0;
69
+ let lim = 26;
70
+ let r = 0;
71
+ for (let p of data) {
72
+ if (p === 255) {
73
+ stdoutBuffer += NL;
74
+ c = col = 0;
75
+ if (line++ === 5) {
76
+ factor = factor / -3;
77
+ }
78
+ lim = Math.round(lim * (1 + factor));
79
+ r = Math.round(Math.random() * 18);
80
+ } else {
81
+ while (p-- >= 0 && col < MAX_COLS) {
82
+ if (col < lim - 1) {
83
+ stdoutBuffer += M_COL;
84
+ } else if (col === lim - 1) {
85
+ stdoutBuffer += F_COL;
86
+ } else if (col === lim + r) {
87
+ stdoutBuffer += `${RESET}${BOLD}`;
88
+ }
89
+ stdoutBuffer += c ? (col >= 35 ? '#' : 's') : ' ';
90
+ col++;
66
91
  }
67
- process.stdout.write(c ? (col >= 35 ? '#' : 's') : ' ');
68
- col++;
92
+ c = !c;
69
93
  }
70
- c = !c;
71
94
  }
72
- }
73
- process.stdout.write(NL);
74
- }
95
+ stdoutBuffer += NL;
96
+ process.stdout.write(stdoutBuffer);
97
+ });
75
98
 
76
- const port = process.argv.length >= 3 ? Number(process.argv[2]) : undefined;
77
- const MANIFEST_NAME = 'manifest.json';
78
- const ENTRY_POINT_NAME = 'src/index.html';
79
- const basePath = process.cwd();
80
- const filesToServe = Object.create(null);
99
+ startSpan({ name: 'Setup Sidecar', op: 'cli.setup.sidecar' }, () => {
100
+ const port = process.argv.length >= 3 ? Number(process.argv[2]) : undefined;
101
+ const MANIFEST_NAME = 'manifest.json';
102
+ const ENTRY_POINT_NAME = 'src/index.html';
103
+ const basePath = process.cwd();
104
+ const filesToServe = Object.create(null);
81
105
 
82
- // Following the guide here: https://vite.dev/guide/backend-integration.html
83
- const manifest = JSON.parse(readAsset(MANIFEST_NAME));
84
- filesToServe[ENTRY_POINT_NAME] = readAsset(ENTRY_POINT_NAME);
85
- const entries = Object.values(manifest);
86
- for (const entry of entries) {
87
- filesToServe[entry.file] = readAsset(entry.file);
88
- }
89
- setupSidecar({ port, basePath, filesToServe });
106
+ startSpan({ name: 'Setup Server Assets', op: 'cli.setup.sidecar.assets' }, () => {
107
+ // Following the guide here: https://vite.dev/guide/backend-integration.html
108
+ const manifest = JSON.parse(readAsset(MANIFEST_NAME));
109
+ filesToServe[ENTRY_POINT_NAME] = readAsset(ENTRY_POINT_NAME);
110
+ const entries = Object.values(manifest);
111
+ for (const entry of entries) {
112
+ filesToServe[entry.file] = readAsset(entry.file);
113
+ }
114
+ });
115
+
116
+ setupSidecar({ port, basePath, filesToServe });
117
+ });
118
+ });