-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
test(e2e): Add e2e metrics tests in Next.js 16 #18643
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
add metric tests to nextjs
- Loading branch information
commit 3e977c1e5f4bfc40f58a3ed481bafe8ce52fe988
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
dev-packages/e2e-tests/test-applications/nextjs-16/app/metrics/page.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| 'use client'; | ||
|
|
||
| import * as Sentry from '@sentry/nextjs'; | ||
|
|
||
| export default function Page() { | ||
| const handleClick = async () => { | ||
| Sentry.metrics.count('test.page.count', 1, { | ||
| attributes: { | ||
| page: '/metrics', | ||
| 'random.attribute': 'Apples', | ||
| }, | ||
| }); | ||
| Sentry.metrics.distribution('test.page.distribution', 100, { | ||
| attributes: { | ||
| page: '/metrics', | ||
| 'random.attribute': 'Manzanas', | ||
| }, | ||
| }); | ||
| Sentry.metrics.gauge('test.page.gauge', 200, { | ||
| attributes: { | ||
| page: '/metrics', | ||
| 'random.attribute': 'Mele', | ||
| }, | ||
| }); | ||
| await fetch('/metrics/route-handler'); | ||
| }; | ||
|
|
||
| return ( | ||
| <div> | ||
| <h1>Metrics page</h1> | ||
| <button onClick={handleClick}>Emit</button> | ||
| </div> | ||
| ); | ||
| } |
23 changes: 23 additions & 0 deletions
23
dev-packages/e2e-tests/test-applications/nextjs-16/app/metrics/route-handler/route.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import * as Sentry from '@sentry/nextjs'; | ||
|
|
||
| export const GET = async () => { | ||
| Sentry.metrics.count('test.route.handler.count', 1, { | ||
| attributes: { | ||
| endpoint: '/metrics/route-handler', | ||
| 'random.attribute': 'Potatoes', | ||
| }, | ||
| }); | ||
| Sentry.metrics.distribution('test.route.handler.distribution', 100, { | ||
| attributes: { | ||
| endpoint: '/metrics/route-handler', | ||
| 'random.attribute': 'Patatas', | ||
| }, | ||
| }); | ||
| Sentry.metrics.gauge('test.route.handler.gauge', 200, { | ||
| attributes: { | ||
| endpoint: '/metrics/route-handler', | ||
| 'random.attribute': 'Patate', | ||
| }, | ||
| }); | ||
| return Response.json({ message: 'Bueno' }); | ||
| }; |
133 changes: 133 additions & 0 deletions
133
dev-packages/e2e-tests/test-applications/nextjs-16/tests/metrics.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| import { expect, test } from '@playwright/test'; | ||
| import { waitForMetric } from '@sentry-internal/test-utils'; | ||
|
|
||
| test.only('Should emit metrics from server and client', async ({ request, page }) => { | ||
chargome marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const clientCountPromise = waitForMetric('nextjs-16', async metric => { | ||
| return metric.name === 'test.page.count'; | ||
| }); | ||
|
|
||
| const clientDistributionPromise = waitForMetric('nextjs-16', async metric => { | ||
| return metric.name === 'test.page.distribution'; | ||
| }); | ||
|
|
||
| const clientGaugePromise = waitForMetric('nextjs-16', async metric => { | ||
| return metric.name === 'test.page.gauge'; | ||
| }); | ||
|
|
||
| const serverCountPromise = waitForMetric('nextjs-16', async metric => { | ||
| return metric.name === 'test.route.handler.count'; | ||
| }); | ||
|
|
||
| const serverDistributionPromise = waitForMetric('nextjs-16', async metric => { | ||
| return metric.name === 'test.route.handler.distribution'; | ||
| }); | ||
|
|
||
| const serverGaugePromise = waitForMetric('nextjs-16', async metric => { | ||
| return metric.name === 'test.route.handler.gauge'; | ||
| }); | ||
|
|
||
| await page.goto('/metrics'); | ||
| await page.getByText('Emit').click(); | ||
| const clientCount = await clientCountPromise; | ||
| const clientDistribution = await clientDistributionPromise; | ||
| const clientGauge = await clientGaugePromise; | ||
| const serverCount = await serverCountPromise; | ||
| const serverDistribution = await serverDistributionPromise; | ||
| const serverGauge = await serverGaugePromise; | ||
|
|
||
| expect(clientCount).toMatchObject({ | ||
| timestamp: expect.any(Number), | ||
| trace_id: expect.any(String), | ||
| span_id: expect.any(String), | ||
| name: 'test.page.count', | ||
| type: 'counter', | ||
| value: 1, | ||
| attributes: { | ||
| page: { value: '/metrics', type: 'string' }, | ||
| 'random.attribute': { value: 'Apples', type: 'string' }, | ||
| 'sentry.environment': { value: 'qa', type: 'string' }, | ||
| 'sentry.sdk.name': { value: 'sentry.javascript.nextjs', type: 'string' }, | ||
| 'sentry.sdk.version': { value: expect.any(String), type: 'string' }, | ||
| }, | ||
| }); | ||
|
|
||
| expect(clientDistribution).toMatchObject({ | ||
| timestamp: expect.any(Number), | ||
| trace_id: expect.any(String), | ||
| span_id: expect.any(String), | ||
| name: 'test.page.distribution', | ||
| type: 'distribution', | ||
| value: 100, | ||
| attributes: { | ||
| page: { value: '/metrics', type: 'string' }, | ||
| 'random.attribute': { value: 'Manzanas', type: 'string' }, | ||
| 'sentry.environment': { value: 'qa', type: 'string' }, | ||
| 'sentry.sdk.name': { value: 'sentry.javascript.nextjs', type: 'string' }, | ||
| 'sentry.sdk.version': { value: expect.any(String), type: 'string' }, | ||
| }, | ||
| }); | ||
|
|
||
| expect(clientGauge).toMatchObject({ | ||
| timestamp: expect.any(Number), | ||
| trace_id: expect.any(String), | ||
| span_id: expect.any(String), | ||
| name: 'test.page.gauge', | ||
| type: 'gauge', | ||
| value: 200, | ||
| attributes: { | ||
| page: { value: '/metrics', type: 'string' }, | ||
| 'random.attribute': { value: 'Mele', type: 'string' }, | ||
| 'sentry.environment': { value: 'qa', type: 'string' }, | ||
| 'sentry.sdk.name': { value: 'sentry.javascript.nextjs', type: 'string' }, | ||
| 'sentry.sdk.version': { value: expect.any(String), type: 'string' }, | ||
| }, | ||
| }); | ||
|
|
||
| expect(serverCount).toMatchObject({ | ||
| timestamp: expect.any(Number), | ||
| trace_id: expect.any(String), | ||
| name: 'test.route.handler.count', | ||
| type: 'counter', | ||
| value: 1, | ||
| attributes: { | ||
| 'server.address': { value: expect.any(String), type: 'string' }, | ||
| 'random.attribute': { value: 'Potatoes', type: 'string' }, | ||
| endpoint: { value: '/metrics/route-handler', type: 'string' }, | ||
| 'sentry.environment': { value: 'qa', type: 'string' }, | ||
| 'sentry.sdk.name': { value: 'sentry.javascript.nextjs', type: 'string' }, | ||
| 'sentry.sdk.version': { value: expect.any(String), type: 'string' }, | ||
| }, | ||
| }); | ||
|
|
||
| expect(serverDistribution).toMatchObject({ | ||
| timestamp: expect.any(Number), | ||
| trace_id: expect.any(String), | ||
| name: 'test.route.handler.distribution', | ||
| type: 'distribution', | ||
| value: 100, | ||
| attributes: { | ||
| 'server.address': { value: expect.any(String), type: 'string' }, | ||
| 'random.attribute': { value: 'Patatas', type: 'string' }, | ||
| endpoint: { value: '/metrics/route-handler', type: 'string' }, | ||
| 'sentry.environment': { value: 'qa', type: 'string' }, | ||
| 'sentry.sdk.name': { value: 'sentry.javascript.nextjs', type: 'string' }, | ||
| 'sentry.sdk.version': { value: expect.any(String), type: 'string' }, | ||
| }, | ||
| }); | ||
|
|
||
| expect(serverGauge).toMatchObject({ | ||
| timestamp: expect.any(Number), | ||
| trace_id: expect.any(String), | ||
| name: 'test.route.handler.gauge', | ||
| type: 'gauge', | ||
| value: 200, | ||
| attributes: { | ||
| 'server.address': { value: expect.any(String), type: 'string' }, | ||
| 'random.attribute': { value: 'Patate', type: 'string' }, | ||
| endpoint: { value: '/metrics/route-handler', type: 'string' }, | ||
| 'sentry.environment': { value: 'qa', type: 'string' }, | ||
| 'sentry.sdk.name': { value: 'sentry.javascript.nextjs', type: 'string' }, | ||
| 'sentry.sdk.version': { value: expect.any(String), type: 'string' }, | ||
| }, | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.