You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2021/09/26 08:59:20 UTC
[skywalking-client-js] branch master updated: fix: update
conditions for traceSDKInternal (#73)
This is an automated email from the ASF dual-hosted git repository.
wusheng 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 2666901 fix: update conditions for traceSDKInternal (#73)
2666901 is described below
commit 2666901e2ecd6fb52177b3a084d1833be5e01d22
Author: Fine0830 <fi...@outlook.com>
AuthorDate: Sun Sep 26 16:59:15 2021 +0800
fix: update conditions for traceSDKInternal (#73)
---
src/trace/interceptors/fetch.ts | 16 ++++++----------
src/trace/interceptors/xhr.ts | 17 ++++++++---------
2 files changed, 14 insertions(+), 19 deletions(-)
diff --git a/src/trace/interceptors/fetch.ts b/src/trace/interceptors/fetch.ts
index 740a30f..0db6fa8 100644
--- a/src/trace/interceptors/fetch.ts
+++ b/src/trace/interceptors/fetch.ts
@@ -54,7 +54,7 @@ export default function windowFetch(options: CustomOptionsType, segments: Segmen
url.pathname = args[0];
}
- const noTrace = options.noTraceOrigins.some((rule: string | RegExp) => {
+ const noTraceOrigins = options.noTraceOrigins.some((rule: string | RegExp) => {
if (typeof rule === 'string') {
if (rule === url.origin) {
return true;
@@ -65,15 +65,11 @@ export default function windowFetch(options: CustomOptionsType, segments: Segmen
}
}
});
-
- const collectorURL = new URL(options.collector);
- const hasTrace = !(
- noTrace ||
- (([ReportTypes.ERROR, ReportTypes.ERRORS, ReportTypes.PERF, ReportTypes.SEGMENTS] as string[]).includes(
- url.pathname.replace(new RegExp(`^${collectorURL.pathname}`), ''),
- ) &&
- !options.traceSDKInternal)
- );
+ const cURL = new URL(options.collector);
+ const pathname = cURL.pathname === '/' ? url.pathname : url.pathname.replace(new RegExp(`^${cURL.pathname}`), '');
+ const internals = [ReportTypes.ERROR, ReportTypes.ERRORS, ReportTypes.PERF, ReportTypes.SEGMENTS] as string[];
+ const isSDKInternal = internals.includes(pathname);
+ const hasTrace = !noTraceOrigins || (isSDKInternal && options.traceSDKInternal);
if (hasTrace) {
const traceIdStr = String(encode(traceId));
diff --git a/src/trace/interceptors/xhr.ts b/src/trace/interceptors/xhr.ts
index b829e5b..a6f0156 100644
--- a/src/trace/interceptors/xhr.ts
+++ b/src/trace/interceptors/xhr.ts
@@ -86,7 +86,7 @@ export default function xhrInterceptor(options: CustomOptionsType, segments: Seg
url.pathname = config[1];
}
- const noTrace = options.noTraceOrigins.some((rule: string | RegExp) => {
+ const noTraceOrigins = options.noTraceOrigins.some((rule: string | RegExp) => {
if (typeof rule === 'string') {
if (rule === url.origin) {
return true;
@@ -97,17 +97,16 @@ export default function xhrInterceptor(options: CustomOptionsType, segments: Seg
}
}
});
- if (noTrace) {
+ if (noTraceOrigins) {
return;
}
- const collectorURL = new URL(options.collector)
- if (
- ([ReportTypes.ERROR, ReportTypes.ERRORS, ReportTypes.PERF, ReportTypes.SEGMENTS] as string[]).includes(
- url.pathname.replace(new RegExp(`^${collectorURL.pathname}`), ''),
- ) &&
- !options.traceSDKInternal
- ) {
+ const cURL = new URL(options.collector);
+ const pathname = cURL.pathname === '/' ? url.pathname : url.pathname.replace(new RegExp(`^${cURL.pathname}`), '');
+ const internals = [ReportTypes.ERROR, ReportTypes.ERRORS, ReportTypes.PERF, ReportTypes.SEGMENTS] as string[];
+ const isSDKInternal = internals.includes(pathname);
+
+ if (isSDKInternal && !options.traceSDKInternal) {
return;
}