|
1 | 1 | import { expect, test } from '@playwright/test'; |
2 | | -import { collectSpanNamesUntilSegment, collectStreamedSpansUntilSegment } from '@sentry-internal/test-utils'; |
| 2 | +import { collectStreamedSpansUntilSegment, getSpanOp } from '@sentry-internal/test-utils'; |
| 3 | + |
| 4 | +// Next.js emits these spans itself. The SDK attaches no op, description or function name to |
| 5 | +// them, so asserting `undefined` pins that they stay untouched. |
| 6 | +const nextjsSpan = { op: undefined, description: undefined, codeFunctionName: undefined }; |
3 | 7 |
|
4 | 8 | // TODO: Server component tests need SDK adjustments for Cloudflare Workers |
5 | 9 | test.skip('Sends a span for a request to app router with URL', async ({ page }) => { |
@@ -45,40 +49,104 @@ test.skip('Sends a span for a request to app router with URL', async ({ page }) |
45 | 49 | test.skip('Will create spans for every server component and metadata generation functions when visiting a page', async ({ |
46 | 50 | page, |
47 | 51 | }) => { |
48 | | - const spanNamesPromise = collectSpanNamesUntilSegment('nextjs-16-cf-workers', 'GET /nested-layout'); |
| 52 | + const spansPromise = collectStreamedSpansUntilSegment('nextjs-16-cf-workers', 'GET /nested-layout'); |
49 | 53 |
|
50 | 54 | await page.goto('/nested-layout'); |
51 | 55 |
|
52 | | - const spanNames = await spanNamesPromise; |
| 56 | + const fullSpans = await spansPromise; |
| 57 | + const spans = fullSpans.map(span => ({ |
| 58 | + name: span.name, |
| 59 | + op: getSpanOp(span), |
| 60 | + description: span.attributes['sentry.description']?.value, |
| 61 | + codeFunctionName: span.attributes['code.function.name']?.value, |
| 62 | + })); |
53 | 63 |
|
54 | | - expect(spanNames).toContainEqual('render route (app) /nested-layout'); |
55 | | - expect(spanNames).toContainEqual('build component tree'); |
56 | | - expect(spanNames).toContainEqual('resolve root layout server component'); |
57 | | - expect(spanNames).toContainEqual('resolve layout server component "(nested-layout)"'); |
58 | | - expect(spanNames).toContainEqual('resolve layout server component "nested-layout"'); |
59 | | - expect(spanNames).toContainEqual('resolve page server component "/nested-layout"'); |
60 | | - expect(spanNames).toContainEqual('generateMetadata /(nested-layout)/nested-layout/page'); |
61 | | - expect(spanNames).toContainEqual('start response'); |
| 64 | + expect(spans).toContainEqual({ ...nextjsSpan, name: 'render route (app) /nested-layout' }); |
| 65 | + expect(spans).toContainEqual({ ...nextjsSpan, name: 'build component tree' }); |
| 66 | + // Server component spans: the name is the low-cardinality `code.function.name`, and the |
| 67 | + // segment each one resolved for is on the description. |
| 68 | + expect(spans).toContainEqual({ |
| 69 | + name: 'Layout', |
| 70 | + op: 'function', |
| 71 | + description: 'resolve root layout server component', |
| 72 | + codeFunctionName: 'Layout', |
| 73 | + }); |
| 74 | + expect(spans).toContainEqual({ |
| 75 | + name: 'Layout', |
| 76 | + op: 'function', |
| 77 | + description: 'resolve layout server component "(nested-layout)"', |
| 78 | + codeFunctionName: 'Layout', |
| 79 | + }); |
| 80 | + expect(spans).toContainEqual({ |
| 81 | + name: 'Layout', |
| 82 | + op: 'function', |
| 83 | + description: 'resolve layout server component "nested-layout"', |
| 84 | + codeFunctionName: 'Layout', |
| 85 | + }); |
| 86 | + expect(spans).toContainEqual({ |
| 87 | + name: 'Page', |
| 88 | + op: 'function', |
| 89 | + description: 'resolve page server component "/nested-layout"', |
| 90 | + codeFunctionName: 'Page', |
| 91 | + }); |
| 92 | + expect(spans).toContainEqual({ ...nextjsSpan, name: 'generateMetadata /(nested-layout)/nested-layout/page' }); |
| 93 | + expect(spans).toContainEqual({ ...nextjsSpan, name: 'start response' }); |
62 | 94 | }); |
63 | 95 |
|
64 | 96 | // TODO: Server component span tests need SDK adjustments for Cloudflare Workers |
65 | 97 | test.skip('Will create spans for every server component and metadata generation functions when visiting a dynamic page', async ({ |
66 | 98 | page, |
67 | 99 | }) => { |
68 | | - const spanNamesPromise = collectSpanNamesUntilSegment('nextjs-16-cf-workers', 'GET /nested-layout/[dynamic]'); |
| 100 | + const spansPromise = collectStreamedSpansUntilSegment('nextjs-16-cf-workers', 'GET /nested-layout/[dynamic]'); |
69 | 101 |
|
70 | 102 | await page.goto('/nested-layout/123'); |
71 | 103 |
|
72 | | - const spanNames = await spanNamesPromise; |
| 104 | + const fullSpans = await spansPromise; |
| 105 | + const spans = fullSpans.map(span => ({ |
| 106 | + name: span.name, |
| 107 | + op: getSpanOp(span), |
| 108 | + description: span.attributes['sentry.description']?.value, |
| 109 | + codeFunctionName: span.attributes['code.function.name']?.value, |
| 110 | + })); |
73 | 111 |
|
74 | | - expect(spanNames).toContainEqual('resolve page components'); |
75 | | - expect(spanNames).toContainEqual('render route (app) /nested-layout/[dynamic]'); |
76 | | - expect(spanNames).toContainEqual('build component tree'); |
77 | | - expect(spanNames).toContainEqual('resolve root layout server component'); |
78 | | - expect(spanNames).toContainEqual('resolve layout server component "(nested-layout)"'); |
79 | | - expect(spanNames).toContainEqual('resolve layout server component "nested-layout"'); |
80 | | - expect(spanNames).toContainEqual('resolve layout server component "[dynamic]"'); |
81 | | - expect(spanNames).toContainEqual('resolve page server component "/nested-layout/[dynamic]"'); |
82 | | - expect(spanNames).toContainEqual('generateMetadata /(nested-layout)/nested-layout/[dynamic]/page'); |
83 | | - expect(spanNames).toContainEqual('start response'); |
| 112 | + expect(spans).toContainEqual({ ...nextjsSpan, name: 'resolve page components' }); |
| 113 | + expect(spans).toContainEqual({ ...nextjsSpan, name: 'render route (app) /nested-layout/[dynamic]' }); |
| 114 | + expect(spans).toContainEqual({ ...nextjsSpan, name: 'build component tree' }); |
| 115 | + // Server component spans: the name is the low-cardinality `code.function.name`, and the |
| 116 | + // segment each one resolved for is on the description. |
| 117 | + expect(spans).toContainEqual({ |
| 118 | + name: 'Layout', |
| 119 | + op: 'function', |
| 120 | + description: 'resolve root layout server component', |
| 121 | + codeFunctionName: 'Layout', |
| 122 | + }); |
| 123 | + expect(spans).toContainEqual({ |
| 124 | + name: 'Layout', |
| 125 | + op: 'function', |
| 126 | + description: 'resolve layout server component "(nested-layout)"', |
| 127 | + codeFunctionName: 'Layout', |
| 128 | + }); |
| 129 | + expect(spans).toContainEqual({ |
| 130 | + name: 'Layout', |
| 131 | + op: 'function', |
| 132 | + description: 'resolve layout server component "nested-layout"', |
| 133 | + codeFunctionName: 'Layout', |
| 134 | + }); |
| 135 | + expect(spans).toContainEqual({ |
| 136 | + name: 'Layout', |
| 137 | + op: 'function', |
| 138 | + description: 'resolve layout server component "[dynamic]"', |
| 139 | + codeFunctionName: 'Layout', |
| 140 | + }); |
| 141 | + expect(spans).toContainEqual({ |
| 142 | + name: 'Page', |
| 143 | + op: 'function', |
| 144 | + description: 'resolve page server component "/nested-layout/[dynamic]"', |
| 145 | + codeFunctionName: 'Page', |
| 146 | + }); |
| 147 | + expect(spans).toContainEqual({ |
| 148 | + ...nextjsSpan, |
| 149 | + name: 'generateMetadata /(nested-layout)/nested-layout/[dynamic]/page', |
| 150 | + }); |
| 151 | + expect(spans).toContainEqual({ ...nextjsSpan, name: 'start response' }); |
84 | 152 | }); |
0 commit comments