|
| 1 | +import { expect } from '@playwright/test'; |
| 2 | +import type { MetricEnvelope } from '@sentry/core'; |
| 3 | +import { sentryTest } from '../../../../utils/fixtures'; |
| 4 | +import { getFirstSentryEnvelopeRequest, properFullEnvelopeRequestParser } from '../../../../utils/helpers'; |
| 5 | + |
| 6 | +sentryTest('should capture all metric types', async ({ getLocalTestUrl, page }) => { |
| 7 | + const bundle = process.env.PW_BUNDLE || ''; |
| 8 | + if (bundle.startsWith('bundle') || bundle.startsWith('loader')) { |
| 9 | + sentryTest.skip(); |
| 10 | + } |
| 11 | + |
| 12 | + const url = await getLocalTestUrl({ testDir: __dirname }); |
| 13 | + |
| 14 | + const event = await getFirstSentryEnvelopeRequest<MetricEnvelope>(page, url, properFullEnvelopeRequestParser); |
| 15 | + const envelopeItems = event[1]; |
| 16 | + |
| 17 | + expect(envelopeItems[0]).toEqual([ |
| 18 | + { |
| 19 | + type: 'trace_metric', |
| 20 | + item_count: 5, |
| 21 | + content_type: 'application/vnd.sentry.items.trace-metric+json', |
| 22 | + }, |
| 23 | + { |
| 24 | + items: [ |
| 25 | + { |
| 26 | + timestamp: expect.any(Number), |
| 27 | + trace_id: expect.any(String), |
| 28 | + name: 'test.counter', |
| 29 | + type: 'counter', |
| 30 | + value: 1, |
| 31 | + attributes: { |
| 32 | + endpoint: { value: '/api/test', type: 'string' }, |
| 33 | + 'sentry.release': { value: '1.0.0', type: 'string' }, |
| 34 | + 'sentry.environment': { value: 'test', type: 'string' }, |
| 35 | + 'sentry.sdk.name': { value: 'sentry.javascript.browser', type: 'string' }, |
| 36 | + 'sentry.sdk.version': { value: expect.any(String), type: 'string' }, |
| 37 | + }, |
| 38 | + }, |
| 39 | + { |
| 40 | + timestamp: expect.any(Number), |
| 41 | + trace_id: expect.any(String), |
| 42 | + name: 'test.gauge', |
| 43 | + type: 'gauge', |
| 44 | + unit: 'millisecond', |
| 45 | + value: 42, |
| 46 | + attributes: { |
| 47 | + server: { value: 'test-1', type: 'string' }, |
| 48 | + 'sentry.release': { value: '1.0.0', type: 'string' }, |
| 49 | + 'sentry.environment': { value: 'test', type: 'string' }, |
| 50 | + 'sentry.sdk.name': { value: 'sentry.javascript.browser', type: 'string' }, |
| 51 | + 'sentry.sdk.version': { value: expect.any(String), type: 'string' }, |
| 52 | + }, |
| 53 | + }, |
| 54 | + { |
| 55 | + timestamp: expect.any(Number), |
| 56 | + trace_id: expect.any(String), |
| 57 | + name: 'test.distribution', |
| 58 | + type: 'distribution', |
| 59 | + unit: 'second', |
| 60 | + value: 200, |
| 61 | + attributes: { |
| 62 | + priority: { value: 'high', type: 'string' }, |
| 63 | + 'sentry.release': { value: '1.0.0', type: 'string' }, |
| 64 | + 'sentry.environment': { value: 'test', type: 'string' }, |
| 65 | + 'sentry.sdk.name': { value: 'sentry.javascript.browser', type: 'string' }, |
| 66 | + 'sentry.sdk.version': { value: expect.any(String), type: 'string' }, |
| 67 | + }, |
| 68 | + }, |
| 69 | + { |
| 70 | + timestamp: expect.any(Number), |
| 71 | + trace_id: expect.any(String), |
| 72 | + span_id: expect.any(String), |
| 73 | + name: 'test.span.counter', |
| 74 | + type: 'counter', |
| 75 | + value: 1, |
| 76 | + attributes: { |
| 77 | + operation: { value: 'test', type: 'string' }, |
| 78 | + 'sentry.release': { value: '1.0.0', type: 'string' }, |
| 79 | + 'sentry.environment': { value: 'test', type: 'string' }, |
| 80 | + 'sentry.sdk.name': { value: 'sentry.javascript.browser', type: 'string' }, |
| 81 | + 'sentry.sdk.version': { value: expect.any(String), type: 'string' }, |
| 82 | + }, |
| 83 | + }, |
| 84 | + { |
| 85 | + timestamp: expect.any(Number), |
| 86 | + trace_id: expect.any(String), |
| 87 | + name: 'test.user.counter', |
| 88 | + type: 'counter', |
| 89 | + value: 1, |
| 90 | + attributes: { |
| 91 | + action: { value: 'click', type: 'string' }, |
| 92 | + 'user.id': { value: 'user-123', type: 'string' }, |
| 93 | + 'user.email': { value: '[email protected]', type: 'string' }, |
| 94 | + 'user.name': { value: 'testuser', type: 'string' }, |
| 95 | + 'sentry.release': { value: '1.0.0', type: 'string' }, |
| 96 | + 'sentry.environment': { value: 'test', type: 'string' }, |
| 97 | + 'sentry.sdk.name': { value: 'sentry.javascript.browser', type: 'string' }, |
| 98 | + 'sentry.sdk.version': { value: expect.any(String), type: 'string' }, |
| 99 | + }, |
| 100 | + }, |
| 101 | + ], |
| 102 | + }, |
| 103 | + ]); |
| 104 | +}); |
0 commit comments