@bugsnag/plugin-react-native-span-access 2.15.0 → 3.0.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/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 +5 -5
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
package com.bugsnag.reactnative.performance.nativespans;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
|
|
5
|
+
public interface JavascriptSpanControl {
|
|
6
|
+
JavascriptSpanTransaction createUpdateTransaction();
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Request the {@code SpanContext} data represented by the named span. If the span is not currently open,
|
|
10
|
+
* is not available or the app is not connected: the callback will be invoked with a {@code null} value.
|
|
11
|
+
*
|
|
12
|
+
* @param callback the callback that should recieve the remote {@code SpanContext}
|
|
13
|
+
*/
|
|
14
|
+
void retrieveSpanContext(@NonNull OnSpanContextRetrievedCallback callback);
|
|
15
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
package com.bugsnag.reactnative.performance.nativespans;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
|
|
5
|
+
import com.facebook.react.bridge.Arguments;
|
|
6
|
+
import com.facebook.react.bridge.WritableArray;
|
|
7
|
+
import com.facebook.react.bridge.WritableMap;
|
|
8
|
+
|
|
9
|
+
import static com.bugsnag.reactnative.performance.nativespans.JavascriptSpanTransactionImpl.ID;
|
|
10
|
+
import static com.bugsnag.reactnative.performance.nativespans.JavascriptSpanTransactionImpl.NAME;
|
|
11
|
+
|
|
12
|
+
class JavascriptSpanControlImpl implements JavascriptSpanControl {
|
|
13
|
+
private final String spanName;
|
|
14
|
+
|
|
15
|
+
JavascriptSpanControlImpl(String spanName) {
|
|
16
|
+
this.spanName = spanName;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@Override
|
|
20
|
+
public JavascriptSpanTransaction createUpdateTransaction() {
|
|
21
|
+
return new JavascriptSpanTransactionImpl(spanName);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@Override
|
|
25
|
+
public void retrieveSpanContext(@NonNull OnSpanContextRetrievedCallback callback) {
|
|
26
|
+
if (callback == null) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
BugsnagNativeSpans spans = BugsnagNativeSpans.getInstance();
|
|
31
|
+
|
|
32
|
+
if (spans == null) {
|
|
33
|
+
callback.onSpanContextRetrieved(null);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
WritableMap retrieveSpanEvent = Arguments.createMap();
|
|
37
|
+
retrieveSpanEvent.putString(NAME, spanName);
|
|
38
|
+
|
|
39
|
+
int callbackId = spans.registerSpanContextCallback(callback);
|
|
40
|
+
retrieveSpanEvent.putInt(ID, callbackId);
|
|
41
|
+
|
|
42
|
+
if (!spans.emitRetrieveSpanContextEvent(retrieveSpanEvent)) {
|
|
43
|
+
callback.onSpanContextRetrieved(null);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
package com.bugsnag.reactnative.performance.nativespans;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.Nullable;
|
|
4
|
+
import androidx.annotation.NonNull;
|
|
5
|
+
|
|
6
|
+
import com.bugsnag.android.performance.controls.SpanQuery;
|
|
7
|
+
import com.bugsnag.android.performance.controls.SpanControlProvider;
|
|
8
|
+
|
|
9
|
+
class JavascriptSpanControlProvider implements SpanControlProvider<JavascriptSpanControl> {
|
|
10
|
+
@Nullable
|
|
11
|
+
@Override
|
|
12
|
+
public <Q extends SpanQuery<? extends JavascriptSpanControl>> JavascriptSpanControl get(@NonNull Q query) {
|
|
13
|
+
if (query instanceof JavascriptSpanByName) {
|
|
14
|
+
String spanName = ((JavascriptSpanByName) query).getSpanName();
|
|
15
|
+
return new JavascriptSpanControlImpl(spanName);
|
|
16
|
+
}
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
package com.bugsnag.reactnative.performance.nativespans;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import androidx.annotation.Nullable;
|
|
5
|
+
|
|
6
|
+
public interface JavascriptSpanTransaction {
|
|
7
|
+
JavascriptSpanTransaction end();
|
|
8
|
+
JavascriptSpanTransaction end(long endTime);
|
|
9
|
+
|
|
10
|
+
JavascriptSpanTransaction setAttribute(@NonNull String key, @Nullable Object value);
|
|
11
|
+
|
|
12
|
+
void commit(@Nullable OnRemoteSpanUpdatedCallback callback);
|
|
13
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
package com.bugsnag.reactnative.performance.nativespans;
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.Arguments;
|
|
4
|
+
import com.facebook.react.bridge.WritableArray;
|
|
5
|
+
import com.facebook.react.bridge.WritableMap;
|
|
6
|
+
|
|
7
|
+
import java.util.LinkedHashMap;
|
|
8
|
+
import java.util.Collection;
|
|
9
|
+
import java.util.ArrayList;
|
|
10
|
+
import java.util.List;
|
|
11
|
+
import java.util.Map;
|
|
12
|
+
import java.util.Set;
|
|
13
|
+
|
|
14
|
+
import com.bugsnag.android.performance.internal.BugsnagClock;
|
|
15
|
+
|
|
16
|
+
class JavascriptSpanTransactionImpl implements JavascriptSpanTransaction {
|
|
17
|
+
|
|
18
|
+
static final String ID = "id";
|
|
19
|
+
static final String NAME = "name";
|
|
20
|
+
static final String VALUE = "value";
|
|
21
|
+
static final String ATTRIBUTES = "attributes";
|
|
22
|
+
static final String END_TIME = "endTime";
|
|
23
|
+
static final String IS_ENDED = "isEnded";
|
|
24
|
+
|
|
25
|
+
private final String spanName;
|
|
26
|
+
|
|
27
|
+
private final LinkedHashMap<String, Object> attributes = new LinkedHashMap<>();
|
|
28
|
+
|
|
29
|
+
private boolean isEnded = false;
|
|
30
|
+
private long endTime = -1L;
|
|
31
|
+
private boolean isOpen = true;
|
|
32
|
+
|
|
33
|
+
JavascriptSpanTransactionImpl(String spanName) {
|
|
34
|
+
this.spanName = spanName;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@Override
|
|
38
|
+
public JavascriptSpanTransaction end() {
|
|
39
|
+
return end(-1L);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@Override
|
|
43
|
+
public JavascriptSpanTransaction end(long endTime) {
|
|
44
|
+
if (!isOpen) {
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
this.isEnded = true;
|
|
49
|
+
this.endTime = endTime >= 0
|
|
50
|
+
? BugsnagClock.INSTANCE.elapsedNanosToUnixTime(endTime)
|
|
51
|
+
: BugsnagClock.INSTANCE.currentUnixNanoTime();
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@Override
|
|
56
|
+
public JavascriptSpanTransaction setAttribute(String key, Object value) {
|
|
57
|
+
if (!isOpen) {
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
attributes.remove(key); // Remove any existing attribute, moving the value to the end
|
|
62
|
+
attributes.put(key, value);
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@Override
|
|
67
|
+
public void commit(OnRemoteSpanUpdatedCallback callback) {
|
|
68
|
+
if (!isOpen) {
|
|
69
|
+
if (callback != null) callback.onRemoteSpanUpdated(false);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
isOpen = false;
|
|
74
|
+
|
|
75
|
+
BugsnagNativeSpans spans = BugsnagNativeSpans.getInstance();
|
|
76
|
+
if (spans == null) {
|
|
77
|
+
if (callback != null) callback.onRemoteSpanUpdated(false);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
WritableMap updateTransaction = Arguments.createMap();
|
|
82
|
+
updateTransaction.putString(NAME, spanName);
|
|
83
|
+
|
|
84
|
+
Set<Map.Entry<String, Object>> entries = attributes.entrySet();
|
|
85
|
+
WritableArray attributesArray = Arguments.createArray();
|
|
86
|
+
for (Map.Entry<String, Object> entry : entries) {
|
|
87
|
+
try {
|
|
88
|
+
WritableMap attributeMap = Arguments.createMap();
|
|
89
|
+
attributeMap.putString(NAME, entry.getKey());
|
|
90
|
+
Object value = entry.getValue();
|
|
91
|
+
|
|
92
|
+
if (value instanceof String) {
|
|
93
|
+
attributeMap.putString(VALUE, (String) value);
|
|
94
|
+
} else if (value instanceof Integer) {
|
|
95
|
+
attributeMap.putInt(VALUE, (Integer) value);
|
|
96
|
+
} else if (value instanceof Number) {
|
|
97
|
+
attributeMap.putDouble(VALUE, ((Number) value).doubleValue());
|
|
98
|
+
} else if (value instanceof Boolean) {
|
|
99
|
+
attributeMap.putBoolean(VALUE, (Boolean) value);
|
|
100
|
+
} else if (value instanceof int[] ||
|
|
101
|
+
value instanceof long[] ||
|
|
102
|
+
value instanceof float[] ||
|
|
103
|
+
value instanceof double[] ||
|
|
104
|
+
value instanceof Integer[] ||
|
|
105
|
+
value instanceof Long[] ||
|
|
106
|
+
value instanceof Float[] ||
|
|
107
|
+
value instanceof Double[] ||
|
|
108
|
+
value instanceof String[] ||
|
|
109
|
+
value instanceof boolean[] ||
|
|
110
|
+
value instanceof Boolean[]
|
|
111
|
+
) {
|
|
112
|
+
attributeMap.putArray(VALUE, Arguments.makeNativeArray(value));
|
|
113
|
+
} else if (value instanceof List) {
|
|
114
|
+
attributeMap.putArray(VALUE, Arguments.makeNativeArray((List<?>) value));
|
|
115
|
+
} else if (value instanceof Collection) {
|
|
116
|
+
attributeMap.putArray(
|
|
117
|
+
VALUE,
|
|
118
|
+
Arguments.makeNativeArray(new ArrayList<>((Collection<?>) value))
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
attributesArray.pushMap(attributeMap);
|
|
123
|
+
} catch (Exception e) {
|
|
124
|
+
// If we can't convert the value to a supported type, skip it
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
updateTransaction.putArray(ATTRIBUTES, attributesArray);
|
|
130
|
+
|
|
131
|
+
if (isEnded) {
|
|
132
|
+
updateTransaction.putDouble(END_TIME, endTime);
|
|
133
|
+
updateTransaction.putBoolean(IS_ENDED, true);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
int callbackId = -1;
|
|
137
|
+
if (callback != null) {
|
|
138
|
+
// register the callback *last* to avoid memory leaks from earlier exceptions
|
|
139
|
+
callbackId = spans.registerUpdateCallback(callback);
|
|
140
|
+
updateTransaction.putInt(ID, callbackId);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (!spans.emitSpanUpdateEvent(updateTransaction) && callback != null) {
|
|
144
|
+
// If the event could not be emitted, notify the callback with a failure
|
|
145
|
+
callback.onRemoteSpanUpdated(false);
|
|
146
|
+
|
|
147
|
+
if (callbackId >= 0) {
|
|
148
|
+
// If we registered a callback, unregister it
|
|
149
|
+
spans.takeUpdateCallback(callbackId);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
package com.bugsnag.reactnative.performance.nativespans;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.Nullable;
|
|
4
|
+
|
|
5
|
+
import com.bugsnag.android.performance.SpanContext;
|
|
6
|
+
|
|
7
|
+
public interface OnSpanContextRetrievedCallback {
|
|
8
|
+
/**
|
|
9
|
+
* Called with the retrieved remote {@link SpanContext} or {@code null} if the context could not be retrieved.
|
|
10
|
+
*
|
|
11
|
+
* @param remoteSpanContext the remote {@link SpanContext} that was requested (or {@code null})
|
|
12
|
+
*/
|
|
13
|
+
void onSpanContextRetrieved(@Nullable SpanContext remoteSpanContext);
|
|
14
|
+
}
|
|
@@ -33,4 +33,24 @@ public class BugsnagNativeSpansModule extends NativeBugsnagNativeSpansSpec {
|
|
|
33
33
|
public void updateSpan(ReadableMap spanId, ReadableMap updates, Promise promise) {
|
|
34
34
|
delegate.updateSpan(spanId, updates, promise);
|
|
35
35
|
}
|
|
36
|
+
|
|
37
|
+
@Override
|
|
38
|
+
public void reportSpanUpdateResult(double eventId, boolean result, Promise promise) {
|
|
39
|
+
delegate.reportSpanUpdateResult(eventId, result, promise);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@Override
|
|
43
|
+
public void reportSpanContextResult(double eventId, String result, Promise promise) {
|
|
44
|
+
delegate.reportSpanContextResult(eventId, result, promise);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@Override
|
|
48
|
+
public void addListener(String eventType) {
|
|
49
|
+
// noop - required for EventEmitter support
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@Override
|
|
53
|
+
public void removeListeners(double count) {
|
|
54
|
+
// noop - required for EventEmitter support
|
|
55
|
+
}
|
|
36
56
|
}
|
|
@@ -33,4 +33,24 @@ public class BugsnagNativeSpansModule extends ReactContextBaseJavaModule {
|
|
|
33
33
|
public void updateSpan(ReadableMap spanId, ReadableMap updates, Promise promise) {
|
|
34
34
|
delegate.updateSpan(spanId, updates, promise);
|
|
35
35
|
}
|
|
36
|
+
|
|
37
|
+
@ReactMethod
|
|
38
|
+
public void reportSpanUpdateResult(double eventId, boolean result, Promise promise) {
|
|
39
|
+
delegate.reportSpanUpdateResult(eventId, result, promise);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@ReactMethod
|
|
43
|
+
public void reportSpanContextResult(double eventId, String result, Promise promise) {
|
|
44
|
+
delegate.reportSpanContextResult(eventId, result, promise);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@ReactMethod
|
|
48
|
+
public void addListener(String eventType) {
|
|
49
|
+
// noop - required for EventEmitter support
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@ReactMethod
|
|
53
|
+
public void removeListeners(double count) {
|
|
54
|
+
// noop - required for EventEmitter support
|
|
55
|
+
}
|
|
36
56
|
}
|
|
@@ -6,6 +6,14 @@ export interface Spec extends TurboModule {
|
|
|
6
6
|
getSpanIdByName: (spanName: string) => UnsafeObject | undefined
|
|
7
7
|
|
|
8
8
|
updateSpan: (spanId: UnsafeObject, updates: UnsafeObject) => Promise<boolean>
|
|
9
|
+
|
|
10
|
+
addListener: (eventType: string) => void
|
|
11
|
+
|
|
12
|
+
removeListeners: (count: number) => void
|
|
13
|
+
|
|
14
|
+
reportSpanUpdateResult: (eventId: number, result: boolean) => Promise<void>
|
|
15
|
+
|
|
16
|
+
reportSpanContextResult: (eventId: number, result: string | null) => Promise<void>
|
|
9
17
|
}
|
|
10
18
|
|
|
11
19
|
export default TurboModuleRegistry.get<Spec>(
|
package/dist/index.js
CHANGED
|
@@ -1,58 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
class NativeSpanQuery extends SpanQuery {
|
|
5
|
-
constructor(name) {
|
|
6
|
-
super();
|
|
7
|
-
this.name = name;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
const NativeNativeSpansModule = TurboModuleRegistry.get('BugsnagNativeSpans');
|
|
11
|
-
class NativeSpanControlImpl {
|
|
12
|
-
constructor(id, traceId, clock) {
|
|
13
|
-
this.id = id;
|
|
14
|
-
this.traceId = traceId;
|
|
15
|
-
this.clock = clock;
|
|
16
|
-
}
|
|
17
|
-
updateSpan(update) {
|
|
18
|
-
const transaction = {
|
|
19
|
-
attributes: [],
|
|
20
|
-
isEnded: false
|
|
21
|
-
};
|
|
22
|
-
update({
|
|
23
|
-
end: (endTime) => {
|
|
24
|
-
const safeEndTime = timeToNumber(this.clock, endTime);
|
|
25
|
-
transaction.endTime = this.clock.toUnixNanoseconds(safeEndTime);
|
|
26
|
-
transaction.isEnded = true;
|
|
27
|
-
},
|
|
28
|
-
setAttribute: (name, value) => {
|
|
29
|
-
transaction.attributes.push({ name, value });
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
33
|
-
return NativeNativeSpansModule.updateSpan({ spanId: this.id, traceId: this.traceId }, transaction);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
class NativeSpanControlProvider {
|
|
37
|
-
constructor(clock) {
|
|
38
|
-
this.clock = clock;
|
|
39
|
-
}
|
|
40
|
-
getSpanControls(query) {
|
|
41
|
-
if (query instanceof NativeSpanQuery && NativeNativeSpansModule) {
|
|
42
|
-
const spanId = NativeNativeSpansModule.getSpanIdByName(query.name);
|
|
43
|
-
if (spanId) {
|
|
44
|
-
return new NativeSpanControlImpl(spanId.spanId, spanId.traceId, this.clock);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
class BugsnagNativeSpansPlugin {
|
|
51
|
-
install(context) {
|
|
52
|
-
const spanControlProvider = new NativeSpanControlProvider(context.clock);
|
|
53
|
-
context.addSpanControlProvider(spanControlProvider);
|
|
54
|
-
}
|
|
55
|
-
start() { }
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export { BugsnagNativeSpansPlugin, NativeSpanControlProvider, NativeSpanQuery };
|
|
1
|
+
export { BugsnagNativeSpansPlugin, NativeSpanControlProvider, NativeSpanQuery } from './native-spans-plugin.js';
|
|
2
|
+
export { BugsnagJavascriptSpansPlugin } from './javascript-spans-plugin.js';
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { TurboModuleRegistry, NativeEventEmitter } from 'react-native';
|
|
2
|
+
import { RemoteParentContext } from '@bugsnag/core-performance';
|
|
3
|
+
|
|
4
|
+
const HOUR_IN_MILLISECONDS = 60 * 60 * 1000;
|
|
5
|
+
const NativeNativeSpansModule = TurboModuleRegistry.get('BugsnagNativeSpans');
|
|
6
|
+
class BugsnagJavascriptSpansPlugin {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.spansByName = new Map();
|
|
9
|
+
this.timeout = null;
|
|
10
|
+
}
|
|
11
|
+
install(context) {
|
|
12
|
+
if (!NativeNativeSpansModule) {
|
|
13
|
+
throw new Error('BugsnagNativeSpans module is not available. Ensure the native module is linked correctly.');
|
|
14
|
+
}
|
|
15
|
+
this.clock = context.clock;
|
|
16
|
+
context.addOnSpanStartCallback(this.onSpanStart.bind(this));
|
|
17
|
+
context.addOnSpanEndCallback(this.onSpanEnd.bind(this));
|
|
18
|
+
const eventEmitter = new NativeEventEmitter(NativeNativeSpansModule);
|
|
19
|
+
eventEmitter.addListener('bugsnag:spanUpdate', this.onNativeSpanUpdate.bind(this));
|
|
20
|
+
eventEmitter.addListener('bugsnag:retrieveSpanContext', this.onSpanContextEvent.bind(this));
|
|
21
|
+
}
|
|
22
|
+
start() {
|
|
23
|
+
this.cleanup();
|
|
24
|
+
}
|
|
25
|
+
onSpanStart(span) {
|
|
26
|
+
this.spansByName.set(span.name, span);
|
|
27
|
+
}
|
|
28
|
+
onSpanEnd(span) {
|
|
29
|
+
const trackedSpan = this.spansByName.get(span.name);
|
|
30
|
+
if (trackedSpan && trackedSpan.id === span.id && trackedSpan.traceId === span.traceId) {
|
|
31
|
+
this.spansByName.delete(span.name);
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
onNativeSpanUpdate(event) {
|
|
36
|
+
let result = false;
|
|
37
|
+
try {
|
|
38
|
+
const span = this.spansByName.get(event.name);
|
|
39
|
+
if (!span) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (event.attributes && event.attributes.length > 0) {
|
|
43
|
+
for (const { name, value } of event.attributes) {
|
|
44
|
+
span.setAttribute(name, value);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (event.isEnded) {
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
49
|
+
span.end(event.endTime ? this.clock.fromUnixNanoseconds(event.endTime) : undefined);
|
|
50
|
+
}
|
|
51
|
+
result = true;
|
|
52
|
+
}
|
|
53
|
+
finally {
|
|
54
|
+
if (event.id !== undefined) {
|
|
55
|
+
NativeNativeSpansModule?.reportSpanUpdateResult(event.id, result);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
onSpanContextEvent(event) {
|
|
60
|
+
let result = null;
|
|
61
|
+
try {
|
|
62
|
+
const span = this.spansByName.get(event.name);
|
|
63
|
+
if (span) {
|
|
64
|
+
result = RemoteParentContext.toTraceParentString(span);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
finally {
|
|
68
|
+
NativeNativeSpansModule?.reportSpanContextResult(event.id, result);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
cleanup() {
|
|
72
|
+
for (const [name, span] of this.spansByName.entries()) {
|
|
73
|
+
if (!span.isValid()) {
|
|
74
|
+
this.spansByName.delete(name);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (this.timeout)
|
|
78
|
+
clearTimeout(this.timeout);
|
|
79
|
+
this.timeout = setTimeout(this.cleanup.bind(this), HOUR_IN_MILLISECONDS);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export { BugsnagJavascriptSpansPlugin };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { TurboModuleRegistry } from 'react-native';
|
|
2
|
+
import { SpanQuery, timeToNumber } from '@bugsnag/core-performance';
|
|
3
|
+
|
|
4
|
+
class NativeSpanQuery extends SpanQuery {
|
|
5
|
+
constructor(name) {
|
|
6
|
+
super();
|
|
7
|
+
this.name = name;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
const NativeNativeSpansModule = TurboModuleRegistry.get('BugsnagNativeSpans');
|
|
11
|
+
class NativeSpanControlImpl {
|
|
12
|
+
constructor(id, traceId, clock) {
|
|
13
|
+
this.id = id;
|
|
14
|
+
this.traceId = traceId;
|
|
15
|
+
this.clock = clock;
|
|
16
|
+
}
|
|
17
|
+
updateSpan(update) {
|
|
18
|
+
const transaction = {
|
|
19
|
+
attributes: [],
|
|
20
|
+
isEnded: false
|
|
21
|
+
};
|
|
22
|
+
update({
|
|
23
|
+
end: (endTime) => {
|
|
24
|
+
const safeEndTime = timeToNumber(this.clock, endTime);
|
|
25
|
+
transaction.endTime = this.clock.toUnixNanoseconds(safeEndTime);
|
|
26
|
+
transaction.isEnded = true;
|
|
27
|
+
},
|
|
28
|
+
setAttribute: (name, value) => {
|
|
29
|
+
transaction.attributes.push({ name, value });
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
33
|
+
return NativeNativeSpansModule.updateSpan({ spanId: this.id, traceId: this.traceId }, transaction);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
class NativeSpanControlProvider {
|
|
37
|
+
constructor(clock) {
|
|
38
|
+
this.clock = clock;
|
|
39
|
+
}
|
|
40
|
+
getSpanControls(query) {
|
|
41
|
+
if (query instanceof NativeSpanQuery && NativeNativeSpansModule) {
|
|
42
|
+
const spanId = NativeNativeSpansModule.getSpanIdByName(query.name);
|
|
43
|
+
if (spanId) {
|
|
44
|
+
return new NativeSpanControlImpl(spanId.spanId, spanId.traceId, this.clock);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
class BugsnagNativeSpansPlugin {
|
|
51
|
+
install(context) {
|
|
52
|
+
if (!NativeNativeSpansModule) {
|
|
53
|
+
throw new Error('BugsnagNativeSpans module is not available. Ensure the native module is linked correctly.');
|
|
54
|
+
}
|
|
55
|
+
const spanControlProvider = new NativeSpanControlProvider(context.clock);
|
|
56
|
+
context.addSpanControlProvider(spanControlProvider);
|
|
57
|
+
}
|
|
58
|
+
start() { }
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export { BugsnagNativeSpansPlugin, NativeSpanControlProvider, NativeSpanQuery };
|
|
@@ -3,6 +3,10 @@ import type { UnsafeObject } from 'react-native/Libraries/Types/CodegenTypes';
|
|
|
3
3
|
export interface Spec extends TurboModule {
|
|
4
4
|
getSpanIdByName: (spanName: string) => UnsafeObject | undefined;
|
|
5
5
|
updateSpan: (spanId: UnsafeObject, updates: UnsafeObject) => Promise<boolean>;
|
|
6
|
+
addListener: (eventType: string) => void;
|
|
7
|
+
removeListeners: (count: number) => void;
|
|
8
|
+
reportSpanUpdateResult: (eventId: number, result: boolean) => Promise<void>;
|
|
9
|
+
reportSpanContextResult: (eventId: number, result: string | null) => Promise<void>;
|
|
6
10
|
}
|
|
7
11
|
declare const _default: Spec | null;
|
|
8
12
|
export default _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeBugsnagNativeSpans.d.ts","sourceRoot":"","sources":["../../lib/NativeBugsnagNativeSpans.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8CAA8C,CAAA;AAC/E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2CAA2C,CAAA;AAG7E,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,eAAe,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,YAAY,GAAG,SAAS,CAAA;IAE/D,UAAU,EAAE,CAAC,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"NativeBugsnagNativeSpans.d.ts","sourceRoot":"","sources":["../../lib/NativeBugsnagNativeSpans.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8CAA8C,CAAA;AAC/E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2CAA2C,CAAA;AAG7E,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,eAAe,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,YAAY,GAAG,SAAS,CAAA;IAE/D,UAAU,EAAE,CAAC,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;IAE7E,WAAW,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAA;IAExC,eAAe,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IAExC,sBAAsB,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAE3E,uBAAuB,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CACnF;wBAII,IAAI,GAAG,IAAI;AAFhB,wBAEgB"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,24 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import type { ReactNativeConfiguration } from '@bugsnag/react-native-performance';
|
|
4
|
-
export declare class NativeSpanQuery extends SpanQuery<NativeSpanControl> {
|
|
5
|
-
readonly name: string;
|
|
6
|
-
constructor(name: string);
|
|
7
|
-
}
|
|
8
|
-
export interface NativeSpanMutator {
|
|
9
|
-
end: (endTime?: Time) => void;
|
|
10
|
-
setAttribute: (name: string, value?: SpanAttribute) => void;
|
|
11
|
-
}
|
|
12
|
-
export interface NativeSpanControl extends ParentContext {
|
|
13
|
-
updateSpan: (update: (mutator: NativeSpanMutator) => void) => Promise<boolean>;
|
|
14
|
-
}
|
|
15
|
-
export declare class NativeSpanControlProvider implements SpanControlProvider<NativeSpanControl> {
|
|
16
|
-
private readonly clock;
|
|
17
|
-
constructor(clock: Clock);
|
|
18
|
-
getSpanControls<Q>(query: Q): NativeSpanControl | null;
|
|
19
|
-
}
|
|
20
|
-
export declare class BugsnagNativeSpansPlugin implements Plugin<ReactNativeConfiguration> {
|
|
21
|
-
install(context: PluginContext<ReactNativeConfiguration>): void;
|
|
22
|
-
start(): void;
|
|
23
|
-
}
|
|
1
|
+
export * from './native-spans-plugin';
|
|
2
|
+
export * from './javascript-spans-plugin';
|
|
24
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA;AACrC,cAAc,2BAA2B,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Plugin, PluginContext } from '@bugsnag/core-performance';
|
|
2
|
+
import type { ReactNativeConfiguration } from '@bugsnag/react-native-performance';
|
|
3
|
+
export declare class BugsnagJavascriptSpansPlugin implements Plugin<ReactNativeConfiguration> {
|
|
4
|
+
private spansByName;
|
|
5
|
+
private timeout;
|
|
6
|
+
private clock?;
|
|
7
|
+
install(context: PluginContext<ReactNativeConfiguration>): void;
|
|
8
|
+
start(): void;
|
|
9
|
+
private onSpanStart;
|
|
10
|
+
private onSpanEnd;
|
|
11
|
+
private onNativeSpanUpdate;
|
|
12
|
+
private onSpanContextEvent;
|
|
13
|
+
private cleanup;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=javascript-spans-plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"javascript-spans-plugin.d.ts","sourceRoot":"","sources":["../../lib/javascript-spans-plugin.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAS,MAAM,EAAE,aAAa,EAAuB,MAAM,2BAA2B,CAAA;AAClG,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAA;AAmBjF,qBAAa,4BAA6B,YAAW,MAAM,CAAC,wBAAwB,CAAC;IACnF,OAAO,CAAC,WAAW,CAA0B;IAC7C,OAAO,CAAC,OAAO,CAA6C;IAC5D,OAAO,CAAC,KAAK,CAAC,CAAO;IAErB,OAAO,CAAE,OAAO,EAAE,aAAa,CAAC,wBAAwB,CAAC;IAazD,KAAK;IAIL,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,SAAS;IASjB,OAAO,CAAC,kBAAkB;IA4B1B,OAAO,CAAC,kBAAkB;IAY1B,OAAO,CAAC,OAAO;CAUhB"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { SpanQuery } from '@bugsnag/core-performance';
|
|
2
|
+
import type { Clock, ParentContext, Plugin, PluginContext, SpanAttribute, SpanControlProvider, Time } from '@bugsnag/core-performance';
|
|
3
|
+
import type { ReactNativeConfiguration } from '@bugsnag/react-native-performance';
|
|
4
|
+
export declare class NativeSpanQuery extends SpanQuery<NativeSpanControl> {
|
|
5
|
+
readonly name: string;
|
|
6
|
+
constructor(name: string);
|
|
7
|
+
}
|
|
8
|
+
export interface NativeSpanMutator {
|
|
9
|
+
end: (endTime?: Time) => void;
|
|
10
|
+
setAttribute: (name: string, value?: SpanAttribute) => void;
|
|
11
|
+
}
|
|
12
|
+
export interface NativeSpanControl extends ParentContext {
|
|
13
|
+
updateSpan: (update: (mutator: NativeSpanMutator) => void) => Promise<boolean>;
|
|
14
|
+
}
|
|
15
|
+
export declare class NativeSpanControlProvider implements SpanControlProvider<NativeSpanControl> {
|
|
16
|
+
private readonly clock;
|
|
17
|
+
constructor(clock: Clock);
|
|
18
|
+
getSpanControls<Q>(query: Q): NativeSpanControl | null;
|
|
19
|
+
}
|
|
20
|
+
export declare class BugsnagNativeSpansPlugin implements Plugin<ReactNativeConfiguration> {
|
|
21
|
+
install(context: PluginContext<ReactNativeConfiguration>): void;
|
|
22
|
+
start(): void;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=native-spans-plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-spans-plugin.d.ts","sourceRoot":"","sources":["../../lib/native-spans-plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAgB,MAAM,2BAA2B,CAAA;AAEnE,OAAO,KAAK,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,aAAa,EAAE,aAAa,EAAE,mBAAmB,EAAE,IAAI,EAAE,MAAM,2BAA2B,CAAA;AACtI,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAA;AAEjF,qBAAa,eAAgB,SAAQ,SAAS,CAAC,iBAAiB,CAAC;aAClC,IAAI,EAAE,MAAM;gBAAZ,IAAI,EAAE,MAAM;CAG1C;AAED,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,CAAC,OAAO,CAAC,EAAE,IAAI,KAAK,IAAI,CAAA;IAC7B,YAAY,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,aAAa,KAAK,IAAI,CAAA;CAC5D;AAED,MAAM,WAAW,iBAAkB,SAAQ,aAAa;IACtD,UAAU,EAAE,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE,iBAAiB,KAAK,IAAI,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;CAC/E;AA4CD,qBAAa,yBAA0B,YAAW,mBAAmB,CAAC,iBAAiB,CAAC;IACzE,OAAO,CAAC,QAAQ,CAAC,KAAK;gBAAL,KAAK,EAAE,KAAK;IAE1C,eAAe,CAAC,CAAC,EAAG,KAAK,EAAE,CAAC,GAAG,iBAAiB,GAAG,IAAI;CAYxD;AAED,qBAAa,wBAAyB,YAAW,MAAM,CAAC,wBAAwB,CAAC;IAC/E,OAAO,CAAE,OAAO,EAAE,aAAa,CAAC,wBAAwB,CAAC;IASzD,KAAK;CACN"}
|