You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by qi...@apache.org on 2021/03/16 02:40:51 UTC
[skywalking-client-js] branch master updated: feat: add
`noTraceOrigins` option (#45)
This is an automated email from the ASF dual-hosted git repository.
qiuxiafan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking-client-js.git
The following commit(s) were added to refs/heads/master by this push:
new b20a7fa feat: add `noTraceOrigins` option (#45)
b20a7fa is described below
commit b20a7faf2f68c0fc01a57d6394fa7770ec617a49
Author: keke <yo...@gmail.com>
AuthorDate: Tue Mar 16 10:40:43 2021 +0800
feat: add `noTraceOrigins` option (#45)
* add originAllowlist option
* rename originAllowlist to traceOrigins
* rename traceOrigins => originAllowList
* noTraceOrigins
* noTraceOrigins default `[]`
Co-authored-by: Qiuxia Fan <fi...@outlook.com>
---
README.md | 7 ++++---
src/monitor.ts | 1 +
src/trace/segment.ts | 16 ++++++++++++++++
src/types.d.ts | 1 +
4 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/README.md b/README.md
index 4a3afde..bbbaf8d 100644
--- a/README.md
+++ b/README.md
@@ -23,10 +23,10 @@ npm install skywalking-client-js --save
User could use `register` method to load and report data automatically.
-```
+```js
import ClientMonitor from 'skywalking-client-js';
```
-```
+```js
// Report collected data to `http:// + window.location.host + /browser/perfData` in default
ClientMonitor.register({
collector: 'http://127.0.0.1:8080',
@@ -54,6 +54,7 @@ The register method supports the following parameters.
|vue|Vue|Support vue errors monitoring|false|undefined|
|traceSDKInternal|Boolean|Support tracing SDK internal RPC.|false|false|
|detailMode|Boolean|Support tracing http method and url as tags in spans.|false|true|
+|noTraceOrigins|(string \| RegExp)[]|Origin in the `noTraceOrigins` list will not be traced.|false|[]|
## Collect Metrics Manually
Use the `setPerformance` method to report metrics at the moment of page loaded or any other moment meaningful.
@@ -62,7 +63,7 @@ Use the `setPerformance` method to report metrics at the moment of page loaded o
2. Call `ClientMonitor.setPerformance(object)` method to report
- Examples
-```
+```js
import ClientMonitor from 'skywalking-client-js';
ClientMonitor.setPerformance({
diff --git a/src/monitor.ts b/src/monitor.ts
index 560d069..8844305 100644
--- a/src/monitor.ts
+++ b/src/monitor.ts
@@ -31,6 +31,7 @@ const ClientMonitor = {
enableSPA: false,
traceSDKInternal: false,
detailMode: true,
+ noTraceOrigins: [],
} as CustomOptionsType,
register(configs: CustomOptionsType) {
diff --git a/src/trace/segment.ts b/src/trace/segment.ts
index 6e8f650..083fbb1 100644
--- a/src/trace/segment.ts
+++ b/src/trace/segment.ts
@@ -48,6 +48,22 @@ export default function traceSegment(options: CustomOptionsType) {
url = new URL(window.location.href);
url.pathname = config[1];
}
+
+ const noTrace = options.noTraceOrigins.some((rule) => {
+ if (typeof rule === 'string') {
+ if (rule === url.origin) {
+ return true;
+ }
+ } else if (rule instanceof RegExp) {
+ if (rule.test(url.origin)) {
+ return true;
+ }
+ }
+ });
+ if (noTrace) {
+ return;
+ }
+
if (
([ReportTypes.ERROR, ReportTypes.PERF, ReportTypes.SEGMENTS] as string[]).includes(url.pathname) &&
!options.traceSDKInternal
diff --git a/src/types.d.ts b/src/types.d.ts
index 58f39bb..f98546b 100644
--- a/src/types.d.ts
+++ b/src/types.d.ts
@@ -29,4 +29,5 @@ export interface CustomOptionsType {
vue?: any;
traceSDKInternal?: boolean;
detailMode?: boolean;
+ noTraceOrigins?: (string | RegExp)[];
}