jason-trace-log 1.0.5 → 1.0.8

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.
@@ -1,6 +1,5 @@
1
1
  import { BaseTraceInterface } from './core/interface';
2
2
  import { OnFetchError } from './core/fetch';
3
- import { BrowserType } from './typings/common';
4
3
  import { SendMethod } from './typings/common';
5
4
  export interface LTSConfig {
6
5
  region: string;
@@ -9,7 +8,7 @@ export interface LTSConfig {
9
8
  streamId: string;
10
9
  debug?: boolean;
11
10
  }
12
- export interface TraceOptions {
11
+ export interface TraceOptions<T extends Record<string, any> = Record<string, any>> {
13
12
  perfOnSend?: () => void;
14
13
  perfBeforeSend?: () => void;
15
14
  dsn?: string;
@@ -17,35 +16,44 @@ export interface TraceOptions {
17
16
  appId: string;
18
17
  sendMethod?: SendMethod;
19
18
  ltsConfig?: LTSConfig;
19
+ customGlobalFields?: T;
20
20
  }
21
21
  export declare class BaseTrace implements BaseTraceInterface {
22
- dsn: string;
23
- pageId: string;
24
- userAgent: string;
25
- browserType: BrowserType;
26
- fpId: string;
27
- uid: string;
28
- appId: string;
29
- debug: boolean;
30
- sendMethod: SendMethod;
31
- ltsConfig?: LTSConfig;
32
- perfData: TracePerf;
33
- resources: TraceDataResource[];
34
- result: {};
35
- breadcrumb: TraceBreadcrumbs;
36
- maxBreadcrumb: number;
37
- breadcrumbEnabled: boolean;
38
- observer: any;
39
- queue: TraceData[];
40
- sendTimer: number;
22
+ private dsn;
23
+ private pageId;
24
+ private userAgent;
25
+ private browserType;
26
+ private fpId;
27
+ private uid;
28
+ private appId;
29
+ private debug;
30
+ private sendMethod;
31
+ private ltsConfig?;
32
+ private perfData;
33
+ private resources;
34
+ private result;
35
+ private breadcrumb;
36
+ private maxBreadcrumb;
37
+ private breadcrumbEnabled;
38
+ private queue;
39
+ private sendTimer;
40
+ private customGlobalFields;
41
41
  constructor(options: TraceOptions);
42
- log(log: TraceDataLog): void;
43
- info(message: string, tag?: string): void;
44
- warn(message: string, tag?: string): void;
45
- error(message: string, tag?: string): void;
42
+ private log;
43
+ info(message: string, tag?: string, extra?: Record<string, any>): void;
44
+ warn(message: string, tag?: string, extra?: Record<string, any>): void;
45
+ error(message: string, tag?: string, extra?: Record<string, any>): void;
46
46
  setTraceData(data: TraceTypeData | TracePerf): TraceData;
47
47
  send(data: TraceTypeData | TracePerf): void;
48
+ private enqueueOrSend;
48
49
  createPerfReport(): (metric: any) => void;
50
+ /**
51
+ * 保存 Promise 异常
52
+ */
53
+ savePromiseError(reason: any): void;
54
+ /**
55
+ * 保存 JavaScript 运行时错误和资源加载错误
56
+ */
49
57
  saveError(event: ErrorEvent): void;
50
58
  handleObserverResource(entry: PerformanceResourceTiming): void;
51
59
  onFetchError(message: OnFetchError): void;
@@ -54,5 +62,10 @@ export declare class BaseTrace implements BaseTraceInterface {
54
62
  onObserverResource(): void;
55
63
  saveBreadcrumb(data: TraceAction): void;
56
64
  setUserId(userId: string): void;
57
- static init(options: TraceOptions): BaseTrace;
65
+ /**
66
+ * 设置自定义全局字段
67
+ * @param fields 自定义全局字段
68
+ */
69
+ setCustomGlobalFields(fields: Record<string, any>): void;
70
+ static init<T extends Record<string, any> = Record<string, any>>(options: TraceOptions<T>): BaseTrace;
58
71
  }
@@ -17,5 +17,5 @@ export type InterceptFetchType = {
17
17
  onBefore?: (props: OnBeforeProps) => void;
18
18
  onAfter?: (result: any) => void;
19
19
  };
20
- declare const interceptFetch: ({ pagePath, onError, onBefore, onAfter }: InterceptFetchType) => (...args: any) => Promise<any>;
20
+ declare const interceptFetch: ({ onError, onBefore, onAfter }: InterceptFetchType) => (...args: any) => Promise<any>;
21
21
  export default interceptFetch;
@@ -1,14 +1,14 @@
1
- import { BreadcrumbTypes, TraceDataSeverity, TraceDataTypes, BreadcrumbsCategorys, TraceLevelType, TraceTypes } from "../typings/common";
1
+ import { BreadcrumbTypes, TraceDataSeverity, TraceDataTypes, BreadcrumbsCategorys, TraceLevelType, TraceTypes } from '../typings/common';
2
2
  export declare const getTimestamp: () => number;
3
3
  export declare const getFetchStatusLevel: (status: number) => TraceDataSeverity;
4
4
  export declare const isResourceTarget: (target: HTMLElement) => boolean;
5
5
  /**
6
- * 根据字符串生成hashcode
7
- *
8
- * @export
9
- * @param {string} str
10
- * @return {*} {number} 可为正数和负数
11
- */
6
+ * 根据字符串生成hashcode
7
+ *
8
+ * @export
9
+ * @param {string} str
10
+ * @return {*} {number} 可为正数和负数
11
+ */
12
12
  export declare function hashCode(str: string): number;
13
13
  export declare function dataTypes2BreadcrumbsType(data: TraceDataTypes): BreadcrumbTypes.ROUTE | BreadcrumbTypes.CONSOLE | BreadcrumbTypes.FETCH | BreadcrumbTypes.UNHANDLEDREJECTION | BreadcrumbTypes.RESOURCE | BreadcrumbTypes.CODE_ERROR | BreadcrumbTypes.CUSTOMER;
14
14
  export declare function dataCategory2BreadcrumbsCategory(data: TraceDataTypes): BreadcrumbsCategorys.Http | BreadcrumbsCategorys.Debug | BreadcrumbsCategorys.Exception | BreadcrumbsCategorys.Lifecycle;
@@ -1,4 +1,6 @@
1
- import { TraceOptions } from "./baseTrace";
2
- import { SendMethod } from "./typings/common";
3
- export declare const init: (options: TraceOptions) => any;
4
- export { SendMethod };
1
+ import { TraceOptions, BaseTrace } from './baseTrace';
2
+ import { SendMethod } from './typings/common';
3
+ declare let instance: BaseTrace;
4
+ export declare const init: (options: TraceOptions) => BaseTrace;
5
+ export default instance;
6
+ export { SendMethod, BaseTrace };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jason-trace-log",
3
- "version": "1.0.5",
3
+ "version": "1.0.8",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "main": "dist/jason-trace-log.umd.js",