-
-
Notifications
You must be signed in to change notification settings - Fork 54
FIX: missing ip settings from SDK package #390
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { addEventProcessor, getClient } from '@sentry/core'; | ||
|
||
import { SdkInfo } from '../../integrations/sdkinfo'; | ||
import { SDK_NAME, SDK_VERSION } from '../../version'; | ||
|
||
jest.mock('@sentry/core', () => ({ | ||
addEventProcessor: jest.fn(), | ||
getClient: jest.fn(), | ||
})); | ||
|
||
describe('SdkInfo Integration', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should have correct id and name', () => { | ||
const sdkInfo = new SdkInfo(); | ||
expect(SdkInfo.id).toBe('SdkInfo'); | ||
expect(sdkInfo.name).toBe('SdkInfo'); | ||
}); | ||
|
||
it('should add an event processor', () => { | ||
(getClient as jest.Mock).mockReturnValue({ | ||
getOptions: () => ({ sendDefaultPii: true }), | ||
}); | ||
|
||
const sdkInfo = new SdkInfo(); | ||
sdkInfo.setupOnce(); | ||
|
||
expect(addEventProcessor).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should patch event sdk info correctly with sendDefaultPii true', async () => { | ||
(getClient as jest.Mock).mockReturnValue({ | ||
getOptions: () => ({ sendDefaultPii: true }), | ||
}); | ||
|
||
const sdkInfo = new SdkInfo(); | ||
sdkInfo.setupOnce(); | ||
|
||
const eventProcessor = (addEventProcessor as jest.Mock).mock.calls[0][0]; | ||
|
||
const event = { sdk: { packages: [] } }; | ||
const processedEvent = await eventProcessor(event); | ||
|
||
expect(processedEvent.platform).toBe('javascript'); | ||
expect(processedEvent.sdk.name).toBe(SDK_NAME); | ||
expect(processedEvent.sdk.version).toBe(SDK_VERSION); | ||
expect(processedEvent.sdk.packages).toContainEqual({ | ||
name: 'npm:sentry-cordova', | ||
version: SDK_VERSION, | ||
}); | ||
expect(processedEvent.sdk.settings?.infer_ip).toBe('auto'); | ||
}); | ||
|
||
it('should patch event sdk info correctly with sendDefaultPii false', async () => { | ||
(getClient as jest.Mock).mockReturnValue({ | ||
getOptions: () => ({ sendDefaultPii: false }), | ||
}); | ||
|
||
const sdkInfo = new SdkInfo(); | ||
sdkInfo.setupOnce(); | ||
|
||
const eventProcessor = (addEventProcessor as jest.Mock).mock.calls[0][0]; | ||
|
||
const event = { sdk: {} }; | ||
const processedEvent = await eventProcessor(event); | ||
|
||
expect(processedEvent.sdk.settings?.infer_ip).toBe('never'); | ||
}); | ||
|
||
it('should preserve existing sdk settings', async () => { | ||
(getClient as jest.Mock).mockReturnValue({ | ||
getOptions: () => ({ sendDefaultPii: true }), | ||
}); | ||
|
||
const sdkInfo = new SdkInfo(); | ||
sdkInfo.setupOnce(); | ||
|
||
const eventProcessor = (addEventProcessor as jest.Mock).mock.calls[0][0]; | ||
|
||
const event = { | ||
sdk: { | ||
packages: [], | ||
settings: { debug: true }, | ||
}, | ||
}; | ||
const processedEvent = await eventProcessor(event); | ||
|
||
expect(processedEvent.sdk.settings).toEqual({ | ||
infer_ip: 'auto', | ||
debug: true, | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
import { addEventProcessor } from '@sentry/core'; | ||
import type { Integration } from '@sentry/types'; | ||
import { addEventProcessor, getClient } from '@sentry/core'; | ||
import type { Integration, SdkInfo as SdkInfoType} from '@sentry/types'; | ||
|
||
import { SDK_NAME, SDK_VERSION } from '../version'; | ||
|
||
interface IpPatchedSdkInfo extends SdkInfoType { | ||
settings?: { | ||
infer_ip?: 'auto' | 'never'; | ||
}; | ||
} | ||
|
||
/** Default SdkInfo instrumentation */ | ||
export class SdkInfo implements Integration { | ||
/** | ||
|
@@ -19,21 +25,38 @@ export class SdkInfo implements Integration { | |
* @inheritDoc | ||
*/ | ||
public setupOnce(): void { | ||
|
||
let defaultPii: boolean | undefined = undefined; | ||
|
||
const client = getClient(); | ||
if (client) { | ||
const options = client?.getOptions(); | ||
defaultPii = options.sendDefaultPii; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential bug: The
|
||
addEventProcessor(async (event) => { | ||
event.platform = event.platform || 'javascript'; | ||
event.sdk = { | ||
...event.sdk, | ||
name: SDK_NAME, | ||
packages: [ | ||
...((event.sdk && event.sdk.packages) || []), | ||
{ | ||
name: 'npm:sentry-cordova', | ||
version: SDK_VERSION, | ||
}, | ||
], | ||
version: SDK_VERSION, | ||
const sdk = (event.sdk || {}) as IpPatchedSdkInfo; | ||
|
||
sdk.name = sdk.name || SDK_NAME; | ||
sdk.packages = [ | ||
...((event.sdk && event.sdk.packages) || []), | ||
{ | ||
name: 'npm:sentry-cordova', | ||
version: SDK_VERSION, | ||
}, | ||
]; | ||
sdk.version = SDK_VERSION; | ||
|
||
// Patch missing infer_ip. | ||
sdk.settings = { | ||
infer_ip: defaultPii ? 'auto' : 'never', | ||
// purposefully allowing already passed settings to override the default | ||
...sdk.settings | ||
}; | ||
|
||
event.sdk = sdk; | ||
|
||
return event; | ||
}); | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.