@arms/rum-reactnative 0.0.2-bate.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/LICENSE +20 -0
- package/README.md +37 -0
- package/RumSdkReactnative.podspec +21 -0
- package/android/build.gradle +77 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/rumsdkreactnative/RumSdkReactnativeModule.kt +23 -0
- package/android/src/main/java/com/rumsdkreactnative/RumSdkReactnativePackage.kt +33 -0
- package/ios/RumSdkReactnative.h +5 -0
- package/ios/RumSdkReactnative.mm +18 -0
- package/lib/module/collector/action/index.js +68 -0
- package/lib/module/collector/action/index.js.map +1 -0
- package/lib/module/collector/exception/index.js +135 -0
- package/lib/module/collector/exception/index.js.map +1 -0
- package/lib/module/collector/resource/api.js +281 -0
- package/lib/module/collector/resource/api.js.map +1 -0
- package/lib/module/collector/view/perf.js +79 -0
- package/lib/module/collector/view/perf.js.map +1 -0
- package/lib/module/collector/view/pv.js +72 -0
- package/lib/module/collector/view/pv.js.map +1 -0
- package/lib/module/index.js +6 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/plugin.js +39 -0
- package/lib/module/plugin.js.map +1 -0
- package/lib/module/processor/default-processor.js +22 -0
- package/lib/module/processor/default-processor.js.map +1 -0
- package/lib/module/processor/session-processor.js +20 -0
- package/lib/module/processor/session-processor.js.map +1 -0
- package/lib/module/reporter/index.js +56 -0
- package/lib/module/reporter/index.js.map +1 -0
- package/lib/module/shell.js +63 -0
- package/lib/module/shell.js.map +1 -0
- package/lib/module/types/client.js +4 -0
- package/lib/module/types/client.js.map +1 -0
- package/lib/module/types/index.js +2 -0
- package/lib/module/types/index.js.map +1 -0
- package/lib/module/utils/api.js +75 -0
- package/lib/module/utils/api.js.map +1 -0
- package/lib/module/utils/base.js +90 -0
- package/lib/module/utils/base.js.map +1 -0
- package/lib/module/utils/platform.js +95 -0
- package/lib/module/utils/platform.js.map +1 -0
- package/lib/module/utils/session.js +135 -0
- package/lib/module/utils/session.js.map +1 -0
- package/lib/module/utils/url.js +54 -0
- package/lib/module/utils/url.js.map +1 -0
- package/lib/module/utils/view.js +87 -0
- package/lib/module/utils/view.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/collector/action/index.d.ts +15 -0
- package/lib/typescript/src/collector/action/index.d.ts.map +1 -0
- package/lib/typescript/src/collector/exception/index.d.ts +25 -0
- package/lib/typescript/src/collector/exception/index.d.ts.map +1 -0
- package/lib/typescript/src/collector/resource/api.d.ts +21 -0
- package/lib/typescript/src/collector/resource/api.d.ts.map +1 -0
- package/lib/typescript/src/collector/view/perf.d.ts +1 -0
- package/lib/typescript/src/collector/view/perf.d.ts.map +1 -0
- package/lib/typescript/src/collector/view/pv.d.ts +16 -0
- package/lib/typescript/src/collector/view/pv.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +4 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/plugin.d.ts +3 -0
- package/lib/typescript/src/plugin.d.ts.map +1 -0
- package/lib/typescript/src/processor/default-processor.d.ts +6 -0
- package/lib/typescript/src/processor/default-processor.d.ts.map +1 -0
- package/lib/typescript/src/processor/session-processor.d.ts +9 -0
- package/lib/typescript/src/processor/session-processor.d.ts.map +1 -0
- package/lib/typescript/src/reporter/index.d.ts +16 -0
- package/lib/typescript/src/reporter/index.d.ts.map +1 -0
- package/lib/typescript/src/shell.d.ts +29 -0
- package/lib/typescript/src/shell.d.ts.map +1 -0
- package/lib/typescript/src/types/client.d.ts +27 -0
- package/lib/typescript/src/types/client.d.ts.map +1 -0
- package/lib/typescript/src/types/index.d.ts +118 -0
- package/lib/typescript/src/types/index.d.ts.map +1 -0
- package/lib/typescript/src/utils/api.d.ts +59 -0
- package/lib/typescript/src/utils/api.d.ts.map +1 -0
- package/lib/typescript/src/utils/base.d.ts +8 -0
- package/lib/typescript/src/utils/base.d.ts.map +1 -0
- package/lib/typescript/src/utils/platform.d.ts +15 -0
- package/lib/typescript/src/utils/platform.d.ts.map +1 -0
- package/lib/typescript/src/utils/session.d.ts +37 -0
- package/lib/typescript/src/utils/session.d.ts.map +1 -0
- package/lib/typescript/src/utils/url.d.ts +17 -0
- package/lib/typescript/src/utils/url.d.ts.map +1 -0
- package/lib/typescript/src/utils/view.d.ts +13 -0
- package/lib/typescript/src/utils/view.d.ts.map +1 -0
- package/package.json +158 -0
- package/src/collector/action/index.ts +67 -0
- package/src/collector/exception/index.ts +158 -0
- package/src/collector/resource/api.ts +379 -0
- package/src/collector/view/perf.ts +77 -0
- package/src/collector/view/pv.ts +73 -0
- package/src/index.ts +4 -0
- package/src/plugin.ts +41 -0
- package/src/processor/default-processor.ts +22 -0
- package/src/processor/session-processor.ts +23 -0
- package/src/reporter/index.ts +67 -0
- package/src/shell.ts +81 -0
- package/src/types/client.ts +32 -0
- package/src/types/index.ts +159 -0
- package/src/utils/api.ts +119 -0
- package/src/utils/base.ts +92 -0
- package/src/utils/platform.ts +107 -0
- package/src/utils/session.ts +168 -0
- package/src/utils/url.ts +53 -0
- package/src/utils/view.ts +93 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 光粒
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# rum-sdk-reactnative
|
|
2
|
+
|
|
3
|
+
RUM SDK For ReactNative
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
npm install rum-sdk-reactnative
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
```js
|
|
17
|
+
import { multiply } from 'rum-sdk-reactnative';
|
|
18
|
+
|
|
19
|
+
// ...
|
|
20
|
+
|
|
21
|
+
const result = multiply(3, 7);
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
|
|
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)
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { RumEventType } from '@arms/rum-core';
|
|
4
|
+
import { getCurView } from "../../utils/view.js";
|
|
5
|
+
export default class ActionCollector {
|
|
6
|
+
name = 'action-collector';
|
|
7
|
+
DELAY_TIME = 300;
|
|
8
|
+
events = ['tap'];
|
|
9
|
+
setup(ctx, sendEvent) {
|
|
10
|
+
const {
|
|
11
|
+
collectors = {}
|
|
12
|
+
} = ctx.getConfig();
|
|
13
|
+
if (collectors.action === false) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
this.ctx = ctx;
|
|
17
|
+
this.sendEvent = sendEvent;
|
|
18
|
+
// addPageListener('*', this.onEvent)
|
|
19
|
+
}
|
|
20
|
+
onEvent = e => {
|
|
21
|
+
if (e && this.events.includes(e.type) && e.target) {
|
|
22
|
+
const {
|
|
23
|
+
target,
|
|
24
|
+
currentTarget,
|
|
25
|
+
type
|
|
26
|
+
} = e;
|
|
27
|
+
const {
|
|
28
|
+
dataset,
|
|
29
|
+
id
|
|
30
|
+
} = target;
|
|
31
|
+
if (!id) return;
|
|
32
|
+
if (currentTarget && id !== currentTarget.id) return;
|
|
33
|
+
let view;
|
|
34
|
+
if (this.ctx) {
|
|
35
|
+
view = getCurView(this.ctx);
|
|
36
|
+
}
|
|
37
|
+
const event = {
|
|
38
|
+
event_type: RumEventType.ACTION,
|
|
39
|
+
type,
|
|
40
|
+
name: id,
|
|
41
|
+
snapshots: Object.keys(dataset).length ? JSON.stringify(dataset) : undefined,
|
|
42
|
+
times: 1,
|
|
43
|
+
view
|
|
44
|
+
};
|
|
45
|
+
clearTimeout(this.timer);
|
|
46
|
+
if (this.lastEvent) {
|
|
47
|
+
if (this.lastEvent.name !== event.name) {
|
|
48
|
+
this.sendAction();
|
|
49
|
+
} else {
|
|
50
|
+
// @ts-ignore
|
|
51
|
+
this.lastEvent.times += 1;
|
|
52
|
+
}
|
|
53
|
+
} else {
|
|
54
|
+
this.lastEvent = event;
|
|
55
|
+
}
|
|
56
|
+
this.timer = setTimeout(this.sendAction, this.DELAY_TIME);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
sendAction = () => {
|
|
60
|
+
// @ts-ignore
|
|
61
|
+
this.sendEvent(this.lastEvent);
|
|
62
|
+
this.lastEvent = undefined;
|
|
63
|
+
};
|
|
64
|
+
destroy() {
|
|
65
|
+
// removePageListener('*', this.onEvent);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["RumEventType","getCurView","ActionCollector","name","DELAY_TIME","events","setup","ctx","sendEvent","collectors","getConfig","action","onEvent","e","includes","type","target","currentTarget","dataset","id","view","event","event_type","ACTION","snapshots","Object","keys","length","JSON","stringify","undefined","times","clearTimeout","timer","lastEvent","sendAction","setTimeout","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OAAO,CAAC,GACvBY,SAAS;QACbC,KAAK,EAAE,CAAC;QACRX;MACF,CAAC;MACDY,YAAY,CAAC,IAAI,CAACC,KAAK,CAAC;MACxB,IAAI,IAAI,CAACC,SAAS,EAAE;QAClB,IAAI,IAAI,CAACA,SAAS,CAAC/B,IAAI,KAAKkB,KAAK,CAAClB,IAAI,EAAE;UACtC,IAAI,CAACgC,UAAU,CAAC,CAAC;QACnB,CAAC,MAAM;UACL;UACA,IAAI,CAACD,SAAS,CAACH,KAAK,IAAI,CAAC;QAC3B;MACF,CAAC,MAAM;QACL,IAAI,CAACG,SAAS,GAAGb,KAAK;MACxB;MACA,IAAI,CAACY,KAAK,GAAGG,UAAU,CAAC,IAAI,CAACD,UAAU,EAAE,IAAI,CAAC/B,UAAU,CAAC;IAC3D;EACF,CAAC;EAED+B,UAAU,GAAGA,CAAA,KAAM;IACjB;IACA,IAAI,CAAC3B,SAAS,CAAC,IAAI,CAAC0B,SAAS,CAAC;IAC9B,IAAI,CAACA,SAAS,GAAGJ,SAAS;EAC5B,CAAC;EAEDO,OAAOA,CAAA,EAAG;IACR;EAAA;AAEJ","ignoreList":[]}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { isArray, interceptFunction, matchList, RumEventType } from '@arms/rum-core';
|
|
4
|
+
export default class ExceptionCollector {
|
|
5
|
+
name = 'exception-collector';
|
|
6
|
+
origin = {
|
|
7
|
+
consoleError: console.error,
|
|
8
|
+
originalOnError: null
|
|
9
|
+
};
|
|
10
|
+
setup(ctx, sendEvent) {
|
|
11
|
+
this.ctx = ctx;
|
|
12
|
+
this.sendEvent = sendEvent;
|
|
13
|
+
this.hackOrigin();
|
|
14
|
+
}
|
|
15
|
+
hackOrigin() {
|
|
16
|
+
const self = this;
|
|
17
|
+
const {
|
|
18
|
+
collectors = {}
|
|
19
|
+
} = this.ctx.getConfig();
|
|
20
|
+
if (collectors.jsError !== false) {
|
|
21
|
+
if (ErrorUtils) {
|
|
22
|
+
this.origin.originalOnError = ErrorUtils.getGlobalHandler?.();
|
|
23
|
+
ErrorUtils.setGlobalHandler(this.onError);
|
|
24
|
+
}
|
|
25
|
+
if (HermesInternal?.enablePromiseRejectionTracker && HermesInternal?.hasPromise?.()) {
|
|
26
|
+
HermesInternal.enablePromiseRejectionTracker({
|
|
27
|
+
allRejections: true,
|
|
28
|
+
onUnhandled: this.onUnhandled
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (collectors.consoleError !== false) {
|
|
33
|
+
interceptFunction(console, 'error', function (error) {
|
|
34
|
+
self.errorHandle(error, 'console.error');
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
onError = (e, isFatal) => {
|
|
39
|
+
if (this.origin.originalOnError) {
|
|
40
|
+
// @ts-ignore
|
|
41
|
+
this.origin.originalOnError(e, isFatal);
|
|
42
|
+
}
|
|
43
|
+
this.errorHandle(e, 'onError');
|
|
44
|
+
};
|
|
45
|
+
onUnhandled = (_id, error) => {
|
|
46
|
+
this.errorHandle(error, 'onUnhandled');
|
|
47
|
+
};
|
|
48
|
+
errorHandle = (error, source = '') => {
|
|
49
|
+
let name = '';
|
|
50
|
+
let message = '';
|
|
51
|
+
let file = '';
|
|
52
|
+
let stack = '';
|
|
53
|
+
let line = '';
|
|
54
|
+
let column = '';
|
|
55
|
+
if (error instanceof Object) {
|
|
56
|
+
name = error.name;
|
|
57
|
+
message = error.message;
|
|
58
|
+
file = error.filename || error.fileName;
|
|
59
|
+
stack = error.stack;
|
|
60
|
+
line = error.lineno || error.lineNumber;
|
|
61
|
+
column = error.colno || error.columnNumber;
|
|
62
|
+
} else if (typeof error === 'string') {
|
|
63
|
+
stack = error;
|
|
64
|
+
const err = this.getErrorByStack(error);
|
|
65
|
+
if (err) {
|
|
66
|
+
name = err.name;
|
|
67
|
+
message = err.message;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (!name || !message || this.errorFilter(error)) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (this.ctx && this.sendEvent) {
|
|
74
|
+
const baseRumEvent = this.ctx.session.getBaseEvent();
|
|
75
|
+
this.sendEvent({
|
|
76
|
+
...baseRumEvent,
|
|
77
|
+
event_type: RumEventType.EXCEPTION,
|
|
78
|
+
source,
|
|
79
|
+
type: 'error',
|
|
80
|
+
name,
|
|
81
|
+
message,
|
|
82
|
+
file,
|
|
83
|
+
stack,
|
|
84
|
+
line,
|
|
85
|
+
column
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* 根据stack获取Error信息
|
|
92
|
+
* TODO: 增加基于Stack解析filename和lineNumber的能力
|
|
93
|
+
* @param stack
|
|
94
|
+
* @returns
|
|
95
|
+
*/
|
|
96
|
+
getErrorByStack(stack = '') {
|
|
97
|
+
const res = stack.split('\n');
|
|
98
|
+
const prefix = 'at ';
|
|
99
|
+
if (res.length < 2) return;
|
|
100
|
+
for (let i = 1; i < res.length; i++) {
|
|
101
|
+
const str = res[i] || '';
|
|
102
|
+
if (str.trim().startsWith(prefix)) {
|
|
103
|
+
const line = res[i - 1] || '';
|
|
104
|
+
const index = line.indexOf(': ');
|
|
105
|
+
return {
|
|
106
|
+
name: line.substring(0, index),
|
|
107
|
+
message: line.substring(index + 2)
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
errorFilter(err) {
|
|
114
|
+
let {
|
|
115
|
+
exception: filters
|
|
116
|
+
} = this.ctx.getConfig().filters || {};
|
|
117
|
+
if (!filters) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
if (!isArray(filters)) {
|
|
121
|
+
filters = [filters];
|
|
122
|
+
}
|
|
123
|
+
return matchList(filters, err.name, true, err) || matchList(filters, err.message, true, err) || matchList(filters, err.stack || '', true, err);
|
|
124
|
+
}
|
|
125
|
+
destroy() {
|
|
126
|
+
const origin = this.origin;
|
|
127
|
+
if (origin.consoleError) {
|
|
128
|
+
console.error = origin.consoleError;
|
|
129
|
+
}
|
|
130
|
+
// if (isFunction(sdk.offError)) {
|
|
131
|
+
// sdk.offError(this.onError);
|
|
132
|
+
// }
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["isArray","interceptFunction","matchList","RumEventType","ExceptionCollector","name","origin","consoleError","console","error","originalOnError","setup","ctx","sendEvent","hackOrigin","self","collectors","getConfig","jsError","ErrorUtils","getGlobalHandler","setGlobalHandler","onError","HermesInternal","enablePromiseRejectionTracker","hasPromise","allRejections","onUnhandled","errorHandle","e","isFatal","_id","source","message","file","stack","line","column","Object","filename","fileName","lineno","lineNumber","colno","columnNumber","err","getErrorByStack","errorFilter","baseRumEvent","session","getBaseEvent","event_type","EXCEPTION","type","res","split","prefix","length","i","str","trim","startsWith","index","indexOf","substring","exception","filters","destroy"],"sourceRoot":"../../../../src","sources":["collector/exception/index.ts"],"mappings":";;AAAA,SAGEA,OAAO,EACPC,iBAAiB,EACjBC,SAAS,EAETC,YAAY,QACP,gBAAgB;AAMvB,eAAe,MAAMC,kBAAkB,CAAuB;EAC5DC,IAAI,GAAG,qBAAqB;EAIpBC,MAAM,GAAG;IACfC,YAAY,EAAEC,OAAO,CAACC,KAAK;IAC3BC,eAAe,EAAE;EACnB,CAAC;EAEDC,KAAKA,CAACC,GAAa,EAAEC,SAAsC,EAAE;IAC3D,IAAI,CAACD,GAAG,GAAGA,GAAG;IACd,IAAI,CAACC,SAAS,GAAGA,SAAS;IAC1B,IAAI,CAACC,UAAU,CAAC,CAAC;EACnB;EAEAA,UAAUA,CAAA,EAAG;IACX,MAAMC,IAAI,GAAG,IAAI;IACjB,MAAM;MAAEC,UAAU,GAAG,CAAC;IAAE,CAAC,GAAI,IAAI,CAACJ,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