@blueking/open-telemetry 0.0.33 → 0.0.35-beta.1
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.
- package/README.md +67 -57
- package/dist/bk-rum.global.js +2 -2
- package/dist/bk-rum.global.js.map +1 -1
- package/dist/core/action-activity.d.ts +5 -1
- package/dist/core/action-target.d.ts +19 -0
- package/dist/core/config.d.ts +15 -5
- package/dist/core/event-time.d.ts +7 -0
- package/dist/core/performance-timing.d.ts +13 -0
- package/dist/core/plugin.d.ts +37 -2
- package/dist/core/processor.d.ts +24 -2
- package/dist/core/request-timing.d.ts +3 -2
- package/dist/core/runtime-context.d.ts +62 -2
- package/dist/core/sdk.d.ts +23 -1
- package/dist/core/session-transition.d.ts +19 -0
- package/dist/core/trace-context.d.ts +6 -7
- package/dist/core/view-location.d.ts +10 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2955 -1483
- package/dist/index.js.map +1 -1
- package/dist/integrations/vue-router.d.ts +25 -0
- package/dist/plugins/action.d.ts +1 -1
- package/dist/plugins/blank-screen-detection.d.ts +11 -0
- package/dist/plugins/blank-screen.d.ts +10 -18
- package/dist/plugins/common.d.ts +4 -2
- package/dist/plugins/document-vitals.d.ts +25 -0
- package/dist/plugins/page-view.d.ts +1 -1
- package/dist/plugins/resource.d.ts +14 -1
- package/dist/plugins/session-state.d.ts +14 -2
- package/dist/plugins/session-store.d.ts +12 -0
- package/dist/plugins/session.d.ts +1 -0
- package/dist/plugins/web-vitals-metrics.d.ts +80 -0
- package/dist/plugins/web-vitals.d.ts +2 -59
- package/dist/schema/attributes.d.ts +63 -0
- package/dist/schema/span.d.ts +5 -2
- package/package.json +9 -4
- package/skills/bk-rum-otele/references/actions.md +54 -37
- package/skills/bk-rum-otele/references/api.md +72 -51
- package/skills/bk-rum-otele/references/architecture.md +16 -16
- package/skills/bk-rum-otele/references/blank-screen.md +72 -142
- package/skills/bk-rum-otele/references/capabilities.md +66 -60
- package/skills/bk-rum-otele/references/configuration.md +101 -98
- package/skills/bk-rum-otele/references/data-model.md +22 -17
- package/skills/bk-rum-otele/references/errors-security.md +13 -13
- package/skills/bk-rum-otele/references/extensions.md +5 -3
- package/skills/bk-rum-otele/references/framework-integration.md +7 -24
- package/skills/bk-rum-otele/references/network.md +62 -49
- package/skills/bk-rum-otele/references/performance.md +62 -30
- package/skills/bk-rum-otele/references/privacy.md +5 -5
- package/skills/bk-rum-otele/references/production.md +9 -13
- package/skills/bk-rum-otele/references/session-context.md +67 -38
- package/skills/bk-rum-otele/references/span-protocol.md +771 -315
- package/skills/bk-rum-otele/references/telemetry-reference.md +288 -213
- package/skills/bk-rum-otele/references/troubleshooting.md +2 -2
- package/skills/bk-rum-otele/references/views-routing.md +103 -27
|
@@ -18,8 +18,12 @@ export type BkOTActivityEvent = {
|
|
|
18
18
|
type: 'request_start';
|
|
19
19
|
url?: string;
|
|
20
20
|
} | {
|
|
21
|
+
actionIds: string[];
|
|
21
22
|
time: number;
|
|
22
|
-
type: '
|
|
23
|
+
type: 'error';
|
|
24
|
+
} | {
|
|
25
|
+
time: number;
|
|
26
|
+
type: 'dom_mutation' | 'window_open';
|
|
23
27
|
};
|
|
24
28
|
export declare class RumActivityObserver {
|
|
25
29
|
private readonly listeners;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface ActionTargetOptions {
|
|
2
|
+
actionNameAttribute?: string;
|
|
3
|
+
nameCollection?: 'explicit' | 'text';
|
|
4
|
+
}
|
|
5
|
+
export interface ActionTargetSnapshot {
|
|
6
|
+
name: string;
|
|
7
|
+
nameSource: 'explicit' | 'accessible_name' | 'text' | 'fallback';
|
|
8
|
+
tag: string;
|
|
9
|
+
/** ::shadow 分隔各自根节点内唯一的 selector;它不是标准 CSS 组合符。 */
|
|
10
|
+
selector?: string;
|
|
11
|
+
path?: string[];
|
|
12
|
+
width?: number;
|
|
13
|
+
height?: number;
|
|
14
|
+
x?: number;
|
|
15
|
+
y?: number;
|
|
16
|
+
}
|
|
17
|
+
/** 隐藏/隐私目标返回 undefined,调用方应跳过整个自动 Action。 */
|
|
18
|
+
export declare const captureActionTarget: (target: Element, event: Event, options?: ActionTargetOptions) => ActionTargetSnapshot | undefined;
|
|
19
|
+
export declare const getActionNameFromElement: (target: Element, actionNameAttribute?: string, includeText?: boolean) => string;
|
package/dist/core/config.d.ts
CHANGED
|
@@ -6,8 +6,10 @@ import type { BkOTSessionConfig } from '../plugins/session';
|
|
|
6
6
|
import type { RumRequestOutcome } from '../schema/span';
|
|
7
7
|
import type { BkOTPlugin } from './plugin';
|
|
8
8
|
import type { BkOTUserContext } from './runtime-context';
|
|
9
|
-
import type {
|
|
9
|
+
import type { BkOTViewRouteMode } from './view-location';
|
|
10
|
+
import type { Attributes, Link } from '@opentelemetry/api';
|
|
10
11
|
import type { Instrumentation } from '@opentelemetry/instrumentation';
|
|
12
|
+
import type { TimedEvent } from '@opentelemetry/sdk-trace-base';
|
|
11
13
|
export interface BkOTActionEventPayload {
|
|
12
14
|
attributes?: Attributes;
|
|
13
15
|
name: string;
|
|
@@ -31,6 +33,9 @@ export interface BkOTBatchConfig {
|
|
|
31
33
|
}
|
|
32
34
|
export interface BkOTBeforeSendEvent {
|
|
33
35
|
attributes: Record<string, unknown>;
|
|
36
|
+
/** 脱敏后的导出副本,可原地修改或移除;不改变已结束的原 Span。 */
|
|
37
|
+
events?: TimedEvent[];
|
|
38
|
+
links?: Link[];
|
|
34
39
|
name: string;
|
|
35
40
|
signal: 'span';
|
|
36
41
|
}
|
|
@@ -62,7 +67,7 @@ export interface BkOTOptions {
|
|
|
62
67
|
export interface BkOTPrivacyConfig {
|
|
63
68
|
/** 初始化时的采集授权状态;运行期可通过 setTrackingConsent 更新。 */
|
|
64
69
|
trackingConsent?: BkOTTrackingConsent;
|
|
65
|
-
/**
|
|
70
|
+
/** 过滤 Span、Event、Link 属性;导出前再次执行,应保持幂等。抛错时丢弃该条遥测。 */
|
|
66
71
|
redactAttributes?: (attributes: Attributes) => Attributes;
|
|
67
72
|
/** 所有写入 attribute 的 URL 都会先经过此函数。 */
|
|
68
73
|
redactUrl?: (url: string) => string;
|
|
@@ -75,13 +80,15 @@ export interface BkOTRequestConfig {
|
|
|
75
80
|
getUrlTemplate?: (url: string) => string | undefined;
|
|
76
81
|
}
|
|
77
82
|
export type BkOTRequestContext = {
|
|
83
|
+
/** 本次 send 的终态快照;xhr 原实例可能已被业务复用,不保存正文。 */
|
|
84
|
+
responseSnapshot?: Readonly<Pick<XMLHttpRequest, 'responseType' | 'responseURL' | 'status' | 'statusText'>>;
|
|
85
|
+
type: 'xhr';
|
|
86
|
+
xhr: XMLHttpRequest;
|
|
87
|
+
} | {
|
|
78
88
|
error?: unknown;
|
|
79
89
|
request: Request | RequestInit;
|
|
80
90
|
response?: Response;
|
|
81
91
|
type: 'fetch';
|
|
82
|
-
} | {
|
|
83
|
-
type: 'xhr';
|
|
84
|
-
xhr: XMLHttpRequest;
|
|
85
92
|
};
|
|
86
93
|
export interface BkOTRequestEvent {
|
|
87
94
|
attributes: Attributes;
|
|
@@ -125,6 +132,8 @@ export interface BkOTViewConfig {
|
|
|
125
132
|
excludedActivityUrls?: BkOTUrlMatcher | BkOTUrlMatcher[];
|
|
126
133
|
/** 自动计算初始加载与 SPA 路由的页面稳定耗时,默认开启。 */
|
|
127
134
|
loadingTime?: boolean;
|
|
135
|
+
/** auto 识别 #/ 与 #!/;history 忽略片段,hash 使用片段内路径,document 不自动划分同文档 View。 */
|
|
136
|
+
routeMode?: BkOTViewRouteMode;
|
|
128
137
|
tracking?: 'auto' | 'manual';
|
|
129
138
|
/** 返回页面路由的低基数模板,例如 `/trace/:id`;返回空值时回退到默认折叠规则。 */
|
|
130
139
|
getUrlTemplate?: (url: string) => string | undefined;
|
|
@@ -173,6 +182,7 @@ export interface ResolvedTransportConfig {
|
|
|
173
182
|
export interface ResolvedViewConfig {
|
|
174
183
|
excludedActivityUrls?: BkOTUrlMatcher | BkOTUrlMatcher[];
|
|
175
184
|
loadingTime: boolean;
|
|
185
|
+
routeMode: BkOTViewRouteMode;
|
|
176
186
|
tracking: 'auto' | 'manual';
|
|
177
187
|
}
|
|
178
188
|
export declare const resolveConfig: (config: BkOTOptions) => ResolvedBkOTConfig;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session、Action 和 View 使用同一事件时刻。休眠时 performance.timeOrigin 与墙上时间可能漂移,
|
|
3
|
+
* 因此用当前时间减去事件已流逝时间换算;缓存同一个 Event,避免监听器之间毫秒取整的偏差。
|
|
4
|
+
*/
|
|
5
|
+
export declare const getEventEpochTime: (event: Event) => number;
|
|
6
|
+
/** Event.timeStamp 在现代浏览器中直接属于 Performance 时钟,不经墙钟回算。 */
|
|
7
|
+
export declare const getEventRelativeTime: (event: Event) => number;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
type NavigationTimingPoints = PerformanceNavigationTiming & {
|
|
2
|
+
activationStart?: number;
|
|
3
|
+
};
|
|
4
|
+
type TimingPoints = PerformanceResourceTiming & {
|
|
5
|
+
finalResponseHeadersStart?: number;
|
|
6
|
+
workerCacheLookupStart?: number;
|
|
7
|
+
workerRouterEvaluationStart?: number;
|
|
8
|
+
};
|
|
9
|
+
/** 采集 Resource 与 Navigation 共用的浏览器原始时间点。 */
|
|
10
|
+
export declare const getTimingPointAttributes: (entry: TimingPoints) => Record<string, number>;
|
|
11
|
+
/** Navigation 专属时间点,原样上报;请求阶段由 getTimingPointAttributes 提供。 */
|
|
12
|
+
export declare const getNavigationTimingPointAttributes: (entry: NavigationTimingPoints) => Record<string, number>;
|
|
13
|
+
export {};
|
package/dist/core/plugin.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ import type { Instrumentation } from '@opentelemetry/instrumentation';
|
|
|
7
7
|
export interface BkOTPlugin {
|
|
8
8
|
enabled?: ((config: ResolvedBkOTConfig) => boolean) | boolean;
|
|
9
9
|
name: string;
|
|
10
|
+
/** 同步读取浏览器待交付队列;所有插件 drain 后才允许 checkpoint 或停止请求。 */
|
|
11
|
+
drain?: () => void;
|
|
10
12
|
flush?: () => Promise<void> | void;
|
|
11
13
|
init: (context: BkOTRuntimeContext) => Promise<void> | void;
|
|
12
14
|
shutdown?: () => Promise<void> | void;
|
|
@@ -14,13 +16,27 @@ export interface BkOTPlugin {
|
|
|
14
16
|
export interface BkOTRuntimeContext {
|
|
15
17
|
config: ResolvedBkOTConfig;
|
|
16
18
|
tracer: Tracer;
|
|
19
|
+
/** afterAssociation 加入身份关联队列,按注册顺序执行;默认阶段仍用于先初始化 View。 */
|
|
20
|
+
afterSessionTransition: (callback: () => void, afterAssociation?: boolean) => void;
|
|
17
21
|
/** 对外提供的属性脱敏入口,所有插件在 emit 前都应过一次 */
|
|
18
22
|
applyRedact: (attributes: Attributes) => Attributes;
|
|
23
|
+
beginSessionTransition: (at: number) => () => void;
|
|
24
|
+
/** 关闭该动作的半开关联区间;不会影响其他重叠 Action。 */
|
|
25
|
+
endActionContext: (id: string, endTime: number, relativeEndTime?: number) => void;
|
|
19
26
|
flush: () => Promise<void>;
|
|
20
27
|
getRuntimeAttributes: () => Attributes;
|
|
21
28
|
getRuntimeAttributesAt: (timestamp: number) => Attributes;
|
|
29
|
+
getRuntimeContextAtRelativeTime?: (relativeTime: number) => undefined | {
|
|
30
|
+
attributes: Attributes;
|
|
31
|
+
time: number;
|
|
32
|
+
};
|
|
33
|
+
getViewHistory?: () => Array<{
|
|
34
|
+
runtimeAttributes: Attributes;
|
|
35
|
+
view: BkOTViewContext;
|
|
36
|
+
}>;
|
|
22
37
|
isSampled: () => boolean;
|
|
23
38
|
isSessionActive: () => boolean;
|
|
39
|
+
isSessionTransitionPending: () => boolean;
|
|
24
40
|
isViewActive: () => boolean;
|
|
25
41
|
notifyActivity: (event: BkOTActivityEvent) => void;
|
|
26
42
|
notifySessionLifecycle: (event: BkOTSessionLifecycleEvent) => void;
|
|
@@ -28,13 +44,24 @@ export interface BkOTRuntimeContext {
|
|
|
28
44
|
onSessionLifecycle: (listener: (event: BkOTSessionLifecycleEvent) => void) => () => void;
|
|
29
45
|
onViewChange: (listener: (view: BkOTViewContext) => void) => () => void;
|
|
30
46
|
onViewCommand: (listener: (command: BkOTViewCommand) => void) => () => void;
|
|
47
|
+
/** attributes 保留捕获引用,以支持待定 Session 提交后回填。 */
|
|
48
|
+
registerActionContext: (id: string, startTime: number, attributes: Attributes) => void;
|
|
31
49
|
registerInstrumentations: (instrumentations: Instrumentation[]) => void;
|
|
50
|
+
registerSessionCheck: (check: () => void) => () => void;
|
|
32
51
|
setRuntimeAttributes: (attributes: Attributes, changedAt?: number) => void;
|
|
33
52
|
/** 更新用户上下文;user.id 由接入方传入,SDK 原样透传 */
|
|
34
53
|
setUser: (user: BkOTUserContext) => void;
|
|
35
54
|
/** 更新当前 View 上下文,后续 span 会自动带上 view.* 关联字段 */
|
|
36
55
|
setView: (view: BkOTViewContext, changedAt?: number) => void;
|
|
37
56
|
startSpan: (name: string, attributes?: Attributes, options?: BkOTStartSpanOptions) => Span;
|
|
57
|
+
/** 本次授权采集区间;再次授权不能重新生成物理文档加载指标。 */
|
|
58
|
+
collectionStart?: {
|
|
59
|
+
/** 仅最初即允许采集的实例可读取安装前资源,不补采未授权区间。 */
|
|
60
|
+
allowInitialResourceHistory?: boolean;
|
|
61
|
+
isInitialDocument: boolean;
|
|
62
|
+
relativeStartedAt: number;
|
|
63
|
+
startedAt: number;
|
|
64
|
+
};
|
|
38
65
|
}
|
|
39
66
|
/**
|
|
40
67
|
* startSpan 的扩展选项。
|
|
@@ -47,20 +74,28 @@ export interface BkOTRuntimeContext {
|
|
|
47
74
|
* 配合 span.end(endTime?) 可控制结束时间。
|
|
48
75
|
*/
|
|
49
76
|
export interface BkOTStartSpanOptions {
|
|
50
|
-
/**
|
|
51
|
-
|
|
77
|
+
/** 完整运行时快照;缺失字段表示明确不存在,不再从当前或历史上下文补齐。 */
|
|
78
|
+
contextAttributes?: Attributes;
|
|
52
79
|
/** 用于从历史中解析 Session/View/Action 归属;默认复用数字类型 startTime。 */
|
|
53
80
|
contextTime?: number;
|
|
54
81
|
kind?: SpanKind;
|
|
55
82
|
/** 关联其他 trace 的 Span Link;OTel 要求在创建时传入。 */
|
|
56
83
|
links?: Link[];
|
|
84
|
+
/** 内置 Span 根据脱敏后的属性生成名称;自定义 startSpan 默认保留传入名称。 */
|
|
85
|
+
rumSpanType?: RumSpanType;
|
|
57
86
|
startTime?: TimeInput;
|
|
58
87
|
}
|
|
59
88
|
export declare const isPluginEnabled: (plugin: BkOTPlugin, config: ResolvedBkOTConfig) => boolean;
|
|
60
89
|
export declare const createPlugin: (plugin: BkOTPlugin) => BkOTPlugin;
|
|
61
90
|
export declare class PluginManager {
|
|
91
|
+
private debug;
|
|
62
92
|
private readonly plugins;
|
|
63
93
|
private startedPlugins;
|
|
94
|
+
private stopped;
|
|
95
|
+
private stopping?;
|
|
96
|
+
private drain;
|
|
97
|
+
private invoke;
|
|
98
|
+
private warn;
|
|
64
99
|
constructor(plugins: BkOTPlugin[]);
|
|
65
100
|
flush(): Promise<void>;
|
|
66
101
|
shutdown(): Promise<void>;
|
package/dist/core/processor.d.ts
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
|
+
import type { BkOTActivityEvent } from './action-activity';
|
|
1
2
|
import type { ResolvedBkOTConfig } from './config';
|
|
2
|
-
import type {
|
|
3
|
+
import type { Span as ApiSpan, Attributes, Context } from '@opentelemetry/api';
|
|
3
4
|
import type { ReadableSpan, Span, SpanProcessor } from '@opentelemetry/sdk-trace-base';
|
|
5
|
+
export declare const RUM_CONTEXT_TIME: symbol;
|
|
6
|
+
export declare const RUM_CONTEXT_SNAPSHOT: symbol;
|
|
7
|
+
/** 请求先创建 Span、后得到最终字段;setAttributes 的合并语义无法表达 Hook 删除。 */
|
|
8
|
+
export declare const replaceSpanAttributes: (span: ApiSpan, attributes: Attributes, replacedKeys: Iterable<string>) => void;
|
|
4
9
|
export declare const markSpanDiscarded: (span: ApiSpan) => void;
|
|
10
|
+
/** Action 自身用单值身份,只有有明确类型的子事件携带多 Action 关联。 */
|
|
11
|
+
export declare const filterActionAttributes: (attributes: Attributes) => Attributes;
|
|
12
|
+
interface SessionAssociation {
|
|
13
|
+
checkSession: () => void;
|
|
14
|
+
getAttributesAt: (at: number) => Attributes;
|
|
15
|
+
isPending: (at?: number) => boolean;
|
|
16
|
+
isSampled: (attributes: Attributes) => boolean;
|
|
17
|
+
whenReady: (callback: () => void) => void;
|
|
18
|
+
}
|
|
5
19
|
/**
|
|
6
20
|
* 给所有 span 固化创建时的运行时上下文,并在 onEnd 阶段过滤自身上报请求和无 RUM 上下文 span。
|
|
7
21
|
*/
|
|
@@ -9,9 +23,17 @@ export declare class FilteringSpanProcessor implements SpanProcessor {
|
|
|
9
23
|
private readonly inner;
|
|
10
24
|
private readonly config;
|
|
11
25
|
private readonly getRuntimeAttributes;
|
|
12
|
-
|
|
26
|
+
private readonly association?;
|
|
27
|
+
private readonly onError?;
|
|
28
|
+
private readonly actionContexts;
|
|
29
|
+
private readonly pending;
|
|
30
|
+
private redactEnvelope;
|
|
31
|
+
constructor(inner: SpanProcessor, config: ResolvedBkOTConfig, getRuntimeAttributes: () => Attributes, association?: SessionAssociation | undefined, onError?: ((event: Extract<BkOTActivityEvent, {
|
|
32
|
+
type: "error";
|
|
33
|
+
}>) => void) | undefined);
|
|
13
34
|
forceFlush(): Promise<void>;
|
|
14
35
|
onEnd(span: ReadableSpan): void;
|
|
15
36
|
onStart(span: Span, parentContext: Context): void;
|
|
16
37
|
shutdown(): Promise<void>;
|
|
17
38
|
}
|
|
39
|
+
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export declare const notifyRequestTiming: (entry: PerformanceResourceTiming) => void;
|
|
2
|
-
export declare const trackRequestTiming: (url: string, startTime?: number) => {
|
|
2
|
+
export declare const trackRequestTiming: (url: string, startTime?: number, initiatorType?: string) => {
|
|
3
|
+
sent: () => void;
|
|
3
4
|
cancel: () => void;
|
|
4
|
-
complete: (callback: (entry?: PerformanceResourceTiming) => void) => void;
|
|
5
|
+
complete: (callback: (entry?: PerformanceResourceTiming) => void, waitForBody?: boolean) => void;
|
|
5
6
|
};
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import type { Attributes } from '@opentelemetry/api';
|
|
2
2
|
export type BkOTSessionLifecycleEvent = {
|
|
3
|
+
/** false 表示仅截断本地关联,expiredAt 不是已确认的全局结束时间,不能据此生成结束遥测。 */
|
|
4
|
+
endTimeKnown?: boolean;
|
|
3
5
|
expiredAt: number;
|
|
4
6
|
id: string;
|
|
5
7
|
reason: 'external' | 'inactivity' | 'maxLifetime';
|
|
6
8
|
type: 'expired';
|
|
7
9
|
} | {
|
|
10
|
+
/** 本 Tab 绑定该 Session 的生效时间,不等同于共享 Session 的创建时间。 */
|
|
11
|
+
activatedAt?: number;
|
|
8
12
|
id: string;
|
|
9
13
|
previousId?: string;
|
|
10
14
|
reason: 'inactivity' | 'init' | 'maxLifetime' | 'shared';
|
|
@@ -15,16 +19,32 @@ export interface BkOTStartViewOptions {
|
|
|
15
19
|
attributes?: Attributes;
|
|
16
20
|
name?: string;
|
|
17
21
|
url?: string;
|
|
22
|
+
/** 框架路由定义中的低基数路径,例如 /orders/:orderId;优先于 URL 推断。 */
|
|
23
|
+
urlTemplate?: string;
|
|
18
24
|
}
|
|
19
25
|
export interface BkOTUserContext {
|
|
20
26
|
/** 由接入方传入并由 SDK 原样透传;SDK 不 hash、不脱敏、不改写。 */
|
|
21
27
|
id?: string;
|
|
22
28
|
}
|
|
23
29
|
export type BkOTViewCommand = {
|
|
30
|
+
attributes: Attributes;
|
|
31
|
+
type: 'set_context';
|
|
32
|
+
} | {
|
|
33
|
+
elapsed?: number;
|
|
34
|
+
name: string;
|
|
35
|
+
time: number;
|
|
36
|
+
type: 'add_timing';
|
|
37
|
+
} | {
|
|
38
|
+
key: string;
|
|
39
|
+
type: 'set_context_property';
|
|
40
|
+
value: Attributes[string];
|
|
41
|
+
} | {
|
|
24
42
|
name: string;
|
|
25
43
|
type: 'set_name';
|
|
26
44
|
} | {
|
|
27
45
|
options: BkOTStartViewOptions;
|
|
46
|
+
relativeStartedAt?: number;
|
|
47
|
+
startedAt?: number;
|
|
28
48
|
type: 'start';
|
|
29
49
|
} | {
|
|
30
50
|
time: number;
|
|
@@ -32,13 +52,23 @@ export type BkOTViewCommand = {
|
|
|
32
52
|
};
|
|
33
53
|
export interface BkOTViewContext {
|
|
34
54
|
attributes?: Attributes;
|
|
55
|
+
/** 清空 View 时传递已确认的结束边界,供迟到指标归属;不是接收通知的时间。 */
|
|
56
|
+
endedAt?: number;
|
|
35
57
|
id?: string;
|
|
58
|
+
interactionCountAtEnd?: number;
|
|
59
|
+
/** 原生交互计数在 View 边界的快照,供迟安装的 INP 采集器恢复分位数基线。 */
|
|
60
|
+
interactionCountAtStart?: number;
|
|
36
61
|
loadingType?: 'bf_cache' | 'initial_load' | 'route_change' | 'session_renewal';
|
|
37
62
|
name?: string;
|
|
63
|
+
relativeEndedAt?: number;
|
|
64
|
+
/** 与 PerformanceEntry.startTime 同一时钟;不能由 timeOrigin 与墙钟差值推导。 */
|
|
65
|
+
relativeStartedAt?: number;
|
|
38
66
|
startedAt?: number;
|
|
39
67
|
url?: string;
|
|
40
68
|
urlTemplate?: string;
|
|
41
69
|
}
|
|
70
|
+
/** OTel 属性只允许标量和标量数组;复制数组即可隔离调用方、当前状态与历史快照。 */
|
|
71
|
+
export declare const copyAttributes: (attributes?: Attributes) => Attributes;
|
|
42
72
|
/**
|
|
43
73
|
* 管理 SDK 运行期公共属性快照。
|
|
44
74
|
*
|
|
@@ -47,12 +77,13 @@ export interface BkOTViewContext {
|
|
|
47
77
|
*/
|
|
48
78
|
export declare class RumRuntimeContext {
|
|
49
79
|
private readonly actionHistory;
|
|
80
|
+
private appendActionIds;
|
|
50
81
|
private readonly attributes;
|
|
51
82
|
private readonly queuedViewCommands;
|
|
52
83
|
private recordAssociation;
|
|
53
|
-
private readonly sessionHistory;
|
|
54
84
|
private sampled;
|
|
55
85
|
private readonly samplingHistory;
|
|
86
|
+
private readonly sessionHistory;
|
|
56
87
|
private readonly sessionLifecycleListeners;
|
|
57
88
|
private readonly setOptionalAttribute;
|
|
58
89
|
private user;
|
|
@@ -61,12 +92,40 @@ export declare class RumRuntimeContext {
|
|
|
61
92
|
private readonly viewChangeListeners;
|
|
62
93
|
private readonly viewCommandListeners;
|
|
63
94
|
private readonly viewHistory;
|
|
95
|
+
private readonly viewLifecycles;
|
|
64
96
|
private readonly viewScopedAttributeKeys;
|
|
65
97
|
dispatchViewCommand: (command: BkOTViewCommand) => void;
|
|
98
|
+
endActionContext: (id: string, endedAt: number, relativeEndedAt?: number) => void;
|
|
66
99
|
getAttributes: () => Attributes;
|
|
67
100
|
getAttributesAt: (timestamp: number) => Attributes;
|
|
101
|
+
/** PerformanceEntry 按相对区间选择身份;epoch 只用于最终 Span 时间,不再反查身份。 */
|
|
102
|
+
getRuntimeContextAtRelativeTime: (relativeTime: number) => undefined | {
|
|
103
|
+
attributes: Attributes;
|
|
104
|
+
time: number;
|
|
105
|
+
};
|
|
68
106
|
getUser: () => BkOTUserContext;
|
|
69
107
|
getView: () => BkOTViewContext;
|
|
108
|
+
/** 指标插件可能晚于首个路由安装,只保留每个 View 的最后快照与原始边界。 */
|
|
109
|
+
getViewHistory: () => {
|
|
110
|
+
view: {
|
|
111
|
+
attributes: Attributes;
|
|
112
|
+
/** 清空 View 时传递已确认的结束边界,供迟到指标归属;不是接收通知的时间。 */
|
|
113
|
+
endedAt?: number;
|
|
114
|
+
id?: string;
|
|
115
|
+
interactionCountAtEnd?: number;
|
|
116
|
+
/** 原生交互计数在 View 边界的快照,供迟安装的 INP 采集器恢复分位数基线。 */
|
|
117
|
+
interactionCountAtStart?: number;
|
|
118
|
+
loadingType?: "bf_cache" | "initial_load" | "route_change" | "session_renewal";
|
|
119
|
+
name?: string;
|
|
120
|
+
relativeEndedAt?: number;
|
|
121
|
+
/** 与 PerformanceEntry.startTime 同一时钟;不能由 timeOrigin 与墙钟差值推导。 */
|
|
122
|
+
relativeStartedAt?: number;
|
|
123
|
+
startedAt?: number;
|
|
124
|
+
url?: string;
|
|
125
|
+
urlTemplate?: string;
|
|
126
|
+
};
|
|
127
|
+
runtimeAttributes: Attributes;
|
|
128
|
+
}[];
|
|
70
129
|
isSessionActive: () => boolean;
|
|
71
130
|
isSessionSampledAt: (timestamp: number) => boolean;
|
|
72
131
|
isViewActive: () => boolean;
|
|
@@ -74,9 +133,10 @@ export declare class RumRuntimeContext {
|
|
|
74
133
|
onSessionLifecycle: (listener: (event: BkOTSessionLifecycleEvent) => void) => () => boolean;
|
|
75
134
|
onViewChange: (listener: (view: BkOTViewContext) => void) => () => boolean;
|
|
76
135
|
onViewCommand: (listener: (command: BkOTViewCommand) => void) => () => boolean;
|
|
136
|
+
registerActionContext: (id: string, startedAt: number, attributes: Attributes) => void;
|
|
77
137
|
setAttributes: (attributes: Attributes, changedAt?: number) => void;
|
|
78
|
-
setUser: (user: BkOTUserContext) => void;
|
|
79
138
|
setSessionSampled: (sampled: boolean, changedAt?: number) => void;
|
|
139
|
+
setUser: (user: BkOTUserContext) => void;
|
|
80
140
|
setView: (view: BkOTViewContext, changedAt?: number) => void;
|
|
81
141
|
constructor(initialAttributes?: Attributes, user?: BkOTUserContext);
|
|
82
142
|
}
|
package/dist/core/sdk.d.ts
CHANGED
|
@@ -3,12 +3,16 @@ import { type BkOTActionEventPayload, type BkOTCustomEventPayload, type BkOTOpti
|
|
|
3
3
|
import { type BkOTPlugin, type BkOTRuntimeContext, type BkOTStartSpanOptions } from './plugin';
|
|
4
4
|
import { type BkOTSessionLifecycleEvent, type BkOTStartViewOptions, type BkOTUserContext } from './runtime-context';
|
|
5
5
|
import type { Instrumentation } from '@opentelemetry/instrumentation';
|
|
6
|
-
export interface BkOTInstance extends Omit<BkOTRuntimeContext, 'notifyActivity' | 'onActivity' | 'onViewChange' | 'onViewCommand' | 'registerInstrumentations' | 'setView'> {
|
|
6
|
+
export interface BkOTInstance extends Omit<BkOTRuntimeContext, 'endActionContext' | 'notifyActivity' | 'onActivity' | 'onViewChange' | 'onViewCommand' | 'registerActionContext' | 'registerInstrumentations' | 'setView'> {
|
|
7
|
+
addTiming: (name: string, elapsed?: number) => void;
|
|
7
8
|
flush: () => Promise<void>;
|
|
9
|
+
getViewContext: () => Attributes;
|
|
8
10
|
reportAction: (payload: BkOTActionEventPayload) => void;
|
|
9
11
|
reportCustomEvent: (payload: BkOTCustomEventPayload) => void;
|
|
10
12
|
setTrackingConsent: (consent: BkOTTrackingConsent) => Promise<void>;
|
|
11
13
|
setUser: (user: BkOTUserContext) => void;
|
|
14
|
+
setViewContext: (attributes: Attributes) => void;
|
|
15
|
+
setViewContextProperty: (key: string, value: Attributes[string]) => void;
|
|
12
16
|
setViewLoadingTime: () => void;
|
|
13
17
|
setViewName: (name: string) => void;
|
|
14
18
|
shutdown: () => Promise<void>;
|
|
@@ -23,36 +27,54 @@ export interface BkOTInstance extends Omit<BkOTRuntimeContext, 'notifyActivity'
|
|
|
23
27
|
*/
|
|
24
28
|
export declare class BkOpenTelemetry implements BkOTInstance {
|
|
25
29
|
private readonly activityObserver;
|
|
30
|
+
private allowInitialResourceHistory;
|
|
31
|
+
private readonly collectAttributesAt;
|
|
32
|
+
private collectionStopping?;
|
|
26
33
|
private readonly flushProviders;
|
|
34
|
+
private hasStartedCollection;
|
|
35
|
+
private readonly isStopped;
|
|
36
|
+
private latestManualViewOptions?;
|
|
27
37
|
private phase;
|
|
28
38
|
private pluginManager?;
|
|
29
39
|
private readonly registeredInstrumentations;
|
|
30
40
|
private releaseOtelGlobals?;
|
|
31
41
|
private readonly runtimeContext;
|
|
32
42
|
private sampled;
|
|
43
|
+
private readonly sessionTransition;
|
|
44
|
+
private shutdownTask?;
|
|
33
45
|
private readonly startCollection;
|
|
34
46
|
private readonly stopCollection;
|
|
47
|
+
private tabId?;
|
|
35
48
|
private readonly teardownCallbacks;
|
|
36
49
|
private readonly tracerProvider;
|
|
37
50
|
private assertBeforeStart;
|
|
38
51
|
private createPluginContext;
|
|
39
52
|
private createPluginManager;
|
|
53
|
+
/** elapsed 为相对当前 View 起点的毫秒;省略时使用调用时刻,避免混用 epoch 时间。 */
|
|
54
|
+
readonly addTiming: (name: string, elapsed?: number) => void;
|
|
55
|
+
readonly afterSessionTransition: (callback: () => void, afterAssociation?: boolean) => void;
|
|
40
56
|
readonly applyRedact: (attributes: Attributes) => Attributes;
|
|
57
|
+
readonly beginSessionTransition: (at: number) => () => void;
|
|
41
58
|
readonly config: ResolvedBkOTConfig;
|
|
42
59
|
readonly flush: () => Promise<void>;
|
|
43
60
|
readonly getRuntimeAttributes: () => Attributes;
|
|
44
61
|
readonly getRuntimeAttributesAt: (timestamp: number) => Attributes;
|
|
62
|
+
readonly getViewContext: () => Attributes;
|
|
45
63
|
readonly isSampled: () => boolean;
|
|
46
64
|
readonly isSessionActive: () => boolean;
|
|
65
|
+
readonly isSessionTransitionPending: () => boolean;
|
|
47
66
|
readonly isViewActive: () => boolean;
|
|
48
67
|
readonly notifySessionLifecycle: (event: BkOTSessionLifecycleEvent) => void;
|
|
49
68
|
readonly onSessionLifecycle: (listener: (event: BkOTSessionLifecycleEvent) => void) => () => boolean;
|
|
50
69
|
readonly registerInstrumentations: (instrumentations: Instrumentation[]) => void;
|
|
70
|
+
readonly registerSessionCheck: (check: () => void) => () => void;
|
|
51
71
|
readonly reportAction: ({ attributes, name }: BkOTActionEventPayload) => void;
|
|
52
72
|
readonly reportCustomEvent: ({ attributes, error, name }: BkOTCustomEventPayload) => void;
|
|
53
73
|
readonly setRuntimeAttributes: (attributes: Attributes, changedAt?: number) => void;
|
|
54
74
|
readonly setTrackingConsent: (consent: BkOTTrackingConsent) => Promise<void>;
|
|
55
75
|
readonly setUser: (user: BkOTUserContext) => void;
|
|
76
|
+
readonly setViewContext: (attributes: Attributes) => void;
|
|
77
|
+
readonly setViewContextProperty: (key: string, value: Attributes[string]) => void;
|
|
56
78
|
readonly setViewLoadingTime: () => void;
|
|
57
79
|
readonly setViewName: (name: string) => void;
|
|
58
80
|
readonly shutdown: () => Promise<void>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 串行提交 Session 时先采集事件,再关联会话。View 变更先落地,随后解析待定快照,
|
|
3
|
+
* 防止第一击在 Web Lock 返回前继承旧 ID。停止采集会使所有旧回调失效。
|
|
4
|
+
*/
|
|
5
|
+
export declare class SessionTransition {
|
|
6
|
+
private readonly capacity;
|
|
7
|
+
private readonly associations;
|
|
8
|
+
private readonly callbacks;
|
|
9
|
+
private check?;
|
|
10
|
+
private checking;
|
|
11
|
+
private readonly pending;
|
|
12
|
+
begin: (at: number) => () => void;
|
|
13
|
+
checkSession: () => void;
|
|
14
|
+
isPending: (at?: number) => boolean;
|
|
15
|
+
registerCheck: (check: () => void) => () => void;
|
|
16
|
+
reset: () => void;
|
|
17
|
+
whenReady: (callback: () => void, association?: boolean) => void;
|
|
18
|
+
constructor(capacity: number);
|
|
19
|
+
}
|
|
@@ -6,16 +6,17 @@
|
|
|
6
6
|
* Span Link 把后端 trace 关联回 RUM Span。
|
|
7
7
|
*
|
|
8
8
|
* 如果业务已经自行设置了 trace header(`traceparent`、`sentry-trace`、b3、Datadog、sw8),则完全
|
|
9
|
-
*
|
|
9
|
+
* 不注入,避免破坏业务既有的传播方式;只有可映射的合法链路才建 Link。
|
|
10
10
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
11
|
+
* `context` 承载 trace-id/span-id,`attributes` 只记录命中的格式和是否由 SDK 注入。
|
|
12
|
+
* 原始厂商 header 可能包含业务标签、服务地址等内容,不进入遥测事件。
|
|
13
|
+
* sw8 这类无法映射为合法 OTel id 的格式不建 Link,避免把不存在的链路提供给检索端。
|
|
13
14
|
*/
|
|
14
|
-
import type {
|
|
15
|
+
import type { Link } from '@opentelemetry/api';
|
|
15
16
|
/** 大小写不敏感地读取一个请求 header */
|
|
16
17
|
export type BkOTHeaderReader = (name: string) => string | undefined;
|
|
17
18
|
export interface BkOTRequestTracePlan {
|
|
18
|
-
/** 关联后端 trace 的 Span Link
|
|
19
|
+
/** 关联后端 trace 的 Span Link;既有厂商上下文无法映射时为空 */
|
|
19
20
|
links: Link[];
|
|
20
21
|
/** 需要注入的 traceparent;业务已有 trace header 时为 undefined */
|
|
21
22
|
traceparent?: string;
|
|
@@ -24,8 +25,6 @@ export type BkOTUpstreamTraceFormat = 'b3' | 'b3-multi' | 'datadog' | 'sentry-tr
|
|
|
24
25
|
export declare const TRACEPARENT_HEADER = "traceparent";
|
|
25
26
|
interface UpstreamTrace {
|
|
26
27
|
format: BkOTUpstreamTraceFormat;
|
|
27
|
-
/** 命中格式的原始 header,原样写入 Link Attributes */
|
|
28
|
-
headers: Attributes;
|
|
29
28
|
sampled?: boolean;
|
|
30
29
|
/** 规范化后的合法 OTel id;无法映射时两者同时缺失 */
|
|
31
30
|
spanId?: string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type BkOTViewRouteMode = 'auto' | 'document' | 'hash' | 'history';
|
|
2
|
+
/** 仅用于身份比较与模板生成;routePath 仍可能含业务 ID,不能当作已脱敏 URL 直接上报。 */
|
|
3
|
+
export declare const getViewLocation: (url: string, mode?: BkOTViewRouteMode) => {
|
|
4
|
+
hash: string;
|
|
5
|
+
kind: "hash" | "history";
|
|
6
|
+
pathname: string;
|
|
7
|
+
routePath: string;
|
|
8
|
+
};
|
|
9
|
+
/** 同文档导航边界;整页导航由新 Document 初始化产生 initial_load,不经过此比较。 */
|
|
10
|
+
export declare const isViewLocationChange: (fromUrl: string, toUrl: string, mode?: BkOTViewRouteMode) => boolean;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ export { type BkOTPlugin, type BkOTRuntimeContext, createPlugin, type PluginMana
|
|
|
3
3
|
export { FilteringSpanProcessor } from './core/processor';
|
|
4
4
|
export { type BkOTSessionLifecycleEvent, type BkOTStartViewOptions, type BkOTUserContext, type BkOTViewContext, RumRuntimeContext, } from './core/runtime-context';
|
|
5
5
|
export { BkOpenTelemetry, type BkOTInstance } from './core/sdk';
|
|
6
|
+
export { type BkOTViewRouteMode } from './core/view-location';
|
|
7
|
+
export { type BkOTVueRoute, type BkOTVueRouter, type BkOTVueViewClient, trackVueRouterViews, } from './integrations/vue-router';
|
|
6
8
|
export { type BkOTActionPluginOptions, createActionPlugin } from './plugins/action';
|
|
7
9
|
export { EXCLUDED_ACTIVITY_MUTATIONS_ATTRIBUTE } from './plugins/activity';
|
|
8
10
|
export { type BkOTBlankScreenPluginOptions, createBlankScreenPlugin } from './plugins/blank-screen';
|