traceTree.ssr.spec.tsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import {
  2. makeEventTransaction,
  3. makeSpan,
  4. makeTrace,
  5. makeTransaction,
  6. } from 'sentry/views/performance/newTraceDetails/traceModels/traceTreeTestUtils';
  7. import {TraceTree} from './traceTree';
  8. const start = new Date('2024-02-29T00:00:00Z').getTime() / 1e3;
  9. const traceMetadata = {replay: null, meta: null};
  10. const ssrTrace = makeTrace({
  11. transactions: [
  12. makeTransaction({
  13. start_timestamp: start,
  14. timestamp: start + 2,
  15. ['transaction.op']: 'http.server',
  16. children: [
  17. makeTransaction({
  18. start_timestamp: start,
  19. timestamp: start + 2,
  20. ['transaction.op']: 'pageload',
  21. children: [],
  22. }),
  23. ],
  24. }),
  25. ],
  26. });
  27. const ssrSpans = [
  28. makeSpan({
  29. op: 'tls.connect',
  30. start_timestamp: start,
  31. timestamp: start + 2,
  32. }),
  33. makeSpan({
  34. op: 'browser.request',
  35. description: 'browser',
  36. start_timestamp: start,
  37. timestamp: start + 2,
  38. }),
  39. ];
  40. describe('server side rendering', () => {
  41. it('reparents pageload transaction as parent of server handler', () => {
  42. const tree = TraceTree.FromTrace(ssrTrace, traceMetadata);
  43. const pageload = tree.root.children[0].children[0];
  44. const serverHandler = pageload.children[0];
  45. expect(serverHandler.parent).toBe(pageload);
  46. expect(pageload.parent).toBe(tree.root.children[0]);
  47. expect(tree.build().serialize()).toMatchSnapshot();
  48. });
  49. it('reparents server handler under browser request span', () => {
  50. const tree = TraceTree.FromTrace(ssrTrace, traceMetadata);
  51. TraceTree.FromSpans(
  52. tree.root.children[0].children[0],
  53. ssrSpans,
  54. makeEventTransaction()
  55. );
  56. expect(tree.build().serialize()).toMatchSnapshot();
  57. });
  58. it('does not reparent if server handler has multiple direct transaction children', () => {
  59. const tree = TraceTree.FromTrace(
  60. makeTrace({
  61. transactions: [
  62. makeTransaction({
  63. transaction: 'SSR',
  64. ['transaction.op']: 'http.server',
  65. children: [
  66. makeTransaction({
  67. transaction: 'pageload',
  68. ['transaction.op']: 'pageload',
  69. }),
  70. makeTransaction({
  71. transaction: 'pageload',
  72. ['transaction.op']: 'pageload',
  73. }),
  74. ],
  75. }),
  76. ],
  77. }),
  78. traceMetadata
  79. );
  80. expect(tree.build().serialize()).toMatchSnapshot();
  81. });
  82. });