|
| 1 | +// @ts-check |
1 | 2 | /* eslint-disable no-console */
|
2 | 3 |
|
3 | 4 | const fs = require('fs');
|
4 | 5 | const path = require('path');
|
| 6 | +const glob = require('glob'); |
| 7 | + |
| 8 | +glob.glob( |
| 9 | + '../dev-packages/e2e-tests/test-applications/*/event-dumps/*.dump', |
| 10 | + { |
| 11 | + cwd: __dirname, |
| 12 | + absolute: true, |
| 13 | + }, |
| 14 | + (err, dumpPaths) => { |
| 15 | + if (err) { |
| 16 | + throw err; |
| 17 | + } |
5 | 18 |
|
6 |
| -if (process.argv.length < 4) { |
7 |
| - throw new Error('Please provide an input and output file path as an argument.'); |
8 |
| -} |
9 |
| - |
10 |
| -const resolvedInputPath = path.resolve(process.argv[2]); |
11 |
| -const resolvedOutputPath = path.resolve(process.argv[3]); |
12 |
| - |
13 |
| -const fileContents = fs.readFileSync(resolvedInputPath, 'utf8'); |
14 |
| - |
15 |
| -const transactionNodes = []; |
16 |
| - |
17 |
| -fileContents.split('\n').forEach(serializedEnvelope => { |
18 |
| - let envelope; |
19 |
| - try { |
20 |
| - envelope = JSON.parse(serializedEnvelope); |
21 |
| - } catch (e) { |
22 |
| - return; |
23 |
| - // noop |
24 |
| - } |
| 19 | + dumpPaths.forEach(dumpPath => { |
| 20 | + const fileContents = fs.readFileSync(dumpPath, 'utf8'); |
25 | 21 |
|
26 |
| - const envelopeItems = envelope[1]; |
27 |
| - |
28 |
| - envelopeItems.forEach(([envelopeItemHeader, transaction]) => { |
29 |
| - if (envelopeItemHeader.type === 'transaction') { |
30 |
| - const rootNode = { |
31 |
| - runtime: transaction.contexts.runtime?.name, |
32 |
| - op: transaction.contexts.trace.op, |
33 |
| - name: transaction.transaction, |
34 |
| - children: [], |
35 |
| - }; |
36 |
| - |
37 |
| - const spanMap = new Map(); |
38 |
| - spanMap.set(transaction.contexts.trace.span_id, rootNode); |
39 |
| - |
40 |
| - transaction.spans.forEach(span => { |
41 |
| - const node = { |
42 |
| - op: span.data['sentry.op'], |
43 |
| - name: span.description, |
44 |
| - parent_span_id: span.parent_span_id, |
45 |
| - children: [], |
46 |
| - }; |
47 |
| - spanMap.set(span.span_id, node); |
48 |
| - }); |
| 22 | + const transactionNodes = []; |
49 | 23 |
|
50 |
| - transaction.spans.forEach(span => { |
51 |
| - const node = spanMap.get(span.span_id); |
52 |
| - if (node && node.parent_span_id) { |
53 |
| - const parentNode = spanMap.get(node.parent_span_id); |
54 |
| - parentNode.children.push(node); |
| 24 | + fileContents.split('\n').forEach(serializedEnvelope => { |
| 25 | + let envelope; |
| 26 | + try { |
| 27 | + envelope = JSON.parse(serializedEnvelope); |
| 28 | + } catch (e) { |
| 29 | + return; |
| 30 | + // noop |
55 | 31 | }
|
56 |
| - }); |
57 | 32 |
|
58 |
| - transactionNodes.push(rootNode); |
59 |
| - } |
60 |
| - }); |
61 |
| -}); |
62 |
| - |
63 |
| -const output = transactionNodes |
64 |
| - .sort((a, b) => { |
65 |
| - const aSerialized = serializeNode(a); |
66 |
| - const bSerialized = serializeNode(b); |
67 |
| - if (aSerialized < bSerialized) { |
68 |
| - return -1; |
69 |
| - } else if (aSerialized > bSerialized) { |
70 |
| - return 1; |
71 |
| - } else { |
72 |
| - return 0; |
73 |
| - } |
74 |
| - }) |
75 |
| - .map(node => buildDeterministicStringFromNode(node)) |
76 |
| - .join('\n\n-----------------------\n\n'); |
| 33 | + const envelopeItems = envelope[1]; |
| 34 | + |
| 35 | + envelopeItems.forEach(([envelopeItemHeader, transaction]) => { |
| 36 | + if (envelopeItemHeader.type === 'transaction') { |
| 37 | + const rootNode = { |
| 38 | + runtime: transaction.contexts.runtime?.name, |
| 39 | + op: transaction.contexts.trace.op, |
| 40 | + name: transaction.transaction, |
| 41 | + children: [], |
| 42 | + }; |
| 43 | + |
| 44 | + const spanMap = new Map(); |
| 45 | + spanMap.set(transaction.contexts.trace.span_id, rootNode); |
| 46 | + |
| 47 | + transaction.spans.forEach(span => { |
| 48 | + const node = { |
| 49 | + op: span.data['sentry.op'], |
| 50 | + name: span.description, |
| 51 | + parent_span_id: span.parent_span_id, |
| 52 | + children: [], |
| 53 | + }; |
| 54 | + spanMap.set(span.span_id, node); |
| 55 | + }); |
| 56 | + |
| 57 | + transaction.spans.forEach(span => { |
| 58 | + const node = spanMap.get(span.span_id); |
| 59 | + if (node && node.parent_span_id) { |
| 60 | + const parentNode = spanMap.get(node.parent_span_id); |
| 61 | + parentNode.children.push(node); |
| 62 | + } |
| 63 | + }); |
| 64 | + |
| 65 | + transactionNodes.push(rootNode); |
| 66 | + } |
| 67 | + }); |
| 68 | + }); |
77 | 69 |
|
78 |
| -fs.writeFileSync(resolvedOutputPath, output, 'utf-8'); |
| 70 | + const output = transactionNodes |
| 71 | + .sort((a, b) => { |
| 72 | + const aSerialized = serializeNode(a); |
| 73 | + const bSerialized = serializeNode(b); |
| 74 | + if (aSerialized < bSerialized) { |
| 75 | + return -1; |
| 76 | + } else if (aSerialized > bSerialized) { |
| 77 | + return 1; |
| 78 | + } else { |
| 79 | + return 0; |
| 80 | + } |
| 81 | + }) |
| 82 | + .map(node => buildDeterministicStringFromNode(node)) |
| 83 | + .join('\n\n-----------------------\n\n'); |
| 84 | + |
| 85 | + fs.writeFileSync( |
| 86 | + path.join(path.dirname(dumpPath), `normalized-transactions-${path.basename(dumpPath, '.dump')}.txt`), |
| 87 | + output, |
| 88 | + 'utf-8', |
| 89 | + ); |
| 90 | + }); |
| 91 | + }, |
| 92 | +); |
79 | 93 |
|
80 | 94 | // ------- utility fns ----------
|
81 | 95 |
|
|
0 commit comments