makeExampleTrace.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import {TraceTree} from './traceTree';
  2. // Creates an example trace response that we use to render the loading placeholder
  3. function partialTransaction(
  4. partial: Partial<TraceTree.Transaction>
  5. ): TraceTree.Transaction {
  6. return {
  7. start_timestamp: 0,
  8. timestamp: 0,
  9. errors: [],
  10. performance_issues: [],
  11. parent_span_id: '',
  12. span_id: '',
  13. parent_event_id: '',
  14. project_id: 0,
  15. sdk_name: '',
  16. profiler_id: '',
  17. 'transaction.duration': 0,
  18. 'transaction.op': 'loading-transaction',
  19. 'transaction.status': 'loading-status',
  20. generation: 0,
  21. project_slug: '',
  22. event_id: `event_id`,
  23. transaction: `transaction`,
  24. children: [],
  25. ...partial,
  26. };
  27. }
  28. export function makeExampleTrace(metadata: TraceTree.Metadata): TraceTree {
  29. const trace: TraceTree.Trace = {
  30. transactions: [],
  31. orphan_errors: [],
  32. };
  33. function randomBetween(min: number, max: number) {
  34. return Math.floor(Math.random() * (max - min + 1) + min);
  35. }
  36. let start = new Date().getTime();
  37. const root = partialTransaction({
  38. ...metadata,
  39. generation: 0,
  40. start_timestamp: start,
  41. transaction: 'root transaction',
  42. timestamp: start + randomBetween(100, 200),
  43. });
  44. trace.transactions.push(root);
  45. for (let i = 0; i < 50; i++) {
  46. const end = start + randomBetween(100, 200);
  47. const nest = i > 0 && Math.random() > 0.33;
  48. if (nest) {
  49. const parent = root.children[root.children.length - 1];
  50. parent.children.push(
  51. partialTransaction({
  52. ...metadata,
  53. generation: 0,
  54. start_timestamp: start,
  55. transaction: `parent transaction ${i}`,
  56. timestamp: end,
  57. })
  58. );
  59. parent.timestamp = end;
  60. } else {
  61. root.children.push(
  62. partialTransaction({
  63. ...metadata,
  64. generation: 0,
  65. start_timestamp: start,
  66. transaction: 'loading...',
  67. ['transaction.op']: 'loading',
  68. timestamp: end,
  69. })
  70. );
  71. }
  72. start = end;
  73. }
  74. return TraceTree.FromTrace(trace, {meta: null, replay: null});
  75. }