@blueking/open-telemetry 0.0.21 → 0.0.22

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.
Files changed (46) hide show
  1. package/README.md +11 -25
  2. package/dist/bk-rum.global.js +2 -12
  3. package/dist/bk-rum.global.js.map +1 -1
  4. package/dist/core/config.d.ts +10 -48
  5. package/dist/core/hash.d.ts +2 -0
  6. package/dist/core/plugin.d.ts +2 -7
  7. package/dist/core/processor.d.ts +0 -20
  8. package/dist/core/runtime-context.d.ts +1 -1
  9. package/dist/core/sdk.d.ts +2 -8
  10. package/dist/core/telemetry-attributes.d.ts +1 -2
  11. package/dist/index.d.ts +3 -3
  12. package/dist/index.js +1074 -1484
  13. package/dist/index.js.map +1 -1
  14. package/dist/plugins/common.d.ts +1 -1
  15. package/dist/plugins/csp-violation.d.ts +0 -8
  16. package/dist/plugins/device.d.ts +2 -2
  17. package/dist/plugins/error.d.ts +1 -5
  18. package/dist/plugins/long-task.d.ts +1 -3
  19. package/dist/plugins/resource.d.ts +1 -0
  20. package/dist/plugins/web-vitals.d.ts +2 -7
  21. package/dist/schema/attributes.d.ts +8 -10
  22. package/dist/schema/span.d.ts +2 -0
  23. package/package.json +1 -6
  24. package/skills/bk-rum-otele/SKILL.md +12 -14
  25. package/skills/bk-rum-otele/evals/evals.json +2 -2
  26. package/skills/bk-rum-otele/references/api.md +10 -22
  27. package/skills/bk-rum-otele/references/architecture.md +38 -118
  28. package/skills/bk-rum-otele/references/capabilities.md +26 -28
  29. package/skills/bk-rum-otele/references/concepts.md +14 -106
  30. package/skills/bk-rum-otele/references/configuration.md +28 -69
  31. package/skills/bk-rum-otele/references/custom-plugin.md +10 -13
  32. package/skills/bk-rum-otele/references/data-model.md +23 -95
  33. package/skills/bk-rum-otele/references/getting-started.md +1 -1
  34. package/skills/bk-rum-otele/references/plugins-basic.md +7 -7
  35. package/skills/bk-rum-otele/references/plugins-error-security.md +4 -7
  36. package/skills/bk-rum-otele/references/plugins-experience.md +8 -9
  37. package/skills/bk-rum-otele/references/plugins-network.md +19 -128
  38. package/skills/bk-rum-otele/references/plugins.md +3 -3
  39. package/skills/bk-rum-otele/references/privacy.md +4 -25
  40. package/skills/bk-rum-otele/references/telemetry-reference.md +49 -279
  41. package/skills/bk-rum-otele/references/transport-sampling.md +15 -50
  42. package/skills/bk-rum-otele/references/troubleshooting.md +7 -34
  43. package/dist/core/metric.d.ts +0 -2
  44. package/dist/core/signal.d.ts +0 -3
  45. package/dist/core/throttle.d.ts +0 -20
  46. package/dist/plugins/request-body.d.ts +0 -15
@@ -1,7 +1,6 @@
1
1
  import type { BkOTActionPluginOptions } from '../plugins/action';
2
2
  import type { BkOTBlankScreenPluginOptions } from '../plugins/blank-screen';
3
3
  import type { BkOTDevicePluginOptions } from '../plugins/device';
4
- import type { BkOTErrorPluginOptions } from '../plugins/error';
5
4
  import type { BkOTLongTaskPluginOptions } from '../plugins/long-task';
6
5
  import type { BkOTSessionConfig } from '../plugins/session';
7
6
  import type { BkOTPlugin } from './plugin';
