@bugsnag/plugin-react-native-span-access 3.3.0 → 3.4.1
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/BugsnagNativeSpans.podspec +1 -0
- package/android/src/main/java/com/bugsnag/reactnative/performance/nativespans/BugsnagReactNativeAppStartPlugin.java +132 -0
- package/ios/BugsnagNativeSpans.xcodeproj/project.pbxproj +6 -0
- package/ios/BugsnagReactNativeAppStartPlugin.h +14 -0
- package/ios/BugsnagReactNativeAppStartPlugin.mm +138 -0
- package/package.json +3 -3
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
package com.bugsnag.reactnative.performance.nativespans;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.Nullable;
|
|
4
|
+
|
|
5
|
+
import com.bugsnag.android.performance.Span;
|
|
6
|
+
import com.bugsnag.android.performance.SpanContext;
|
|
7
|
+
import com.bugsnag.android.performance.OnSpanEndCallback;
|
|
8
|
+
import com.bugsnag.android.performance.OnSpanStartCallback;
|
|
9
|
+
import com.bugsnag.android.performance.Plugin;
|
|
10
|
+
import com.bugsnag.android.performance.PluginContext;
|
|
11
|
+
import com.bugsnag.android.performance.RemoteSpanContext;
|
|
12
|
+
|
|
13
|
+
import com.bugsnag.android.performance.internal.SpanImpl.Condition;
|
|
14
|
+
import com.bugsnag.android.performance.internal.SpanCategory;
|
|
15
|
+
import com.bugsnag.android.performance.internal.SpanImpl;
|
|
16
|
+
|
|
17
|
+
import com.bugsnag.reactnative.performance.AppStartProvider;
|
|
18
|
+
import com.bugsnag.reactnative.performance.AppStartRegistry;
|
|
19
|
+
|
|
20
|
+
import java.util.concurrent.atomic.AtomicReference;
|
|
21
|
+
import java.util.concurrent.atomic.AtomicBoolean;
|
|
22
|
+
|
|
23
|
+
public class BugsnagReactNativeAppStartPlugin implements Plugin, AppStartProvider {
|
|
24
|
+
|
|
25
|
+
private static final long DEFAULT_SPAN_BLOCK_TIMEOUT_MS = 5000;
|
|
26
|
+
|
|
27
|
+
// Container class to ensure atomic updates of related fields
|
|
28
|
+
private static class ViewLoadCondition {
|
|
29
|
+
final String spanId;
|
|
30
|
+
final Condition condition;
|
|
31
|
+
|
|
32
|
+
ViewLoadCondition(String spanId, Condition condition) {
|
|
33
|
+
this.spanId = spanId;
|
|
34
|
+
this.condition = condition;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private final AtomicReference<ViewLoadCondition> viewLoadCondition = new AtomicReference<>(null);
|
|
39
|
+
private volatile boolean appStartComplete = false;
|
|
40
|
+
private final long spanBlockTimeoutMs;
|
|
41
|
+
|
|
42
|
+
public BugsnagReactNativeAppStartPlugin() {
|
|
43
|
+
this(DEFAULT_SPAN_BLOCK_TIMEOUT_MS);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public BugsnagReactNativeAppStartPlugin(long timeoutMs) {
|
|
47
|
+
this.spanBlockTimeoutMs = timeoutMs;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@Override
|
|
51
|
+
public void install(PluginContext ctx) {
|
|
52
|
+
// Register this plugin as the AppStartProvider with the core React Native Performance module
|
|
53
|
+
AppStartRegistry.register(this);
|
|
54
|
+
|
|
55
|
+
ctx.addOnSpanStartCallback(PluginContext.NORM_PRIORITY + 1, new OnSpanStartCallback() {
|
|
56
|
+
@Override
|
|
57
|
+
public void onSpanStart(Span span) {
|
|
58
|
+
BugsnagReactNativeAppStartPlugin.this.onSpanStart(span);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
ctx.addOnSpanEndCallback(PluginContext.NORM_PRIORITY - 1, new OnSpanEndCallback() {
|
|
63
|
+
@Override
|
|
64
|
+
public boolean onSpanEnd(Span span) {
|
|
65
|
+
return BugsnagReactNativeAppStartPlugin.this.onSpanEnd(span);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@Override
|
|
71
|
+
public void start() {}
|
|
72
|
+
|
|
73
|
+
@Nullable
|
|
74
|
+
@Override
|
|
75
|
+
public String getAppStartParent() {
|
|
76
|
+
ViewLoadCondition currentCondition = viewLoadCondition.get();
|
|
77
|
+
if (currentCondition != null) {
|
|
78
|
+
SpanContext nativeParent = currentCondition.condition.upgrade();
|
|
79
|
+
if (nativeParent != null) {
|
|
80
|
+
return RemoteSpanContext.encodeAsTraceParent(nativeParent);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
@Override
|
|
88
|
+
public void endAppStart(long endTime) {
|
|
89
|
+
ViewLoadCondition currentCondition = viewLoadCondition.getAndSet(null);
|
|
90
|
+
if (currentCondition != null) {
|
|
91
|
+
currentCondition.condition.close(endTime);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
appStartComplete = true;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
private void onSpanStart(Span span) {
|
|
98
|
+
if (appStartComplete) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
SpanImpl spanImpl = (SpanImpl)span;
|
|
103
|
+
if (spanImpl.getAttributes().get("bugsnag.span.category") != SpanCategory.CATEGORY_VIEW_LOAD) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
ViewLoadCondition currentCondition = viewLoadCondition.get();
|
|
108
|
+
if (currentCondition != null) {
|
|
109
|
+
currentCondition.condition.cancel();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Only set viewLoadCondition if block() returned a non-null value
|
|
113
|
+
Condition spanCondition = spanImpl.block(spanBlockTimeoutMs);
|
|
114
|
+
if (spanCondition != null) {
|
|
115
|
+
String spanId = RemoteSpanContext.encodeAsTraceParent(spanImpl);
|
|
116
|
+
viewLoadCondition.set(new ViewLoadCondition(spanId, spanCondition));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
private boolean onSpanEnd(Span span) {
|
|
121
|
+
String spanId = RemoteSpanContext.encodeAsTraceParent(span);
|
|
122
|
+
ViewLoadCondition currentCondition = viewLoadCondition.get();
|
|
123
|
+
|
|
124
|
+
if (currentCondition != null && spanId.equals(currentCondition.spanId)) {
|
|
125
|
+
if (viewLoadCondition.compareAndSet(currentCondition, null)) {
|
|
126
|
+
currentCondition.condition.cancel();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -9,6 +9,7 @@
|
|
|
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
|
+
DA862E902ED89F1700F95EAD /* BugsnagReactNativeAppStartPlugin.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA862E8F2ED89F1700F95EAD /* BugsnagReactNativeAppStartPlugin.mm */; };
|
|
12
13
|
DAADC7312E1EBBFC0085E633 /* BugsnagJavascriptSpansPlugin.mm in Sources */ = {isa = PBXBuildFile; fileRef = DAADC7302E1EBBFC0085E633 /* BugsnagJavascriptSpansPlugin.mm */; };
|
|
13
14
|
DAADC7352E1EBE750085E633 /* BugsnagJavascriptSpanControlProvider.mm in Sources */ = {isa = PBXBuildFile; fileRef = DAADC7342E1EBE750085E633 /* BugsnagJavascriptSpanControlProvider.mm */; };
|
|
14
15
|
DAADC73A2E1F2E080085E633 /* BugsnagJavascriptSpanControl.mm in Sources */ = {isa = PBXBuildFile; fileRef = DAADC7392E1F2E080085E633 /* BugsnagJavascriptSpanControl.mm */; };
|
|
@@ -34,6 +35,8 @@
|
|
|
34
35
|
DA3192A72E0AE8B7009B1271 /* BugsnagNativeSpansPlugin.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BugsnagNativeSpansPlugin.h; sourceTree = "<group>"; };
|
|
35
36
|
DA3192A82E0AE8B7009B1271 /* BugsnagNativeSpansPlugin.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = BugsnagNativeSpansPlugin.mm; sourceTree = "<group>"; };
|
|
36
37
|
DA3192A92E0AE8B7009B1271 /* BugsnagNativeSpansPlugin+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "BugsnagNativeSpansPlugin+Private.h"; sourceTree = "<group>"; };
|
|
38
|
+
DA862E8E2ED89F1700F95EAD /* BugsnagReactNativeAppStartPlugin.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BugsnagReactNativeAppStartPlugin.h; sourceTree = "<group>"; };
|
|
39
|
+
DA862E8F2ED89F1700F95EAD /* BugsnagReactNativeAppStartPlugin.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = BugsnagReactNativeAppStartPlugin.mm; sourceTree = "<group>"; };
|
|
37
40
|
DAADC72F2E1EBB9D0085E633 /* BugsnagJavascriptSpansPlugin.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BugsnagJavascriptSpansPlugin.h; sourceTree = "<group>"; };
|
|
38
41
|
DAADC7302E1EBBFC0085E633 /* BugsnagJavascriptSpansPlugin.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = BugsnagJavascriptSpansPlugin.mm; sourceTree = "<group>"; };
|
|
39
42
|
DAADC7322E1EBCA00085E633 /* BugsnagJavascriptSpansPlugin+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "BugsnagJavascriptSpansPlugin+Private.h"; sourceTree = "<group>"; };
|
|
@@ -60,6 +63,8 @@
|
|
|
60
63
|
DA31928B2E0AE7D4009B1271 = {
|
|
61
64
|
isa = PBXGroup;
|
|
62
65
|
children = (
|
|
66
|
+
DA862E8E2ED89F1700F95EAD /* BugsnagReactNativeAppStartPlugin.h */,
|
|
67
|
+
DA862E8F2ED89F1700F95EAD /* BugsnagReactNativeAppStartPlugin.mm */,
|
|
63
68
|
DAADC73E2E1FF0040085E633 /* BugsnagJavascriptSpanControl+Private.h */,
|
|
64
69
|
DAADC7372E1F2AD40085E633 /* BugsnagJavascriptSpanControl.h */,
|
|
65
70
|
DAADC7332E1EBE5B0085E633 /* BugsnagJavascriptSpanControlProvider.h */,
|
|
@@ -147,6 +152,7 @@
|
|
|
147
152
|
isa = PBXSourcesBuildPhase;
|
|
148
153
|
buildActionMask = 2147483647;
|
|
149
154
|
files = (
|
|
155
|
+
DA862E902ED89F1700F95EAD /* BugsnagReactNativeAppStartPlugin.mm in Sources */,
|
|
150
156
|
DAADC73A2E1F2E080085E633 /* BugsnagJavascriptSpanControl.mm in Sources */,
|
|
151
157
|
DAADC7312E1EBBFC0085E633 /* BugsnagJavascriptSpansPlugin.mm in Sources */,
|
|
152
158
|
DAADC7352E1EBE750085E633 /* BugsnagJavascriptSpanControlProvider.mm in Sources */,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#import <Foundation/Foundation.h>
|
|
2
|
+
#import <BugsnagPerformance/BugsnagPerformancePlugin.h>
|
|
3
|
+
#import <BugsnagReactNativePerformance/BugsnagPerformanceAppStartProvider.h>
|
|
4
|
+
|
|
5
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
6
|
+
|
|
7
|
+
@interface BugsnagReactNativeAppStartPlugin: NSObject <BugsnagPerformancePlugin, BugsnagPerformanceAppStartProvider>
|
|
8
|
+
|
|
9
|
+
- (instancetype)init;
|
|
10
|
+
- (instancetype)initWithTimeout:(NSTimeInterval)timeout;
|
|
11
|
+
|
|
12
|
+
@end
|
|
13
|
+
|
|
14
|
+
NS_ASSUME_NONNULL_END
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
|
|
2
|
+
#import "BugsnagReactNativeAppStartPlugin.h"
|
|
3
|
+
#import <BugsnagPerformance/BugsnagPerformancePluginContext.h>
|
|
4
|
+
#import <BugsnagPerformance/BugsnagPerformanceSpan.h>
|
|
5
|
+
#import <BugsnagPerformance/BugsnagPerformanceSpanCondition.h>
|
|
6
|
+
#import <BugsnagPerformance/BugsnagPerformanceSpanContext.h>
|
|
7
|
+
#import <BugsnagReactNativePerformance/BugsnagPerformanceAppStartRegistry.h>
|
|
8
|
+
|
|
9
|
+
static const NSTimeInterval kDefaultSpanBlockTimeoutInterval = 5; // 5s default timeout
|
|
10
|
+
|
|
11
|
+
@interface BugsnagReactNativeAppStartPlugin ()
|
|
12
|
+
@property (nonatomic, strong) NSString *currentSpanId;
|
|
13
|
+
@property (nonatomic, strong) BugsnagPerformanceSpanCondition *currentCondition;
|
|
14
|
+
@property (atomic, assign) BOOL appStartComplete;
|
|
15
|
+
@property (nonatomic, assign) NSTimeInterval spanBlockTimeoutInterval;
|
|
16
|
+
@end
|
|
17
|
+
|
|
18
|
+
// Attributes are in the private header for BugsnagPerformanceSpan,
|
|
19
|
+
// but are needed to check span category, so we declare them here
|
|
20
|
+
@interface BugsnagPerformanceSpan ()
|
|
21
|
+
@property (nonatomic,readonly) NSMutableDictionary *attributes;
|
|
22
|
+
@end
|
|
23
|
+
|
|
24
|
+
@implementation BugsnagReactNativeAppStartPlugin
|
|
25
|
+
|
|
26
|
+
- (instancetype)init {
|
|
27
|
+
return [self initWithTimeout:kDefaultSpanBlockTimeoutInterval];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
- (instancetype)initWithTimeout:(NSTimeInterval)timeout {
|
|
31
|
+
if (self = [super init]) {
|
|
32
|
+
_spanBlockTimeoutInterval = timeout;
|
|
33
|
+
}
|
|
34
|
+
return self;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
- (void)installWithContext:(BugsnagPerformancePluginContext *)context {
|
|
38
|
+
// Register this plugin as the AppStartProvider with the core React Native Performance module
|
|
39
|
+
[BugsnagPerformanceAppStartRegistry registerProvider:self];
|
|
40
|
+
__weak BugsnagReactNativeAppStartPlugin *weakSelf = self;
|
|
41
|
+
|
|
42
|
+
// Add span start callback with high priority (equivalent to NORM_PRIORITY + 1)
|
|
43
|
+
BugsnagPerformanceSpanStartCallback spanStartCallback = ^(BugsnagPerformanceSpan *span) {
|
|
44
|
+
[weakSelf onSpanStart:span];
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// Add span end callback with low priority (equivalent to NORM_PRIORITY - 1)
|
|
48
|
+
BugsnagPerformanceSpanEndCallback spanEndCallback = ^(BugsnagPerformanceSpan *span) {
|
|
49
|
+
return [weakSelf onSpanEnd:span];
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
[context addOnSpanStartCallback:spanStartCallback priority:BugsnagPerformancePriorityHigh];
|
|
53
|
+
[context addOnSpanEndCallback:spanEndCallback priority:BugsnagPerformancePriorityLow];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
- (void)start {
|
|
57
|
+
// Plugin start implementation
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
- (NSString *)getAppStartParent {
|
|
61
|
+
BugsnagPerformanceSpanCondition *condition;
|
|
62
|
+
@synchronized (self) {
|
|
63
|
+
condition = _currentCondition;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (condition) {
|
|
67
|
+
BugsnagPerformanceSpanContext *nativeParent = [condition upgrade];
|
|
68
|
+
if (nativeParent) {
|
|
69
|
+
return [nativeParent encodedAsTraceParent];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return nil;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
- (void)endAppStart:(NSDate *)endTime {
|
|
76
|
+
BugsnagPerformanceSpanCondition *condition;
|
|
77
|
+
@synchronized (self) {
|
|
78
|
+
condition = _currentCondition;
|
|
79
|
+
_currentCondition = nil;
|
|
80
|
+
_currentSpanId = nil;
|
|
81
|
+
_appStartComplete = YES;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (condition) {
|
|
85
|
+
[condition closeWithEndTime:endTime];
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
- (void)onSpanStart:(BugsnagPerformanceSpan *)span {
|
|
90
|
+
// Check app start completion status (atomic read)
|
|
91
|
+
if (_appStartComplete) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Check if this is a view_load span by examining attributes
|
|
96
|
+
NSString *category = span.attributes[@"bugsnag.span.category"];
|
|
97
|
+
if (![category isEqualToString:@"view_load"]) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Block the span (outside synchronized block)
|
|
102
|
+
BugsnagPerformanceSpanCondition *spanCondition = [span blockWithTimeout:_spanBlockTimeoutInterval];
|
|
103
|
+
|
|
104
|
+
// Update shared state atomically
|
|
105
|
+
@synchronized (self) {
|
|
106
|
+
// Cancel any existing condition
|
|
107
|
+
if (_currentCondition) {
|
|
108
|
+
[_currentCondition cancel];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Only set current condition if block() returned a non-null value
|
|
112
|
+
if (spanCondition) {
|
|
113
|
+
_currentSpanId = [span encodedAsTraceParent];
|
|
114
|
+
_currentCondition = spanCondition;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
- (BOOL)onSpanEnd:(BugsnagPerformanceSpan *)span {
|
|
120
|
+
NSString *spanId = [span encodedAsTraceParent];
|
|
121
|
+
|
|
122
|
+
BugsnagPerformanceSpanCondition *conditionToCancel = nil;
|
|
123
|
+
@synchronized (self) {
|
|
124
|
+
if (_currentCondition && [spanId isEqualToString:_currentSpanId]) {
|
|
125
|
+
conditionToCancel = _currentCondition;
|
|
126
|
+
_currentCondition = nil;
|
|
127
|
+
_currentSpanId = nil;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (conditionToCancel) {
|
|
132
|
+
[conditionToCancel cancel];
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return YES;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
@end
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bugsnag/plugin-react-native-span-access",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.1",
|
|
4
4
|
"description": "BugSnag performance monitoring for react-native",
|
|
5
5
|
"homepage": "https://www.bugsnag.com/",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@bugsnag/core-performance": "^3.2.0",
|
|
27
|
-
"@bugsnag/react-native-performance": "^3.
|
|
27
|
+
"@bugsnag/react-native-performance": "^3.4.1",
|
|
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": "24b03e940681936df464f464e1cb5990ac302987"
|
|
52
52
|
}
|