-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nuxt): Filter out Nuxt build assets (#13148)
Filtering out events of the `_nuxt` [buildAssetDir](https://nuxt.com/docs/api/nuxt-config#buildassetsdir). Next step would be to change the regex based on the folder name (as this could be changed in the nuxt config during build time - but probably doesn't happen too often). Also added some unit tests for the server-side of the SDK. Before: <img width="698" alt="image" src="https://github.com/user-attachments/assets/2ec5ccfb-b8fb-449b-97ba-24fbecabd998"> After: <img width="686" alt="image" src="https://github.com/user-attachments/assets/adf43031-7521-44f5-b155-ea57259001f5">
- Loading branch information
Showing
5 changed files
with
125 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
dev-packages/e2e-tests/test-applications/nuxt-3/public/instrument.server.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import * as Sentry from '@sentry/nuxt'; | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
environment: 'qa', // dynamic sampling bias to keep transactions | ||
tracesSampleRate: 1.0, // Capture 100% of the transactions | ||
tunnel: 'http://localhost:3031/', // proxy server | ||
}); |
46 changes: 46 additions & 0 deletions
46
dev-packages/e2e-tests/test-applications/nuxt-3/tests/performance.server.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { expect, test } from '@playwright/test'; | ||
import { waitForTransaction } from '@sentry-internal/test-utils'; | ||
import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/core'; | ||
|
||
test('sends a server action transaction on pageload', async ({ page }) => { | ||
const transactionPromise = waitForTransaction('nuxt-3', transactionEvent => { | ||
return transactionEvent.transaction.includes('GET /test-param/'); | ||
}); | ||
|
||
await page.goto('/test-param/1234'); | ||
|
||
const transaction = await transactionPromise; | ||
|
||
expect(transaction.contexts.trace).toEqual( | ||
expect.objectContaining({ | ||
data: expect.objectContaining({ | ||
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'http.server', | ||
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.otel.http', | ||
}), | ||
}), | ||
); | ||
}); | ||
|
||
test('does not send transactions for build asset folder "_nuxt"', async ({ page }) => { | ||
let buildAssetFolderOccurred = false; | ||
|
||
waitForTransaction('nuxt-3', transactionEvent => { | ||
if (transactionEvent.transaction?.match(/^GET \/_nuxt\//)) { | ||
buildAssetFolderOccurred = true; | ||
} | ||
return false; // expects to return a boolean (but not relevant here) | ||
}); | ||
|
||
const transactionEventPromise = waitForTransaction('nuxt-3', transactionEvent => { | ||
return transactionEvent.transaction.includes('GET /test-param/'); | ||
}); | ||
|
||
await page.goto('/test-param/1234'); | ||
|
||
const transactionEvent = await transactionEventPromise; | ||
|
||
expect(buildAssetFolderOccurred).toBe(false); | ||
|
||
// todo: url not yet parametrized | ||
expect(transactionEvent.transaction).toBe('GET /test-param/1234'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import * as SentryNode from '@sentry/node'; | ||
import { SDK_VERSION } from '@sentry/node'; | ||
import { beforeEach, describe, expect, it, vi } from 'vitest'; | ||
import { init } from '../../src/server'; | ||
|
||
const nodeInit = vi.spyOn(SentryNode, 'init'); | ||
|
||
describe('Nuxt Server SDK', () => { | ||
describe('init', () => { | ||
beforeEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
it('Adds Nuxt metadata to the SDK options', () => { | ||
expect(nodeInit).not.toHaveBeenCalled(); | ||
|
||
init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
}); | ||
|
||
const expectedMetadata = { | ||
_metadata: { | ||
sdk: { | ||
name: 'sentry.javascript.nuxt', | ||
version: SDK_VERSION, | ||
packages: [ | ||
{ name: 'npm:@sentry/nuxt', version: SDK_VERSION }, | ||
{ name: 'npm:@sentry/node', version: SDK_VERSION }, | ||
], | ||
}, | ||
}, | ||
}; | ||
|
||
expect(nodeInit).toHaveBeenCalledTimes(1); | ||
expect(nodeInit).toHaveBeenLastCalledWith(expect.objectContaining(expectedMetadata)); | ||
}); | ||
|
||
it('returns client from init', () => { | ||
expect(init({})).not.toBeUndefined(); | ||
}); | ||
}); | ||
}); |