|
| 1 | +import { expect, test } from '@playwright/test'; |
| 2 | +import { waitForMetric } from '@sentry-internal/test-utils'; |
| 3 | + |
| 4 | +test('Should emit metrics from server and client', async ({ request, page }) => { |
| 5 | + const clientCountPromise = waitForMetric('nextjs-16', async metric => { |
| 6 | + return metric.name === 'test.page.count'; |
| 7 | + }); |
| 8 | + |
| 9 | + const clientDistributionPromise = waitForMetric('nextjs-16', async metric => { |
| 10 | + return metric.name === 'test.page.distribution'; |
| 11 | + }); |
| 12 | + |
| 13 | + const clientGaugePromise = waitForMetric('nextjs-16', async metric => { |
| 14 | + return metric.name === 'test.page.gauge'; |
| 15 | + }); |
| 16 | + |
| 17 | + const serverCountPromise = waitForMetric('nextjs-16', async metric => { |
| 18 | + return metric.name === 'test.route.handler.count'; |
| 19 | + }); |
| 20 | + |
| 21 | + const serverDistributionPromise = waitForMetric('nextjs-16', async metric => { |
| 22 | + return metric.name === 'test.route.handler.distribution'; |
| 23 | + }); |
| 24 | + |
| 25 | + const serverGaugePromise = waitForMetric('nextjs-16', async metric => { |
| 26 | + return metric.name === 'test.route.handler.gauge'; |
| 27 | + }); |
| 28 | + |
| 29 | + await page.goto('/metrics'); |
| 30 | + await page.getByText('Emit').click(); |
| 31 | + const clientCount = await clientCountPromise; |
| 32 | + const clientDistribution = await clientDistributionPromise; |
| 33 | + const clientGauge = await clientGaugePromise; |
| 34 | + const serverCount = await serverCountPromise; |
| 35 | + const serverDistribution = await serverDistributionPromise; |
| 36 | + const serverGauge = await serverGaugePromise; |
| 37 | + |
| 38 | + expect(clientCount).toMatchObject({ |
| 39 | + timestamp: expect.any(Number), |
| 40 | + trace_id: expect.any(String), |
| 41 | + span_id: expect.any(String), |
| 42 | + name: 'test.page.count', |
| 43 | + type: 'counter', |
| 44 | + value: 1, |
| 45 | + attributes: { |
| 46 | + page: { value: '/metrics', type: 'string' }, |
| 47 | + 'random.attribute': { value: 'Apples', type: 'string' }, |
| 48 | + 'sentry.environment': { value: 'qa', type: 'string' }, |
| 49 | + 'sentry.sdk.name': { value: 'sentry.javascript.nextjs', type: 'string' }, |
| 50 | + 'sentry.sdk.version': { value: expect.any(String), type: 'string' }, |
| 51 | + }, |
| 52 | + }); |
| 53 | + |
| 54 | + expect(clientDistribution).toMatchObject({ |
| 55 | + timestamp: expect.any(Number), |
| 56 | + trace_id: expect.any(String), |
| 57 | + span_id: expect.any(String), |
| 58 | + name: 'test.page.distribution', |
| 59 | + type: 'distribution', |
| 60 | + value: 100, |
| 61 | + attributes: { |
| 62 | + page: { value: '/metrics', type: 'string' }, |
| 63 | + 'random.attribute': { value: 'Manzanas', type: 'string' }, |
| 64 | + 'sentry.environment': { value: 'qa', type: 'string' }, |
| 65 | + 'sentry.sdk.name': { value: 'sentry.javascript.nextjs', type: 'string' }, |
| 66 | + 'sentry.sdk.version': { value: expect.any(String), type: 'string' }, |
| 67 | + }, |
| 68 | + }); |
| 69 | + |
| 70 | + expect(clientGauge).toMatchObject({ |
| 71 | + timestamp: expect.any(Number), |
| 72 | + trace_id: expect.any(String), |
| 73 | + span_id: expect.any(String), |
| 74 | + name: 'test.page.gauge', |
| 75 | + type: 'gauge', |
| 76 | + value: 200, |
| 77 | + attributes: { |
| 78 | + page: { value: '/metrics', type: 'string' }, |
| 79 | + 'random.attribute': { value: 'Mele', type: 'string' }, |
| 80 | + 'sentry.environment': { value: 'qa', type: 'string' }, |
| 81 | + 'sentry.sdk.name': { value: 'sentry.javascript.nextjs', type: 'string' }, |
| 82 | + 'sentry.sdk.version': { value: expect.any(String), type: 'string' }, |
| 83 | + }, |
| 84 | + }); |
| 85 | + |
| 86 | + expect(serverCount).toMatchObject({ |
| 87 | + timestamp: expect.any(Number), |
| 88 | + trace_id: expect.any(String), |
| 89 | + name: 'test.route.handler.count', |
| 90 | + type: 'counter', |
| 91 | + value: 1, |
| 92 | + attributes: { |
| 93 | + 'server.address': { value: expect.any(String), type: 'string' }, |
| 94 | + 'random.attribute': { value: 'Potatoes', type: 'string' }, |
| 95 | + endpoint: { value: '/metrics/route-handler', type: 'string' }, |
| 96 | + 'sentry.environment': { value: 'qa', type: 'string' }, |
| 97 | + 'sentry.sdk.name': { value: 'sentry.javascript.nextjs', type: 'string' }, |
| 98 | + 'sentry.sdk.version': { value: expect.any(String), type: 'string' }, |
| 99 | + }, |
| 100 | + }); |
| 101 | + |
| 102 | + expect(serverDistribution).toMatchObject({ |
| 103 | + timestamp: expect.any(Number), |
| 104 | + trace_id: expect.any(String), |
| 105 | + name: 'test.route.handler.distribution', |
| 106 | + type: 'distribution', |
| 107 | + value: 100, |
| 108 | + attributes: { |
| 109 | + 'server.address': { value: expect.any(String), type: 'string' }, |
| 110 | + 'random.attribute': { value: 'Patatas', type: 'string' }, |
| 111 | + endpoint: { value: '/metrics/route-handler', type: 'string' }, |
| 112 | + 'sentry.environment': { value: 'qa', type: 'string' }, |
| 113 | + 'sentry.sdk.name': { value: 'sentry.javascript.nextjs', type: 'string' }, |
| 114 | + 'sentry.sdk.version': { value: expect.any(String), type: 'string' }, |
| 115 | + }, |
| 116 | + }); |
| 117 | + |
| 118 | + expect(serverGauge).toMatchObject({ |
| 119 | + timestamp: expect.any(Number), |
| 120 | + trace_id: expect.any(String), |
| 121 | + name: 'test.route.handler.gauge', |
| 122 | + type: 'gauge', |
| 123 | + value: 200, |
| 124 | + attributes: { |
| 125 | + 'server.address': { value: expect.any(String), type: 'string' }, |
| 126 | + 'random.attribute': { value: 'Patate', type: 'string' }, |
| 127 | + endpoint: { value: '/metrics/route-handler', type: 'string' }, |
| 128 | + 'sentry.environment': { value: 'qa', type: 'string' }, |
| 129 | + 'sentry.sdk.name': { value: 'sentry.javascript.nextjs', type: 'string' }, |
| 130 | + 'sentry.sdk.version': { value: expect.any(String), type: 'string' }, |
| 131 | + }, |
| 132 | + }); |
| 133 | +}); |
0 commit comments