-
Notifications
You must be signed in to change notification settings - Fork 3
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
feat(react-native): support for starting native spans on ios #540
Open
yousif-bugsnag
wants to merge
5
commits into
integration/rn-native-integration
Choose a base branch
from
PLAT-12937/start-native-spans-cocoa
base: integration/rn-native-integration
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7373858
feat(react-native): support for starting native spans on ios
yousif-bugsnag e84642f
add noop implementations for BugsnagPerformance classes
yousif-bugsnag 529a173
Revert "add noop implementations for BugsnagPerformance classes"
yousif-bugsnag 1bdfb5e
refactor(react-native): pass span options to crosstalk API as an NSDi…
yousif-bugsnag 5979437
build(react-native): update coca performance branch
yousif-bugsnag 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
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
28 changes: 28 additions & 0 deletions
28
packages/platforms/react-native/ios/BugsnagPerformanceSpan.h
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,28 @@ | ||
#import "BugsnagPerformanceSpanContext.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface BugsnagPerformanceSpan : BugsnagPerformanceSpanContext | ||
|
||
@property(nonatomic,readonly) BOOL isValid; | ||
|
||
@property (nonatomic,readonly) NSString *name; | ||
@property (nonatomic,readonly) NSDate *_Nullable startTime; | ||
@property (nonatomic,readonly) NSDate *_Nullable endTime; | ||
|
||
@property (nonatomic,readwrite) SpanId parentId; | ||
@property (nonatomic,readonly) NSMutableDictionary *attributes; | ||
|
||
- (void)abortIfOpen; | ||
|
||
- (void)abortUnconditionally; | ||
|
||
- (void)end; | ||
|
||
- (void)endWithEndTime:(NSDate *)endTime NS_SWIFT_NAME(end(endTime:)); | ||
|
||
- (void)setAttribute:(NSString *)attributeName withValue:(_Nullable id)value; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
22 changes: 22 additions & 0 deletions
22
packages/platforms/react-native/ios/BugsnagPerformanceSpanContext.h
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,22 @@ | ||
#import <Foundation/Foundation.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
typedef union { | ||
__uint128_t value; | ||
struct { | ||
uint64_t lo; | ||
uint64_t hi; | ||
}; | ||
} TraceId; | ||
|
||
typedef uint64_t SpanId; | ||
|
||
@interface BugsnagPerformanceSpanContext : NSObject | ||
|
||
@property(nonatomic) TraceId traceId; | ||
@property(nonatomic) SpanId spanId; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
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 |
---|---|---|
|
@@ -41,6 +41,15 @@ @implementation BugsnagReactNativePerformance | |
#endif | ||
} | ||
|
||
static uint64_t hexStringToUInt64(NSString *hexString) { | ||
uint64_t result = 0; | ||
NSScanner *scanner = [NSScanner scannerWithString:hexString]; | ||
[scanner setScanLocation:0]; | ||
[scanner scanHexLongLong:&result]; | ||
|
||
return result; | ||
} | ||
|
||
static NSString *getRandomBytes() noexcept { | ||
const int POOL_SIZE = 1024; | ||
UInt8 bytes[POOL_SIZE]; | ||
|
@@ -129,6 +138,29 @@ @implementation BugsnagReactNativePerformance | |
return config; | ||
} | ||
|
||
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(startNativeSpan:(NSString *)name | ||
options:(NSDictionary *)options) { | ||
|
||
// native spans are always first class and should never become the current context | ||
NSMutableDictionary *spanOptions = [options mutableCopy]; | ||
spanOptions[@"makeCurrentContext"] = [NSNumber numberWithBool:NO]; | ||
spanOptions[@"firstClass"] = [NSNumber numberWithBool:YES]; | ||
|
||
BugsnagPerformanceSpan *nativeSpan = [BugsnagCocoaPerformanceFromBugsnagReactNativePerformance.sharedInstance startSpan:name options:spanOptions]; | ||
[nativeSpan.attributes removeAllObjects]; | ||
|
||
NSMutableDictionary *span = [NSMutableDictionary new]; | ||
span[@"name"] = nativeSpan.name; | ||
span[@"id"] = [NSString stringWithFormat:@"%llx", nativeSpan.spanId]; | ||
span[@"traceId"] = [NSString stringWithFormat:@"%llx%llx", nativeSpan.traceId.hi, nativeSpan.traceId.lo]; | ||
span[@"startTime"] = [NSNumber numberWithDouble: [nativeSpan.startTime timeIntervalSince1970] * NSEC_PER_SEC]; | ||
Comment on lines
+152
to
+156
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. do we also need to add the first class property, or does that only matter for the native side? |
||
if (nativeSpan.parentId > 0) { | ||
span[@"parentSpanId"] = [NSString stringWithFormat:@"%llx", nativeSpan.parentId]; | ||
} | ||
|
||
return span; | ||
} | ||
|
||
#ifdef RCT_NEW_ARCH_ENABLED | ||
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule: | ||
(const facebook::react::ObjCTurboModule::InitParams &)params | ||
|
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
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
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.
I'm sure you won't miss it, but just a reminder to update this branch!