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 99352bc fix typo (#50) 99352bc is described below commit 99352bcf31c8c3605bdedbf12a695cd5a66dbbfb Author: zhang-wei <pk...@outlook.com> AuthorDate: Sun Apr 25 15:08:29 2021 +0800 fix typo (#50) --- src/services/base.ts | 4 ++-- src/services/task.ts | 6 +++--- src/services/types.d.ts | 2 +- src/trace/interceptors/fetch.ts | 16 +++++++++------- src/trace/interceptors/xhr.ts | 17 ++++++++++------- src/trace/segment.ts | 4 ++-- src/trace/type.d.ts | 6 +++--- 7 files changed, 30 insertions(+), 25 deletions(-) diff --git a/src/services/base.ts b/src/services/base.ts index 9c8ac20..16908fe 100644 --- a/src/services/base.ts +++ b/src/services/base.ts @@ -16,11 +16,11 @@ */ import Task from './task'; import { ErrorsCategory, GradeTypeEnum } from './constant'; -import { ErrorInfoFeilds, ReportFields } from './types'; +import { ErrorInfoFields, ReportFields } from './types'; let jsErrorPv = false; export default class Base { - public logInfo: ErrorInfoFeilds & ReportFields & { collector: string } = { + public logInfo: ErrorInfoFields & ReportFields & { collector: string } = { uniqueId: '', service: '', serviceVersion: '', diff --git a/src/services/task.ts b/src/services/task.ts index b777a43..952a098 100644 --- a/src/services/task.ts +++ b/src/services/task.ts @@ -14,14 +14,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { ErrorInfoFeilds, ReportFields } from './types'; +import { ErrorInfoFields, ReportFields } from './types'; import Report from './report'; class TaskQueue { - private queues: ((ErrorInfoFeilds & ReportFields) | undefined)[] = []; + private queues: ((ErrorInfoFields & ReportFields) | undefined)[] = []; private collector: string = ''; - public addTask(data: ErrorInfoFeilds & ReportFields, collector: string) { + public addTask(data: ErrorInfoFields & ReportFields, collector: string) { this.queues.push(data); this.collector = collector; } diff --git a/src/services/types.d.ts b/src/services/types.d.ts index 1b214a8..2785520 100644 --- a/src/services/types.d.ts +++ b/src/services/types.d.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -export interface ErrorInfoFeilds { +export interface ErrorInfoFields { uniqueId: string; category: string; grade: string; diff --git a/src/trace/interceptors/fetch.ts b/src/trace/interceptors/fetch.ts index 5bbb1e2..1936302 100644 --- a/src/trace/interceptors/fetch.ts +++ b/src/trace/interceptors/fetch.ts @@ -16,11 +16,11 @@ */ import { encode } from 'js-base64'; import uuid from '../../services/uuid'; -import { SegmentFeilds, SpanFeilds } from '../type'; +import { SegmentFields, SpanFields } from '../type'; import { CustomOptionsType } from '../../types'; -import { SpanLayer, SpanType, ComponentId, ServiceTag, ReportTypes } from '../../services/constant'; +import { ComponentId, ReportTypes, ServiceTag, SpanLayer, SpanType } from '../../services/constant'; -export default function windowFetch(options: CustomOptionsType, segments: SegmentFeilds[]) { +export default function windowFetch(options: CustomOptionsType, segments: SegmentFields[]) { const fetch: any = window.fetch; let segment = { traceId: '', @@ -28,7 +28,7 @@ export default function windowFetch(options: CustomOptionsType, segments: Segmen spans: [], serviceInstance: options.serviceVersion, traceSegmentId: '', - } as SegmentFeilds; + } as SegmentFields; let url = {} as URL; window.fetch = (...args) => @@ -59,7 +59,9 @@ export default function windowFetch(options: CustomOptionsType, segments: Segmen }); const hasTrace = !( noTrace || - (([ReportTypes.ERROR, ReportTypes.PERF, ReportTypes.SEGMENTS] as string[]).includes(url.pathname) && + (([ReportTypes.ERROR, ReportTypes.ERRORS, ReportTypes.PERF, ReportTypes.SEGMENTS] as string[]).includes( + url.pathname, + ) && !options.traceSDKInternal) ); @@ -84,14 +86,14 @@ export default function windowFetch(options: CustomOptionsType, segments: Segmen if (hasTrace) { const endTime = new Date().getTime(); - const exitSpan: SpanFeilds = { + const exitSpan: SpanFields = { operationName: options.pagePath, startTime: startTime, endTime, spanId: segment.spans.length, spanLayer: SpanLayer, spanType: SpanType, - isError: result.status === 0 || result.status >= 400 ? true : false, // when requests failed, the status is 0 + isError: result.status === 0 || result.status >= 400, // when requests failed, the status is 0 parentSpanId: segment.spans.length - 1, componentId: ComponentId, peer: result.url.host, diff --git a/src/trace/interceptors/xhr.ts b/src/trace/interceptors/xhr.ts index 1274f51..a4b0119 100644 --- a/src/trace/interceptors/xhr.ts +++ b/src/trace/interceptors/xhr.ts @@ -14,13 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { SpanLayer, SpanType, ReadyStatus, ComponentId, ServiceTag, ReportTypes } from '../../services/constant'; +import { ComponentId, ReadyStatus, ReportTypes, ServiceTag, SpanLayer, SpanType } from '../../services/constant'; import uuid from '../../services/uuid'; import { encode } from 'js-base64'; import { CustomOptionsType } from '../../types'; -import { SegmentFeilds, SpanFeilds } from '../type'; +import { SegmentFields, SpanFields } from '../type'; -export default function xhrInterceptor(options: CustomOptionsType, segments: SegmentFeilds[]) { +export default function xhrInterceptor(options: CustomOptionsType, segments: SegmentFields[]) { const originalXHR = window.XMLHttpRequest as any; const xhrSend = XMLHttpRequest.prototype.send; const xhrOpen = XMLHttpRequest.prototype.open; @@ -61,6 +61,7 @@ export default function xhrInterceptor(options: CustomOptionsType, segments: Seg return liveXHR; } + (window as any).XMLHttpRequest = customizedXHR; const segCollector: { event: XMLHttpRequest; startTime: number; traceId: string; traceSegmentId: string }[] = []; @@ -72,7 +73,7 @@ export default function xhrInterceptor(options: CustomOptionsType, segments: Seg spans: [], serviceInstance: options.serviceVersion, traceSegmentId: '', - } as SegmentFeilds; + } as SegmentFields; const xhrState = event.detail.readyState; const config = event.detail.getRequestConfig; let url = {} as URL; @@ -101,7 +102,9 @@ export default function xhrInterceptor(options: CustomOptionsType, segments: Seg } if ( - ([ReportTypes.ERROR, ReportTypes.PERF, ReportTypes.SEGMENTS] as string[]).includes(url.pathname) && + ([ReportTypes.ERROR, ReportTypes.ERRORS, ReportTypes.PERF, ReportTypes.SEGMENTS] as string[]).includes( + url.pathname, + ) && !options.traceSDKInternal ) { return; @@ -139,14 +142,14 @@ export default function xhrInterceptor(options: CustomOptionsType, segments: Seg if (segCollector[i].event.status) { url = new URL(segCollector[i].event.responseURL); } - const exitSpan: SpanFeilds = { + const exitSpan: SpanFields = { operationName: options.pagePath, startTime: segCollector[i].startTime, endTime, spanId: segment.spans.length, spanLayer: SpanLayer, spanType: SpanType, - isError: event.detail.status === 0 || event.detail.status >= 400 ? true : false, // when requests failed, the status is 0 + isError: event.detail.status === 0 || event.detail.status >= 400, // when requests failed, the status is 0 parentSpanId: segment.spans.length - 1, componentId: ComponentId, peer: url.host, diff --git a/src/trace/segment.ts b/src/trace/segment.ts index e050daf..c5211ea 100644 --- a/src/trace/segment.ts +++ b/src/trace/segment.ts @@ -18,11 +18,11 @@ import xhrInterceptor from './interceptors/xhr'; import windowFetch from './interceptors/fetch'; import Report from '../services/report'; -import { SegmentFeilds } from './type'; +import { SegmentFields } from './type'; import { CustomOptionsType } from '../types'; export default function traceSegment(options: CustomOptionsType) { - let segments = [] as SegmentFeilds[]; + let segments = [] as SegmentFields[]; // inject interceptor xhrInterceptor(options, segments); windowFetch(options, segments); diff --git a/src/trace/type.d.ts b/src/trace/type.d.ts index 7e5af5f..2e49bd6 100644 --- a/src/trace/type.d.ts +++ b/src/trace/type.d.ts @@ -15,15 +15,15 @@ * limitations under the License. */ -export interface SegmentFeilds { +export interface SegmentFields { traceId: string; service: string; - spans: SpanFeilds[]; + spans: SpanFields[]; serviceInstance: string; traceSegmentId: string; } -export interface SpanFeilds { +export interface SpanFields { operationName: string; startTime: number; endTime: number;