@arms/rum-reactnative 0.0.2-bate.1 → 0.0.2-bate.3

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/README.md CHANGED
@@ -1,37 +1,39 @@
1
1
  # rum-sdk-reactnative
2
2
 
3
- RUM SDK For ReactNative
3
+ Aliyun RUM SDK For ReactNative
4
4
 
5
5
  ## Installation
6
6
 
7
7
 
8
8
  ```sh
9
- npm install rum-sdk-reactnative
9
+ npm install @arms/rum-reactnative
10
10
  ```
11
11
 
12
12
 
13
13
  ## Usage
14
14
 
15
15
 
16
- ```js
17
- import { multiply } from 'rum-sdk-reactnative';
16
+ ```ts
17
+ import armsRum from '@arms/rum-reactnative';
18
+
19
+ armsRum.init({
20
+ pid: '${pid}',
21
+ endpoint: '${endpoint}',
22
+ // 设置环境信息,参考值:'prod' | 'gray' | 'pre' | 'daily' | 'local'
23
+ env: 'prod',
24
+ collectors: {
25
+ api: true,
26
+ // JS错误监听开关,默认开启
27
+ jsError: true,
28
+ // 控制台错误监听开关,默认开启
29
+ consoleError: true
30
+ },
31
+ // 链路追踪配置开关,默认关闭
32
+ tracing: false,
33
+ });
18
34
 
