-
-
Notifications
You must be signed in to change notification settings - Fork 343
feat(expo): Add Expo Modules Integration #3466
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
Merged
Changes from 18 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
7b2c4f7
feat(expo): Dynamically resolve default integrations based on platform
krystofwoldrich 1fad9df
add more tests
krystofwoldrich 59bf2c1
Merge remote-tracking branch 'origin/expo' into kw-add-dynamic-defaul…
krystofwoldrich e22570f
fix changelog
krystofwoldrich e55b180
feat(expo): Add Expo Modules Integration
krystofwoldrich a941cca
disable native nagging on unsupported platforms
krystofwoldrich c475c85
Add expo modules getters js docs
krystofwoldrich 287e9f3
fix(logs): Do not report native SDK info error if native availability…
krystofwoldrich 5163ae4
Add expo go message
krystofwoldrich 7c1ea8c
update changelog
krystofwoldrich ecde2d0
Merge branch 'expo' into kw-add-dynamic-default-integrations
krystofwoldrich 6799b06
Merge branch 'kw-add-dynamic-default-integrations' into kw-add-expo-m…
krystofwoldrich f48adb9
Merge remote-tracking branch 'origin/expo' into kw-add-expo-modules
krystofwoldrich 133e929
Add expo to rect native context, add expo device and os context
krystofwoldrich 19c9c24
WIP! Add Expo context integration tests
krystofwoldrich 5dc939f
Finish expo context integration tests
krystofwoldrich d43b172
Add merge tests
krystofwoldrich 085337e
Merge branch 'expo' into kw-add-expo-modules
krystofwoldrich eb26127
Update type source links
krystofwoldrich 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,8 @@ This release is compatible with `[email protected]` and newer. | |
- Resolve Default Integrations based on current platform ([#3465](https://github.com/getsentry/sentry-react-native/pull/3465)) | ||
- Native Integrations are only added if Native Module is available | ||
- Web Integrations only for React Native Web builds | ||
- Remove Native Modules warning from platform where the absence is expected ([#3466](https://github.com/getsentry/sentry-react-native/pull/3466)) | ||
- Add Expo Context information using Expo Native Modules ([#3466](https://github.com/getsentry/sentry-react-native/pull/3466)) | ||
|
||
### Fixes | ||
|
||
|
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,78 @@ | ||
import type { DeviceContext, Event, EventProcessor, Hub, Integration, OsContext } from '@sentry/types'; | ||
|
||
import { getExpoDevice } from '../utils/expomodules'; | ||
|
||
/** Load device context from expo modules. */ | ||
export class ExpoContext implements Integration { | ||
/** | ||
* @inheritDoc | ||
*/ | ||
public static id: string = 'ExpoContext'; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public name: string = ExpoContext.id; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public setupOnce(addGlobalEventProcessor: (callback: EventProcessor) => void, getCurrentHub: () => Hub): void { | ||
addGlobalEventProcessor(async (event: Event) => { | ||
const self = getCurrentHub().getIntegration(ExpoContext); | ||
if (!self) { | ||
return event; | ||
} | ||
|
||
const expoDeviceContext = getExpoDeviceContext(); | ||
if (expoDeviceContext) { | ||
event.contexts = event.contexts || {}; | ||
event.contexts.device = { ...expoDeviceContext, ...event.contexts.device }; | ||
} | ||
|
||
const expoOsContext = getExpoOsContext(); | ||
if (expoOsContext) { | ||
event.contexts = event.contexts || {}; | ||
event.contexts.os = { ...expoOsContext, ...event.contexts.os }; | ||
} | ||
|
||
return event; | ||
}); | ||
} | ||
} | ||
|
||
/** | ||
* Returns the Expo Device context if present | ||
*/ | ||
function getExpoDeviceContext(): DeviceContext | undefined { | ||
const expoDevice = getExpoDevice(); | ||
|
||
if (!expoDevice) { | ||
return undefined; | ||
} | ||
|
||
return { | ||
name: expoDevice.deviceName, | ||
simulator: !expoDevice?.isDevice, | ||
model: expoDevice.modelName, | ||
manufacturer: expoDevice.manufacturer, | ||
memory_size: expoDevice.totalMemory, | ||
}; | ||
} | ||
|
||
/** | ||
* Returns the Expo OS context if present | ||
*/ | ||
function getExpoOsContext(): OsContext | undefined { | ||
const expoDevice = getExpoDevice(); | ||
|
||
if (!expoDevice) { | ||
return undefined; | ||
} | ||
|
||
return { | ||
build: expoDevice.osBuildId, | ||
version: expoDevice.osVersion, | ||
name: expoDevice.osName, | ||
}; | ||
} |
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,51 @@ | ||
/** | ||
* Interface from the Expo SDK defined here | ||
* (we are describing the native Module | ||
* the TS typing is only guideline): | ||
* | ||
* https://github.com/expo/expo/blob/5d1153e6ae7c497fa1281ffee85fabe90d2321c2/packages/expo-constants/src/Constants.types.ts#L124 | ||
*/ | ||
export interface ExpoConstants { | ||
appOwnership?: 'standalone' | 'expo' | 'guest'; | ||
/** | ||
* Deprecated. But until removed we can use it as user ID to match the native SDKs. | ||
*/ | ||
installationId?: string; | ||
/** | ||
* Version of the Expo Go app | ||
*/ | ||
expoVersion?: string | null; | ||
manifest?: null | { | ||
[key: string]: unknown; | ||
/** | ||
* Expo SDK version should match `expo` version from the app `package.json`. | ||
* Example "exposdk:50.0.0" | ||
*/ | ||
runtimeVersion?: string; | ||
}; | ||
} | ||
|
||
/** | ||
* Interface from the Expo SDK defined here | ||
* (we are describing the native module | ||
* the TS typing is only guideline) | ||
* | ||
* https://github.com/expo/expo/blob/5d1153e6ae7c497fa1281ffee85fabe90d2321c2/packages/expo-device/src/Device.ts | ||
*/ | ||
export interface ExpoDevice { | ||
deviceName?: string; | ||
isDevice?: boolean; | ||
manufacturer?: string; | ||
modelName?: string; | ||
osName?: string; | ||
osBuildId?: string; | ||
osVersion?: string; | ||
totalMemory?: number; | ||
} | ||
|
||
export interface ExpoGlobalObject { | ||
modules?: { | ||
ExponentConstants?: ExpoConstants; | ||
ExpoDevice?: ExpoDevice; | ||
}; | ||
} |
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,18 @@ | ||
import type { ExpoConstants, ExpoDevice } from './expoglobalobject'; | ||
import { RN_GLOBAL_OBJ } from './worldwide'; | ||
|
||
/** | ||
* Returns the Expo Constants module if present | ||
*/ | ||
export function getExpoConstants(): ExpoConstants | undefined { | ||
return ( | ||
(RN_GLOBAL_OBJ.expo && RN_GLOBAL_OBJ.expo.modules && RN_GLOBAL_OBJ.expo.modules.ExponentConstants) || undefined | ||
); | ||
} | ||
|
||
/** | ||
* Returns the Expo Device module if present | ||
*/ | ||
export function getExpoDevice(): ExpoDevice | undefined { | ||
return (RN_GLOBAL_OBJ.expo && RN_GLOBAL_OBJ.expo.modules && RN_GLOBAL_OBJ.expo.modules.ExpoDevice) || undefined; | ||
} |
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.
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.