Skip to content
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .size-limit.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ module.exports = [
path: 'packages/browser/build/npm/esm/index.js',
import: createImport('init', 'sendFeedback'),
gzip: true,
limit: '29 KB',
limit: '30 KB',
},
{
name: '@sentry/browser (incl. FeedbackAsync)',
Expand Down Expand Up @@ -150,13 +150,13 @@ module.exports = [
name: 'CDN Bundle',
path: createCDNPath('bundle.min.js'),
gzip: true,
limit: '26 KB',
limit: '27 KB',
},
{
name: 'CDN Bundle (incl. Tracing)',
path: createCDNPath('bundle.tracing.min.js'),
gzip: true,
limit: '41 KB',
limit: '42 KB',
},
{
name: 'CDN Bundle (incl. Tracing, Replay)',
Expand All @@ -183,7 +183,7 @@ module.exports = [
path: createCDNPath('bundle.tracing.min.js'),
gzip: false,
brotli: false,
limit: '120 KB',
limit: '123 KB',
},
{
name: 'CDN Bundle (incl. Tracing, Replay) - uncompressed',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as Sentry from '@sentry/browser';

window.Sentry = Sentry;

Sentry.init({
dsn: 'https://[email protected]/1337',
_experiments: {
enableMetrics: true,
},
release: '1.0.0',
environment: 'test',
integrations: integrations => {
return integrations.filter(integration => integration.name !== 'BrowserSession');
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Sentry.metrics.count('test.counter', 1, { attributes: { endpoint: '/api/test' } });
Sentry.metrics.gauge('test.gauge', 42, { unit: 'millisecond', attributes: { server: 'test-1' } });
Sentry.metrics.distribution('test.distribution', 200, { unit: 'second', attributes: { priority: 'high' } });

Sentry.startSpan({ name: 'test-span', op: 'test' }, () => {
Sentry.metrics.count('test.span.counter', 1, { attributes: { operation: 'test' } });
});

Sentry.setUser({ id: 'user-123', email: '[email protected]', username: 'testuser' });
Sentry.metrics.count('test.user.counter', 1, { attributes: { action: 'click' } });

Sentry.flush();
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { expect } from '@playwright/test';
import type { MetricEnvelope } from '@sentry/core';
import { sentryTest } from '../../../../utils/fixtures';
import { getFirstSentryEnvelopeRequest, properFullEnvelopeRequestParser } from '../../../../utils/helpers';

sentryTest('should capture all metric types', async ({ getLocalTestUrl, page }) => {
const bundle = process.env.PW_BUNDLE || '';
if (bundle.startsWith('bundle') || bundle.startsWith('loader')) {
sentryTest.skip();
}

const url = await getLocalTestUrl({ testDir: __dirname });

const event = await getFirstSentryEnvelopeRequest<MetricEnvelope>(page, url, properFullEnvelopeRequestParser);
const envelopeItems = event[1];

expect(envelopeItems[0]).toEqual([
{
type: 'trace_metric',
item_count: 5,
content_type: 'application/vnd.sentry.items.trace-metric+json',
},
{
items: [
{
timestamp: expect.any(Number),
trace_id: expect.any(String),
name: 'test.counter',
type: 'counter',
value: 1,
attributes: {
endpoint: { value: '/api/test', type: 'string' },
'sentry.release': { value: '1.0.0', type: 'string' },
'sentry.environment': { value: 'test', type: 'string' },
'sentry.sdk.name': { value: 'sentry.javascript.browser', type: 'string' },
'sentry.sdk.version': { value: expect.any(String), type: 'string' },
},
},
{
timestamp: expect.any(Number),
trace_id: expect.any(String),
name: 'test.gauge',
type: 'gauge',
unit: 'millisecond',
value: 42,
attributes: {
server: { value: 'test-1', type: 'string' },
'sentry.release': { value: '1.0.0', type: 'string' },
'sentry.environment': { value: 'test', type: 'string' },
'sentry.sdk.name': { value: 'sentry.javascript.browser', type: 'string' },
'sentry.sdk.version': { value: expect.any(String), type: 'string' },
},
},
{
timestamp: expect.any(Number),
trace_id: expect.any(String),
name: 'test.distribution',
type: 'distribution',
unit: 'second',
value: 200,
attributes: {
priority: { value: 'high', type: 'string' },
'sentry.release': { value: '1.0.0', type: 'string' },
'sentry.environment': { value: 'test', type: 'string' },
'sentry.sdk.name': { value: 'sentry.javascript.browser', type: 'string' },
'sentry.sdk.version': { value: expect.any(String), type: 'string' },
},
},
{
timestamp: expect.any(Number),
trace_id: expect.any(String),
span_id: expect.any(String),
name: 'test.span.counter',
type: 'counter',
value: 1,
attributes: {
operation: { value: 'test', type: 'string' },
'sentry.release': { value: '1.0.0', type: 'string' },
'sentry.environment': { value: 'test', type: 'string' },
'sentry.sdk.name': { value: 'sentry.javascript.browser', type: 'string' },
'sentry.sdk.version': { value: expect.any(String), type: 'string' },
},
},
{
timestamp: expect.any(Number),
trace_id: expect.any(String),
name: 'test.user.counter',
type: 'counter',
value: 1,
attributes: {
action: { value: 'click', type: 'string' },
'user.id': { value: 'user-123', type: 'string' },
'user.email': { value: '[email protected]', type: 'string' },
'user.name': { value: 'testuser', type: 'string' },
'sentry.release': { value: '1.0.0', type: 'string' },
'sentry.environment': { value: 'test', type: 'string' },
'sentry.sdk.name': { value: 'sentry.javascript.browser', type: 'string' },
'sentry.sdk.version': { value: expect.any(String), type: 'string' },
},
},
],
},
]);
});
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ const DEPENDENTS: Dependent[] = [
ignoreExports: [
// Not needed for Astro
'setupFastifyErrorHandler',
// Todo(metrics): Add metrics exports for beta
'metrics',
],
},
{
Expand All @@ -54,6 +56,8 @@ const DEPENDENTS: Dependent[] = [
'childProcessIntegration',
'systemErrorIntegration',
'pinoIntegration',
// Todo(metrics): Add metrics exports for beta
'metrics',
],
},
{
Expand All @@ -75,6 +79,8 @@ const DEPENDENTS: Dependent[] = [
ignoreExports: [
// Not needed for Serverless
'setupFastifyErrorHandler',
// Todo(metrics): Add metrics exports for beta
'metrics',
],
},
{
Expand All @@ -84,6 +90,8 @@ const DEPENDENTS: Dependent[] = [
ignoreExports: [
// Not needed for Serverless
'setupFastifyErrorHandler',
// Todo(metrics): Add metrics exports for beta
'metrics',
],
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import * as Sentry from '@sentry/node-core';
import { loggingTransport } from '@sentry-internal/node-integration-tests';
import { setupOtel } from '../../../utils/setupOtel';

const client = Sentry.init({
dsn: 'https://[email protected]/1337',
release: '1.0.0',
environment: 'test',
_experiments: {
enableMetrics: true,
},
transport: loggingTransport,
});

setupOtel(client);

async function run(): Promise<void> {
Sentry.metrics.count('test.counter', 1, { attributes: { endpoint: '/api/test' } });

Sentry.metrics.gauge('test.gauge', 42, { unit: 'millisecond', attributes: { server: 'test-1' } });

Sentry.metrics.distribution('test.distribution', 200, { unit: 'second', attributes: { priority: 'high' } });

await Sentry.startSpan({ name: 'test-span', op: 'test' }, async () => {
Sentry.metrics.count('test.span.counter', 1, { attributes: { operation: 'test' } });
});

Sentry.setUser({ id: 'user-123', email: '[email protected]', username: 'testuser' });
Sentry.metrics.count('test.user.counter', 1, { attributes: { action: 'click' } });

await Sentry.flush();
}

// eslint-disable-next-line @typescript-eslint/no-floating-promises
void run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { afterAll, describe, expect, test } from 'vitest';
import { cleanupChildProcesses, createRunner } from '../../../utils/runner';

describe('metrics', () => {
afterAll(() => {
cleanupChildProcesses();
});

test('should capture all metric types', async () => {
const runner = createRunner(__dirname, 'scenario.ts')
.unignore('metric')
.expect({
metric: {
items: [
{
timestamp: expect.any(Number),
trace_id: expect.any(String),
name: 'test.counter',
type: 'counter',
value: 1,
attributes: {
endpoint: { value: '/api/test', type: 'string' },
'sentry.release': { value: '1.0.0', type: 'string' },
'sentry.environment': { value: 'test', type: 'string' },
'sentry.sdk.name': { value: 'sentry.javascript.node-core', type: 'string' },
'sentry.sdk.version': { value: expect.any(String), type: 'string' },
},
},
{
timestamp: expect.any(Number),
trace_id: expect.any(String),
name: 'test.gauge',
type: 'gauge',
unit: 'millisecond',
value: 42,
attributes: {
server: { value: 'test-1', type: 'string' },
'sentry.release': { value: '1.0.0', type: 'string' },
'sentry.environment': { value: 'test', type: 'string' },
'sentry.sdk.name': { value: 'sentry.javascript.node-core', type: 'string' },
'sentry.sdk.version': { value: expect.any(String), type: 'string' },
},
},
{
timestamp: expect.any(Number),
trace_id: expect.any(String),
name: 'test.distribution',
type: 'distribution',
unit: 'second',
value: 200,
attributes: {
priority: { value: 'high', type: 'string' },
'sentry.release': { value: '1.0.0', type: 'string' },
'sentry.environment': { value: 'test', type: 'string' },
'sentry.sdk.name': { value: 'sentry.javascript.node-core', type: 'string' },
'sentry.sdk.version': { value: expect.any(String), type: 'string' },
},
},
{
timestamp: expect.any(Number),
trace_id: expect.any(String),
name: 'test.span.counter',
type: 'counter',
value: 1,
attributes: {
operation: { value: 'test', type: 'string' },
'sentry.release': { value: '1.0.0', type: 'string' },
'sentry.environment': { value: 'test', type: 'string' },
'sentry.sdk.name': { value: 'sentry.javascript.node-core', type: 'string' },
'sentry.sdk.version': { value: expect.any(String), type: 'string' },
},
},
{
timestamp: expect.any(Number),
trace_id: expect.any(String),
name: 'test.user.counter',
type: 'counter',
value: 1,
attributes: {
action: { value: 'click', type: 'string' },
'user.id': { value: 'user-123', type: 'string' },
'user.email': { value: '[email protected]', type: 'string' },
'user.name': { value: 'testuser', type: 'string' },
'sentry.release': { value: '1.0.0', type: 'string' },
'sentry.environment': { value: 'test', type: 'string' },
'sentry.sdk.name': { value: 'sentry.javascript.node-core', type: 'string' },
'sentry.sdk.version': { value: expect.any(String), type: 'string' },
},
},
],
},
})
.start();

await runner.completed();
});
});
10 changes: 10 additions & 0 deletions dev-packages/node-core-integration-tests/utils/assertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
Event,
SerializedCheckIn,
SerializedLogContainer,
SerializedMetricContainer,
SerializedSession,
SessionAggregates,
TransactionEvent,
Expand Down Expand Up @@ -76,6 +77,15 @@ export function assertSentryLogContainer(
});
}

export function assertSentryMetricContainer(
actual: SerializedMetricContainer,
expected: Partial<SerializedMetricContainer>,
): void {
expect(actual).toMatchObject({
...expected,
});
}

export function assertEnvelopeHeader(actual: Envelope[0], expected: Partial<Envelope[0]>): void {
expect(actual).toEqual({
event_id: expect.any(String),
Expand Down
Loading
Loading