19
- // ...
20
-
21
- const result = multiply(3, 7);
22
35
  ```
23
36
 
37
+ ## Help
38
+ https://help.aliyun.com/zh/arms/user-experience-monitoring/
24
39
 
25
- ## Contributing
26
-
27
- - [Development workflow](CONTRIBUTING.md#development-workflow)
28
- - [Sending a pull request](CONTRIBUTING.md#sending-a-pull-request)
29
- - [Code of conduct](CODE_OF_CONDUCT.md)
30
-
31
- ## License
32
-
33
- MIT
34
-
35
- ---
36
-
37
- Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
package/package.json CHANGED
@@ -1,24 +1,23 @@
1
1
  {
2
2
  "name": "@arms/rum-reactnative",
3
- "version": "0.0.2-bate.1",
3
+ "version": "0.0.2-bate.3",
4
4
  "description": "RUM SDK For ReactNative",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",
7
7
  "exports": {
8
8
  ".": {
9
- "source": "./src/index.tsx",
10
9
  "types": "./lib/typescript/src/index.d.ts",
11
10
  "default": "./lib/module/index.js"
12
11
  },
13
12
  "./package.json": "./package.json"
14
13
  },
15
14
  "files": [
16
- "src",
15
+ "!src",
17
16
  "lib",
18
- "android",
19
- "ios",
20
- "cpp",
21
- "*.podspec",
17
+ "!android",
18
+ "!ios",
19
+ "!cpp",
20
+ "!*.podspec",
22
21
  "react-native.config.js",
23
22
  "!ios/build",
24
23
  "!android/build",
@@ -1,21 +0,0 @@
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 = "RumSdkReactnative"
7
- s.version = package["version"]
8
- s.summary = package["description"]
9
- s.homepage = package["homepage"]
10
- s.license = package["license"]
11
- s.authors = package["author"]
12
-
13
- s.platforms = { :ios => min_ios_version_supported }
14
- s.source = { :git => "https://code.alibaba-inc.com/aliyun-rum/rum-sdk-reactnative.git", :tag => "#{s.version}" }
15
-
16
- s.source_files = "ios/**/*.{h,m,mm,cpp}"
17
- s.private_header_files = "ios/**/*.h"
18
-
19
-
20
- install_modules_dependencies(s)
21
- end
@@ -1,77 +0,0 @@
1
- buildscript {
2
- ext.getExtOrDefault = {name ->
3
- return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['RumSdkReactnative_' + name]
4
- }
5
-
6
- repositories {
7
- google()
8
- mavenCentral()
9
- }
10
-
11
- dependencies {
12
- classpath "com.android.tools.build:gradle:8.7.2"
13
- // noinspection DifferentKotlinGradleVersion
14
- classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
15
- }
16
- }
17
-
18
-
19
- apply plugin: "com.android.library"
20
- apply plugin: "kotlin-android"
21
-
22
- apply plugin: "com.facebook.react"
23
-
24
- def getExtOrIntegerDefault(name) {
25
- return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["RumSdkReactnative_" + name]).toInteger()
26
- }
27
-
28
- android {
29
- namespace "com.rumsdkreactnative"
30
-
31
- compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
32
-
33
- defaultConfig {
34
- minSdkVersion getExtOrIntegerDefault("minSdkVersion")
35
- targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
36
- }
37
-
38
- buildFeatures {
39
- buildConfig true
40
- }
41
-
42
- buildTypes {
43
- release {
44
- minifyEnabled false
45
- }
46
- }
47
-
48
- lintOptions {
49
- disable "GradleCompatible"
50
- }
51
-
52
- compileOptions {
53
- sourceCompatibility JavaVersion.VERSION_1_8
54
- targetCompatibility JavaVersion.VERSION_1_8
55
- }
56
-
57
- sourceSets {
58
- main {
59
- java.srcDirs += [
60
- "generated/java",
61
- "generated/jni"
62
- ]
63
- }
64
- }
65
- }
66
-
67
- repositories {
68
- mavenCentral()
69
- google()
70
- }
71
-
72
- def kotlin_version = getExtOrDefault("kotlinVersion")
73
-
74
- dependencies {
75
- implementation "com.facebook.react:react-android"
76
- implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
77
- }
@@ -1,5 +0,0 @@
1
- RumSdkReactnative_kotlinVersion=2.0.21
2
- RumSdkReactnative_minSdkVersion=24
3
- RumSdkReactnative_targetSdkVersion=34
4
- RumSdkReactnative_compileSdkVersion=35
5
- RumSdkReactnative_ndkVersion=27.1.12297006
@@ -1,2 +0,0 @@
1
- <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
- </manifest>
@@ -1,23 +0,0 @@
1
- package com.rumsdkreactnative
2
-
3
- import com.facebook.react.bridge.ReactApplicationContext
4
- import com.facebook.react.module.annotations.ReactModule
5
-
6
- @ReactModule(name = RumSdkReactnativeModule.NAME)
7
- class RumSdkReactnativeModule(reactContext: ReactApplicationContext) :
8
- NativeRumSdkReactnativeSpec(reactContext) {
9
-
10
- override fun getName(): String {
11
- return NAME
12
- }
13
-
14
- // Example method
15
- // See https://reactnative.dev/docs/native-modules-android
16
- override fun multiply(a: Double, b: Double): Double {
17
- return a * b
18
- }
19
-
20
- companion object {
21
- const val NAME = "RumSdkReactnative"
22
- }
23
- }
@@ -1,33 +0,0 @@
1
- package com.rumsdkreactnative
2
-
3
- import com.facebook.react.BaseReactPackage
4
- import com.facebook.react.bridge.NativeModule
5
- import com.facebook.react.bridge.ReactApplicationContext
6
- import com.facebook.react.module.model.ReactModuleInfo
7
- import com.facebook.react.module.model.ReactModuleInfoProvider
8
- import java.util.HashMap
9
-
10
- class RumSdkReactnativePackage : BaseReactPackage() {
11
- override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
12
- return if (name == RumSdkReactnativeModule.NAME) {
13
- RumSdkReactnativeModule(reactContext)
14
- } else {
15
- null
16
- }
17
- }
18
-
19
- override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
20
- return ReactModuleInfoProvider {
21
- val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
22
- moduleInfos[RumSdkReactnativeModule.NAME] = ReactModuleInfo(
23
- RumSdkReactnativeModule.NAME,
24
- RumSdkReactnativeModule.NAME,
25
- false, // canOverrideExistingModule
26
- false, // needsEagerInit
27
- false, // isCxxModule
28
- true // isTurboModule
29
- )
30
- moduleInfos
31
- }
32
- }
33
- }
@@ -1,5 +0,0 @@
1
- #import <RumSdkReactnativeSpec/RumSdkReactnativeSpec.h>
2
-
3
- @interface RumSdkReactnative : NSObject <NativeRumSdkReactnativeSpec>
4
-
5
- @end
@@ -1,18 +0,0 @@
1
- #import "RumSdkReactnative.h"
2
-
3
- @implementation RumSdkReactnative
4
- RCT_EXPORT_MODULE()
5
-
6
- - (NSNumber *)multiply:(double)a b:(double)b {
7
- NSNumber *result = @(a * b);
8
-
9
- return result;
10
- }
11
-
12
- - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
13
- (const facebook::react::ObjCTurboModule::InitParams &)params
14
- {
15
- return std::make_shared<facebook::react::NativeRumSdkReactnativeSpecJSI>(params);
16
- }
17
-
18
- @end
@@ -1,67 +0,0 @@
1
- import { ICollector, IContext, IViewData, RumActionEvent, RumEvent, RumEventType } from '@arms/rum-core';
2
- import { getCurView } from "../../utils/view";
3
-
4
- export default class ActionCollector implements ICollector {
5
- name = 'action-collector';
6
- private DELAY_TIME = 300;
7
- ctx?: IContext;
8
- sendEvent?: ((payload: RumEvent) => void);
9
- events = ['tap'];
10
- lastEvent?: RumActionEvent;
11
- timer: any;
12
-
13
- setup(ctx: IContext, sendEvent: (payload: RumEvent) => void) {
14
- const { collectors = {} } = ctx.getConfig();
15
- if (collectors.action === false) {
16
- return;
17
- }
18
- this.ctx = ctx;
19
- this.sendEvent = sendEvent;
20
- // addPageListener('*', this.onEvent)
21
- }
22
-
23
- onEvent = (e: any) => {
24
- if (e && this.events.includes(e.type) && e.target) {
25
- const { target, currentTarget, type } = e;
26
- const { dataset, id } = target;
27
- if (!id) return;
28
- if (currentTarget && id !== currentTarget.id) return;
29
- let view: undefined | IViewData;
30
- if (this.ctx) {
31
- view = getCurView(this.ctx) as IViewData;
32
- }
33
- const event: RumActionEvent = {
34
- event_type: RumEventType.ACTION,
35
- type,
36
- name: id,
37
- snapshots: Object.keys(dataset).length
38
- ? JSON.stringify(dataset)
39
- : undefined,
40
- times: 1,
41
- view,
42
- };
43
- clearTimeout(this.timer);
44
- if (this.lastEvent) {
45
- if (this.lastEvent.name !== event.name) {
46
- this.sendAction();
47
- } else {
48
- // @ts-ignore
49
- this.lastEvent.times += 1;
50
- }
51
- } else {
52
- this.lastEvent = event;
53
- }
54
- this.timer = setTimeout(this.sendAction, this.DELAY_TIME);
55
- }
56
- };
57
-
58
- sendAction = () => {
59
- // @ts-ignore
60
- this.sendEvent(this.lastEvent);
61
- this.lastEvent = undefined;
62
- };
63
-
64
- destroy() {
65
- // removePageListener('*', this.onEvent);
66
- }
67
- }
@@ -1,158 +0,0 @@
1
- import {
2
- ICollector,
3
- IContext,
4
- isArray,
5
- interceptFunction,
6
- matchList,
7
- RumEvent,
8
- RumEventType,
9
- } from '@arms/rum-core';
10
-
11
- declare const console: any;
12
- declare const ErrorUtils: any;
13
- declare const HermesInternal: any;
14
-
15
- export default class ExceptionCollector implements ICollector {
16
- name = 'exception-collector';
17
- ctx?: IContext;
18
- sendEvent?: (payload: RumEvent) => void;
19
-
20
- private origin = {
21
- consoleError: console.error,
22
- originalOnError: null,
23
- };
24
-
25
- setup(ctx: IContext, sendEvent: (payload: RumEvent) => void) {
26
- this.ctx = ctx;
27
- this.sendEvent = sendEvent;
28
- this.hackOrigin();
29
- }
30
-
31
- hackOrigin() {
32
- const self = this;
33
- const { collectors = {} } = (this.ctx as IContext).getConfig();
34
- if (collectors.jsError !== false) {
35
- if (ErrorUtils) {
36
- this.origin.originalOnError = ErrorUtils.getGlobalHandler?.();
37
- ErrorUtils.setGlobalHandler(this.onError);
38
- }
39
- if (
40
- HermesInternal?.enablePromiseRejectionTracker &&
41
- HermesInternal?.hasPromise?.()
42
- ) {
43
- HermesInternal.enablePromiseRejectionTracker({
44
- allRejections: true,
45
- onUnhandled: this.onUnhandled,
46
- });
47
- }
48
- }
49
- if (collectors.consoleError !== false) {
50
- interceptFunction(console, 'error', function (error: any) {
51
- self.errorHandle(error, 'console.error');
52
- });
53
- }
54
- }
55
-
56
- onError = (e: Error | string, isFatal?: boolean) => {
57
- if (this.origin.originalOnError) {
58
- // @ts-ignore
59
- this.origin.originalOnError(e, isFatal);
60
- }
61
- this.errorHandle(e, 'onError');
62
- };
63
-
64
- onUnhandled = (_id: string, error: unknown) => {
65
- this.errorHandle(error, 'onUnhandled');
66
- };
67
-
68
- errorHandle = (error: any, source = '') => {
69
- let name: string = '';
70
- let message: string = '';
71
- let file: string = '';
72
- let stack: string = '';
73
- let line: string = '';
74
- let column: string = '';
75
- if (error instanceof Object) {
76
- name = error.name;
77
- message = error.message;
78
- file = error.filename || error.fileName;
79
- stack = error.stack;
80
- line = error.lineno || error.lineNumber;
81
- column = error.colno || error.columnNumber;
82
- } else if (typeof error === 'string') {
83
- stack = error;
84
- const err = this.getErrorByStack(error);
85
- if (err) {
86
- name = err.name;
87
- message = err.message;
88
- }
89
- }
90
- if (!name || !message || this.errorFilter(error)) {
91
- return;
92
- }
93
- if (this.ctx && this.sendEvent) {
94
- const baseRumEvent = this.ctx.session.getBaseEvent();
95
- this.sendEvent({
96
- ...baseRumEvent,
97
- event_type: RumEventType.EXCEPTION,
98
- source,
99
- type: 'error',
100
- name,
101
- message,
102
- file,
103
- stack,
104
- line,
105
- column,
106
- });
107
- }
108
- };
109
-
110
- /**
111
- * 根据stack获取Error信息
112
- * TODO: 增加基于Stack解析filename和lineNumber的能力
113
- * @param stack
114
- * @returns
115
- */
116
- getErrorByStack(stack: string = '') {
117
- const res = stack.split('\n');
118
- const prefix = 'at ';
119
- if (res.length < 2) return;
120
- for (let i = 1; i < res.length; i++) {
121
- const str = res[i] || '';
122
- if (str.trim().startsWith(prefix)) {
123
- const line = res[i - 1] || '';
124
- const index = line.indexOf(': ');
125
- return {
126
- name: line.substring(0, index),
127
- message: line.substring(index + 2),
128
- };
129
- }
130
- }
131
- return;
132
- }
133
-
134
- errorFilter(err: Error) {
135
- let { exception: filters } = (this.ctx as IContext).getConfig().filters || {};
136
- if (!filters) {
137
- return false;
138
- }
139
- if (!isArray(filters)) {
140
- filters = [filters];
141
- }
142
- return (
143
- matchList(filters, err.name, true, err) ||
144
- matchList(filters, err.message, true, err) ||
145
- matchList(filters, err.stack || '', true, err)
146
- );
147
- }
148
-
149
- destroy() {
150
- const origin = this.origin;
151
- if (origin.consoleError) {
152
- console.error = origin.consoleError;
153
- }
154
- // if (isFunction(sdk.offError)) {
155
- // sdk.offError(this.onError);
156
- // }
157
- }
158
- }