@@ -20,7 +19,6 @@ export interface BkOTApplicationConfig {
20
19
  export interface BkOTAttributesConfig {
21
20
  custom?: () => Attributes;
22
21
  error?: () => Attributes;
23
- metric?: () => Attributes;
24
22
  page?: () => Attributes;
25
23
  }
26
24
  export type BkOTAttributeValue = boolean | number | string;
@@ -33,7 +31,7 @@ export interface BkOTBatchConfig {
33
31
  export interface BkOTBeforeSendEvent {
34
32
  attributes: Record<string, unknown>;
35
33
  name: string;
36
- signal: 'log' | 'span';
34
+ signal: 'span';
37
35
  }
38
36
  export interface BkOTContextConfig {
39
37
  attributes?: BkOTAttributesConfig;
@@ -68,25 +66,8 @@ export interface BkOTPrivacyConfig {
68
66
  /** 所有写入 attribute 的 URL 都会先经过此函数。 */
69
67
  redactUrl?: (url: string) => string;
70
68
  }
71
- export interface BkOTRequestBodyConfig {
72
- allowedContentTypes?: Array<RegExp | string>;
73
- capture?: 'all' | 'errors';
74
- maxSize?: number;
75
- redact: (payload: BkOTRequestBodyRedactPayload) => string | undefined;
76
- }
77
- export interface BkOTRequestBodyRedactPayload {
78
- body: string;
79
- contentType?: string;
80
- kind: 'request' | 'response';
81
- method?: string;
82
- statusCode?: number;
83
- truncated: boolean;
84
- type: 'fetch' | 'xhr';
85
- url?: string;
86
- }
87
69
  export interface BkOTRequestConfig {
88
70
  allowedTracingUrls?: BkOTUrlMatcher | BkOTUrlMatcher[];
89
- body?: BkOTRequestBodyConfig;
90
71
  excludedUrls?: BkOTUrlMatcher | BkOTUrlMatcher[];
91
72
  beforeSend?: (event: BkOTRequestEvent, context: BkOTRequestContext) => boolean | void;
92
73
  }
@@ -96,7 +77,6 @@ export type BkOTRequestContext = {
96
77
  response?: Response;
97
78
  type: 'fetch';
98
79
  } | {
99
- requestBody?: Document | null | XMLHttpRequestBodyInit;
100
80
  type: 'xhr';
101
81
  xhr: XMLHttpRequest;
102
82
  };
@@ -116,7 +96,7 @@ export interface BkOTTrackingConfig {
116
96
  blankScreen?: BkOTBlankScreenPluginOptions | boolean;
117
97
  cspViolation?: boolean;
118
98
  device?: BkOTDevicePluginOptions | boolean;
119
- error?: BkOTErrorPluginOptions | boolean;
99
+ error?: boolean;
120
100
  longTask?: BkOTLongTaskPluginOptions | boolean;
121
101
  request?: BkOTRequestConfig | boolean;
122
102
  resource?: boolean;
@@ -127,9 +107,12 @@ export interface BkOTTrackingConfig {
127
107
  }
128
108
  export type BkOTTrackingConsent = 'granted' | 'not-granted';
129
109
  export interface BkOTTransportConfig {
130
- endpoint?: string;
110
+ batch?: BkOTBatchConfig;
111
+ concurrencyLimit?: number;
112
+ endpoint: string;
131
113
  headers?: Record<string, string>;
132
- signals?: SignalExportersInputConfig;
114
+ processor?: BkOTSpanProcessorMode;
115
+ timeoutMillis?: number;
133
116
  token?: string;
134
117
  }
135
118
  export type BkOTUrlMatcher = ((url: string) => boolean) | RegExp | string;
@@ -142,9 +125,6 @@ export interface BkOTViewConfig {
142
125
  /** 返回低基数路由分组,例如 `/trace/:id`。 */
143
126
  getPathGroup?: (url: string) => string | undefined;
144
127
  }
145
- export interface MetricExporterInputConfig extends SignalExporterInputConfig {
146
- intervalMillis?: number;
147
- }
148
128
  export interface ResolvedApplicationConfig {
149
129
  environment: string;
150
130
  name: string;
@@ -157,7 +137,6 @@ export interface ResolvedBkOTConfig {
157
137
  enabled: boolean;
158
138
  extensions: BkOTExtensionsConfig;
159
139
  hooks: ResolvedConfigHooks;
160
- metricIntervalMillis: number;
161
140
  resourceAttributes: Attributes;
162
141
  session: ResolvedSessionConfig;
163
142
  spanBatch?: BkOTBatchConfig;
@@ -172,7 +151,6 @@ export interface ResolvedConfigHooks {
172
151
  beforeSend?: (event: BkOTBeforeSendEvent) => boolean | void;
173
152
  getCustomAttributes: () => Attributes;
174
153
  getErrorAttributes: () => Attributes;
175
- getMetricAttributes: () => Attributes;
176
154
  getPageAttributes: () => Attributes;
177
155
  getViewPathGroup: (url: string) => string;
178
156
  redactAttributes: (attributes: Attributes) => Attributes;
@@ -182,30 +160,14 @@ export interface ResolvedSessionConfig extends BkOTSessionConfig {
182
160
  sampleRate: number;
183
161
  }
184
162
  export interface ResolvedTransportConfig {
163
+ concurrencyLimit?: number;
185
164
  endpoint: string;
186
- logs: false | SignalExporterConfig;
187
- metrics: false | SignalExporterConfig;
188
- traces: false | SignalExporterConfig;
165
+ headers?: Record<string, string>;
166
+ timeoutMillis?: number;
189
167
  }
190
168
  export interface ResolvedViewConfig {
191
169
  excludedActivityUrls?: BkOTUrlMatcher | BkOTUrlMatcher[];
192
170
  loadingTime: boolean;
193
171
  tracking: 'auto' | 'manual';
194
172
  }
195
- export interface SignalExporterConfig {
196
- concurrencyLimit?: number;
197
- endpoint: string;
198
- headers?: Record<string, string>;
199
- timeoutMillis?: number;
200
- }
201
- export type SignalExporterInputConfig = Partial<SignalExporterConfig>;
202
- export interface SignalExportersInputConfig {
203
- logs?: false | SignalExporterInputConfig;
204
- metrics?: false | MetricExporterInputConfig;
205
- traces?: false | TraceExporterInputConfig;
206
- }
207
- export interface TraceExporterInputConfig extends SignalExporterInputConfig {
208
- batch?: BkOTBatchConfig;
209
- processor?: BkOTSpanProcessorMode;
210
- }
211
173
  export declare const resolveConfig: (config: BkOTOptions) => ResolvedBkOTConfig;
@@ -0,0 +1,2 @@
1
+ /** 非密码学稳定 hash,仅用于生成浏览器本地 storage key。 */
2
+ export declare const hashString: (input: string) => string;
@@ -1,8 +1,7 @@
1
1
  import type { BkOTActivityEvent } from './action-activity';
2
2
  import type { ResolvedBkOTConfig } from './config';
3
3
  import type { BkOTSessionLifecycleEvent, BkOTUserContext, BkOTViewCommand, BkOTViewContext } from './runtime-context';
4
- import type { Attributes, Meter, Span, SpanKind, TimeInput, Tracer } from '@opentelemetry/api';
5
- import type { Logger, LogRecord } from '@opentelemetry/api-logs';
4
+ import type { Attributes, Span, SpanKind, TimeInput, Tracer } from '@opentelemetry/api';
6
5
  import type { Instrumentation } from '@opentelemetry/instrumentation';
7
6
  export interface BkOTPlugin {
8
7
  enabled?: ((config: ResolvedBkOTConfig) => boolean) | boolean;
@@ -13,13 +12,9 @@ export interface BkOTPlugin {
13
12
  }
14
13
  export interface BkOTRuntimeContext {
15
14
  config: ResolvedBkOTConfig;
16
- logger: Logger;
17
- meter: Meter;
18
15
  tracer: Tracer;
19
16
  /** 对外提供的属性脱敏入口,所有插件在 emit 前都应过一次 */
20
17
  applyRedact: (attributes: Attributes) => Attributes;
21
- /** 包装 logger.emit,自动应用 redact 与 runtime attributes */
22
- emitLog: (record: LogRecord) => void;
23
18
  flush: () => Promise<void>;
24
19
  getRuntimeAttributes: () => Attributes;
25
20
  getRuntimeAttributesAt: (timestamp: number) => Attributes;
@@ -36,7 +31,7 @@ export interface BkOTRuntimeContext {
36
31
  setRuntimeAttributes: (attributes: Attributes, changedAt?: number) => void;
37
32
  /** 更新用户上下文;user.id 由接入方传入,SDK 原样透传 */
38
33
  setUser: (user: BkOTUserContext) => void;
39
- /** 更新当前 View 上下文,后续 span/log 会自动带上 view.* 关联字段 */
34
+ /** 更新当前 View 上下文,后续 span 会自动带上 view.* 关联字段 */
40
35
  setView: (view: BkOTViewContext, changedAt?: number) => void;
41
36
  startSpan: (name: string, attributes?: Attributes, options?: BkOTStartSpanOptions) => Span;
42
37
  }
@@ -1,19 +1,7 @@
1
- import { AggregationTemporality } from '@opentelemetry/sdk-metrics';
2
1
  import type { ResolvedBkOTConfig } from './config';
3
2
  import type { Attributes, Context } from '@opentelemetry/api';
4
- import type { LogRecordProcessor, SdkLogRecord } from '@opentelemetry/sdk-logs';
5
- import type { InstrumentType, PushMetricExporter, ResourceMetrics } from '@opentelemetry/sdk-metrics';
6
3
  import type { ReadableSpan, Span, SpanProcessor } from '@opentelemetry/sdk-trace-base';
7
4
  export declare const REQUEST_DISCARD_ATTRIBUTE = "bk.rum.request.discard";
8
- export declare class FilteringLogRecordProcessor implements LogRecordProcessor {
9
- private readonly inner;
10
- private readonly config?;
11
- constructor(inner: LogRecordProcessor, config?: ResolvedBkOTConfig | undefined);
12
- enabled(options: Parameters<NonNullable<LogRecordProcessor['enabled']>>[0]): boolean;
13
- forceFlush(): Promise<void>;
14
- onEmit(logRecord: SdkLogRecord, context?: Context): void;
15
- shutdown(): Promise<void>;
16
- }
17
5
  /**
18
6
  * 给所有 span 固化创建时的运行时上下文,并在 onEnd 阶段过滤自身上报请求和无 RUM 上下文 span。
19
7
  */
@@ -27,11 +15,3 @@ export declare class FilteringSpanProcessor implements SpanProcessor {
27
15
  onStart(span: Span, parentContext: Context): void;
28
16
  shutdown(): Promise<void>;
29
17
  }
30
- export declare class FilteringMetricExporter implements PushMetricExporter {
31
- private readonly inner;
32
- constructor(inner: PushMetricExporter);
33
- export(metrics: ResourceMetrics, resultCallback: Parameters<PushMetricExporter['export']>[1]): void;
34
- forceFlush(): Promise<void>;
35
- selectAggregationTemporality(instrumentType: InstrumentType): AggregationTemporality;
36
- shutdown(): Promise<void>;
37
- }
@@ -43,7 +43,7 @@ export interface BkOTViewContext {
43
43
  * 管理 SDK 运行期公共属性快照。
44
44
  *
45
45
  * 这里仅保存“后续事件都需要带上”的低成本上下文,Session/View/用户切换时更新快照,
46
- * 插件发 span/log 时读取当前快照即可,避免每个插件重复维护公共字段。
46
+ * 插件发 Span 时读取当前快照即可,避免每个插件重复维护公共字段。
47
47
  */
48
48
  export declare class RumRuntimeContext {
49
49
  private readonly actionHistory;
@@ -1,9 +1,8 @@
1
1
  import { type Attributes, type Span } from '@opentelemetry/api';
2
- import { type Instrumentation } from '@opentelemetry/instrumentation';
3
2
  import { type BkOTActionEventPayload, type BkOTCustomEventPayload, type BkOTOptions, type BkOTTrackingConsent, type ResolvedBkOTConfig } from './config';
4
3
  import { type BkOTPlugin, type BkOTRuntimeContext, type BkOTStartSpanOptions } from './plugin';
5
4
  import { type BkOTSessionLifecycleEvent, type BkOTStartViewOptions, type BkOTUserContext } from './runtime-context';
6
- import type { LogRecord } from '@opentelemetry/api-logs';
5
+ import type { Instrumentation } from '@opentelemetry/instrumentation';
7
6
  export interface BkOTInstance extends Omit<BkOTRuntimeContext, 'notifyActivity' | 'onActivity' | 'onViewChange' | 'onViewCommand' | 'registerInstrumentations' | 'setView'> {
8
7
  flush: () => Promise<void>;
9
8
  reportAction: (payload: BkOTActionEventPayload) => void;
@@ -20,13 +19,11 @@ export interface BkOTInstance extends Omit<BkOTRuntimeContext, 'notifyActivity'
20
19
  }
21
20
  /**
22
21
  * 浏览器 RUM SDK 的生命周期入口。Provider 在构造时创建,插件和全局 patch 则随 start、授权变更和
23
- * shutdown 安装或卸载;Session 决定统一作用于 trace、metric、log 三类信号。
22
+ * shutdown 安装或卸载;Session 决定统一作用于所有 RUM span。
24
23
  */
25
24
  export declare class BkOpenTelemetry implements BkOTInstance {
26
25
  private readonly activityObserver;
27
26
  private readonly flushProviders;
28
- private readonly loggerProvider;
29
- private readonly meterProvider;
30
27
  private phase;
31
28
  private pluginManager?;
32
29
  private readonly registeredInstrumentations;
@@ -42,15 +39,12 @@ export declare class BkOpenTelemetry implements BkOTInstance {
42
39
  private createPluginManager;
43
40
  readonly applyRedact: (attributes: Attributes) => Attributes;
44
41
  readonly config: ResolvedBkOTConfig;
45
- readonly emitLog: (record: LogRecord) => void;
46
42
  readonly flush: () => Promise<void>;
47
43
  readonly getRuntimeAttributes: () => Attributes;
48
44
  readonly getRuntimeAttributesAt: (timestamp: number) => Attributes;
49
45
  readonly isSampled: () => boolean;
50
46
  readonly isSessionActive: () => boolean;
51
47
  readonly isViewActive: () => boolean;
52
- readonly logger: BkOTRuntimeContext['logger'];
53
- readonly meter: BkOTRuntimeContext['meter'];
54
48
  readonly notifySessionLifecycle: (event: BkOTSessionLifecycleEvent) => void;
55
49
  readonly onSessionLifecycle: (listener: (event: BkOTSessionLifecycleEvent) => void) => () => boolean;
56
50
  readonly registerInstrumentations: (instrumentations: Instrumentation[]) => void;
@@ -1,4 +1,3 @@
1
1
  import type { Attributes } from '@opentelemetry/api';
2
- export declare const normalizeMetricPathGroup: (pathGroup: string) => string;
3
- export declare const getMetricViewAttributes: (runtimeAttributes: Attributes) => Attributes;
2
+ export declare const normalizeViewPathGroup: (pathGroup: string) => string;
4
3
  export declare const getInstrumentationSpanRuntimeAttributes: (runtimeAttributes: Attributes, fallbackViewPathGroup?: string) => Attributes;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- export { type BkOTActionEventPayload, type BkOTApplicationConfig, type BkOTAttributesConfig, type BkOTAttributeValue, type BkOTBatchConfig, type BkOTBeforeSendEvent, type BkOTContextConfig, type BkOTCustomEventPayload, type BkOTExtensionsConfig, type BkOTOptions, type BkOTPrivacyConfig, type BkOTRequestBodyConfig, type BkOTRequestBodyRedactPayload, type BkOTRequestConfig, type BkOTRequestContext, type BkOTRequestEvent, type BkOTTrackingConfig, type BkOTTrackingConsent, type BkOTTransportConfig, type BkOTUrlMatcher, type BkOTViewConfig, type MetricExporterInputConfig, resolveConfig, type ResolvedApplicationConfig, type ResolvedBkOTConfig, type ResolvedConfigHooks, type ResolvedTransportConfig, type ResolvedViewConfig, type SignalExporterConfig, type SignalExportersInputConfig, type TraceExporterInputConfig, } from './core/config';
1
+ export { type BkOTActionEventPayload, type BkOTApplicationConfig, type BkOTAttributesConfig, type BkOTAttributeValue, type BkOTBatchConfig, type BkOTBeforeSendEvent, type BkOTContextConfig, type BkOTCustomEventPayload, type BkOTExtensionsConfig, type BkOTOptions, type BkOTPrivacyConfig, type BkOTRequestConfig, type BkOTRequestContext, type BkOTRequestEvent, type BkOTTrackingConfig, type BkOTTrackingConsent, type BkOTTransportConfig, type BkOTUrlMatcher, type BkOTViewConfig, resolveConfig, type ResolvedApplicationConfig, type ResolvedBkOTConfig, type ResolvedConfigHooks, type ResolvedTransportConfig, type ResolvedViewConfig, } from './core/config';
2
2
  export { type BkOTPlugin, type BkOTRuntimeContext, createPlugin, type PluginManager } from './core/plugin';
3
- export { FilteringLogRecordProcessor, FilteringMetricExporter, FilteringSpanProcessor } from './core/processor';
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
6
  export { type BkOTActionPluginOptions, createActionPlugin } from './plugins/action';
@@ -9,7 +9,7 @@ export { type BkOTBlankScreenPluginOptions, createBlankScreenPlugin } from './pl
9
9
  export { createCommonInstrumentationsPlugin } from './plugins/common';
10
10
  export { createCspViolationPlugin } from './plugins/csp-violation';
11
11
  export { type BkOTDevicePluginOptions, createDevicePlugin } from './plugins/device';
12
- export { type BkOTErrorPluginOptions, createErrorPlugin } from './plugins/error';
12
+ export { createErrorPlugin } from './plugins/error';
13
13
  export { type BkOTLongTaskPluginOptions, createLongTaskPlugin } from './plugins/long-task';
14
14
  export { createResourcePlugin } from './plugins/resource';
15
15
  export { type BkOTSessionConfig, createSessionPlugin } from './plugins/session';