This page fails while it renders.
+ diff --git a/dev-packages/e2e-tests/test-applications/nuxt-4/tests/cache.streaming-lifecycle.test.ts b/dev-packages/e2e-tests/test-applications/nuxt-4/tests/cache.streaming-lifecycle.test.ts index a1e9672587d7..101861fe022f 100644 --- a/dev-packages/e2e-tests/test-applications/nuxt-4/tests/cache.streaming-lifecycle.test.ts +++ b/dev-packages/e2e-tests/test-applications/nuxt-4/tests/cache.streaming-lifecycle.test.ts @@ -1,5 +1,7 @@ +import { CACHE_HIT, URL_PATH } from '@sentry/conventions/attributes'; +import { CACHE_GET, CACHE_PUT } from '@sentry/conventions/op'; import { expect, test } from '@playwright/test'; -import { collectStreamedSpansUntilSegment } from '@sentry-internal/test-utils'; +import { collectStreamedSpansUntilSegment, getSpanOp } from '@sentry-internal/test-utils'; import { isViteServer, NITRO_ONLY } from './isViteServer'; test.skip(isViteServer, NITRO_ONLY); @@ -18,6 +20,15 @@ test.describe('Cache Instrumentation', () => { return spans.filter(span => span.attributes['sentry.origin']?.value === 'auto.cache.nuxt'); } + /** Every span of the request's trace, whatever created it, so that a second span for one cache access shows up. */ + function collectRequestSpans() { + return collectStreamedSpansUntilSegment( + 'nuxt-4', + span => span.attributes[URL_PATH]?.value === '/api/cache-test', + span => getSpanOp(span) === CACHE_GET, + ); + } + test('instruments cachedFunction and cachedEventHandler calls and creates spans with correct attributes', async ({ request, }) => { @@ -151,4 +162,37 @@ test.describe('Cache Instrumentation', () => { // We should have at least one cache hit (second calls to getCachedUser and getCachedData) expect(cacheHitSpans.length).toBeGreaterThanOrEqual(1); }); + + test('creates exactly one span for each cache read and write', async ({ request }) => { + // Unique keys, so that the first call of each cached function is a cache miss. + const uniqueKey = `count-${Date.now()}`; + const spansPromise = collectRequestSpans(); + + await request.get(`/api/cache-test?user=${uniqueKey}&data=${uniqueKey}`); + + const spans = await spansPromise; + const readSpans = spans.filter(span => getSpanOp(span) === CACHE_GET); + const writeSpans = spans.filter(span => getSpanOp(span) === CACHE_PUT); + const cacheMissSpans = readSpans.filter(span => span.attributes[CACHE_HIT]?.value === false); + + // 3x getCachedUser, 2x getCachedData, 1x cachedHandler. + expect(readSpans).toHaveLength(6); + // One write for each cache miss. An earlier test can have filled the cache of the handler, so the number of + // misses is not fixed. + expect(writeSpans).toHaveLength(cacheMissSpans.length); + }); + + test('makes each cache span a child of the request root span', async ({ request }) => { + const uniqueKey = `parent-${Date.now()}`; + const spansPromise = collectRequestSpans(); + + await request.get(`/api/cache-test?user=${uniqueKey}&data=${uniqueKey}`); + + const spans = await spansPromise; + const rootSpan = spans.find(span => span.is_segment); + const cacheSpans = spans.filter(span => getSpanOp(span) === CACHE_GET || getSpanOp(span) === CACHE_PUT); + const parentSpanIds = new Set(cacheSpans.map(span => span.parent_span_id)); + + expect(parentSpanIds).toEqual(new Set([rootSpan?.span_id])); + }); }); diff --git a/dev-packages/e2e-tests/test-applications/nuxt-4/tests/database.streaming-lifecycle.test.ts b/dev-packages/e2e-tests/test-applications/nuxt-4/tests/database.streaming-lifecycle.test.ts index 7729f0e5251c..552ead3c7216 100644 --- a/dev-packages/e2e-tests/test-applications/nuxt-4/tests/database.streaming-lifecycle.test.ts +++ b/dev-packages/e2e-tests/test-applications/nuxt-4/tests/database.streaming-lifecycle.test.ts @@ -1,3 +1,5 @@ +import { URL_PATH } from '@sentry/conventions/attributes'; +import { DB_QUERY } from '@sentry/conventions/op'; import { expect, test } from '@playwright/test'; import { collectStreamedSpansUntilSegment, getSpanOp, waitForError } from '@sentry-internal/test-utils'; import { isViteServer, NITRO_ONLY } from './isViteServer'; @@ -12,15 +14,19 @@ const DB_ERROR_MECHANISM = ? { handled: false, type: 'auto.function.nuxt.nitro', exception_id: 0 } : { handled: false, type: 'auto.db.nuxt' }; -async function collectDbSpans() { - const spans = await collectStreamedSpansUntilSegment( +function collectRequestSpans() { + return collectStreamedSpansUntilSegment( 'nuxt-4', - span => span.attributes['url.path']?.value === '/api/db-test', - span => getSpanOp(span) === 'db.query', + span => span.attributes[URL_PATH]?.value === '/api/db-test', + span => getSpanOp(span) === DB_QUERY, ); - const rootSpan = spans.find(span => span.is_segment && span.attributes['url.path']?.value === '/api/db-test'); +} - return spans.filter(span => span.trace_id === rootSpan?.trace_id && getSpanOp(span) === 'db.query'); +async function collectDbSpans() { + const spans = await collectRequestSpans(); + const rootSpan = spans.find(span => span.is_segment && span.attributes[URL_PATH]?.value === '/api/db-test'); + + return spans.filter(span => span.trace_id === rootSpan?.trace_id && getSpanOp(span) === DB_QUERY); } test.describe('database integration', () => { @@ -210,4 +216,17 @@ test.describe('database integration', () => { expect(dbSpans.length).toBeGreaterThanOrEqual(1); expect(dbSpans.every(span => !span.is_segment)).toBe(true); }); + + test('makes each db.query span a child of the request root span', async ({ request }) => { + const spansPromise = collectRequestSpans(); + + await request.get('/api/db-test?method=prepare-get'); + + const spans = await spansPromise; + const rootSpan = spans.find(span => span.is_segment); + const dbSpans = spans.filter(span => getSpanOp(span) === DB_QUERY); + const parentSpanIds = new Set(dbSpans.map(span => span.parent_span_id)); + + expect(parentSpanIds).toEqual(new Set([rootSpan?.span_id])); + }); }); diff --git a/dev-packages/e2e-tests/test-applications/nuxt-4/tests/errors.ssr.streaming-lifecycle.test.ts b/dev-packages/e2e-tests/test-applications/nuxt-4/tests/errors.ssr.streaming-lifecycle.test.ts new file mode 100644 index 000000000000..b30ebd221644 --- /dev/null +++ b/dev-packages/e2e-tests/test-applications/nuxt-4/tests/errors.ssr.streaming-lifecycle.test.ts @@ -0,0 +1,101 @@ +import { HTTP_RESPONSE_STATUS_CODE, URL_PATH } from '@sentry/conventions/attributes'; +import { expect, test } from '@playwright/test'; +import { waitForEnvelopeItem, waitForError, waitForStreamedSpan } from '@sentry-internal/test-utils'; +import type { SerializedStreamedSpan } from '@sentry-internal/test-utils'; +import { isViteServer, NITRO_ONLY } from './isViteServer'; + +type EnvelopeItem = ParametersThis page fails while it renders.
+ diff --git a/dev-packages/e2e-tests/test-applications/nuxt-5/tests/cache.test.ts b/dev-packages/e2e-tests/test-applications/nuxt-5/tests/cache.test.ts index e5163a76f359..a76a6e25d1a9 100644 --- a/dev-packages/e2e-tests/test-applications/nuxt-5/tests/cache.test.ts +++ b/dev-packages/e2e-tests/test-applications/nuxt-5/tests/cache.test.ts @@ -1,5 +1,7 @@ +import { CACHE_HIT, URL_PATH } from '@sentry/conventions/attributes'; +import { CACHE_GET, CACHE_PUT } from '@sentry/conventions/op'; import { expect, test } from '@playwright/test'; -import { collectStreamedSpansUntilSegment } from '@sentry-internal/test-utils'; +import { collectStreamedSpansUntilSegment, getSpanOp } from '@sentry-internal/test-utils'; // Nitro v3 only routes cached functions and handlers through KV storage with the `kv` cache driver, // so the default (`memory`) driver is traced through ocache's storage instead. @@ -27,6 +29,15 @@ test.describe('Cache Instrumentation', () => { ); } + /** Every span of the request's trace, whatever created it, so that a second span for one cache access shows up. */ + function collectRequestSpans() { + return collectStreamedSpansUntilSegment( + 'nuxt-5', + span => span.attributes[URL_PATH]?.value === '/api/cache-test', + span => getSpanOp(span) === CACHE_GET, + ); + } + test('instruments cachedFunction and cachedEventHandler calls and creates spans with correct attributes', async ({ request, }) => { @@ -160,4 +171,37 @@ test.describe('Cache Instrumentation', () => { // We should have at least one cache hit (second calls to getCachedUser and getCachedData) expect(cacheHitSpans.length).toBeGreaterThanOrEqual(1); }); + + test('creates exactly one span for each cache read and write', async ({ request }) => { + // Unique keys, so that the first call of each cached function is a cache miss. + const uniqueKey = `count-${Date.now()}`; + const spansPromise = collectRequestSpans(); + + await request.get(`/api/cache-test?user=${uniqueKey}&data=${uniqueKey}`); + + const spans = await spansPromise; + const readSpans = spans.filter(span => getSpanOp(span) === CACHE_GET); + const writeSpans = spans.filter(span => getSpanOp(span) === CACHE_PUT); + const cacheMissSpans = readSpans.filter(span => span.attributes[CACHE_HIT]?.value === false); + + // 3x getCachedUser, 2x getCachedData, 1x cachedHandler. + expect(readSpans).toHaveLength(6); + // One write for each cache miss. An earlier test can have filled the cache of the handler, so the number of + // misses is not fixed. + expect(writeSpans).toHaveLength(cacheMissSpans.length); + }); + + test('makes each cache span a child of the request root span', async ({ request }) => { + const uniqueKey = `parent-${Date.now()}`; + const spansPromise = collectRequestSpans(); + + await request.get(`/api/cache-test?user=${uniqueKey}&data=${uniqueKey}`); + + const spans = await spansPromise; + const rootSpan = spans.find(span => span.is_segment); + const cacheSpans = spans.filter(span => getSpanOp(span) === CACHE_GET || getSpanOp(span) === CACHE_PUT); + const parentSpanIds = new Set(cacheSpans.map(span => span.parent_span_id)); + + expect(parentSpanIds).toEqual(new Set([rootSpan?.span_id])); + }); }); diff --git a/dev-packages/e2e-tests/test-applications/nuxt-5/tests/database.test.ts b/dev-packages/e2e-tests/test-applications/nuxt-5/tests/database.test.ts index 184eac58bb50..7a15343131d8 100644 --- a/dev-packages/e2e-tests/test-applications/nuxt-5/tests/database.test.ts +++ b/dev-packages/e2e-tests/test-applications/nuxt-5/tests/database.test.ts @@ -1,3 +1,5 @@ +import { URL_PATH } from '@sentry/conventions/attributes'; +import { DB_QUERY } from '@sentry/conventions/op'; import { expect, test } from '@playwright/test'; import { collectStreamedSpansUntilSegment, getSpanOp, waitForError } from '@sentry-internal/test-utils'; import { DB_ORIGIN, DB_SYSTEM_NAME, RUNTIME } from './runtime'; @@ -9,15 +11,19 @@ const DB_ERROR_MECHANISM = ? { handled: false, type: 'auto.function.nuxt.nitro', exception_id: 0 } : { handled: false, type: 'auto.db.nuxt' }; -async function collectDbSpans() { - const spans = await collectStreamedSpansUntilSegment( +function collectRequestSpans() { + return collectStreamedSpansUntilSegment( 'nuxt-5', - span => span.attributes['url.path']?.value === '/api/db-test', - span => getSpanOp(span) === 'db.query', + span => span.attributes[URL_PATH]?.value === '/api/db-test', + span => getSpanOp(span) === DB_QUERY, ); - const rootSpan = spans.find(span => span.is_segment && span.attributes['url.path']?.value === '/api/db-test'); +} - return spans.filter(span => span.trace_id === rootSpan?.trace_id && getSpanOp(span) === 'db.query'); +async function collectDbSpans() { + const spans = await collectRequestSpans(); + const rootSpan = spans.find(span => span.is_segment && span.attributes[URL_PATH]?.value === '/api/db-test'); + + return spans.filter(span => span.trace_id === rootSpan?.trace_id && getSpanOp(span) === DB_QUERY); } test.describe('database integration', () => { @@ -207,4 +213,17 @@ test.describe('database integration', () => { expect(dbSpans.length).toBeGreaterThanOrEqual(1); expect(dbSpans.every(span => !span.is_segment)).toBe(true); }); + + test('makes each db.query span a child of the request root span', async ({ request }) => { + const spansPromise = collectRequestSpans(); + + await request.get('/api/db-test?method=prepare-get'); + + const spans = await spansPromise; + const rootSpan = spans.find(span => span.is_segment); + const dbSpans = spans.filter(span => getSpanOp(span) === DB_QUERY); + const parentSpanIds = new Set(dbSpans.map(span => span.parent_span_id)); + + expect(parentSpanIds).toEqual(new Set([rootSpan?.span_id])); + }); }); diff --git a/dev-packages/e2e-tests/test-applications/nuxt-5/tests/errors.ssr.test.ts b/dev-packages/e2e-tests/test-applications/nuxt-5/tests/errors.ssr.test.ts new file mode 100644 index 000000000000..8b3e573b116a --- /dev/null +++ b/dev-packages/e2e-tests/test-applications/nuxt-5/tests/errors.ssr.test.ts @@ -0,0 +1,93 @@ +import { HTTP_RESPONSE_STATUS_CODE, URL_PATH } from '@sentry/conventions/attributes'; +import { expect, test } from '@playwright/test'; +import { waitForEnvelopeItem, waitForError, waitForStreamedSpan } from '@sentry-internal/test-utils'; +import type { SerializedStreamedSpan } from '@sentry-internal/test-utils'; + +type EnvelopeItem = Parameters