UNPKG

@sdc-monitor/demo

Version:

<div align="center"> <a href="#" target="_blank"> <img src="https://i.loli.net/2021/07/28/EvPwd4NjVH3tBfO.jpg" alt="mito-logo" height="90"> </a> <p>A Lightweight SDK For Monitor Web</p>

48 lines (46 loc) 1.91 kB
import { ToStringTypes } from '@sdc-monitor/shared' import { BaseOptionsFieldsIntegrationType, BaseOptionsType, VueInstance } from '@sdc-monitor/types' import { generateUUID, validateOptionsAndSet } from '@sdc-monitor/utils' /** * 公用的基础配置项绑定 * * @export * @class BaseOptions * @implements {BaseOptionsType<O>} * @template O */ export class BaseOptions<O extends BaseOptionsFieldsIntegrationType = BaseOptionsFieldsIntegrationType> implements BaseOptionsType<O> { enableTraceId = false filterXhrUrlRegExp: RegExp includeHttpUrlTraceIdRegExp = /.*/ traceIdFieldName = 'Trace-Id' throttleDelayTime = 0 beforeAppAjaxSend = null vue: VueInstance = null constructor() {} bindOptions(options: O) { const { enableTraceId, vue, filterXhrUrlRegExp, traceIdFieldName, throttleDelayTime, includeHttpUrlTraceIdRegExp, beforeAppAjaxSend } = options const optionArr = [ [enableTraceId, 'enableTraceId', ToStringTypes.Boolean], [traceIdFieldName, 'traceIdFieldName', ToStringTypes.String], [throttleDelayTime, 'throttleDelayTime', ToStringTypes.Number], [filterXhrUrlRegExp, 'filterXhrUrlRegExp', ToStringTypes.RegExp], [includeHttpUrlTraceIdRegExp, 'includeHttpUrlTraceIdRegExp', ToStringTypes.RegExp], [beforeAppAjaxSend, 'beforeAppAjaxSend', ToStringTypes.Function] ] validateOptionsAndSet.call(this, optionArr) // for vue this.vue = vue } isFilterHttpUrl(url: string): boolean { return this.filterXhrUrlRegExp && this.filterXhrUrlRegExp.test(url) } setTraceId(httpUrl: string, callback: (headerFieldName: string, traceId: string) => void) { const { includeHttpUrlTraceIdRegExp, enableTraceId } = this if (enableTraceId && includeHttpUrlTraceIdRegExp && includeHttpUrlTraceIdRegExp.test(httpUrl)) { const traceId = generateUUID() callback(this.traceIdFieldName, traceId) } } }