From 5d2703b2f7709d9b9378f873a1fb4e4608bbc158 Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Mon, 19 Oct 2026 12:47:54 +0000 Subject: [PATCH 1/2] test(nextjs): Fix flaky nextjs-16 metrics test Co-Authored-By: Francesco Gringl-Novy --- .../nextjs-16/app/metrics/page.tsx | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/dev-packages/e2e-tests/test-applications/nextjs-16/app/metrics/page.tsx b/dev-packages/e2e-tests/test-applications/nextjs-16/app/metrics/page.tsx index fdb7bc0a40a7..07f37bac197f 100644 --- a/dev-packages/e2e-tests/test-applications/nextjs-16/app/metrics/page.tsx +++ b/dev-packages/e2e-tests/test-applications/nextjs-16/app/metrics/page.tsx @@ -4,23 +4,26 @@ 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', - }, + // Emit inside a span so `span_id` doesn't depend on whether the pageload span is still active. + Sentry.startSpan({ name: 'emit-metrics' }, () => { + 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'); }; From a5499a3098083306d99688c948ef37e676900373 Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Mon, 19 Oct 2026 12:51:02 +0000 Subject: [PATCH 2/2] test(nextjs): Fix flaky nextjs-16-static metrics test Co-Authored-By: Francesco Gringl-Novy --- .../nextjs-16-static/app/metrics/page.tsx | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/dev-packages/e2e-tests/test-applications/nextjs-16-static/app/metrics/page.tsx b/dev-packages/e2e-tests/test-applications/nextjs-16-static/app/metrics/page.tsx index fdb7bc0a40a7..07f37bac197f 100644 --- a/dev-packages/e2e-tests/test-applications/nextjs-16-static/app/metrics/page.tsx +++ b/dev-packages/e2e-tests/test-applications/nextjs-16-static/app/metrics/page.tsx @@ -4,23 +4,26 @@ 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', - }, + // Emit inside a span so `span_id` doesn't depend on whether the pageload span is still active. + Sentry.startSpan({ name: 'emit-metrics' }, () => { + 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'); };