@blueking/open-telemetry 0.0.21 → 0.0.22-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.
Files changed (43) 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 +8 -44
  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/sdk.d.ts +1 -7
  9. package/dist/core/telemetry-attributes.d.ts +1 -2
  10. package/dist/index.d.ts +3 -3
  11. package/dist/index.js +1045 -1471
  12. package/dist/index.js.map +1 -1
  13. package/dist/plugins/common.d.ts +1 -1
  14. package/dist/plugins/csp-violation.d.ts +0 -8
  15. package/dist/plugins/error.d.ts +1 -5
  16. package/dist/plugins/long-task.d.ts +1 -3
  17. package/dist/plugins/web-vitals.d.ts +1 -4
  18. package/dist/schema/attributes.d.ts +8 -10
  19. package/dist/schema/span.d.ts +2 -0
  20. package/package.json +1 -6
  21. package/skills/bk-rum-otele/SKILL.md +3 -3
  22. package/skills/bk-rum-otele/evals/evals.json +2 -2
  23. package/skills/bk-rum-otele/references/api.md +10 -22
  24. package/skills/bk-rum-otele/references/architecture.md +38 -118
  25. package/skills/bk-rum-otele/references/capabilities.md +26 -28
  26. package/skills/bk-rum-otele/references/concepts.md +14 -106
  27. package/skills/bk-rum-otele/references/configuration.md +25 -66
  28. package/skills/bk-rum-otele/references/custom-plugin.md +10 -13
  29. package/skills/bk-rum-otele/references/data-model.md +23 -95
  30. package/skills/bk-rum-otele/references/getting-started.md +1 -1
  31. package/skills/bk-rum-otele/references/plugins-basic.md +7 -7
  32. package/skills/bk-rum-otele/references/plugins-error-security.md +1 -1
  33. package/skills/bk-rum-otele/references/plugins-experience.md +4 -5
  34. package/skills/bk-rum-otele/references/plugins-network.md +19 -128
  35. package/skills/bk-rum-otele/references/plugins.md +3 -3
  36. package/skills/bk-rum-otele/references/privacy.md +4 -25
  37. package/skills/bk-rum-otele/references/telemetry-reference.md +49 -279
  38. package/skills/bk-rum-otele/references/transport-sampling.md +15 -50
  39. package/skills/bk-rum-otele/references/troubleshooting.md +7 -34
  40. package/dist/core/metric.d.ts +0 -2
  41. package/dist/core/signal.d.ts +0 -3
  42. package/dist/core/throttle.d.ts +0 -20
  43. 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
  }
@@ -116,7 +97,7 @@ export interface BkOTTrackingConfig {
116
97
  blankScreen?: BkOTBlankScreenPluginOptions | boolean;
117
98
  cspViolation?: boolean;
118
99
  device?: BkOTDevicePluginOptions | boolean;
119
- error?: BkOTErrorPluginOptions | boolean;
100
+ error?: boolean;
120
101
  longTask?: BkOTLongTaskPluginOptions | boolean;
121
102
  request?: BkOTRequestConfig | boolean;
122
103
  resource?: boolean;
@@ -127,9 +108,12 @@ export interface BkOTTrackingConfig {
127
108
  }
128
109
  export type BkOTTrackingConsent = 'granted' | 'not-granted';
129
110
  export interface BkOTTransportConfig {
130
- endpoint?: string;
111
+ batch?: BkOTBatchConfig;
112
+ concurrencyLimit?: number;
113
+ endpoint: string;
131
114
  headers?: Record<string, string>;
132
- signals?: SignalExportersInputConfig;
115
+ processor?: BkOTSpanProcessorMode;
116
+ timeoutMillis?: number;
133
117
  token?: string;
134
118
  }
135
119
  export type BkOTUrlMatcher = ((url: string) => boolean) | RegExp | string;
@@ -142,9 +126,6 @@ export interface BkOTViewConfig {
142
126
  /** 返回低基数路由分组,例如 `/trace/:id`。 */
143
127
  getPathGroup?: (url: string) => string | undefined;
144
128
  }
145
- export interface MetricExporterInputConfig extends SignalExporterInputConfig {
146
- intervalMillis?: number;
147
- }
148
129
  export interface ResolvedApplicationConfig {
149
130
  environment: string;
150
131
  name: string;
@@ -157,7 +138,6 @@ export interface ResolvedBkOTConfig {
157
138
  enabled: boolean;
158
139
  extensions: BkOTExtensionsConfig;
159
140
  hooks: ResolvedConfigHooks;
160
- metricIntervalMillis: number;
161
141
  resourceAttributes: Attributes;
162
142
  session: ResolvedSessionConfig;
163
143
  spanBatch?: BkOTBatchConfig;
@@ -172,7 +152,6 @@ export interface ResolvedConfigHooks {
172
152
  beforeSend?: (event: BkOTBeforeSendEvent) => boolean | void;
173
153
  getCustomAttributes: () => Attributes;
174
154
  getErrorAttributes: () => Attributes;
175
- getMetricAttributes: () => Attributes;
176
155
  getPageAttributes: () => Attributes;
177
156
  getViewPathGroup: (url: string) => string;
178
157
  redactAttributes: (attributes: Attributes) => Attributes;
@@ -181,12 +160,7 @@ export interface ResolvedConfigHooks {
181
160
  export interface ResolvedSessionConfig extends BkOTSessionConfig {
182
161
  sampleRate: number;
183
162
  }
184
- export interface ResolvedTransportConfig {
185
- endpoint: string;
186
- logs: false | SignalExporterConfig;
187
- metrics: false | SignalExporterConfig;
188
- traces: false | SignalExporterConfig;
189
- }
163
+ export type ResolvedTransportConfig = SignalExporterConfig;
190
164
  export interface ResolvedViewConfig {
191
165
  excludedActivityUrls?: BkOTUrlMatcher | BkOTUrlMatcher[];
192
166
  loadingTime: boolean;
@@ -198,14 +172,4 @@ export interface SignalExporterConfig {
198
172
  headers?: Record<string, string>;
199
173
  timeoutMillis?: number;
200
174
  }
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
175
  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
- }
@@ -3,7 +3,6 @@ import { type Instrumentation } from '@opentelemetry/instrumentation';
3
3
  import { type BkOTActionEventPayload, type BkOTCustomEventPayload, type BkOTOptions, type BkOTTrackingConsent, type ResolvedBkOTConfig } from './config';
4
4
  import { type BkOTPlugin, type BkOTRuntimeContext, type BkOTStartSpanOptions } from './plugin';
5
5
  import { type BkOTSessionLifecycleEvent, type BkOTStartViewOptions, type BkOTUserContext } from './runtime-context';
6
- import type { LogRecord } from '@opentelemetry/api-logs';
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, type SignalExporterConfig, } 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';