-
-
Notifications
You must be signed in to change notification settings - Fork 349
V7: Uppercase boolean flags #4965
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
Merged
+385
−11
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
24d04fb
initial changes
lucas-zimerman edcd558
update changelog
lucas-zimerman d4f741d
add changelog ID
lucas-zimerman 41be257
Merge branch 'v7' into lz/v7/uc-boolean
lucas-zimerman 53c388e
refactor and use event processor
lucas-zimerman 413ece7
split expo changes UI
lucas-zimerman 21896ff
fix lint
lucas-zimerman 8f4a8f6
Merge branch 'lz/v7/uc-boolean' of https://github.com/getsentry/sentr…
lucas-zimerman 83deb19
fix typo
lucas-zimerman 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
37 changes: 37 additions & 0 deletions
37
packages/core/src/js/integrations/primitiveTagIntegration.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,37 @@ | ||
import type { Integration, Primitive } from '@sentry/core'; | ||
import { PrimitiveToString } from '../utils/primitiveConverter'; | ||
import { NATIVE } from '../wrapper'; | ||
|
||
export const INTEGRATION_NAME = 'PrimitiveTagIntegration'; | ||
|
||
/** | ||
* Format tags set with Primitive values with a standard string format. | ||
* | ||
* When this Integration is enable, the following types will have the following behaviour: | ||
* | ||
* Unaltered: string, null, number, and undefined values remain unchanged. | ||
* | ||
* Altered: | ||
* Boolean values are now capitalized: true -> True, false -> False. | ||
* Symbols are stringified. | ||
* | ||
*/ | ||
export const primtiviteTagIntegration = (): Integration => { | ||
return { | ||
name: INTEGRATION_NAME, | ||
setup(client) { | ||
client.on('beforeSendEvent', event => { | ||
if (event.tags) { | ||
Object.keys(event.tags).forEach(key => { | ||
event.tags![key] = PrimitiveToString(event.tags![key]); | ||
}); | ||
} | ||
}); | ||
}, | ||
afterAllSetup() { | ||
if (NATIVE.enableNative) { | ||
NATIVE._setPrimitiveProcessor((value: Primitive) => PrimitiveToString(value)); | ||
} | ||
}, | ||
}; | ||
}; |
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,26 @@ | ||
import type { Primitive } from '@sentry/core'; | ||
|
||
/** | ||
* Converts primitive to string. | ||
*/ | ||
export function PrimitiveToString(primitive: Primitive): string | undefined { | ||
if (primitive === null) { | ||
return ''; | ||
} | ||
|
||
switch (typeof primitive) { | ||
case 'string': | ||
return primitive; | ||
case 'boolean': | ||
return primitive == true ? 'True' : 'False'; | ||
case 'number': | ||
case 'bigint': | ||
return `${primitive}`; | ||
case 'undefined': | ||
return undefined; | ||
case 'symbol': | ||
return primitive.toString(); | ||
default: | ||
return primitive as string; | ||
} | ||
} |
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
95 changes: 95 additions & 0 deletions
95
packages/core/test/integrations/primitiveTagIntegration.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,95 @@ | ||
import type { Client } from '@sentry/core'; | ||
import { primtiviteTagIntegration } from '../../src/js/integrations/primitiveTagIntegration'; | ||
import { NATIVE } from '../../src/js/wrapper'; | ||
import { setupTestClient } from '../mocks/client'; | ||
|
||
describe('primitiveTagIntegration', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
setupTestClient(); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
describe('integration setup', () => { | ||
it('sets up beforeSendEvent handler', () => { | ||
const integration = primtiviteTagIntegration(); | ||
const mockClient = { | ||
on: jest.fn(), | ||
} as any; | ||
|
||
integration.setup!(mockClient); | ||
|
||
expect(mockClient.on).toHaveBeenCalledWith('beforeSendEvent', expect.any(Function)); | ||
}); | ||
}); | ||
|
||
describe('beforeSendEvent processing', () => { | ||
let beforeSendEventHandler: (event: any) => void; | ||
|
||
beforeEach(() => { | ||
const integration = primtiviteTagIntegration(); | ||
const mockClient = { | ||
on: jest.fn((eventName, handler) => { | ||
if (eventName === 'beforeSendEvent') { | ||
beforeSendEventHandler = handler; | ||
} | ||
}), | ||
} as any; | ||
|
||
integration.setup!(mockClient); | ||
}); | ||
|
||
it('handles events without tags', () => { | ||
const event = { message: 'test' }; | ||
|
||
expect(() => beforeSendEventHandler(event)).not.toThrow(); | ||
expect(event).toEqual({ message: 'test' }); | ||
}); | ||
|
||
it('handles events with empty tags object', () => { | ||
const event = { tags: {} }; | ||
|
||
expect(() => beforeSendEventHandler(event)).not.toThrow(); | ||
expect(event.tags).toEqual({}); | ||
}); | ||
|
||
it('handles events with null tags', () => { | ||
const event = { tags: null }; | ||
|
||
expect(() => beforeSendEventHandler(event)).not.toThrow(); | ||
expect(event.tags).toBeNull(); | ||
}); | ||
}); | ||
|
||
describe('integration with native processor', () => { | ||
it('sets primitiveProcessor to PrimitiveToString function', () => { | ||
const integration = primtiviteTagIntegration(); | ||
NATIVE.enableNative = true; | ||
jest.spyOn(NATIVE, '_setPrimitiveProcessor'); | ||
|
||
integration.afterAllSetup!({ getOptions: () => ({}) } as Client); | ||
|
||
expect(NATIVE._setPrimitiveProcessor).toHaveBeenCalledWith(expect.any(Function)); | ||
|
||
// Verify the function passed is PrimitiveToString | ||
const passedFunction = (NATIVE._setPrimitiveProcessor as jest.Mock).mock.calls[0][0]; | ||
expect(passedFunction(true)).toBe('True'); | ||
expect(passedFunction(false)).toBe('False'); | ||
expect(passedFunction(null)).toBe(''); | ||
expect(passedFunction(42)).toBe('42'); | ||
}); | ||
|
||
it('does not set processor when native is disabled', () => { | ||
const integration = primtiviteTagIntegration(); | ||
NATIVE.enableNative = false; | ||
jest.spyOn(NATIVE, '_setPrimitiveProcessor'); | ||
|
||
integration.afterAllSetup!({ getOptions: () => ({}) } as Client); | ||
|
||
expect(NATIVE._setPrimitiveProcessor).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.