@bugsnag/plugin-react-native-span-access 2.14.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.
@@ -0,0 +1,25 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = "BugsnagNativeSpans"
7
+ s.version = package["version"]
8
+ s.summary = package["description"]
9
+ s.description = package["description"]
10
+ s.homepage = package["homepage"]
11
+ s.license = package["license"]
12
+ s.platforms = { :ios => "10.0" }
13
+ s.author = { "Bugsnag" => "platforms@bugsnag.com" }
14
+ s.source = { :git => "https://github.com/bugsnag/bugsnag-js-performance.git", :tag => "v#{s.version}" }
15
+
16
+ s.source_files = "ios/**/*.{h,m,mm,swift}"
17
+
18
+ s.dependency 'BugsnagPerformance'
19
+
20
+ if ENV["RCT_NEW_ARCH_ENABLED"] == "1"
21
+ install_modules_dependencies(s)
22
+ else
23
+ s.dependency "React-Core"
24
+ end
25
+ end
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 BugSnag
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,42 @@
1
+ def isNewArchitectureEnabled() {
2
+ return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
3
+ }
4
+
5
+ def safeExtGet(prop, fallback) {
6
+ rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
7
+ }
8
+
9
+ repositories {
10
+ mavenLocal()
11
+ mavenCentral()
12
+ google()
13
+ }
14
+
15
+ apply plugin: 'com.android.library'
16
+ if (isNewArchitectureEnabled()) {
17
+ apply plugin: 'com.facebook.react'
18
+ }
19
+
20
+ android {
21
+ compileSdkVersion safeExtGet('compileSdkVersion', 29)
22
+
23
+ if (android.hasProperty('namespace')) {
24
+ namespace 'com.bugsnag.reactnative.performance.nativespans'
25
+ }
26
+
27
+ sourceSets {
28
+ main {
29
+ if (isNewArchitectureEnabled()) {
30
+ java.srcDirs += ['src/newarch/java']
31
+ } else {
32
+ java.srcDirs += ['src/oldarch/java']
33
+ }
34
+ }
35
+ }
36
+ }
37
+
38
+ dependencies {
39
+ implementation 'com.facebook.react:react-native'
40
+ implementation project(':bugsnag_react-native-performance')
41
+ api 'com.bugsnag:bugsnag-android-performance:1.16.0'
42
+ }
@@ -0,0 +1,2 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.bugsnag.reactnative.performance.nativespans">
2
+ </manifest>
@@ -0,0 +1,151 @@
1
+ package com.bugsnag.reactnative.performance.nativespans;
2
+
3
+ import java.util.Date;
4
+ import java.text.DateFormat;
5
+ import java.text.ParseException;
6
+ import java.text.SimpleDateFormat;
7
+
8
+ import android.util.Log;
9
+
10
+ import androidx.annotation.Nullable;
11
+
12
+ import com.bugsnag.android.performance.Span;
13
+ import com.bugsnag.android.performance.internal.BugsnagClock;
14
+ import com.bugsnag.android.performance.internal.EncodingUtils;
15
+ import com.bugsnag.reactnative.performance.ReactNativeSpanAttributes;
16
+ import com.facebook.react.bridge.Arguments;
17
+ import com.facebook.react.bridge.Promise;
18
+ import com.facebook.react.bridge.ReactApplicationContext;
19
+ import com.facebook.react.bridge.ReadableArray;
20
+ import com.facebook.react.bridge.ReadableMap;
21
+ import com.facebook.react.bridge.ReadableType;
22
+ import com.facebook.react.bridge.WritableMap;
23
+
24
+ class BugsnagNativeSpans {
25
+
26
+ // Attribute keys
27
+ private static final String ATTRIBUTES = "attributes";
28
+ private static final String ATTR_NAME = "name";
29
+ private static final String ATTR_VALUE = "value";
30
+
31
+ // Span properties
32
+ private static final String END_TIME = "endTime";
33
+ private static final String IS_ENDED = "isEnded";
34
+ private static final String SPAN_ID = "spanId";
35
+ private static final String TRACE_ID = "traceId";
36
+
37
+ static final String MODULE_NAME = "BugsnagNativeSpans";
38
+
39
+ private final ReactApplicationContext reactContext;
40
+
41
+ public BugsnagNativeSpans(ReactApplicationContext reactContext) {
42
+ this.reactContext = reactContext;
43
+ }
44
+
45
+ @Nullable
46
+ public WritableMap getSpanIdByName(String spanName) {
47
+ BugsnagNativeSpansPlugin nativeSpanAccessPlugin = BugsnagNativeSpansPlugin.getInstance();
48
+
49
+ if (nativeSpanAccessPlugin == null) {
50
+ return null;
51
+ }
52
+
53
+ Span span = nativeSpanAccessPlugin.getSpanByName(spanName);
54
+ if (span == null) {
55
+ return null;
56
+ }
57
+
58
+ WritableMap map = Arguments.createMap();
59
+ map.putString(SPAN_ID, EncodingUtils.toHexString(span.getSpanId()));
60
+ map.putString(TRACE_ID, EncodingUtils.toHexString(span.getTraceId()));
61
+
62
+ return map;
63
+ }
64
+
65
+ public void updateSpan(ReadableMap spanId, ReadableMap updates, Promise promise) {
66
+ BugsnagNativeSpansPlugin nativeSpanAccessPlugin = BugsnagNativeSpansPlugin.getInstance();
67
+
68
+ if (nativeSpanAccessPlugin == null) {
69
+ promise.resolve(false);
70
+ return;
71
+ }
72
+
73
+ String traceIdHex = spanId.getString(TRACE_ID);
74
+ String spanIdHex = spanId.getString(SPAN_ID);
75
+ Span span = nativeSpanAccessPlugin.getSpanById(traceIdHex, spanIdHex);
76
+ if (span == null) {
77
+ promise.resolve(false);
78
+ return;
79
+ }
80
+
81
+ ReadableArray attributes = updates.getArray(ATTRIBUTES);
82
+ if (attributes != null) {
83
+ updateSpanAttributes(attributes, span);
84
+ }
85
+
86
+ if (updates.getBoolean(IS_ENDED)) {
87
+ endSpan(updates, span);
88
+ }
89
+
90
+ promise.resolve(true);
91
+ }
92
+
93
+ private static void endSpan(ReadableMap updates, Span span) {
94
+ if (updates.hasKey(END_TIME)) {
95
+ double endTime = updates.getDouble(END_TIME);
96
+ span.end(BugsnagClock.INSTANCE.unixNanoTimeToElapsedRealtime((long) endTime));
97
+ } else {
98
+ span.end();
99
+ }
100
+ }
101
+
102
+ private static void updateSpanAttributes(ReadableArray attributeUpdates, Span span) {
103
+ for (int i = 0; i < attributeUpdates.size(); i++) {
104
+ ReadableMap attribute = attributeUpdates.getMap(i);
105
+ String name = attribute.getString(ATTR_NAME);
106
+ ReadableType type = attribute.getType(ATTR_VALUE);
107
+
108
+ switch (type) {
109
+ case Null:
110
+ span.setAttribute(name, (String) null);
111
+ break;
112
+ case Boolean:
113
+ span.setAttribute(name, attribute.getBoolean(ATTR_VALUE));
114
+ break;
115
+ case Number:
116
+ setNumberAttribute(span, attribute, name);
117
+ break;
118
+ case String:
119
+ span.setAttribute(name, attribute.getString(ATTR_VALUE));
120
+ break;
121
+ case Array:
122
+ setArrayAttribute(span, attribute, name);
123
+ break;
124
+ }
125
+ }
126
+ }
127
+
128
+ private static void setArrayAttribute(Span span, ReadableMap attribute, String name) {
129
+ Object array = ReactNativeSpanAttributes.transformArray(attribute.getArray(ATTR_VALUE));
130
+ if (array instanceof String[]) {
131
+ span.setAttribute(name, (String[]) array);
132
+ } else if (array instanceof long[]) {
133
+ span.setAttribute(name, (long[]) array);
134
+ } else if (array instanceof double[]) {
135
+ span.setAttribute(name, (double[]) array);
136
+ }
137
+ }
138
+
139
+ private static void setNumberAttribute(Span span, ReadableMap attribute, String name) {
140
+ double n = attribute.getDouble(ATTR_VALUE);
141
+ if (isInteger(n)) {
142
+ span.setAttribute(name, (long) n);
143
+ } else {
144
+ span.setAttribute(name, n);
145
+ }
146
+ }
147
+
148
+ private static boolean isInteger(double n) {
149
+ return n % 1 == 0;
150
+ }
151
+ }
@@ -0,0 +1,131 @@
1
+ package com.bugsnag.reactnative.performance.nativespans;
2
+
3
+ import com.bugsnag.android.performance.Span;
4
+ import com.bugsnag.android.performance.OnSpanEndCallback;
5
+ import com.bugsnag.android.performance.OnSpanStartCallback;
6
+ import com.bugsnag.android.performance.Plugin;
7
+ import com.bugsnag.android.performance.PluginContext;
8
+ import com.bugsnag.android.performance.internal.EncodingUtils;
9
+ import com.bugsnag.android.performance.internal.SpanImpl;
10
+ import com.bugsnag.android.performance.internal.processing.Timeout;
11
+ import com.bugsnag.android.performance.internal.processing.TimeoutExecutor;
12
+
13
+ import android.os.SystemClock;
14
+
15
+ import java.util.UUID;
16
+ import java.util.concurrent.Delayed;
17
+ import java.util.concurrent.TimeUnit;
18
+ import java.util.concurrent.ConcurrentMap;
19
+ import java.util.concurrent.ConcurrentHashMap;
20
+
21
+ public class BugsnagNativeSpansPlugin implements Plugin {
22
+ /**
23
+ * Default 10 minute validity time
24
+ */
25
+ private static final long DEFAULT_VALIDITY_TIME = 10 * 60 * 1000;
26
+
27
+ private static BugsnagNativeSpansPlugin INSTANCE;
28
+
29
+ private final ConcurrentMap<String, Span> spansByName = new ConcurrentHashMap<>();
30
+ private final ConcurrentMap<String, Span> spansById = new ConcurrentHashMap<>();
31
+
32
+ @Override
33
+ public void install(PluginContext ctx) {
34
+ if (INSTANCE == null) {
35
+ INSTANCE = this;
36
+ }
37
+
38
+ ctx.addOnSpanStartCallback(PluginContext.NORM_PRIORITY + 1, new OnSpanStartCallback() {
39
+ @Override
40
+ public void onSpanStart(Span span) {
41
+ BugsnagNativeSpansPlugin.this.onSpanStart(span);
42
+ }
43
+ });
44
+
45
+ ctx.addOnSpanEndCallback(PluginContext.NORM_PRIORITY - 1, new OnSpanEndCallback() {
46
+ @Override
47
+ public boolean onSpanEnd(Span span) {
48
+ return BugsnagNativeSpansPlugin.this.onSpanEnd(span);
49
+ }
50
+ });
51
+ }
52
+
53
+ private void onSpanStart(Span span) {
54
+ spansByName.put(span.getName(), span);
55
+ spansById.put(createSpanId(span), span);
56
+
57
+ TimeoutExecutor timeoutExecutor = ((SpanImpl) span).getTimeoutExecutor$internal();
58
+ if (timeoutExecutor != null) {
59
+ timeoutExecutor.scheduleTimeout(new SpanLostTimeout(DEFAULT_VALIDITY_TIME, span));
60
+ }
61
+ }
62
+
63
+ private boolean onSpanEnd(Span span) {
64
+ spansByName.remove(span.getName(), span);
65
+ spansById.remove(createSpanId(span));
66
+ return true;
67
+ }
68
+
69
+ private void removeSpan(Span span) {
70
+ onSpanEnd(span);
71
+ }
72
+
73
+ private String createSpanId(Span span) {
74
+ StringBuilder id = new StringBuilder(193);
75
+ EncodingUtils.appendHexUUID(id, span.getTraceId());
76
+ id.append(':');
77
+ EncodingUtils.appendHexLong(id, span.getSpanId());
78
+ return id.toString();
79
+ }
80
+
81
+ @Override
82
+ public void start() {
83
+ }
84
+
85
+ Span getSpanByName(String spanName) {
86
+ return spansByName.get(spanName);
87
+ }
88
+
89
+ Span getSpanById(String traceIdHex, String spanIdHex) {
90
+ return spansById.get(traceIdHex + ':' + spanIdHex);
91
+ }
92
+
93
+ static BugsnagNativeSpansPlugin getInstance() {
94
+ return INSTANCE;
95
+ }
96
+
97
+ private class SpanLostTimeout implements Timeout {
98
+ private final long timeoutMs;
99
+ private final Span span;
100
+
101
+ public SpanLostTimeout(long timeoutMs, Span span) {
102
+ this.timeoutMs = SystemClock.elapsedRealtime() + timeoutMs;
103
+ this.span = span;
104
+ }
105
+
106
+ @Override
107
+ public long getTarget() {
108
+ return timeoutMs;
109
+ }
110
+
111
+ @Override
112
+ public void run() {
113
+ removeSpan(span);
114
+ }
115
+
116
+ @Override
117
+ public long getRelativeMs() {
118
+ return Timeout.DefaultImpls.getRelativeMs(this);
119
+ }
120
+
121
+ @Override
122
+ public long getDelay(TimeUnit unit) {
123
+ return Timeout.DefaultImpls.getDelay(this, unit);
124
+ }
125
+
126
+ @Override
127
+ public int compareTo(Delayed other) {
128
+ return Timeout.DefaultImpls.compareTo(this, other);
129
+ }
130
+ }
131
+ }
@@ -0,0 +1,36 @@
1
+ package com.bugsnag.reactnative.performance.nativespans;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import androidx.annotation.Nullable;
5
+
6
+ import com.facebook.react.bridge.ReactApplicationContext;
7
+ import com.facebook.react.bridge.ReadableMap;
8
+ import com.facebook.react.bridge.WritableMap;
9
+ import com.facebook.react.bridge.Promise;
10
+ import com.facebook.react.module.annotations.ReactModule;
11
+
12
+ @ReactModule(name = BugsnagNativeSpans.MODULE_NAME)
13
+ public class BugsnagNativeSpansModule extends NativeBugsnagNativeSpansSpec {
14
+ private final BugsnagNativeSpans delegate;
15
+
16
+ public BugsnagNativeSpansModule(ReactApplicationContext reactContext) {
17
+ super(reactContext);
18
+ this.delegate = new BugsnagNativeSpans(reactContext);
19
+ }
20
+
21
+ @NonNull
22
+ @Override
23
+ public String getName() {
24
+ return BugsnagNativeSpans.MODULE_NAME;
25
+ }
26
+
27
+ @Override
28
+ public @Nullable WritableMap getSpanIdByName(String spanName) {
29
+ return delegate.getSpanIdByName(spanName);
30
+ }
31
+
32
+ @Override
33
+ public void updateSpan(ReadableMap spanId, ReadableMap updates, Promise promise) {
34
+ delegate.updateSpan(spanId, updates, promise);
35
+ }
36
+ }
@@ -0,0 +1,46 @@
1
+ package com.bugsnag.reactnative.performance.nativespans;
2
+
3
+ import androidx.annotation.Nullable;
4
+
5
+ import com.facebook.react.module.model.ReactModuleInfo;
6
+ import com.facebook.react.module.model.ReactModuleInfoProvider;
7
+ import com.facebook.react.TurboReactPackage;
8
+ import com.facebook.react.bridge.NativeModule;
9
+ import com.facebook.react.bridge.ReactApplicationContext;
10
+
11
+ import java.util.Collections;
12
+ import java.util.List;
13
+ import java.util.Map;
14
+ import java.util.HashMap;
15
+
16
+ public class BugsnagNativeSpansPackage extends TurboReactPackage {
17
+ @Nullable
18
+ @Override
19
+ public NativeModule getModule(String name, ReactApplicationContext reactContext) {
20
+ if (name.equals(BugsnagNativeSpans.MODULE_NAME)) {
21
+ return new BugsnagNativeSpansModule(reactContext);
22
+ } else {
23
+ return null;
24
+ }
25
+ }
26
+
27
+ @Override
28
+ public ReactModuleInfoProvider getReactModuleInfoProvider() {
29
+ return () -> {
30
+ final Map<String, ReactModuleInfo> moduleInfos = new HashMap<>();
31
+ moduleInfos.put(
32
+ BugsnagNativeSpans.MODULE_NAME,
33
+ new ReactModuleInfo(
34
+ BugsnagNativeSpans.MODULE_NAME,
35
+ BugsnagNativeSpans.MODULE_NAME,
36
+ false, // canOverrideExistingModule
37
+ false, // needsEagerInit
38
+ true, // hasConstants
39
+ false, // isCxxModule
40
+ true // isTurboModule
41
+ )
42
+ );
43
+ return moduleInfos;
44
+ };
45
+ }
46
+ }
@@ -0,0 +1,36 @@
1
+ package com.bugsnag.reactnative.performance.nativespans;
2
+
3
+ import com.facebook.react.bridge.ReactApplicationContext;
4
+ import com.facebook.react.bridge.ReactContextBaseJavaModule;
5
+ import com.facebook.react.bridge.ReactMethod;
6
+ import com.facebook.react.bridge.ReadableMap;
7
+ import com.facebook.react.bridge.WritableMap;
8
+ import com.facebook.react.bridge.Promise;
9
+ import com.facebook.react.module.annotations.ReactModule;
10
+
11
+ import androidx.annotation.Nullable;
12
+
13
+ @ReactModule(name = BugsnagNativeSpans.MODULE_NAME)
14
+ public class BugsnagNativeSpansModule extends ReactContextBaseJavaModule {
15
+ private final BugsnagNativeSpans delegate;
16
+
17
+ public BugsnagNativeSpansModule(ReactApplicationContext reactContext) {
18
+ super(reactContext);
19
+ this.delegate = new BugsnagNativeSpans(reactContext);
20
+ }
21
+
22
+ @Override
23
+ public String getName() {
24
+ return BugsnagNativeSpans.MODULE_NAME;
25
+ }
26
+
27
+ @ReactMethod(isBlockingSynchronousMethod = true)
28
+ public WritableMap getSpanIdByName(String spanName) {
29
+ return delegate.getSpanIdByName(spanName);
30
+ }
31
+
32
+ @ReactMethod
33
+ public void updateSpan(ReadableMap spanId, ReadableMap updates, Promise promise) {
34
+ delegate.updateSpan(spanId, updates, promise);
35
+ }
36
+ }
@@ -0,0 +1,24 @@
1
+ package com.bugsnag.reactnative.performance.nativespans;
2
+
3
+ import com.facebook.react.ReactPackage;
4
+ import com.facebook.react.bridge.NativeModule;
5
+ import com.facebook.react.bridge.ReactApplicationContext;
6
+ import com.facebook.react.uimanager.ViewManager;
7
+
8
+ import java.util.ArrayList;
9
+ import java.util.Collections;
10
+ import java.util.List;
11
+
12
+ public class BugsnagNativeSpansPackage implements ReactPackage {
13
+ @Override
14
+ public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
15
+ List<NativeModule> modules = new ArrayList<>();
16
+ modules.add(new BugsnagNativeSpansModule(reactContext));
17
+ return modules;
18
+ }
19
+
20
+ @Override
21
+ public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
22
+ return Collections.emptyList();
23
+ }
24
+ }
@@ -0,0 +1,13 @@
1
+ import type { TurboModule } from 'react-native/Libraries/TurboModule/RCTExport'
2
+ import type { UnsafeObject } from 'react-native/Libraries/Types/CodegenTypes'
3
+ import { TurboModuleRegistry } from 'react-native'
4
+
5
+ export interface Spec extends TurboModule {
6
+ getSpanIdByName: (spanName: string) => UnsafeObject | undefined
7
+
8
+ updateSpan: (spanId: UnsafeObject, updates: UnsafeObject) => Promise<boolean>
9
+ }
10
+
11
+ export default TurboModuleRegistry.get<Spec>(
12
+ 'BugsnagNativeSpans'
13
+ ) as Spec | null
package/dist/index.js ADDED
@@ -0,0 +1,58 @@
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
+ const spanControlProvider = new NativeSpanControlProvider(context.clock);
53
+ context.addSpanControlProvider(spanControlProvider);
54
+ }
55
+ start() { }
56
+ }
57
+
58
+ export { BugsnagNativeSpansPlugin, NativeSpanControlProvider, NativeSpanQuery };
@@ -0,0 +1,9 @@
1
+ import type { TurboModule } from 'react-native/Libraries/TurboModule/RCTExport';
2
+ import type { UnsafeObject } from 'react-native/Libraries/Types/CodegenTypes';
3
+ export interface Spec extends TurboModule {
4
+ getSpanIdByName: (spanName: string) => UnsafeObject | undefined;
5
+ updateSpan: (spanId: UnsafeObject, updates: UnsafeObject) => Promise<boolean>;
6
+ }
7
+ declare const _default: Spec | null;
8
+ export default _default;
9
+ //# sourceMappingURL=NativeBugsnagNativeSpans.d.ts.map
@@ -0,0 +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;CAC9E;wBAII,IAAI,GAAG,IAAI;AAFhB,wBAEgB"}
@@ -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=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/index.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;IAKzD,KAAK;CACN"}
@@ -0,0 +1,19 @@
1
+ #import <React/RCTBridgeModule.h>
2
+
3
+ #ifdef RCT_NEW_ARCH_ENABLED
4
+ #import <BugsnagNativeSpansSpec/BugsnagNativeSpansSpec.h>
5
+ #endif
6
+
7
+ NS_ASSUME_NONNULL_BEGIN
8
+
9
+ @interface BugsnagNativeSpans : NSObject <RCTBridgeModule>
10
+
11
+ @end
12
+
13
+ #ifdef RCT_NEW_ARCH_ENABLED
14
+ @interface BugsnagNativeSpans () <NativeBugsnagNativeSpansSpec>
15
+
16
+ @end
17
+ #endif
18
+
19
+ NS_ASSUME_NONNULL_END
@@ -0,0 +1,180 @@
1
+ #import <BugsnagPerformance/BugsnagPerformanceSpan.h>
2
+
3
+ #import "BugsnagNativeSpans.h"
4
+
5
+ #ifdef RCT_NEW_ARCH_ENABLED
6
+ #import "BugsnagNativeSpansSpec.h"
7
+ #endif
8
+
9
+ #import "BugsnagNativeSpansPlugin+Private.h"
10
+
11
+ @implementation BugsnagNativeSpans
12
+
13
+ RCT_EXPORT_MODULE()
14
+
15
+ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(getSpanIdByName:(NSString *)spanName) {
16
+ BugsnagNativeSpansPlugin *plugin = [BugsnagNativeSpansPlugin singleton];
17
+ if (!plugin) {
18
+ return nil;
19
+ }
20
+
21
+ BugsnagPerformanceSpan *span = nil;
22
+ @synchronized (plugin) {
23
+ span = plugin.spansByName[spanName];
24
+ }
25
+
26
+ if (!span) {
27
+ return nil;
28
+ }
29
+
30
+ NSDictionary *returnedId = @{
31
+ @"spanId": [NSString stringWithFormat:@"%016llx", span.spanId],
32
+ @"traceId": [NSString stringWithFormat:@"%016llx%016llx", span.traceIdHi, span.traceIdLo]
33
+ };
34
+
35
+ return returnedId;
36
+ }
37
+
38
+ RCT_EXPORT_METHOD(updateSpan:(NSDictionary *)spanId
39
+ updates:(NSDictionary *)updates
40
+ resolve:(RCTPromiseResolveBlock)resolve
41
+ reject:(RCTPromiseRejectBlock)reject)
42
+ {
43
+ BugsnagNativeSpansPlugin *plugin = [BugsnagNativeSpansPlugin singleton];
44
+ if (!plugin) {
45
+ resolve(@NO);
46
+ return;
47
+ }
48
+
49
+ NSString *id = spanId[@"spanId"];
50
+ NSString *traceId = spanId[@"traceId"];
51
+
52
+ if (!id || !traceId) {
53
+ resolve(@NO);
54
+ return;
55
+ }
56
+
57
+ NSString *spanIdKey = [NSString stringWithFormat:@"%@:%@", id, traceId];
58
+ BugsnagPerformanceSpan *span = nil;
59
+ @synchronized (plugin) {
60
+ span = plugin.spansById[spanIdKey];
61
+ }
62
+
63
+ if (!span) {
64
+ resolve(@NO);
65
+ return;
66
+ }
67
+
68
+ NSArray *attributes = updates[@"attributes"];
69
+ if (attributes) {
70
+ [self updateSpanAttributes:attributes span:span];
71
+ }
72
+
73
+ if (updates[@"isEnded"] == @YES) {
74
+ [self endSpan:updates span:span];
75
+ }
76
+
77
+ resolve(@YES);
78
+ }
79
+
80
+ - (void)endSpan:(NSDictionary *)updates span:(BugsnagPerformanceSpan *)span {
81
+ NSNumber *timestampString = updates[@"endTime"];
82
+ if (timestampString) {
83
+ double endTimestampValue = [timestampString doubleValue];
84
+ NSDate *endTimestamp = [NSDate dateWithTimeIntervalSince1970:(endTimestampValue / NSEC_PER_SEC)];
85
+ [span endWithEndTime:endTimestamp];
86
+ } else {
87
+ [span end];
88
+ }
89
+ }
90
+
91
+ - (void)updateSpanAttributes:(NSArray *)attributes span:(BugsnagPerformanceSpan *)span {
92
+ for (NSDictionary *attribute in attributes) {
93
+ NSString *name = attribute[@"name"];
94
+ id value = attribute[@"value"];
95
+ if (name) {
96
+ [BugsnagNativeSpans setSpanAttribute:name withValue:value span:span];
97
+ }
98
+ }
99
+ }
100
+
101
+ + (void)setSpanAttribute:(NSString *)name
102
+ withValue:(id)value
103
+ span:(BugsnagPerformanceSpan *)span
104
+ {
105
+ if ([value isKindOfClass:[NSNumber class]]) {
106
+ if ([self isBoolean:value]) {
107
+ [span setAttribute:name withValue:value];
108
+ return;
109
+ }
110
+
111
+ double doubleValue = [value doubleValue];
112
+ long longValue = (long)doubleValue;
113
+ if (doubleValue == longValue) {
114
+ [span setAttribute:name withValue:@(longValue)];
115
+ } else {
116
+ [span setAttribute:name withValue:@(doubleValue)];
117
+ }
118
+ } else if ([value isKindOfClass:[NSArray class]]) {
119
+ [span setAttribute:name withValue:[self normaliseAttributeArray:value]];
120
+ } else {
121
+ [span setAttribute:name withValue:value];
122
+ }
123
+ }
124
+
125
+ + (NSArray*)normaliseAttributeArray:(NSArray *)array {
126
+ NSUInteger size = array.count;
127
+ if (size == 0) {
128
+ return @[];
129
+ }
130
+
131
+ if ([self isNumberArray:array]) {
132
+ BOOL allIntegers = YES;
133
+ NSMutableArray *longValues = [NSMutableArray arrayWithCapacity:size];
134
+ for (NSNumber *number in array) {
135
+ double doubleValue = [number doubleValue];
136
+ long longValue = (long)doubleValue;
137
+ if (doubleValue != longValue) {
138
+ allIntegers = NO;
139
+ break;
140
+ }
141
+
142
+ [longValues addObject:@(longValue)];
143
+ }
144
+
145
+ if (allIntegers) {
146
+ return longValues;
147
+ } else {
148
+ NSMutableArray *doubleValues = [NSMutableArray arrayWithCapacity:size];
149
+ for (NSNumber *number in array) {
150
+ [doubleValues addObject:@([number doubleValue])];
151
+ }
152
+ return doubleValues;
153
+ }
154
+ } else {
155
+ return array;
156
+ }
157
+ }
158
+
159
+ + (BOOL)isNumberArray:(NSArray *)array {
160
+ id firstValue = array[0];
161
+ if ([firstValue isKindOfClass:[NSNumber class]]) {
162
+ return ![self isBoolean:firstValue];
163
+ }
164
+
165
+ return NO;
166
+ }
167
+
168
+ + (BOOL) isBoolean:(NSNumber *)value {
169
+ return CFGetTypeID((__bridge CFTypeRef)(value)) == CFBooleanGetTypeID();
170
+ }
171
+
172
+ #ifdef RCT_NEW_ARCH_ENABLED
173
+ - (std::shared_ptr <facebook::react::TurboModule>)getTurboModule:
174
+ (const facebook::react::ObjCTurboModule::InitParams &)params
175
+ {
176
+ return std::make_shared<facebook::react::NativeBugsnagNativeSpansSpecJSI>(params);
177
+ }
178
+ #endif
179
+
180
+ @end
@@ -0,0 +1,296 @@
1
+ // !$*UTF8*$!
2
+ {
3
+ archiveVersion = 1;
4
+ classes = {
5
+ };
6
+ objectVersion = 77;
7
+ objects = {
8
+
9
+ /* Begin PBXBuildFile section */
10
+ DA3192AA2E0AE8B7009B1271 /* BugsnagNativeSpans.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA3192A62E0AE8B7009B1271 /* BugsnagNativeSpans.mm */; };
11
+ DA3192AB2E0AE8B7009B1271 /* BugsnagNativeSpansPlugin.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA3192A82E0AE8B7009B1271 /* BugsnagNativeSpansPlugin.mm */; };
12
+ /* End PBXBuildFile section */
13
+
14
+ /* Begin PBXCopyFilesBuildPhase section */
15
+ DA3192922E0AE7D4009B1271 /* CopyFiles */ = {
16
+ isa = PBXCopyFilesBuildPhase;
17
+ buildActionMask = 2147483647;
18
+ dstPath = "include/$(PRODUCT_NAME)";
19
+ dstSubfolderSpec = 16;
20
+ files = (
21
+ );
22
+ runOnlyForDeploymentPostprocessing = 0;
23
+ };
24
+ /* End PBXCopyFilesBuildPhase section */
25
+
26
+ /* Begin PBXFileReference section */
27
+ DA3192942E0AE7D4009B1271 /* libBugsnagNativeSpans.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libBugsnagNativeSpans.a; sourceTree = BUILT_PRODUCTS_DIR; };
28
+ DA3192A52E0AE8B7009B1271 /* BugsnagNativeSpans.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BugsnagNativeSpans.h; sourceTree = "<group>"; };
29
+ DA3192A62E0AE8B7009B1271 /* BugsnagNativeSpans.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = BugsnagNativeSpans.mm; sourceTree = "<group>"; };
30
+ DA3192A72E0AE8B7009B1271 /* BugsnagNativeSpansPlugin.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BugsnagNativeSpansPlugin.h; sourceTree = "<group>"; };
31
+ DA3192A82E0AE8B7009B1271 /* BugsnagNativeSpansPlugin.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = BugsnagNativeSpansPlugin.mm; sourceTree = "<group>"; };
32
+ DA3192A92E0AE8B7009B1271 /* BugsnagNativeSpansPlugin+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "BugsnagNativeSpansPlugin+Private.h"; sourceTree = "<group>"; };
33
+ /* End PBXFileReference section */
34
+
35
+ /* Begin PBXFrameworksBuildPhase section */
36
+ DA3192912E0AE7D4009B1271 /* Frameworks */ = {
37
+ isa = PBXFrameworksBuildPhase;
38
+ buildActionMask = 2147483647;
39
+ files = (
40
+ );
41
+ runOnlyForDeploymentPostprocessing = 0;
42
+ };
43
+ /* End PBXFrameworksBuildPhase section */
44
+
45
+ /* Begin PBXGroup section */
46
+ DA31928B2E0AE7D4009B1271 = {
47
+ isa = PBXGroup;
48
+ children = (
49
+ DA3192A52E0AE8B7009B1271 /* BugsnagNativeSpans.h */,
50
+ DA3192A62E0AE8B7009B1271 /* BugsnagNativeSpans.mm */,
51
+ DA3192A72E0AE8B7009B1271 /* BugsnagNativeSpansPlugin.h */,
52
+ DA3192A82E0AE8B7009B1271 /* BugsnagNativeSpansPlugin.mm */,
53
+ DA3192A92E0AE8B7009B1271 /* BugsnagNativeSpansPlugin+Private.h */,
54
+ DA3192952E0AE7D4009B1271 /* Products */,
55
+ );
56
+ sourceTree = "<group>";
57
+ };
58
+ DA3192952E0AE7D4009B1271 /* Products */ = {
59
+ isa = PBXGroup;
60
+ children = (
61
+ DA3192942E0AE7D4009B1271 /* libBugsnagNativeSpans.a */,
62
+ );
63
+ name = Products;
64
+ sourceTree = "<group>";
65
+ };
66
+ /* End PBXGroup section */
67
+
68
+ /* Begin PBXNativeTarget section */
69
+ DA3192932E0AE7D4009B1271 /* BugsnagNativeSpans */ = {
70
+ isa = PBXNativeTarget;
71
+ buildConfigurationList = DA31929E2E0AE7D4009B1271 /* Build configuration list for PBXNativeTarget "BugsnagNativeSpans" */;
72
+ buildPhases = (
73
+ DA3192902E0AE7D4009B1271 /* Sources */,
74
+ DA3192912E0AE7D4009B1271 /* Frameworks */,
75
+ DA3192922E0AE7D4009B1271 /* CopyFiles */,
76
+ );
77
+ buildRules = (
78
+ );
79
+ dependencies = (
80
+ );
81
+ name = BugsnagNativeSpans;
82
+ packageProductDependencies = (
83
+ );
84
+ productName = BugsnagNativeSpans;
85
+ productReference = DA3192942E0AE7D4009B1271 /* libBugsnagNativeSpans.a */;
86
+ productType = "com.apple.product-type.library.static";
87
+ };
88
+ /* End PBXNativeTarget section */
89
+
90
+ /* Begin PBXProject section */
91
+ DA31928C2E0AE7D4009B1271 /* Project object */ = {
92
+ isa = PBXProject;
93
+ attributes = {
94
+ BuildIndependentTargetsInParallel = 1;
95
+ LastUpgradeCheck = 1620;
96
+ TargetAttributes = {
97
+ DA3192932E0AE7D4009B1271 = {
98
+ CreatedOnToolsVersion = 16.2;
99
+ };
100
+ };
101
+ };
102
+ buildConfigurationList = DA31928F2E0AE7D4009B1271 /* Build configuration list for PBXProject "BugsnagNativeSpans" */;
103
+ developmentRegion = en;
104
+ hasScannedForEncodings = 0;
105
+ knownRegions = (
106
+ en,
107
+ Base,
108
+ );
109
+ mainGroup = DA31928B2E0AE7D4009B1271;
110
+ minimizedProjectReferenceProxies = 1;
111
+ preferredProjectObjectVersion = 77;
112
+ productRefGroup = DA3192952E0AE7D4009B1271 /* Products */;
113
+ projectDirPath = "";
114
+ projectRoot = "";
115
+ targets = (
116
+ DA3192932E0AE7D4009B1271 /* BugsnagNativeSpans */,
117
+ );
118
+ };
119
+ /* End PBXProject section */
120
+
121
+ /* Begin PBXSourcesBuildPhase section */
122
+ DA3192902E0AE7D4009B1271 /* Sources */ = {
123
+ isa = PBXSourcesBuildPhase;
124
+ buildActionMask = 2147483647;
125
+ files = (
126
+ DA3192AA2E0AE8B7009B1271 /* BugsnagNativeSpans.mm in Sources */,
127
+ DA3192AB2E0AE8B7009B1271 /* BugsnagNativeSpansPlugin.mm in Sources */,
128
+ );
129
+ runOnlyForDeploymentPostprocessing = 0;
130
+ };
131
+ /* End PBXSourcesBuildPhase section */
132
+
133
+ /* Begin XCBuildConfiguration section */
134
+ DA31929C2E0AE7D4009B1271 /* Debug */ = {
135
+ isa = XCBuildConfiguration;
136
+ buildSettings = {
137
+ ALWAYS_SEARCH_USER_PATHS = NO;
138
+ ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
139
+ CLANG_ANALYZER_NONNULL = YES;
140
+ CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
141
+ CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
142
+ CLANG_ENABLE_MODULES = YES;
143
+ CLANG_ENABLE_OBJC_ARC = YES;
144
+ CLANG_ENABLE_OBJC_WEAK = YES;
145
+ CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
146
+ CLANG_WARN_BOOL_CONVERSION = YES;
147
+ CLANG_WARN_COMMA = YES;
148
+ CLANG_WARN_CONSTANT_CONVERSION = YES;
149
+ CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
150
+ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
151
+ CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
152
+ CLANG_WARN_EMPTY_BODY = YES;
153
+ CLANG_WARN_ENUM_CONVERSION = YES;
154
+ CLANG_WARN_INFINITE_RECURSION = YES;
155
+ CLANG_WARN_INT_CONVERSION = YES;
156
+ CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
157
+ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
158
+ CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
159
+ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
160
+ CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
161
+ CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
162
+ CLANG_WARN_STRICT_PROTOTYPES = YES;
163
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
164
+ CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
165
+ CLANG_WARN_UNREACHABLE_CODE = YES;
166
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
167
+ COPY_PHASE_STRIP = NO;
168
+ DEBUG_INFORMATION_FORMAT = dwarf;
169
+ ENABLE_STRICT_OBJC_MSGSEND = YES;
170
+ ENABLE_TESTABILITY = YES;
171
+ ENABLE_USER_SCRIPT_SANDBOXING = YES;
172
+ GCC_C_LANGUAGE_STANDARD = gnu17;
173
+ GCC_DYNAMIC_NO_PIC = NO;
174
+ GCC_NO_COMMON_BLOCKS = YES;
175
+ GCC_OPTIMIZATION_LEVEL = 0;
176
+ GCC_PREPROCESSOR_DEFINITIONS = (
177
+ "DEBUG=1",
178
+ "$(inherited)",
179
+ );
180
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
181
+ GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
182
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
183
+ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
184
+ GCC_WARN_UNUSED_FUNCTION = YES;
185
+ GCC_WARN_UNUSED_VARIABLE = YES;
186
+ IPHONEOS_DEPLOYMENT_TARGET = 18.2;
187
+ LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
188
+ MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
189
+ MTL_FAST_MATH = YES;
190
+ ONLY_ACTIVE_ARCH = YES;
191
+ SDKROOT = iphoneos;
192
+ };
193
+ name = Debug;
194
+ };
195
+ DA31929D2E0AE7D4009B1271 /* Release */ = {
196
+ isa = XCBuildConfiguration;
197
+ buildSettings = {
198
+ ALWAYS_SEARCH_USER_PATHS = NO;
199
+ ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
200
+ CLANG_ANALYZER_NONNULL = YES;
201
+ CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
202
+ CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
203
+ CLANG_ENABLE_MODULES = YES;
204
+ CLANG_ENABLE_OBJC_ARC = YES;
205
+ CLANG_ENABLE_OBJC_WEAK = YES;
206
+ CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
207
+ CLANG_WARN_BOOL_CONVERSION = YES;
208
+ CLANG_WARN_COMMA = YES;
209
+ CLANG_WARN_CONSTANT_CONVERSION = YES;
210
+ CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
211
+ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
212
+ CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
213
+ CLANG_WARN_EMPTY_BODY = YES;
214
+ CLANG_WARN_ENUM_CONVERSION = YES;
215
+ CLANG_WARN_INFINITE_RECURSION = YES;
216
+ CLANG_WARN_INT_CONVERSION = YES;
217
+ CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
218
+ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
219
+ CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
220
+ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
221
+ CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
222
+ CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
223
+ CLANG_WARN_STRICT_PROTOTYPES = YES;
224
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
225
+ CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
226
+ CLANG_WARN_UNREACHABLE_CODE = YES;
227
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
228
+ COPY_PHASE_STRIP = NO;
229
+ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
230
+ ENABLE_NS_ASSERTIONS = NO;
231
+ ENABLE_STRICT_OBJC_MSGSEND = YES;
232
+ ENABLE_USER_SCRIPT_SANDBOXING = YES;
233
+ GCC_C_LANGUAGE_STANDARD = gnu17;
234
+ GCC_NO_COMMON_BLOCKS = YES;
235
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
236
+ GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
237
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
238
+ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
239
+ GCC_WARN_UNUSED_FUNCTION = YES;
240
+ GCC_WARN_UNUSED_VARIABLE = YES;
241
+ IPHONEOS_DEPLOYMENT_TARGET = 18.2;
242
+ LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
243
+ MTL_ENABLE_DEBUG_INFO = NO;
244
+ MTL_FAST_MATH = YES;
245
+ SDKROOT = iphoneos;
246
+ VALIDATE_PRODUCT = YES;
247
+ };
248
+ name = Release;
249
+ };
250
+ DA31929F2E0AE7D4009B1271 /* Debug */ = {
251
+ isa = XCBuildConfiguration;
252
+ buildSettings = {
253
+ CODE_SIGN_STYLE = Automatic;
254
+ OTHER_LDFLAGS = "-ObjC";
255
+ PRODUCT_NAME = "$(TARGET_NAME)";
256
+ SKIP_INSTALL = YES;
257
+ TARGETED_DEVICE_FAMILY = "1,2";
258
+ };
259
+ name = Debug;
260
+ };
261
+ DA3192A02E0AE7D4009B1271 /* Release */ = {
262
+ isa = XCBuildConfiguration;
263
+ buildSettings = {
264
+ CODE_SIGN_STYLE = Automatic;
265
+ OTHER_LDFLAGS = "-ObjC";
266
+ PRODUCT_NAME = "$(TARGET_NAME)";
267
+ SKIP_INSTALL = YES;
268
+ TARGETED_DEVICE_FAMILY = "1,2";
269
+ };
270
+ name = Release;
271
+ };
272
+ /* End XCBuildConfiguration section */
273
+
274
+ /* Begin XCConfigurationList section */
275
+ DA31928F2E0AE7D4009B1271 /* Build configuration list for PBXProject "BugsnagNativeSpans" */ = {
276
+ isa = XCConfigurationList;
277
+ buildConfigurations = (
278
+ DA31929C2E0AE7D4009B1271 /* Debug */,
279
+ DA31929D2E0AE7D4009B1271 /* Release */,
280
+ );
281
+ defaultConfigurationIsVisible = 0;
282
+ defaultConfigurationName = Release;
283
+ };
284
+ DA31929E2E0AE7D4009B1271 /* Build configuration list for PBXNativeTarget "BugsnagNativeSpans" */ = {
285
+ isa = XCConfigurationList;
286
+ buildConfigurations = (
287
+ DA31929F2E0AE7D4009B1271 /* Debug */,
288
+ DA3192A02E0AE7D4009B1271 /* Release */,
289
+ );
290
+ defaultConfigurationIsVisible = 0;
291
+ defaultConfigurationName = Release;
292
+ };
293
+ /* End XCConfigurationList section */
294
+ };
295
+ rootObject = DA31928C2E0AE7D4009B1271 /* Project object */;
296
+ }
@@ -0,0 +1,10 @@
1
+ #import "BugsnagNativeSpansPlugin.h"
2
+
3
+ @interface BugsnagNativeSpansPlugin ()
4
+
5
+ + (id)singleton;
6
+
7
+ @property(nonatomic, readonly) NSMutableDictionary *spansByName;
8
+ @property(nonatomic, readonly) NSMutableDictionary *spansById;
9
+
10
+ @end
@@ -0,0 +1,10 @@
1
+ #import <Foundation/Foundation.h>
2
+ #import <BugsnagPerformance/BugsnagPerformancePlugin.h>
3
+
4
+ NS_ASSUME_NONNULL_BEGIN
5
+
6
+ @interface BugsnagNativeSpansPlugin: NSObject <BugsnagPerformancePlugin>
7
+
8
+ @end
9
+
10
+ NS_ASSUME_NONNULL_END
@@ -0,0 +1,91 @@
1
+ #import "BugsnagNativeSpansPlugin+Private.h"
2
+ #import <BugsnagPerformance/BugsnagPerformanceSpan.h>
3
+ #import <BugsnagPerformance/BugsnagPerformancePluginContext.h>
4
+ #import <map>
5
+
6
+ static const NSTimeInterval kSpanTimeoutInterval = 600; // 10 minutes
7
+
8
+ // Forward declaration for utility function
9
+ static NSString *createNativeSpanId(BugsnagPerformanceSpan *span);
10
+
11
+ @implementation BugsnagNativeSpansPlugin {
12
+ // Private instance variable for span timeout timers
13
+ std::map<void *, NSTimer *> _spanTimeoutTimers;
14
+ }
15
+
16
+ static BugsnagNativeSpansPlugin *_sharedInstance = nil;
17
+
18
+ + (id)singleton {
19
+ return _sharedInstance;
20
+ }
21
+
22
+ // Create a timeout timer for a span
23
+ - (NSTimer *)createSpanTimeoutTimer:(BugsnagPerformanceSpan *)span {
24
+ __weak BugsnagNativeSpansPlugin *weakSelf = self;
25
+ return [NSTimer scheduledTimerWithTimeInterval:kSpanTimeoutInterval repeats:NO block:^(NSTimer * _Nonnull timer) {
26
+ [weakSelf endNativeSpan:span];
27
+ }];
28
+ }
29
+
30
+ // remove the spans from the caches and clean up timer
31
+ - (BOOL)endNativeSpan:(BugsnagPerformanceSpan *)span {
32
+ NSString *spanId = createNativeSpanId(span);
33
+ void *key = (__bridge void *)span;
34
+
35
+ @synchronized (self) {
36
+ // Remove span from caches
37
+ if ([self.spansByName objectForKey:span.name] == span) {
38
+ [self.spansByName removeObjectForKey:span.name];
39
+ }
40
+ [self.spansById removeObjectForKey:spanId];
41
+
42
+ // Clean up timer for this span using the instance member
43
+ auto& timerMap = _spanTimeoutTimers;
44
+ auto it = timerMap.find(key);
45
+ if (it != timerMap.end()) {
46
+ [it->second invalidate];
47
+ timerMap.erase(it);
48
+ }
49
+ }
50
+ return YES;
51
+ }
52
+
53
+ - (void)installWithContext:(BugsnagPerformancePluginContext *)context {
54
+ _sharedInstance = self;
55
+ _spansByName = [NSMutableDictionary new];
56
+ _spansById = [NSMutableDictionary new];
57
+
58
+ // add the spans to the caches when they are started
59
+ __block BugsnagNativeSpansPlugin *blockSelf = self;
60
+ BugsnagPerformanceSpanStartCallback spanStartCallback = ^(BugsnagPerformanceSpan *span) {
61
+ NSString *spanId = createNativeSpanId(span);
62
+
63
+ @synchronized (blockSelf) {
64
+ blockSelf.spansByName[span.name] = span;
65
+ blockSelf.spansById[spanId] = span;
66
+
67
+ // Add a 10 minute timeout to remove the span from caches if not ended
68
+ void *key = (__bridge void *)span;
69
+ NSTimer *timer = [blockSelf createSpanTimeoutTimer:span];
70
+ blockSelf->_spanTimeoutTimers[key] = timer;
71
+ }
72
+ };
73
+
74
+ // remove the spans from the caches when they are ended
75
+ BugsnagPerformanceSpanEndCallback spanEndCallback = ^(BugsnagPerformanceSpan *span) {
76
+ return [blockSelf endNativeSpan:span];
77
+ };
78
+
79
+ [context addOnSpanStartCallback:spanStartCallback priority:BugsnagPerformancePriorityHigh];
80
+ [context addOnSpanEndCallback:spanEndCallback priority:BugsnagPerformancePriorityLow];
81
+ }
82
+
83
+ - (void)start {
84
+ }
85
+
86
+ @end
87
+
88
+ // generate a unique ID for the span based on its traceId and spanId
89
+ static NSString *createNativeSpanId(BugsnagPerformanceSpan *span) {
90
+ return [NSString stringWithFormat:@"%016llx:%016llx%016llx", span.spanId, span.traceIdHi, span.traceIdLo];
91
+ }
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@bugsnag/plugin-react-native-span-access",
3
+ "version": "2.14.0",
4
+ "description": "BugSnag performance monitoring for react-native",
5
+ "homepage": "https://www.bugsnag.com/",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/bugsnag/bugsnag-js-performance.git"
10
+ },
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "scripts": {
15
+ "build": "rollup --config rollup.config.mjs",
16
+ "clean": "rm -rf dist/*"
17
+ },
18
+ "bugs": {
19
+ "url": "https://github.com/bugsnag/bugsnag-js-performance/issues"
20
+ },
21
+ "peerDependencies": {
22
+ "@bugsnag/core-performance": "*",
23
+ "@bugsnag/react-native-performance": "^2.10.0"
24
+ },
25
+ "devDependencies": {
26
+ "@bugsnag/core-performance": "^2.14.0",
27
+ "@bugsnag/react-native-performance": "^2.14.0",
28
+ "@react-native/babel-preset": "^0.74.0",
29
+ "@testing-library/jest-native": "^5.4.3",
30
+ "@testing-library/react-native": "^12.4.1"
31
+ },
32
+ "type": "module",
33
+ "main": "dist/index.js",
34
+ "types": "dist/types/index.d.ts",
35
+ "files": [
36
+ "dist",
37
+ "android",
38
+ "ios",
39
+ "BugsnagNativeSpans.podspec",
40
+ "!android/build",
41
+ "!ios/build"
42
+ ],
43
+ "codegenConfig": {
44
+ "name": "BugsnagNativeSpansSpec",
45
+ "type": "modules",
46
+ "jsSrcsDir": "dist",
47
+ "android": {
48
+ "javaPackageName": "com.bugsnag.reactnative.performance.nativespans"
49
+ }
50
+ },
51
+ "gitHead": "5e27b05f0e6d139229e89abab4bac74df9051d3b"
52
+ }