@blueking/open-telemetry 0.0.8 → 0.0.10

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,3 +1,9 @@
1
+ import type { BkOTActionPluginOptions } from '../plugins/action';
2
+ import type { BkOTBlankScreenPluginOptions } from '../plugins/blank-screen';
3
+ import type { BkOTDevicePluginOptions } from '../plugins/device';
4
+ import type { BkOTErrorPluginOptions } from '../plugins/error';
5
+ import type { BkOTLongTaskPluginOptions } from '../plugins/long-task';
6
+ import type { BkOTSessionPluginOptions } from '../plugins/session';
1
7
  import type { BkOTPlugin } from './plugin';
2
8
  import type { BkOTUserContext } from './runtime-context';
3
9
  import type { Attributes } from '@opentelemetry/api';
@@ -45,8 +51,25 @@ export interface BkOTHttpBodyRedactPayload {
45
51
  url: string;
46
52
  }
47
53
  export interface BkOTInstrumentationsConfig {
54
+ custom?: Instrumentation[];
48
55
  documentLoad?: boolean;
49
56
  fetch?: boolean;
57
+ /**
58
+ * 控制 fetch/xhr 请求向哪些后台 API 注入 W3C `traceparent`(内含 OpenTelemetry traceId)请求头。
59
+ *
60
+ * 同源请求始终注入;该配置用于把跨域后台 API 也纳入注入范围(在同源基础上扩展):
61
+ * - `'all'`:所有请求都注入(含跨域,使用前确认涉及的隐私/CORS 影响)。
62
+ * - `string`:URL 包含该子串即注入,例如 `'api.example.com'`。
63
+ * - `RegExp`:URL 匹配该正则即注入。
64
+ * - 以上字符串/正则的数组:命中任意一个即注入。
65
+ * - `(url: string) => boolean`:完全自定义判断。
66
+ *
67
+ * 注意:向跨域服务注入自定义头会触发 CORS 预检,目标服务需在
68
+ * `Access-Control-Allow-Headers` 中放行 `traceparent`(以及按需的 `tracestate`)。
69
+ *
70
+ * 默认未配置时仅同源请求注入,保持既有行为。
71
+ */
72
+ propagateTraceHeaderUrls?: BkOTPropagateTraceHeaderUrls;
50
73
  userInteraction?: boolean | {
51
74
  eventNames?: string[];
52
75
  };
@@ -58,21 +81,37 @@ export interface BkOTOptions {
58
81
  autoStart?: boolean;
59
82
  debug?: boolean;
60
83
  enabled?: boolean;
61
- instrumentations?: Instrumentation[];
62
- plugins?: BkOTPlugin[];
84
+ instrumentations?: BkOTInstrumentationsConfig;
85
+ plugins?: BkOTPluginsConfig;
63
86
  privacy?: BkOTPrivacyConfig;
64
87
  route?: BkOTRouteConfig;
65
- rum?: BkOTRumOptions;
66
88
  sampling?: BkOTSamplingConfig;
67
89
  spanBatch?: BkOTBatchConfig;
68
90
  spanProcessor?: BkOTSpanProcessorMode;
69
91
  transport?: BkOTTransportConfig;
70
92
  user?: BkOTUserContext;
71
93
  }
94
+ export interface BkOTPluginsConfig {
95
+ action?: BkOTActionPluginOptions | boolean;
96
+ blankScreen?: BkOTBlankScreenPluginOptions | boolean;
97
+ cspViolation?: boolean;
98
+ custom?: BkOTPlugin[];
99
+ device?: BkOTDevicePluginOptions | boolean;
100
+ error?: BkOTErrorPluginOptions | boolean;
101
+ httpBody?: BkOTHttpBodyConfig | boolean;
102
+ longTask?: BkOTLongTaskPluginOptions | boolean;
103
+ pageView?: boolean;
104
+ resource?: boolean;
105
+ routeTiming?: boolean;
106
+ session?: BkOTSessionPluginOptions | boolean;
107
+ websocket?: boolean;
108
+ webVitals?: boolean;
109
+ }
72
110
  export interface BkOTPrivacyConfig {
73
111
  redactAttributes?: (attributes: Attributes) => Attributes;
74
112
  redactUrl?: (url: string) => string;
75
113
  }
114
+ export type BkOTPropagateTraceHeaderUrls = 'all' | ((url: string) => boolean) | Array<RegExp | string> | RegExp | string;
76
115
  export interface BkOTRouteConfig {
77
116
  /**
78
117
  * 返回低基数路由分组,例如 `/trace/:id`。
@@ -80,43 +119,6 @@ export interface BkOTRouteConfig {
80
119
  */
81
120
  getPathGroup?: (url: string) => string | undefined;
82
121
  }
83
- export interface BkOTRumOptions {
84
- instrumentations?: BkOTInstrumentationsConfig;
85
- plugins?: BkOTRumPluginOptions;
86
- }
87
- export interface BkOTRumPluginOptions {
88
- cspViolation?: boolean;
89
- device?: boolean | {
90
- storageKey?: string;
91
- };
92
- httpBody?: BkOTHttpBodyConfig | boolean;
93
- pageView?: boolean;
94
- resource?: boolean;
95
- routeTiming?: boolean;
96
- websocket?: boolean;
97
- webVitals?: boolean;
98
- action?: boolean | {
99
- eventNames?: Array<'click' | 'input' | 'keydown' | 'pointerdown' | 'scroll' | 'submit'>;
100
- };
101
- blankScreen?: {
102
- checkDelay?: number;
103
- ignoreSelectors?: string[];
104
- rootSelector?: string;
105
- threshold?: number;
106
- } | boolean;
107
- error?: {
108
- maxPerWindow?: number;
109
- windowMs?: number;
110
- } | boolean;
111
- longTask?: {
112
- threshold?: number;
113
- } | boolean;
114
- session?: {
115
- inactivityMs?: number;
116
- maxLifetimeMs?: number;
117
- storageKey?: string;
118
- } | boolean;
119
- }
120
122
  export interface BkOTSamplingConfig {
121
123
  rate?: number;
122
124
  }
@@ -138,11 +140,10 @@ export interface ResolvedBkOTConfig {
138
140
  debug: boolean;
139
141
  enabled: boolean;
140
142
  hooks: ResolvedConfigHooks;
141
- instrumentations: Instrumentation[];
143
+ instrumentations: BkOTInstrumentationsConfig;
142
144
  metricIntervalMillis: number;
143
- plugins: BkOTPlugin[];
145
+ plugins: BkOTPluginsConfig;
144
146
  resourceAttributes: Attributes;
145
- rum: ResolvedRumConfig;
146
147
  sampling: ResolvedSamplingConfig;
147
148
  spanBatch?: BkOTBatchConfig;
148
149
  spanProcessor: BkOTSpanProcessorMode;
@@ -158,50 +159,6 @@ export interface ResolvedConfigHooks {
158
159
  redactAttributes: (attributes: Attributes) => Attributes;
159
160
  redactUrl: (url: string) => string;
160
161
  }
161
- export type ResolvedPluginOption<TConfig extends object = object> = (TConfig & {
162
- enabled: true;
163
- }) | {
164
- enabled: false;
165
- };
166
- export interface ResolvedRumConfig {
167
- plugins: ResolvedRumPluginConfig;
168
- instrumentations: Required<Pick<BkOTInstrumentationsConfig, 'documentLoad' | 'fetch' | 'xhr'>> & {
169
- userInteraction: BkOTInstrumentationsConfig['userInteraction'];
170
- };
171
- }
172
- export interface ResolvedRumPluginConfig {
173
- cspViolation: ResolvedPluginOption;
174
- device: ResolvedPluginOption<{
175
- storageKey?: string;
176
- }>;
177
- error: ResolvedPluginOption<{
178
- maxPerWindow: number;
179
- windowMs: number;
180
- }>;
181
- httpBody: ResolvedPluginOption<Required<BkOTHttpBodyConfig>>;
182
- longTask: ResolvedPluginOption<{
183
- threshold: number;
184
- }>;
185
- pageView: ResolvedPluginOption;
186
- resource: ResolvedPluginOption;
187
- routeTiming: ResolvedPluginOption;
188
- websocket: ResolvedPluginOption;
189
- webVitals: ResolvedPluginOption;
190
- action: ResolvedPluginOption<{
191
- eventNames: Array<'click' | 'input' | 'keydown' | 'pointerdown' | 'scroll' | 'submit'>;
192
- }>;
193
- blankScreen: ResolvedPluginOption<{
194
- checkDelay: number;
195
- ignoreSelectors?: string[];
196
- rootSelector?: string;
197
- threshold: number;
198
- }>;
199
- session: ResolvedPluginOption<{
200
- inactivityMs: number;
201
- maxLifetimeMs: number;
202
- storageKey?: string;
203
- }>;
204
- }
205
162
  export interface ResolvedSamplingConfig {
206
163
  rate: number;
207
164
  }
@@ -0,0 +1,3 @@
1
+ import type { Attributes } from '@opentelemetry/api';
2
+ export declare const getMetricViewAttributes: (runtimeAttributes: Attributes) => Attributes;
3
+ export declare const getInstrumentationSpanRuntimeAttributes: (runtimeAttributes: Attributes, fallbackViewPathGroup?: string) => Attributes;
@@ -1,4 +1,4 @@
1
1
  import type { ResolvedBkOTConfig } from './config';
2
2
  export declare const isBkOTEndpoint: (config: ResolvedBkOTConfig, url: string) => boolean;
3
3
  export declare const shouldIgnoreUrl: (config: ResolvedBkOTConfig, url: string) => boolean;
4
- export declare const shouldPropagateTraceHeader: (_config: ResolvedBkOTConfig, url: string) => boolean;
4
+ export declare const shouldPropagateTraceHeader: (config: ResolvedBkOTConfig, url: string) => boolean;
package/dist/index.d.ts CHANGED
@@ -1,21 +1,21 @@
1
- export { type BkOTActionEventPayload, type BkOTAppConfig, type BkOTAttributesConfig, type BkOTAttributeValue, type BkOTBatchConfig, type BkOTCustomEventPayload, type BkOTHttpBodyConfig, type BkOTHttpBodyRedactPayload, type BkOTInstrumentationsConfig, type BkOTOptions, type BkOTPrivacyConfig, type BkOTRumOptions, type BkOTRumPluginOptions, type BkOTSamplingConfig, type BkOTTransportConfig, resolveConfig, type ResolvedBkOTConfig, type ResolvedConfigHooks, type ResolvedPluginOption, type ResolvedRumConfig, type ResolvedRumPluginConfig, type ResolvedTransportConfig, type SignalExporterConfig, type SignalExportersInputConfig, } from './core/config';
1
+ export { type BkOTActionEventPayload, type BkOTAppConfig, type BkOTAttributesConfig, type BkOTAttributeValue, type BkOTBatchConfig, type BkOTCustomEventPayload, type BkOTHttpBodyConfig, type BkOTHttpBodyRedactPayload, type BkOTInstrumentationsConfig, type BkOTOptions, type BkOTPluginsConfig, type BkOTPrivacyConfig, type BkOTPropagateTraceHeaderUrls, type BkOTSamplingConfig, type BkOTTransportConfig, resolveConfig, type ResolvedBkOTConfig, type ResolvedConfigHooks, type ResolvedTransportConfig, type SignalExporterConfig, type SignalExportersInputConfig, } from './core/config';
2
2
  export { type BkOTPlugin, type BkOTRuntimeContext, createPlugin, type PluginManager } from './core/plugin';
3
3
  export { FilteringSpanProcessor } from './core/processor';
4
4
  export { type BkOTUserContext, type BkOTViewContext, RumRuntimeContext } from './core/runtime-context';
5
5
  export { BkOpenTelemetry, type BkOTInstance } from './core/sdk';
6
6
  export { RUM_ATTRIBUTES, type RumAttributeKey } from './schema/attributes';
7
7
  export { buildRumSpanAttributes, getDurationBucket, RUM_SPAN_RESULT, RUM_SPAN_TYPE, type RumSpanClassification, type RumSpanResult, type RumSpanType, } from './schema/span';
8
- export { createActionPlugin } from './plugins/action';
9
- export { createBlankScreenPlugin } from './plugins/blank-screen';
8
+ export { createActionPlugin, type BkOTActionEventName, type BkOTActionPluginOptions } from './plugins/action';
9
+ export { createBlankScreenPlugin, type BkOTBlankScreenPluginOptions } from './plugins/blank-screen';
10
10
  export { createCommonInstrumentationsPlugin } from './plugins/common';
11
11
  export { createCspViolationPlugin } from './plugins/csp-violation';
12
- export { createDevicePlugin } from './plugins/device';
13
- export { createErrorPlugin } from './plugins/error';
12
+ export { createDevicePlugin, type BkOTDevicePluginOptions } from './plugins/device';
13
+ export { createErrorPlugin, type BkOTErrorPluginOptions } from './plugins/error';
14
14
  export { createHttpBodyPlugin } from './plugins/http-body';
15
- export { createLongTaskPlugin } from './plugins/long-task';
15
+ export { createLongTaskPlugin, type BkOTLongTaskPluginOptions } from './plugins/long-task';
16
16
  export { createPageViewPlugin } from './plugins/page-view';
17
17
  export { createResourcePlugin } from './plugins/resource';
18
18
  export { createRouteTimingPlugin } from './plugins/route-timing';
19
- export { createSessionPlugin } from './plugins/session';
19
+ export { createSessionPlugin, type BkOTSessionPluginOptions } from './plugins/session';
20
20
  export { createWebVitalsPlugin } from './plugins/web-vitals';
21
21
  export { createWebSocketPlugin } from './plugins/websocket';