-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[Gutenberg] Add Sentry React native SDK #16700
Closed
Closed
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
99596ca
Add bridge methods for React native crash logging
fluiddot ed72263
Autocorrect lint issues
fluiddot 2ef1920
Add getSentryUser to Gutenberg view controller
fluiddot edd59e5
Add upload Gutenberg source maps lane to Fastfile
fluiddot 23d2a62
Update Tracks ref
fluiddot 4d40f39
Update Podfile.lock
fluiddot 6440d98
Update Gutenberg Mobile ref
fluiddot 1240e89
Change internal value in build_and_upload_internal lane
fluiddot 86a6ca9
Merge branch 'develop' into gutenberg/add/sentry-react-native
fluiddot 70aa63d
Update Gutenberg Mobile ref
fluiddot 32ff050
Remove redundant comment from Fastfile file
fluiddot d1f3788
Remove redundant comment from Fastfile file
fluiddot cff282e
Remove redundant comment from Fastfile file
fluiddot 73aadc9
Add details to RN bundle naming in Fastfile file
fluiddot 98f7252
Add info comments to upload_gutenberg_sourcemaps lane
fluiddot 20f1892
Use temporary dir for uploading JS source maps
fluiddot ac313a9
Add Gutenberg Sentry native module
fluiddot 14f6cd7
Rename RNSentry to GutenbergSentry
fluiddot 2adce8c
Update Gutenberg Mobile ref
fluiddot 04d18c8
Apply swift lint autocorrection
fluiddot 8d591c8
Rename gutenberg sentry options function
fluiddot 7fb5928
Update Gutenberg Mobile ref
fluiddot 3f1a4fc
Merge branch 'develop' into gutenberg/add/sentry-react-native
fluiddot 848924d
Update WordPress/Classes/ViewRelated/Gutenberg/GutenbergViewControlle…
fluiddot 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 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
40 changes: 40 additions & 0 deletions
40
WordPress/Classes/ViewRelated/Gutenberg/Sentry/GutenbergSentry.m
This file contains 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,40 @@ | ||
#import <React/RCTBridgeModule.h> | ||
|
||
@interface RCT_EXTERN_MODULE(RNSentry, NSObject) | ||
|
||
// Extra methods to extract data from the Sentry SDK configured in the main apps. | ||
RCT_EXTERN_METHOD(getUser:(RCTPromiseResolveBlock)resolve | ||
rejecter:(RCTPromiseRejectBlock)rejecter) | ||
RCT_EXTERN_METHOD(attachScopeToEvent:(NSDictionary * _Nonnull)event resolve:(RCTPromiseResolveBlock)resolve | ||
rejecter:(RCTPromiseRejectBlock)rejecter) | ||
RCT_EXTERN_METHOD(shouldSendEvent:(RCTPromiseResolveBlock)resolve | ||
rejecter:(RCTPromiseRejectBlock)rejecter) | ||
|
||
|
||
// This methods are extracted from the original implementation. | ||
// Reference: https://github.com/getsentry/sentry-react-native/blob/master/ios/RNSentry.m | ||
RCT_EXTERN_METHOD(startWithOptions:(NSDictionary *_Nonnull)options resolve:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)rejecter) | ||
RCT_EXTERN_METHOD(deviceContexts:(RCTPromiseResolveBlock)resolve | ||
rejecter:(RCTPromiseRejectBlock)rejecter) | ||
RCT_EXTERN_METHOD(setLogLevel:(int)level) | ||
RCT_EXTERN_METHOD(fetchRelease:(RCTPromiseResolveBlock)resolve | ||
rejecter:(RCTPromiseRejectBlock)rejecter) | ||
RCT_EXTERN_METHOD(captureEnvelope:(NSDictionary * _Nonnull)envelopeDict | ||
resolve:(RCTPromiseResolveBlock)resolve | ||
rejecter:(RCTPromiseRejectBlock)rejecter) | ||
RCT_EXTERN_METHOD(setUser:(NSDictionary *)user | ||
otherUserKeys:(NSDictionary *)otherUserKeys | ||
) | ||
RCT_EXTERN_METHOD(addBreadcrumb:(NSDictionary *)breadcrumb) | ||
RCT_EXTERN_METHOD(clearBreadcrumbs) | ||
RCT_EXTERN_METHOD(setExtra:(NSString *)key | ||
extra:(NSString *)extra | ||
) | ||
RCT_EXTERN_METHOD(setContext:(NSString *)key | ||
context:(NSDictionary *)context | ||
) | ||
RCT_EXTERN_METHOD(setTag:(NSString *)key | ||
value:(NSString *)value | ||
) | ||
RCT_EXTERN_METHOD(crash) | ||
@end |
108 changes: 108 additions & 0 deletions
108
WordPress/Classes/ViewRelated/Gutenberg/Sentry/GutenbergSentry.swift
This file contains 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,108 @@ | ||
@objc (RNSentry) | ||
public class GutenbergSentry: NSObject, RCTBridgeModule { | ||
public static func moduleName() -> String! { | ||
return "RNSentry" | ||
} | ||
|
||
public static func requiresMainQueueSetup() -> Bool { | ||
return true | ||
} | ||
|
||
public func constantsToExport() -> [AnyHashable: Any]! { | ||
return ["nativeClientAvailable": true, "nativeTransport": true] | ||
} | ||
|
||
/// Asks the Crash logging library for the current Sentry scope and includes it to an event. | ||
/// | ||
/// - Returns: Event object with attached scope. | ||
@objc | ||
func attachScopeToEvent(_ event: [String: Any], resolve: @escaping RCTPromiseResolveBlock, rejecter:@escaping RCTPromiseRejectBlock) { | ||
DispatchQueue.main.async { | ||
let eventWithScope = WordPressAppDelegate.crashLogging?.attachScopeToEvent(event) | ||
resolve(eventWithScope) | ||
} | ||
} | ||
|
||
/// Asks the Crash logging library to know if the app should send Sentry events depending on user preferences. | ||
/// | ||
/// - Returns: True if Sentry events can be sent. | ||
@objc | ||
func shouldSendEvent(_ resolve: @escaping RCTPromiseResolveBlock, rejecter:@escaping RCTPromiseRejectBlock) { | ||
DispatchQueue.main.async { | ||
let shouldSendEvent = WordPressAppDelegate.crashLogging?.shouldSendEvent() | ||
resolve(shouldSendEvent) | ||
} | ||
} | ||
|
||
/// Asks the Crash logging library for the current user of Sentry SDK. | ||
/// | ||
/// - Returns: Sentry user. | ||
@objc | ||
func getUser(_ resolve: @escaping RCTPromiseResolveBlock, rejecter:@escaping RCTPromiseRejectBlock) { | ||
DispatchQueue.main.async { | ||
resolve(WordPressAppDelegate.crashLogging?.getSentryUserDict()) | ||
} | ||
} | ||
|
||
@objc | ||
func captureEnvelope(_ envelopeDict: [String: Any], resolve: @escaping RCTPromiseResolveBlock, rejecter:@escaping RCTPromiseRejectBlock) { | ||
DispatchQueue.main.async { | ||
WordPressAppDelegate.crashLogging?.logEnvelope(envelopeDict) | ||
resolve(true) | ||
} | ||
} | ||
} | ||
|
||
// MARK: - Disabled original methods | ||
|
||
extension GutenbergSentry { | ||
// Disabled because the Sentry SDK is initialized in the main apps. | ||
@objc | ||
func startWithOptions(_ options: [String: Any], resolve: @escaping RCTPromiseResolveBlock, rejecter:@escaping RCTPromiseRejectBlock) { | ||
resolve(true) | ||
} | ||
|
||
// Disabled because the device context is fetched via the attachScopeToEvent method. | ||
@objc | ||
func deviceContexts(_ resolve: @escaping RCTPromiseResolveBlock, rejecter:@escaping RCTPromiseRejectBlock) { | ||
resolve({}) | ||
} | ||
|
||
// Disabled as it's set by the main apps. | ||
@objc | ||
func setLogLevel(_ level: Int) { } | ||
|
||
// Disabled as it's not required by the current Sentry integrations. | ||
@objc | ||
func fetchRelease(_ resolve: @escaping RCTPromiseResolveBlock, rejecter:@escaping RCTPromiseRejectBlock) { | ||
resolve({}) | ||
} | ||
|
||
// Disabled as it's set by the main apps. | ||
@objc | ||
func setUser(_ user: [String: Any], otherUserKeys: [String: Any]) { } | ||
|
||
// Disabled as breadcrumbs are managed by the main apps. | ||
@objc | ||
func addBreadcrumb(_ breadcrumb: [String: Any]) { } | ||
|
||
// Disabled as breadcrumbs are managed by the main apps. | ||
@objc | ||
func clearBreadcrumbs() { } | ||
|
||
// Disabled as extra tags are managed by the main apps. | ||
@objc | ||
func setExtra(_ key: String, extra: String) { } | ||
|
||
// Disabled as context is managed by the main apps. | ||
@objc | ||
func setContext(_ key: String, context: [String: Any]) { } | ||
|
||
// Disabled as tags are managed by the main apps. | ||
@objc | ||
func setTag(_ key: String, value: String) { } | ||
|
||
// Disabled as it's already exposed from the main apps. | ||
@objc | ||
func crash() { } | ||
} |
This file contains 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 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
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.
The build version is different depending on the
internal
option, here is an example:internal: true
:17.6.0.20210614
(reference)internal: false
:17.6.0.0
(reference)