-
-
Notifications
You must be signed in to change notification settings - Fork 359
Feat(Expo): Add expo constants on event context. #5748
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
+382
−11
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
fd91570
add expo constants
lucas-zimerman 6eee583
Merge branch 'main' into lz/expo-cons
lucas-zimerman e66aa2b
Merge branch 'main' of https://github.com/getsentry/sentry-react-nati…
lucas-zimerman 7fc9724
changelog
lucas-zimerman e99a0d0
Merge branch 'lz/expo-cons' of https://github.com/getsentry/sentry-re…
lucas-zimerman 89e2bcf
Apply suggestion from @lucas-zimerman
lucas-zimerman cfe558e
add back "useNativeInit": true,
lucas-zimerman e71d8b7
Apply suggestions from code review
lucas-zimerman 6dcc0f4
update type
lucas-zimerman 8ee8dce
Merge branch 'main' into lz/expo-cons
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| import type { Event, Integration } from '@sentry/core'; | ||
| import { isExpo } from '../utils/environment'; | ||
| import type { ExpoConstants } from '../utils/expoglobalobject'; | ||
| import { getExpoConstants } from '../utils/expomodules'; | ||
|
|
||
| const INTEGRATION_NAME = 'ExpoConstants'; | ||
|
|
||
| export const EXPO_CONSTANTS_CONTEXT_KEY = 'expo_constants'; | ||
|
|
||
| /** Load Expo Constants as event context. */ | ||
| export const expoConstantsIntegration = (): Integration => { | ||
| let _expoConstantsContextCached: ExpoConstantsContext | undefined; | ||
|
|
||
| function processEvent(event: Event): Event { | ||
| if (!isExpo()) { | ||
| return event; | ||
| } | ||
|
|
||
| event.contexts = event.contexts || {}; | ||
| event.contexts[EXPO_CONSTANTS_CONTEXT_KEY] = { | ||
| ...getExpoConstantsContextCached(), | ||
| }; | ||
|
|
||
| return event; | ||
| } | ||
|
|
||
| function getExpoConstantsContextCached(): ExpoConstantsContext { | ||
| if (_expoConstantsContextCached) { | ||
| return _expoConstantsContextCached; | ||
| } | ||
|
|
||
| return (_expoConstantsContextCached = getExpoConstantsContext()); | ||
| } | ||
|
|
||
| return { | ||
| name: INTEGRATION_NAME, | ||
| processEvent, | ||
| }; | ||
| }; | ||
|
|
||
| /** | ||
| * @internal Exposed for testing purposes | ||
| */ | ||
| export function getExpoConstantsContext(): ExpoConstantsContext { | ||
| const expoConstants = getExpoConstants(); | ||
| if (!expoConstants) { | ||
| return {}; | ||
| } | ||
|
|
||
| const context: ExpoConstantsContext = {}; | ||
|
|
||
| addStringField(context, 'execution_environment', expoConstants.executionEnvironment); | ||
| addStringField(context, 'app_ownership', expoConstants.appOwnership); | ||
| addBooleanField(context, 'debug_mode', expoConstants.debugMode); | ||
| addStringField(context, 'expo_version', expoConstants.expoVersion); | ||
| addStringField(context, 'expo_runtime_version', expoConstants.expoRuntimeVersion); | ||
| addStringField(context, 'session_id', expoConstants.sessionId); | ||
| addNumberField(context, 'status_bar_height', expoConstants.statusBarHeight); | ||
|
|
||
| addExpoConfigFields(context, expoConstants); | ||
| addEasConfigFields(context, expoConstants); | ||
|
|
||
| return context; | ||
| } | ||
|
|
||
| function addStringField( | ||
| context: ExpoConstantsContext, | ||
| key: keyof ExpoConstantsContext, | ||
| value: string | null | undefined, | ||
| ): void { | ||
| if (typeof value === 'string' && value) { | ||
| (context as Record<string, unknown>)[key] = value; | ||
| } | ||
| } | ||
|
|
||
| function addBooleanField( | ||
| context: ExpoConstantsContext, | ||
| key: keyof ExpoConstantsContext, | ||
| value: boolean | undefined, | ||
| ): void { | ||
| if (typeof value === 'boolean') { | ||
| (context as Record<string, unknown>)[key] = value; | ||
| } | ||
| } | ||
|
|
||
| function addNumberField( | ||
| context: ExpoConstantsContext, | ||
| key: keyof ExpoConstantsContext, | ||
| value: number | undefined, | ||
| ): void { | ||
| if (typeof value === 'number') { | ||
| (context as Record<string, unknown>)[key] = value; | ||
| } | ||
| } | ||
|
|
||
| function addExpoConfigFields(context: ExpoConstantsContext, expoConstants: ExpoConstants): void { | ||
| if (!expoConstants.expoConfig) { | ||
| return; | ||
| } | ||
|
|
||
| addStringField(context, 'app_name', expoConstants.expoConfig.name); | ||
| addStringField(context, 'app_slug', expoConstants.expoConfig.slug); | ||
| addStringField(context, 'app_version', expoConstants.expoConfig.version); | ||
| addStringField(context, 'expo_sdk_version', expoConstants.expoConfig.sdkVersion); | ||
| } | ||
|
|
||
| function addEasConfigFields(context: ExpoConstantsContext, expoConstants: ExpoConstants): void { | ||
| if (!expoConstants.easConfig) { | ||
| return; | ||
| } | ||
|
|
||
| addStringField(context, 'eas_project_id', expoConstants.easConfig.projectId); | ||
| } | ||
|
|
||
| type ExpoConstantsContext = Partial<{ | ||
| execution_environment: string; | ||
| app_ownership: string; | ||
| debug_mode: boolean; | ||
| expo_version: string; | ||
| expo_runtime_version: string; | ||
| session_id: string; | ||
| status_bar_height: number; | ||
| app_name: string; | ||
| app_slug: string; | ||
| app_version: string; | ||
| expo_sdk_version?: string; | ||
| eas_project_id: 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
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.
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.
This field no longer exists on expo and is not used by out SDK.