@bugsnag/plugin-react-native-span-access 2.14.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/build.gradle +2 -1
- package/android/src/main/java/com/bugsnag/reactnative/performance/nativespans/BugsnagJavascriptSpansPlugin.java +32 -0
- package/android/src/main/java/com/bugsnag/reactnative/performance/nativespans/BugsnagNativeSpans.java +217 -131
- package/android/src/main/java/com/bugsnag/reactnative/performance/nativespans/BugsnagNativeSpansPlugin.java +91 -91
- package/android/src/main/java/com/bugsnag/reactnative/performance/nativespans/CallbackState.java +32 -0
- package/android/src/main/java/com/bugsnag/reactnative/performance/nativespans/JavascriptSpanByName.java +37 -0
- package/android/src/main/java/com/bugsnag/reactnative/performance/nativespans/JavascriptSpanControl.java +15 -0
- package/android/src/main/java/com/bugsnag/reactnative/performance/nativespans/JavascriptSpanControlImpl.java +46 -0
- package/android/src/main/java/com/bugsnag/reactnative/performance/nativespans/JavascriptSpanControlProvider.java +19 -0
- package/android/src/main/java/com/bugsnag/reactnative/performance/nativespans/JavascriptSpanTransaction.java +13 -0
- package/android/src/main/java/com/bugsnag/reactnative/performance/nativespans/JavascriptSpanTransactionImpl.java +153 -0
- package/android/src/main/java/com/bugsnag/reactnative/performance/nativespans/OnRemoteSpanUpdatedCallback.java +5 -0
- package/android/src/main/java/com/bugsnag/reactnative/performance/nativespans/OnSpanContextRetrievedCallback.java +14 -0
- package/android/src/newarch/java/com/bugsnag/reactnative/performance/nativespans/BugsnagNativeSpansModule.java +20 -0
- package/android/src/oldarch/java/com/bugsnag/reactnative/performance/nativespans/BugsnagNativeSpansModule.java +20 -0
- package/dist/NativeBugsnagNativeSpans.ts +8 -0
- package/dist/index.js +2 -58
- package/dist/javascript-spans-plugin.js +83 -0
- package/dist/native-spans-plugin.js +61 -0
- package/dist/types/NativeBugsnagNativeSpans.d.ts +4 -0
- package/dist/types/NativeBugsnagNativeSpans.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -23
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/javascript-spans-plugin.d.ts +15 -0
- package/dist/types/javascript-spans-plugin.d.ts.map +1 -0
- package/dist/types/native-spans-plugin.d.ts +24 -0
- package/dist/types/native-spans-plugin.d.ts.map +1 -0
- package/ios/BugsnagJavascriptSpanControl+Private.h +7 -0
- package/ios/BugsnagJavascriptSpanControl.h +31 -0
- package/ios/BugsnagJavascriptSpanControl.mm +148 -0
- package/ios/BugsnagJavascriptSpanControlProvider.h +10 -0
- package/ios/BugsnagJavascriptSpanControlProvider.mm +18 -0
- package/ios/BugsnagJavascriptSpanQuery.h +12 -0
- package/ios/BugsnagJavascriptSpanQuery.mm +13 -0
- package/ios/BugsnagJavascriptSpansPlugin+Private.h +24 -0
- package/ios/BugsnagJavascriptSpansPlugin.h +10 -0
- package/ios/BugsnagJavascriptSpansPlugin.mm +117 -0
- package/ios/BugsnagNativeSpans.h +2 -1
- package/ios/BugsnagNativeSpans.mm +49 -3
- package/ios/BugsnagNativeSpans.xcodeproj/project.pbxproj +30 -2
- package/ios/BugsnagNativeSpansPlugin.mm +24 -6
- package/package.json +4 -4
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#import <Foundation/Foundation.h>
|
|
2
|
+
#import <BugsnagPerformance/BugsnagPerformanceSpanControl.h>
|
|
3
|
+
#import <BugsnagPerformance/BugsnagPerformanceSpanContext.h>
|
|
4
|
+
|
|
5
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
6
|
+
|
|
7
|
+
typedef void (^OnSpanUpdatedCallback)(BOOL result);
|
|
8
|
+
|
|
9
|
+
typedef void (^RemoteSpanContextCallback)(BugsnagPerformanceSpanContext * _Nullable context);
|
|
10
|
+
|
|
11
|
+
@interface BugsnagJavascriptSpanTransaction : NSObject
|
|
12
|
+
|
|
13
|
+
- (void)end;
|
|
14
|
+
|
|
15
|
+
- (void)endWithEndTime:(NSDate *)endTime NS_SWIFT_NAME(end(endTime:));
|
|
16
|
+
|
|
17
|
+
- (void)setAttribute:(NSString *)attributeName withValue:(_Nullable id)value;
|
|
18
|
+
|
|
19
|
+
- (void)commit:(OnSpanUpdatedCallback)callback;
|
|
20
|
+
|
|
21
|
+
@end
|
|
22
|
+
|
|
23
|
+
@interface BugsnagJavascriptSpanControl : NSObject<BugsnagPerformanceSpanControl>
|
|
24
|
+
|
|
25
|
+
- (BugsnagJavascriptSpanTransaction *)createUpdateTransaction;
|
|
26
|
+
|
|
27
|
+
- (void)retrieveSpanContext:(RemoteSpanContextCallback)callback;
|
|
28
|
+
|
|
29
|
+
@end
|
|
30
|
+
|
|
31
|
+
NS_ASSUME_NONNULL_END
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
#import "BugsnagJavascriptSpanControl.h"
|
|
2
|
+
#import "BugsnagJavascriptSpansPlugin+Private.h"
|
|
3
|
+
#import <stdlib.h>
|
|
4
|
+
|
|
5
|
+
static NSString * const idTransactionKey = @"id";
|
|
6
|
+
static NSString * const nameTransactionKey = @"name";
|
|
7
|
+
static NSString * const endTimeTransactionKey = @"endTime";
|
|
8
|
+
static NSString * const isEndedTransactionKey = @"isEnded";
|
|
9
|
+
static NSString * const attributesTransactionKey = @"attributes";
|
|
10
|
+
static NSString * const attributeNameKey = @"name";
|
|
11
|
+
static NSString * const attributeValueKey = @"value";
|
|
12
|
+
|
|
13
|
+
@interface BugsnagJavascriptSpanTransaction ()
|
|
14
|
+
|
|
15
|
+
- (instancetype)initWithSpanName:(NSString *)spanName;
|
|
16
|
+
|
|
17
|
+
@end
|
|
18
|
+
|
|
19
|
+
@implementation BugsnagJavascriptSpanTransaction
|
|
20
|
+
|
|
21
|
+
NSMutableDictionary *updateEvent;
|
|
22
|
+
|
|
23
|
+
BOOL isOpen = YES;
|
|
24
|
+
|
|
25
|
+
- (instancetype)initWithSpanName:(NSString *)spanName; {
|
|
26
|
+
self = [super init];
|
|
27
|
+
if (self) {
|
|
28
|
+
updateEvent = [NSMutableDictionary dictionaryWithDictionary:@{
|
|
29
|
+
nameTransactionKey: spanName,
|
|
30
|
+
isEndedTransactionKey: @NO
|
|
31
|
+
}];
|
|
32
|
+
}
|
|
33
|
+
return self;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
- (void)end {
|
|
37
|
+
if(!isOpen) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
[self endWithEndTime:[NSDate date]];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
- (void)endWithEndTime:(NSDate *)endTime {
|
|
45
|
+
if (!isOpen) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
NSTimeInterval currentTime = [endTime timeIntervalSince1970];
|
|
50
|
+
NSNumber *unixNanos = @((double)(currentTime * NSEC_PER_SEC));
|
|
51
|
+
updateEvent[endTimeTransactionKey] = unixNanos;
|
|
52
|
+
updateEvent[isEndedTransactionKey] = @YES;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
- (void)setAttribute:(NSString *)attributeName withValue:(_Nullable id)value {
|
|
56
|
+
if (!isOpen || attributeName == nil || ![self isValidAttribute:value]) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
NSMutableArray *attributes = updateEvent[attributesTransactionKey];
|
|
61
|
+
if (!attributes) {
|
|
62
|
+
attributes = [NSMutableArray array];
|
|
63
|
+
updateEvent[attributesTransactionKey] = attributes;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
NSDictionary *attribute = @{
|
|
67
|
+
attributeNameKey: attributeName,
|
|
68
|
+
attributeValueKey: value ?: [NSNull null]
|
|
69
|
+
};
|
|
70
|
+
[attributes addObject:attribute];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
- (void)commit:(OnSpanUpdatedCallback)callback {
|
|
74
|
+
if (!isOpen) {
|
|
75
|
+
callback(NO);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
isOpen = NO;
|
|
80
|
+
BugsnagJavascriptSpansPlugin *plugin = [BugsnagJavascriptSpansPlugin singleton];
|
|
81
|
+
if (!plugin) {
|
|
82
|
+
callback(NO);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
int eventId = [plugin registerSpanUpdateCallback:callback];
|
|
87
|
+
updateEvent[idTransactionKey] = @(eventId);
|
|
88
|
+
[plugin sendSpanUpdateEvent:updateEvent];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
- (BOOL)isValidAttribute:(_Nullable id)value {
|
|
92
|
+
if (value == nil || [value isKindOfClass:[NSString class]] || [value isKindOfClass:[NSNumber class]]) {
|
|
93
|
+
return YES;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if ([value isKindOfClass:[NSArray class]]) {
|
|
97
|
+
NSUInteger idx = [value indexOfObjectPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {
|
|
98
|
+
if ([obj isKindOfClass:[NSString class]] || [obj isKindOfClass:[NSNumber class]]) {
|
|
99
|
+
return NO;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// stop the iteration if we find an invalid object
|
|
103
|
+
*stop = YES;
|
|
104
|
+
return YES;
|
|
105
|
+
}];
|
|
106
|
+
|
|
107
|
+
return idx == NSNotFound; // means all objects are valid
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return NO;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
@end
|
|
114
|
+
|
|
115
|
+
@implementation BugsnagJavascriptSpanControl
|
|
116
|
+
|
|
117
|
+
NSString *spanName;
|
|
118
|
+
|
|
119
|
+
- (instancetype)initWithSpanName:(NSString *)name {
|
|
120
|
+
self = [super init];
|
|
121
|
+
if (self) {
|
|
122
|
+
spanName = name;
|
|
123
|
+
}
|
|
124
|
+
return self;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
- (BugsnagJavascriptSpanTransaction *)createUpdateTransaction {
|
|
128
|
+
return [[BugsnagJavascriptSpanTransaction alloc] initWithSpanName:spanName];
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
- (void)retrieveSpanContext:(RemoteSpanContextCallback)callback {
|
|
132
|
+
BugsnagJavascriptSpansPlugin *plugin = [BugsnagJavascriptSpansPlugin singleton];
|
|
133
|
+
if (!plugin) {
|
|
134
|
+
callback(nil);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
int eventId = [plugin registerSpanContextCallback:callback];
|
|
139
|
+
|
|
140
|
+
NSDictionary *contextEvent = @{
|
|
141
|
+
idTransactionKey: @(eventId),
|
|
142
|
+
nameTransactionKey: spanName,
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
[plugin sendSpanContextEvent:contextEvent];
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
@end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#import <Foundation/Foundation.h>
|
|
2
|
+
#import <BugsnagPerformance/BugsnagPerformanceSpanControlProvider.h>
|
|
3
|
+
|
|
4
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
5
|
+
|
|
6
|
+
@interface BugsnagJavascriptSpanControlProvider: NSObject <BugsnagPerformanceSpanControlProvider>
|
|
7
|
+
|
|
8
|
+
@end
|
|
9
|
+
|
|
10
|
+
NS_ASSUME_NONNULL_END
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#import "BugsnagJavascriptSpanControl.h"
|
|
2
|
+
#import "BugsnagJavascriptSpanControl+Private.h"
|
|
3
|
+
#import "BugsnagJavascriptSpanControlProvider.h"
|
|
4
|
+
|
|
5
|
+
@implementation BugsnagJavascriptSpanControlProvider
|
|
6
|
+
|
|
7
|
+
- (id<BugsnagPerformanceSpanControl>)getSpanControlsWithQuery:(BugsnagPerformanceSpanQuery *)query {
|
|
8
|
+
if (query.resultType == [BugsnagJavascriptSpanControl class]) {
|
|
9
|
+
NSString *spanName = [query getAttributeWithName:@"name"];
|
|
10
|
+
if (spanName != nil) {
|
|
11
|
+
return [[BugsnagJavascriptSpanControl alloc] initWithSpanName: spanName];
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return nil;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#import <BugsnagPerformance/BugsnagPerformanceSpanQuery.h>
|
|
2
|
+
|
|
3
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
4
|
+
|
|
5
|
+
@interface BugsnagJavascriptSpanQuery : BugsnagPerformanceSpanQuery
|
|
6
|
+
|
|
7
|
+
+ (instancetype)queryWithName:(nonnull NSString *)name;
|
|
8
|
+
|
|
9
|
+
@end
|
|
10
|
+
|
|
11
|
+
NS_ASSUME_NONNULL_END
|
|
12
|
+
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#import "BugsnagJavascriptSpanQuery.h"
|
|
2
|
+
#import "BugsnagJavascriptSpanControl.h"
|
|
3
|
+
|
|
4
|
+
static NSString * const spanNameAttributeKey = @"name";
|
|
5
|
+
|
|
6
|
+
@implementation BugsnagJavascriptSpanQuery
|
|
7
|
+
|
|
8
|
+
+ (instancetype)queryWithName:(NSString *)spanName {
|
|
9
|
+
NSDictionary *attributes = @{spanNameAttributeKey: spanName};
|
|
10
|
+
return [self queryWithResultType:[BugsnagJavascriptSpanControl class] attributes:attributes];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
@end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#import "BugsnagJavascriptSpansPlugin.h"
|
|
2
|
+
#import "BugsnagJavascriptSpanControl.h"
|
|
3
|
+
#import <React/RCTEventEmitter.h>
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@interface BugsnagJavascriptSpansPlugin ()
|
|
7
|
+
|
|
8
|
+
+ (id)singleton;
|
|
9
|
+
|
|
10
|
+
- (void)setEventEmitter:(RCTEventEmitter *)eventEmitter;
|
|
11
|
+
|
|
12
|
+
- (int)registerSpanUpdateCallback:(OnSpanUpdatedCallback)callback;
|
|
13
|
+
|
|
14
|
+
- (void)sendSpanUpdateEvent:(NSDictionary *)event;
|
|
15
|
+
|
|
16
|
+
- (void)onRemoteSpanUpdated:(int)eventId withResult:(BOOL)result;
|
|
17
|
+
|
|
18
|
+
- (int)registerSpanContextCallback:(RemoteSpanContextCallback)callback;
|
|
19
|
+
|
|
20
|
+
- (void)sendSpanContextEvent:(NSDictionary *)event;
|
|
21
|
+
|
|
22
|
+
- (void)onRemoteSpanContextReceived:(int)eventId withContext:(NSString *)context;
|
|
23
|
+
|
|
24
|
+
@end
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
#import "BugsnagJavascriptSpansPlugin+Private.h"
|
|
2
|
+
#import "BugsnagJavascriptSpanControlProvider.h"
|
|
3
|
+
#import <BugsnagPerformance/BugsnagPerformanceSpan.h>
|
|
4
|
+
#import <BugsnagPerformance/BugsnagPerformancePluginContext.h>
|
|
5
|
+
#import <BugsnagPerformance/BugsnagPerformanceRemoteSpanContext.h>
|
|
6
|
+
|
|
7
|
+
@interface CallbackRegistry : NSObject
|
|
8
|
+
- (int)registerCallback:(id)callback;
|
|
9
|
+
- (id)takeCallback:(int)callbackId;
|
|
10
|
+
@end
|
|
11
|
+
|
|
12
|
+
@implementation CallbackRegistry {
|
|
13
|
+
NSMutableDictionary *_callbacks;
|
|
14
|
+
int _nextCallbackId;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
- (instancetype)init {
|
|
18
|
+
if (self = [super init]) {
|
|
19
|
+
_callbacks = [NSMutableDictionary new];
|
|
20
|
+
_nextCallbackId = 0;
|
|
21
|
+
}
|
|
22
|
+
return self;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
- (int)registerCallback:(id)callback {
|
|
26
|
+
@synchronized (_callbacks) {
|
|
27
|
+
int callbackId = _nextCallbackId++;
|
|
28
|
+
_callbacks[@(callbackId)] = callback;
|
|
29
|
+
return callbackId;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
- (id)takeCallback:(int)callbackId {
|
|
34
|
+
@synchronized (_callbacks) {
|
|
35
|
+
id callback = [_callbacks objectForKey:@(callbackId)];
|
|
36
|
+
if (!callback) {
|
|
37
|
+
return nil;
|
|
38
|
+
}
|
|
39
|
+
[_callbacks removeObjectForKey:@(callbackId)];
|
|
40
|
+
return callback;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@end
|
|
45
|
+
|
|
46
|
+
@interface BugsnagJavascriptSpansPlugin ()
|
|
47
|
+
|
|
48
|
+
@property (nonatomic, weak) RCTEventEmitter *eventEmitter;
|
|
49
|
+
|
|
50
|
+
@end
|
|
51
|
+
|
|
52
|
+
@implementation BugsnagJavascriptSpansPlugin
|
|
53
|
+
|
|
54
|
+
static BugsnagJavascriptSpansPlugin *_sharedInstance = nil;
|
|
55
|
+
|
|
56
|
+
CallbackRegistry *_spanUpdateCallbacks;
|
|
57
|
+
|
|
58
|
+
CallbackRegistry *_spanContextCallbacks;
|
|
59
|
+
|
|
60
|
+
+ (id)singleton {
|
|
61
|
+
return _sharedInstance;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
- (void)installWithContext:(BugsnagPerformancePluginContext *)context {
|
|
65
|
+
_sharedInstance = self;
|
|
66
|
+
_spanUpdateCallbacks = [CallbackRegistry new];
|
|
67
|
+
_spanContextCallbacks = [CallbackRegistry new];
|
|
68
|
+
BugsnagJavascriptSpanControlProvider *spanControlProvider = [BugsnagJavascriptSpanControlProvider new];
|
|
69
|
+
[context addSpanControlProvider:spanControlProvider];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
- (void)start {
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
- (void)setEventEmitter:(RCTEventEmitter *)eventEmitter {
|
|
76
|
+
_eventEmitter = eventEmitter;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
- (int)registerSpanUpdateCallback:(OnSpanUpdatedCallback)callback {
|
|
80
|
+
return [_spanUpdateCallbacks registerCallback:callback];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
- (void)sendSpanUpdateEvent:(NSDictionary *)event {
|
|
84
|
+
@synchronized (self) {
|
|
85
|
+
if (_eventEmitter) {
|
|
86
|
+
[_eventEmitter sendEventWithName:@"bugsnag:spanUpdate" body:event];
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
- (void)onRemoteSpanUpdated:(int)eventId withResult:(BOOL)result {
|
|
92
|
+
OnSpanUpdatedCallback callback = [_spanUpdateCallbacks takeCallback:eventId];
|
|
93
|
+
if (callback) {
|
|
94
|
+
callback(result);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
- (int)registerSpanContextCallback:(RemoteSpanContextCallback)callback {
|
|
99
|
+
return [_spanContextCallbacks registerCallback:callback];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
- (void)sendSpanContextEvent:(NSDictionary *)event {
|
|
103
|
+
@synchronized (self) {
|
|
104
|
+
if (_eventEmitter) {
|
|
105
|
+
[_eventEmitter sendEventWithName:@"bugsnag:retrieveSpanContext" body:event];
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
- (void)onRemoteSpanContextReceived:(int)eventId withContext:(NSString *)context {
|
|
111
|
+
RemoteSpanContextCallback callback = [_spanContextCallbacks takeCallback:eventId];
|
|
112
|
+
if (callback) {
|
|
113
|
+
callback([BugsnagPerformanceRemoteSpanContext contextWithTraceParentString:context]);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
@end
|
package/ios/BugsnagNativeSpans.h
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#import <React/RCTBridgeModule.h>
|
|
2
|
+
#import <React/RCTEventEmitter.h>
|
|
2
3
|
|
|
3
4
|
#ifdef RCT_NEW_ARCH_ENABLED
|
|
4
5
|
#import <BugsnagNativeSpansSpec/BugsnagNativeSpansSpec.h>
|
|
@@ -6,7 +7,7 @@
|
|
|
6
7
|
|
|
7
8
|
NS_ASSUME_NONNULL_BEGIN
|
|
8
9
|
|
|
9
|
-
@interface BugsnagNativeSpans :
|
|
10
|
+
@interface BugsnagNativeSpans : RCTEventEmitter <RCTBridgeModule>
|
|
10
11
|
|
|
11
12
|
@end
|
|
12
13
|
|
|
@@ -1,17 +1,39 @@
|
|
|
1
1
|
#import <BugsnagPerformance/BugsnagPerformanceSpan.h>
|
|
2
|
-
|
|
2
|
+
#import "BugsnagNativeSpansPlugin+Private.h"
|
|
3
|
+
#import "BugsnagJavascriptSpansPlugin+Private.h"
|
|
3
4
|
#import "BugsnagNativeSpans.h"
|
|
4
5
|
|
|
5
6
|
#ifdef RCT_NEW_ARCH_ENABLED
|
|
6
7
|
#import "BugsnagNativeSpansSpec.h"
|
|
7
8
|
#endif
|
|
8
9
|
|
|
9
|
-
#import "BugsnagNativeSpansPlugin+Private.h"
|
|
10
|
-
|
|
11
10
|
@implementation BugsnagNativeSpans
|
|
12
11
|
|
|
13
12
|
RCT_EXPORT_MODULE()
|
|
14
13
|
|
|
14
|
+
- (NSArray<NSString *> *)supportedEvents
|
|
15
|
+
{
|
|
16
|
+
return @[@"bugsnag:spanUpdate", @"bugsnag:retrieveSpanContext"];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
- (void)startObserving
|
|
20
|
+
{
|
|
21
|
+
// Register this instance with the BugsnagJavascriptSpansPlugin
|
|
22
|
+
BugsnagJavascriptSpansPlugin *plugin = [BugsnagJavascriptSpansPlugin singleton];
|
|
23
|
+
if (plugin) {
|
|
24
|
+
[plugin setEventEmitter:self];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
- (void)stopObserving
|
|
29
|
+
{
|
|
30
|
+
// Unregister this instance from the BugsnagJavascriptSpansPlugin
|
|
31
|
+
BugsnagJavascriptSpansPlugin *plugin = [BugsnagJavascriptSpansPlugin singleton];
|
|
32
|
+
if (plugin) {
|
|
33
|
+
[plugin setEventEmitter:nil];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
15
37
|
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(getSpanIdByName:(NSString *)spanName) {
|
|
16
38
|
BugsnagNativeSpansPlugin *plugin = [BugsnagNativeSpansPlugin singleton];
|
|
17
39
|
if (!plugin) {
|
|
@@ -77,6 +99,30 @@ RCT_EXPORT_METHOD(updateSpan:(NSDictionary *)spanId
|
|
|
77
99
|
resolve(@YES);
|
|
78
100
|
}
|
|
79
101
|
|
|
102
|
+
RCT_EXPORT_METHOD(reportSpanUpdateResult:(double)eventId
|
|
103
|
+
result:(BOOL)result
|
|
104
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
105
|
+
reject:(RCTPromiseRejectBlock)reject)
|
|
106
|
+
{
|
|
107
|
+
BugsnagJavascriptSpansPlugin *plugin = [BugsnagJavascriptSpansPlugin singleton];
|
|
108
|
+
if (plugin) {
|
|
109
|
+
[plugin onRemoteSpanUpdated:(int)eventId withResult:result];
|
|
110
|
+
}
|
|
111
|
+
resolve(nil);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
RCT_EXPORT_METHOD(reportSpanContextResult:(double)eventId
|
|
115
|
+
result:(NSString *)result
|
|
116
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
117
|
+
reject:(RCTPromiseRejectBlock)reject)
|
|
118
|
+
{
|
|
119
|
+
BugsnagJavascriptSpansPlugin *plugin = [BugsnagJavascriptSpansPlugin singleton];
|
|
120
|
+
if (plugin) {
|
|
121
|
+
[plugin onRemoteSpanContextReceived:(int)eventId withContext:result];
|
|
122
|
+
}
|
|
123
|
+
resolve(nil);
|
|
124
|
+
}
|
|
125
|
+
|
|
80
126
|
- (void)endSpan:(NSDictionary *)updates span:(BugsnagPerformanceSpan *)span {
|
|
81
127
|
NSNumber *timestampString = updates[@"endTime"];
|
|
82
128
|
if (timestampString) {
|
|
@@ -9,6 +9,10 @@
|
|
|
9
9
|
/* Begin PBXBuildFile section */
|
|
10
10
|
DA3192AA2E0AE8B7009B1271 /* BugsnagNativeSpans.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA3192A62E0AE8B7009B1271 /* BugsnagNativeSpans.mm */; };
|
|
11
11
|
DA3192AB2E0AE8B7009B1271 /* BugsnagNativeSpansPlugin.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA3192A82E0AE8B7009B1271 /* BugsnagNativeSpansPlugin.mm */; };
|
|
12
|
+
DAADC7312E1EBBFC0085E633 /* BugsnagJavascriptSpansPlugin.mm in Sources */ = {isa = PBXBuildFile; fileRef = DAADC7302E1EBBFC0085E633 /* BugsnagJavascriptSpansPlugin.mm */; };
|
|
13
|
+
DAADC7352E1EBE750085E633 /* BugsnagJavascriptSpanControlProvider.mm in Sources */ = {isa = PBXBuildFile; fileRef = DAADC7342E1EBE750085E633 /* BugsnagJavascriptSpanControlProvider.mm */; };
|
|
14
|
+
DAADC73A2E1F2E080085E633 /* BugsnagJavascriptSpanControl.mm in Sources */ = {isa = PBXBuildFile; fileRef = DAADC7392E1F2E080085E633 /* BugsnagJavascriptSpanControl.mm */; };
|
|
15
|
+
DAADC73C2E1F2E3B0085E633 /* BugsnagJavascriptSpanQuery.mm in Sources */ = {isa = PBXBuildFile; fileRef = DAADC73B2E1F2E3B0085E633 /* BugsnagJavascriptSpanQuery.mm */; };
|
|
12
16
|
/* End PBXBuildFile section */
|
|
13
17
|
|
|
14
18
|
/* Begin PBXCopyFilesBuildPhase section */
|
|
@@ -30,6 +34,16 @@
|
|
|
30
34
|
DA3192A72E0AE8B7009B1271 /* BugsnagNativeSpansPlugin.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BugsnagNativeSpansPlugin.h; sourceTree = "<group>"; };
|
|
31
35
|
DA3192A82E0AE8B7009B1271 /* BugsnagNativeSpansPlugin.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = BugsnagNativeSpansPlugin.mm; sourceTree = "<group>"; };
|
|
32
36
|
DA3192A92E0AE8B7009B1271 /* BugsnagNativeSpansPlugin+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "BugsnagNativeSpansPlugin+Private.h"; sourceTree = "<group>"; };
|
|
37
|
+
DAADC72F2E1EBB9D0085E633 /* BugsnagJavascriptSpansPlugin.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BugsnagJavascriptSpansPlugin.h; sourceTree = "<group>"; };
|
|
38
|
+
DAADC7302E1EBBFC0085E633 /* BugsnagJavascriptSpansPlugin.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = BugsnagJavascriptSpansPlugin.mm; sourceTree = "<group>"; };
|
|
39
|
+
DAADC7322E1EBCA00085E633 /* BugsnagJavascriptSpansPlugin+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "BugsnagJavascriptSpansPlugin+Private.h"; sourceTree = "<group>"; };
|
|
40
|
+
DAADC7332E1EBE5B0085E633 /* BugsnagJavascriptSpanControlProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BugsnagJavascriptSpanControlProvider.h; sourceTree = "<group>"; };
|
|
41
|
+
DAADC7342E1EBE750085E633 /* BugsnagJavascriptSpanControlProvider.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = BugsnagJavascriptSpanControlProvider.mm; sourceTree = "<group>"; };
|
|
42
|
+
DAADC7372E1F2AD40085E633 /* BugsnagJavascriptSpanControl.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BugsnagJavascriptSpanControl.h; sourceTree = "<group>"; };
|
|
43
|
+
DAADC7382E1F2AE80085E633 /* BugsnagJavascriptSpanQuery.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BugsnagJavascriptSpanQuery.h; sourceTree = "<group>"; };
|
|
44
|
+
DAADC7392E1F2E080085E633 /* BugsnagJavascriptSpanControl.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = BugsnagJavascriptSpanControl.mm; sourceTree = "<group>"; };
|
|
45
|
+
DAADC73B2E1F2E3B0085E633 /* BugsnagJavascriptSpanQuery.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = BugsnagJavascriptSpanQuery.mm; sourceTree = "<group>"; };
|
|
46
|
+
DAADC73E2E1FF0040085E633 /* BugsnagJavascriptSpanControl+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "BugsnagJavascriptSpanControl+Private.h"; sourceTree = "<group>"; };
|
|
33
47
|
/* End PBXFileReference section */
|
|
34
48
|
|
|
35
49
|
/* Begin PBXFrameworksBuildPhase section */
|
|
@@ -46,11 +60,21 @@
|
|
|
46
60
|
DA31928B2E0AE7D4009B1271 = {
|
|
47
61
|
isa = PBXGroup;
|
|
48
62
|
children = (
|
|
63
|
+
DAADC73E2E1FF0040085E633 /* BugsnagJavascriptSpanControl+Private.h */,
|
|
64
|
+
DAADC7372E1F2AD40085E633 /* BugsnagJavascriptSpanControl.h */,
|
|
65
|
+
DAADC7332E1EBE5B0085E633 /* BugsnagJavascriptSpanControlProvider.h */,
|
|
66
|
+
DAADC7382E1F2AE80085E633 /* BugsnagJavascriptSpanQuery.h */,
|
|
67
|
+
DAADC72F2E1EBB9D0085E633 /* BugsnagJavascriptSpansPlugin.h */,
|
|
68
|
+
DAADC7322E1EBCA00085E633 /* BugsnagJavascriptSpansPlugin+Private.h */,
|
|
49
69
|
DA3192A52E0AE8B7009B1271 /* BugsnagNativeSpans.h */,
|
|
50
|
-
DA3192A62E0AE8B7009B1271 /* BugsnagNativeSpans.mm */,
|
|
51
70
|
DA3192A72E0AE8B7009B1271 /* BugsnagNativeSpansPlugin.h */,
|
|
52
|
-
DA3192A82E0AE8B7009B1271 /* BugsnagNativeSpansPlugin.mm */,
|
|
53
71
|
DA3192A92E0AE8B7009B1271 /* BugsnagNativeSpansPlugin+Private.h */,
|
|
72
|
+
DAADC7392E1F2E080085E633 /* BugsnagJavascriptSpanControl.mm */,
|
|
73
|
+
DAADC7342E1EBE750085E633 /* BugsnagJavascriptSpanControlProvider.mm */,
|
|
74
|
+
DAADC73B2E1F2E3B0085E633 /* BugsnagJavascriptSpanQuery.mm */,
|
|
75
|
+
DAADC7302E1EBBFC0085E633 /* BugsnagJavascriptSpansPlugin.mm */,
|
|
76
|
+
DA3192A62E0AE8B7009B1271 /* BugsnagNativeSpans.mm */,
|
|
77
|
+
DA3192A82E0AE8B7009B1271 /* BugsnagNativeSpansPlugin.mm */,
|
|
54
78
|
DA3192952E0AE7D4009B1271 /* Products */,
|
|
55
79
|
);
|
|
56
80
|
sourceTree = "<group>";
|
|
@@ -123,6 +147,10 @@
|
|
|
123
147
|
isa = PBXSourcesBuildPhase;
|
|
124
148
|
buildActionMask = 2147483647;
|
|
125
149
|
files = (
|
|
150
|
+
DAADC73A2E1F2E080085E633 /* BugsnagJavascriptSpanControl.mm in Sources */,
|
|
151
|
+
DAADC7312E1EBBFC0085E633 /* BugsnagJavascriptSpansPlugin.mm in Sources */,
|
|
152
|
+
DAADC7352E1EBE750085E633 /* BugsnagJavascriptSpanControlProvider.mm in Sources */,
|
|
153
|
+
DAADC73C2E1F2E3B0085E633 /* BugsnagJavascriptSpanQuery.mm in Sources */,
|
|
126
154
|
DA3192AA2E0AE8B7009B1271 /* BugsnagNativeSpans.mm in Sources */,
|
|
127
155
|
DA3192AB2E0AE8B7009B1271 /* BugsnagNativeSpansPlugin.mm in Sources */,
|
|
128
156
|
);
|
|
@@ -10,7 +10,7 @@ static NSString *createNativeSpanId(BugsnagPerformanceSpan *span);
|
|
|
10
10
|
|
|
11
11
|
@implementation BugsnagNativeSpansPlugin {
|
|
12
12
|
// Private instance variable for span timeout timers
|
|
13
|
-
std::map<void *,
|
|
13
|
+
std::map<void *, dispatch_source_t> _spanTimeoutTimers;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
static BugsnagNativeSpansPlugin *_sharedInstance = nil;
|
|
@@ -20,11 +20,23 @@ static BugsnagNativeSpansPlugin *_sharedInstance = nil;
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
// Create a timeout timer for a span
|
|
23
|
-
- (
|
|
23
|
+
- (dispatch_source_t)createSpanTimeoutTimer:(BugsnagPerformanceSpan *)span {
|
|
24
24
|
__weak BugsnagNativeSpansPlugin *weakSelf = self;
|
|
25
|
-
|
|
25
|
+
|
|
26
|
+
dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,
|
|
27
|
+
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0));
|
|
28
|
+
|
|
29
|
+
dispatch_source_set_timer(timer,
|
|
30
|
+
dispatch_time(DISPATCH_TIME_NOW, (int64_t)(kSpanTimeoutInterval * NSEC_PER_SEC)),
|
|
31
|
+
DISPATCH_TIME_FOREVER,
|
|
32
|
+
0);
|
|
33
|
+
|
|
34
|
+
dispatch_source_set_event_handler(timer, ^{
|
|
26
35
|
[weakSelf endNativeSpan:span];
|
|
27
|
-
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
dispatch_resume(timer);
|
|
39
|
+
return timer;
|
|
28
40
|
}
|
|
29
41
|
|
|
30
42
|
// remove the spans from the caches and clean up timer
|
|
@@ -43,7 +55,7 @@ static BugsnagNativeSpansPlugin *_sharedInstance = nil;
|
|
|
43
55
|
auto& timerMap = _spanTimeoutTimers;
|
|
44
56
|
auto it = timerMap.find(key);
|
|
45
57
|
if (it != timerMap.end()) {
|
|
46
|
-
|
|
58
|
+
dispatch_source_cancel(it->second);
|
|
47
59
|
timerMap.erase(it);
|
|
48
60
|
}
|
|
49
61
|
}
|
|
@@ -61,12 +73,18 @@ static BugsnagNativeSpansPlugin *_sharedInstance = nil;
|
|
|
61
73
|
NSString *spanId = createNativeSpanId(span);
|
|
62
74
|
|
|
63
75
|
@synchronized (blockSelf) {
|
|
76
|
+
BugsnagPerformanceSpan *existingSpan = blockSelf.spansByName[span.name];
|
|
77
|
+
if (existingSpan) {
|
|
78
|
+
// If a span with the same name already exists, remove it from the cache and clean up its timer
|
|
79
|
+
[blockSelf endNativeSpan:existingSpan];
|
|
80
|
+
}
|
|
81
|
+
|
|
64
82
|
blockSelf.spansByName[span.name] = span;
|
|
65
83
|
blockSelf.spansById[spanId] = span;
|
|
66
84
|
|
|
67
85
|
// Add a 10 minute timeout to remove the span from caches if not ended
|
|
68
86
|
void *key = (__bridge void *)span;
|
|
69
|
-
|
|
87
|
+
dispatch_source_t timer = [blockSelf createSpanTimeoutTimer:span];
|
|
70
88
|
blockSelf->_spanTimeoutTimers[key] = timer;
|
|
71
89
|
}
|
|
72
90
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bugsnag/plugin-react-native-span-access",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "BugSnag performance monitoring for react-native",
|
|
5
5
|
"homepage": "https://www.bugsnag.com/",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"@bugsnag/react-native-performance": "^2.10.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@bugsnag/core-performance": "^
|
|
27
|
-
"@bugsnag/react-native-performance": "^
|
|
26
|
+
"@bugsnag/core-performance": "^3.0.0",
|
|
27
|
+
"@bugsnag/react-native-performance": "^3.0.0",
|
|
28
28
|
"@react-native/babel-preset": "^0.74.0",
|
|
29
29
|
"@testing-library/jest-native": "^5.4.3",
|
|
30
30
|
"@testing-library/react-native": "^12.4.1"
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"javaPackageName": "com.bugsnag.reactnative.performance.nativespans"
|
|
49
49
|
}
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "efb2df2d41cd87ff875981128b2e8977eaacee49"
|
|
52
52
|
}
|