-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(nextjs): Migrate sendDefaultPii to dataCollection
#21137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
chargome
wants to merge
3
commits into
develop
Choose a base branch
from
cg/next-datacollection
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,54 @@ | ||
| import * as SentryCore from '@sentry/core'; | ||
| import { describe, expect, it, vi } from 'vitest'; | ||
| import { addHeadersAsAttributes } from '../../src/common/utils/addHeadersAsAttributes'; | ||
|
|
||
| describe('addHeadersAsAttributes', () => { | ||
| it('returns empty object when headers are undefined', () => { | ||
| expect(addHeadersAsAttributes(undefined)).toEqual({}); | ||
| }); | ||
|
|
||
| it('returns empty object when httpHeaders.request is false', () => { | ||
| vi.spyOn(SentryCore, 'getClient').mockReturnValue({ | ||
| getDataCollectionOptions: () => ({ | ||
| httpHeaders: { request: false, response: true }, | ||
| }), | ||
| } as unknown as SentryCore.Client); | ||
|
|
||
| const result = addHeadersAsAttributes({ 'content-type': 'application/json' }); | ||
| expect(result).toEqual({}); | ||
| }); | ||
|
|
||
| it('passes PII headers through when httpHeaders.request is true', () => { | ||
| vi.spyOn(SentryCore, 'getClient').mockReturnValue({ | ||
| getDataCollectionOptions: () => ({ | ||
| httpHeaders: { request: true, response: true }, | ||
| }), | ||
| } as unknown as SentryCore.Client); | ||
|
|
||
| const result = addHeadersAsAttributes({ | ||
| 'content-type': 'application/json', | ||
| 'x-forwarded-for': '127.0.0.1', | ||
| }); | ||
|
|
||
| expect(result).toMatchObject({ | ||
| 'http.request.header.content_type': 'application/json', | ||
| 'http.request.header.x_forwarded_for': '127.0.0.1', | ||
| }); | ||
| }); | ||
|
|
||
| it('filters denied headers when httpHeaders.request is a deny list', () => { | ||
| vi.spyOn(SentryCore, 'getClient').mockReturnValue({ | ||
| getDataCollectionOptions: () => ({ | ||
| httpHeaders: { request: { deny: ['forwarded'] }, response: true }, | ||
| }), | ||
| } as unknown as SentryCore.Client); | ||
|
|
||
| const result = addHeadersAsAttributes({ | ||
| 'content-type': 'application/json', | ||
| 'x-forwarded-for': '127.0.0.1', | ||
| }); | ||
|
|
||
| expect(result['http.request.header.content_type']).toBe('application/json'); | ||
| expect(result['http.request.header.x_forwarded_for']).toBe('[Filtered]'); | ||
| }); | ||
| }); | ||
58 changes: 58 additions & 0 deletions
58
packages/nextjs/test/utils/setUrlProcessingMetadata.test.ts
This file contains hidden or 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,58 @@ | ||
| import type { Event } from '@sentry/core'; | ||
| import * as SentryCore from '@sentry/core'; | ||
| import { describe, expect, it, vi } from 'vitest'; | ||
| import { setUrlProcessingMetadata } from '../../src/common/utils/setUrlProcessingMetadata'; | ||
|
|
||
| describe('setUrlProcessingMetadata', () => { | ||
| it('skips non-transaction events', () => { | ||
| const event: Event = { type: undefined }; | ||
| setUrlProcessingMetadata(event); | ||
| }); | ||
|
|
||
| it('adds URL without sendDefaultPii', () => { | ||
| vi.spyOn(SentryCore, 'getClient').mockReturnValue({ | ||
| getOptions: () => ({ sendDefaultPii: false }), | ||
| } as unknown as SentryCore.Client); | ||
|
|
||
| const scopeData = { | ||
| sdkProcessingMetadata: { | ||
| normalizedRequest: { | ||
| headers: { | ||
| 'x-forwarded-proto': 'https', | ||
| host: 'example.com', | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| const event: Event = { | ||
| type: 'transaction', | ||
| contexts: { | ||
| trace: { | ||
| op: 'http.server', | ||
| data: { | ||
| 'next.route': '/api/users/[id]', | ||
| 'http.target': '/api/users/123', | ||
| }, | ||
| }, | ||
| }, | ||
| sdkProcessingMetadata: { | ||
| capturedSpanIsolationScope: { getScopeData: () => scopeData }, | ||
| }, | ||
| }; | ||
|
|
||
| setUrlProcessingMetadata(event); | ||
| expect(scopeData.sdkProcessingMetadata.normalizedRequest.url).toBe('https://example.com/api/users/123'); | ||
| }); | ||
|
|
||
| it('skips when no client is available', () => { | ||
| vi.spyOn(SentryCore, 'getClient').mockReturnValue(undefined); | ||
|
|
||
| const event: Event = { | ||
| type: 'transaction', | ||
| contexts: { trace: { op: 'http.server', data: { 'next.route': '/test' } } }, | ||
| }; | ||
|
|
||
| setUrlProcessingMetadata(event); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feat PR lacks integration or E2E test coverage
Low Severity
This is a
featPR that migrates multiple code paths fromsendDefaultPiito thedataCollectionAPI, but the diff only includes unit tests (with heavy mocking). No integration or E2E test is present to validate the end-to-end behavior of these data-collection changes within an actual Next.js application. Per the review rules,featPRs need at least one integration or E2E test. Flagging this because it was mentioned in the rules file.Additional Locations (1)
packages/nextjs/test/utils/setUrlProcessingMetadata.test.ts#L1-L58Triggered by project rule: PR Review Guidelines for Cursor Bot
Reviewed by Cursor Bugbot for commit 1ea8c62. Configure here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we got existing tests that cover this