@blueking/open-telemetry 0.0.6 → 0.0.7

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/dist/index.js CHANGED
@@ -9,39 +9,85 @@ import { registerInstrumentations as p } from "@opentelemetry/instrumentation";
9
9
  import { resourceFromAttributes as m } from "@opentelemetry/resources";
10
10
  import { BatchLogRecordProcessor as h, LoggerProvider as g } from "@opentelemetry/sdk-logs";
11
11
  import { MeterProvider as _, PeriodicExportingMetricReader as v } from "@opentelemetry/sdk-metrics";
12
- import { BatchSpanProcessor as y, ParentBasedSampler as b, SimpleSpanProcessor as x, TraceIdRatioBasedSampler as S } from "@opentelemetry/sdk-trace-base";
13
- import { WebTracerProvider as C } from "@opentelemetry/sdk-trace-web";
12
+ import { BatchSpanProcessor as y, ParentBasedSampler as ee, SimpleSpanProcessor as te, TraceIdRatioBasedSampler as ne } from "@opentelemetry/sdk-trace-base";
13
+ import { WebTracerProvider as re } from "@opentelemetry/sdk-trace-web";
14
+ //#region src/schema/attributes.ts
15
+ var b = {
16
+ actionType: "action.type",
17
+ deploymentEnvironmentName: "deployment.environment.name",
18
+ browserName: "browser_name",
19
+ browserVersion: "browser_version",
20
+ cacheHit: "cache_hit",
21
+ deviceType: "device_type",
22
+ durationBucket: "duration_bucket",
23
+ errorType: "error_type",
24
+ eventLabel: "event_label",
25
+ exceptionFingerprint: "exception.fingerprint",
26
+ exceptionMessageShort: "exception.message_short",
27
+ exceptionStackTopFrame: "exception.stack_top_frame",
28
+ longtaskAttributionScript: "longtask.attribution_script",
29
+ longtaskBlockingDuration: "longtask.blocking_duration",
30
+ networkEffectiveType: "network.effective_type",
31
+ nextHopProtocol: "next_hop_protocol",
32
+ result: "result",
33
+ serviceName: "service.name",
34
+ serviceVersion: "service.version",
35
+ osName: "os_name",
36
+ sessionHasReplay: "session.has_replay",
37
+ sessionId: "session.id",
38
+ sessionStartTime: "session.start_time",
39
+ spanSubtype: "span_subtype",
40
+ spanType: "span_type",
41
+ statusClass: "status_class",
42
+ targetDomain: "target_domain",
43
+ targetLabel: "target_label",
44
+ targetPathTemplate: "target_path_template",
45
+ targetTag: "target.tag",
46
+ targetTextShort: "target.text_short",
47
+ targetValue: "target_value",
48
+ traceScene: "trace_scene",
49
+ transferSize: "transfer_size",
50
+ userId: "user.id",
51
+ vitalMetric: "vital.metric",
52
+ vitalRating: "vital.rating",
53
+ vitalValue: "vital.value",
54
+ viewId: "view.id",
55
+ viewLoadingType: "view.loading_type",
56
+ viewUrl: "view.url",
57
+ viewUrlPathGroup: "view.url_path_group"
58
+ };
59
+ //#endregion
14
60
  //#region \0@oxc-project+runtime@0.128.0/helpers/typeof.js
15
- function w(e) {
61
+ function x(e) {
16
62
  "@babel/helpers - typeof";
17
- return w = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(e) {
63
+ return x = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(e) {
18
64
  return typeof e;
19
65
  } : function(e) {
20
66
  return e && typeof Symbol == "function" && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e;
21
- }, w(e);
67
+ }, x(e);
22
68
  }
23
69
  //#endregion
24
70
  //#region \0@oxc-project+runtime@0.128.0/helpers/toPrimitive.js
25
- function T(e, t) {
26
- if (w(e) != "object" || !e) return e;
71
+ function S(e, t) {
72
+ if (x(e) != "object" || !e) return e;
27
73
  var n = e[Symbol.toPrimitive];
28
74
  if (n !== void 0) {
29
75
  var r = n.call(e, t || "default");
30
- if (w(r) != "object") return r;
76
+ if (x(r) != "object") return r;
31
77
  throw TypeError("@@toPrimitive must return a primitive value.");
32
78
  }
33
79
  return (t === "string" ? String : Number)(e);
34
80
  }
35
81
  //#endregion
36
82
  //#region \0@oxc-project+runtime@0.128.0/helpers/toPropertyKey.js
37
- function E(e) {
38
- var t = T(e, "string");
39
- return w(t) == "symbol" ? t : t + "";
83
+ function ie(e) {
84
+ var t = S(e, "string");
85
+ return x(t) == "symbol" ? t : t + "";
40
86
  }
41
87
  //#endregion
42
88
  //#region \0@oxc-project+runtime@0.128.0/helpers/defineProperty.js
43
- function D(e, t, n) {
44
- return (t = E(t)) in e ? Object.defineProperty(e, t, {
89
+ function C(e, t, n) {
90
+ return (t = ie(t)) in e ? Object.defineProperty(e, t, {
45
91
  value: n,
46
92
  enumerable: !0,
47
93
  configurable: !0,
@@ -50,7 +96,7 @@ function D(e, t, n) {
50
96
  }
51
97
  //#endregion
52
98
  //#region \0@oxc-project+runtime@0.128.0/helpers/objectSpread2.js
53
- function O(e, t) {
99
+ function w(e, t) {
54
100
  var n = Object.keys(e);
55
101
  if (Object.getOwnPropertySymbols) {
56
102
  var r = Object.getOwnPropertySymbols(e);
@@ -60,12 +106,12 @@ function O(e, t) {
60
106
  }
61
107
  return n;
62
108
  }
63
- function k(e) {
109
+ function T(e) {
64
110
  for (var t = 1; t < arguments.length; t++) {
65
111
  var n = arguments[t] == null ? {} : arguments[t];
66
- t % 2 ? O(Object(n), !0).forEach(function(t) {
67
- D(e, t, n[t]);
68
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(n)) : O(Object(n)).forEach(function(t) {
112
+ t % 2 ? w(Object(n), !0).forEach(function(t) {
113
+ C(e, t, n[t]);
114
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(n)) : w(Object(n)).forEach(function(t) {
69
115
  Object.defineProperty(e, t, Object.getOwnPropertyDescriptor(n, t));
70
116
  });
71
117
  }
@@ -73,94 +119,147 @@ function k(e) {
73
119
  }
74
120
  //#endregion
75
121
  //#region src/core/config.ts
76
- var A = "http://localhost:4318", ee = 60 * 1e3, j = (e) => e.replace(/\/+$/, ""), M = (e, t) => {
77
- let n = j(e || A);
122
+ var ae = "http://localhost:4318", oe = 60 * 1e3, se = "unknown_service", E = (e) => e.replace(/\/+$/, ""), ce = (e, t) => {
123
+ let n = E(e || ae);
78
124
  return n.endsWith(`/v1/${t}`) ? n : n.endsWith("/v1") ? `${n}/${t}` : `${n}/v1/${t}`;
79
- }, N = (e, t) => {
80
- var n, r, i, a;
81
- let o = e[t], s = (n = e.signalEndpoints) == null ? void 0 : n[t], c = e.token || e.headers || o != null && o.headers ? k(k(k({}, e.token ? { Authorization: `Bearer ${e.token}` } : {}), (r = e.headers) == null ? {} : r), (i = o == null ? void 0 : o.headers) == null ? {} : i) : void 0;
125
+ }, D = (e, t) => {
126
+ var n, r, i, a, o;
127
+ let s = e == null || (n = e.signals) == null ? void 0 : n[t], c = e == null || (r = e.signals) == null || (r = r.endpoints) == null ? void 0 : r[t], l = e != null && e.token || e != null && e.headers || s != null && s.headers ? T(T(T({}, e != null && e.token ? { Authorization: `Bearer ${e.token}` } : {}), (i = e == null ? void 0 : e.headers) == null ? {} : i), (a = s == null ? void 0 : s.headers) == null ? {} : a) : void 0;
82
128
  return {
83
- concurrencyLimit: o == null ? void 0 : o.concurrencyLimit,
84
- endpoint: s ? j(s) : M((a = o == null ? void 0 : o.endpoint) == null ? e.endpoint : a, t),
85
- headers: c,
86
- timeoutMillis: o == null ? void 0 : o.timeoutMillis
129
+ concurrencyLimit: s == null ? void 0 : s.concurrencyLimit,
130
+ endpoint: c ? E(c) : ce((o = s == null ? void 0 : s.endpoint) == null ? e == null ? void 0 : e.endpoint : o, t),
131
+ headers: l,
132
+ timeoutMillis: s == null ? void 0 : s.timeoutMillis
87
133
  };
88
- }, te = (e) => typeof e != "number" || !Number.isFinite(e) ? 1 : Math.max(0, Math.min(1, e)), P = (e, t) => typeof e == "number" && Number.isFinite(e) && e > 0 ? e : t, ne = (e, t) => typeof e == "number" && Number.isFinite(e) && e >= 0 ? e : t, re = (e, t) => typeof e != "number" || !Number.isFinite(e) ? t : Math.max(0, Math.min(1, e)), ie = (e) => e.body, ae = (e) => {
134
+ }, le = (e) => typeof e != "number" || !Number.isFinite(e) ? 1 : Math.max(0, Math.min(1, e)), O = (e, t) => typeof e == "number" && Number.isFinite(e) && e > 0 ? e : t, ue = (e, t) => typeof e == "number" && Number.isFinite(e) && e >= 0 ? e : t, de = (e, t) => typeof e != "number" || !Number.isFinite(e) ? t : Math.max(0, Math.min(1, e)), fe = (e) => e.body, k = () => ({ enabled: !1 }), A = (e) => T({ enabled: !0 }, e), j = (e) => e ? { enabled: !0 } : k(), pe = (e) => e === !1 ? k() : { enabled: !0 }, me = (e) => {
89
135
  var t;
90
- return e ? typeof e == "boolean" ? {
136
+ return e ? A(typeof e == "boolean" ? {
91
137
  maxBodySize: 10 * 1024,
92
- redact: ie
138
+ redact: fe
93
139
  } : {
94
- maxBodySize: P(e.maxBodySize, 10 * 1024),
95
- redact: (t = e.redact) == null ? ie : t
96
- } : !1;
97
- }, oe = (e) => {
98
- var t, n, r, i, a, o, s, c, l, u;
140
+ maxBodySize: O(e.maxBodySize, 10 * 1024),
141
+ redact: (t = e.redact) == null ? fe : t
142
+ }) : k();
143
+ }, he = (e) => {
144
+ var t;
99
145
  return {
100
- device: (t = e == null ? void 0 : e.device) == null ? !0 : t,
101
- httpBody: ae(e == null ? void 0 : e.httpBody),
102
- session: typeof (e == null ? void 0 : e.session) == "object" ? k(k({}, e.session), {}, {
103
- inactivityMs: P(e.session.inactivityMs, 1800 * 1e3),
104
- maxLifetimeMs: P(e.session.maxLifetimeMs, 1440 * 60 * 1e3)
105
- }) : (n = e == null ? void 0 : e.session) == null ? !0 : n,
106
- pageView: (r = e == null ? void 0 : e.pageView) == null ? !0 : r,
107
- error: typeof (e == null ? void 0 : e.error) == "object" ? k(k({}, e.error), {}, {
108
- maxPerWindow: P(e.error.maxPerWindow, 5),
109
- windowMs: P(e.error.windowMs, 6e4)
110
- }) : (i = e == null ? void 0 : e.error) == null ? !0 : i,
111
- webVitals: (a = e == null ? void 0 : e.webVitals) == null ? !0 : a,
112
- blankScreen: typeof (e == null ? void 0 : e.blankScreen) == "object" ? k(k({}, e.blankScreen), {}, {
113
- checkDelay: ne(e.blankScreen.checkDelay, 3e3),
114
- threshold: re(e.blankScreen.threshold, .8)
115
- }) : (o = e == null ? void 0 : e.blankScreen) == null ? !0 : o,
116
- websocket: (s = e == null ? void 0 : e.websocket) == null ? !0 : s,
117
- longTask: typeof (e == null ? void 0 : e.longTask) == "object" ? k(k({}, e.longTask), {}, { threshold: ne(e.longTask.threshold, 50) }) : (c = e == null ? void 0 : e.longTask) == null ? !1 : c,
118
- cspViolation: (l = e == null ? void 0 : e.cspViolation) == null ? !1 : l,
119
- routeTiming: (u = e == null ? void 0 : e.routeTiming) == null ? !1 : u
120
- };
121
- }, se = (e) => e, ce = (e) => e, le = (e) => {
122
- var t, n, r, i, a, o, s, c, l, u, d, f, p, m, h, g, _, v, y, b, x, S, C, w, T, E, D, O;
123
- let M = {
124
- "deployment.environment.name": (t = e.environment) == null ? "production" : t,
125
- "rum.provider": "blueking",
126
- "telemetry.sdk.language": "webjs"
146
+ action: typeof (e == null ? void 0 : e.action) == "object" ? A({ eventNames: (t = e.action.eventNames) == null ? [
147
+ "click",
148
+ "submit",
149
+ "keydown"
150
+ ] : t }) : e != null && e.action ? A({ eventNames: [
151
+ "click",
152
+ "submit",
153
+ "keydown"
154
+ ] }) : k(),
155
+ device: typeof (e == null ? void 0 : e.device) == "object" ? A({ storageKey: e.device.storageKey }) : (e == null ? void 0 : e.device) === !1 ? k() : A({}),
156
+ httpBody: me(e == null ? void 0 : e.httpBody),
157
+ session: typeof (e == null ? void 0 : e.session) == "object" ? A({
158
+ inactivityMs: O(e.session.inactivityMs, 1800 * 1e3),
159
+ maxLifetimeMs: O(e.session.maxLifetimeMs, 1440 * 60 * 1e3),
160
+ storageKey: e.session.storageKey
161
+ }) : (e == null ? void 0 : e.session) === !1 ? k() : A({
162
+ inactivityMs: 1800 * 1e3,
163
+ maxLifetimeMs: 1440 * 60 * 1e3
164
+ }),
165
+ pageView: pe(e == null ? void 0 : e.pageView),
166
+ resource: pe(e == null ? void 0 : e.resource),
167
+ error: typeof (e == null ? void 0 : e.error) == "object" ? A({
168
+ maxPerWindow: O(e.error.maxPerWindow, 5),
169
+ windowMs: O(e.error.windowMs, 6e4)
170
+ }) : (e == null ? void 0 : e.error) === !1 ? k() : A({
171
+ maxPerWindow: 5,
172
+ windowMs: 6e4
173
+ }),
174
+ webVitals: pe(e == null ? void 0 : e.webVitals),
175
+ blankScreen: typeof (e == null ? void 0 : e.blankScreen) == "object" ? A({
176
+ checkDelay: ue(e.blankScreen.checkDelay, 3e3),
177
+ ignoreSelectors: e.blankScreen.ignoreSelectors,
178
+ rootSelector: e.blankScreen.rootSelector,
179
+ threshold: de(e.blankScreen.threshold, .8)
180
+ }) : (e == null ? void 0 : e.blankScreen) === !1 ? k() : A({
181
+ checkDelay: 3e3,
182
+ threshold: .8
183
+ }),
184
+ websocket: j(e == null ? void 0 : e.websocket),
185
+ longTask: typeof (e == null ? void 0 : e.longTask) == "object" ? A({ threshold: ue(e.longTask.threshold, 50) }) : e != null && e.longTask ? A({ threshold: 50 }) : k(),
186
+ cspViolation: j(e == null ? void 0 : e.cspViolation),
187
+ routeTiming: j(e == null ? void 0 : e.routeTiming)
127
188
  };
128
- return k(k({}, e), {}, {
129
- debug: (n = e.debug) == null ? !1 : n,
130
- enabled: (r = e.enabled) == null ? !0 : r,
131
- environment: (i = e.environment) == null ? "production" : i,
132
- endpoint: j(e.endpoint || A),
133
- traces: N(e, "traces"),
134
- metrics: N(e, "metrics"),
135
- logs: N(e, "logs"),
136
- sampleRate: te(e.sampleRate),
137
- spanProcessor: (a = e.spanProcessor) == null ? "batch" : a,
138
- resourceAttributes: M,
139
- metricIntervalMillis: ee,
140
- instrumentations: (o = e.instrumentations) == null ? [] : o,
141
- commonInstrumentations: {
142
- documentLoad: (s = (c = e.rum) == null ? void 0 : c.documentLoad) == null ? !0 : s,
143
- fetch: (l = (u = e.rum) == null ? void 0 : u.fetch) == null ? !0 : l,
144
- xhr: (d = (f = e.rum) == null ? void 0 : f.xhr) == null ? !0 : d,
145
- userInteraction: (p = (m = e.rum) == null ? void 0 : m.userInteraction) == null ? !0 : p
189
+ }, ge = (e) => {
190
+ var t, n, r, i, a, o, s, c;
191
+ return {
192
+ instrumentations: {
193
+ documentLoad: (t = e == null || (n = e.instrumentations) == null ? void 0 : n.documentLoad) == null ? !0 : t,
194
+ fetch: (r = e == null || (i = e.instrumentations) == null ? void 0 : i.fetch) == null ? !0 : r,
195
+ xhr: (a = e == null || (o = e.instrumentations) == null ? void 0 : o.xhr) == null ? !0 : a,
196
+ userInteraction: (s = e == null || (c = e.instrumentations) == null ? void 0 : c.userInteraction) == null ? !0 : s
146
197
  },
147
- rum: oe(e.rum),
148
- plugins: (h = e.plugins) == null ? [] : h,
149
- autoStart: (g = e.autoStart) == null ? !0 : g,
150
- getPageAttributes: (_ = (v = e.attributes) == null ? void 0 : v.page) == null ? (() => ({
198
+ plugins: he(e == null ? void 0 : e.plugins)
199
+ };
200
+ }, _e = (e) => e, ve = (e) => e, ye = (e) => {
201
+ try {
202
+ return new URL(e, typeof location > "u" ? "http://localhost" : location.href).pathname || "/";
203
+ } catch (t) {
204
+ return e || "/";
205
+ }
206
+ }, be = (e) => {
207
+ var t, n;
208
+ return {
209
+ environment: (t = e == null ? void 0 : e.environment) == null ? "production" : t,
210
+ name: (n = e == null ? void 0 : e.name) == null ? se : n,
211
+ version: e == null ? void 0 : e.version
212
+ };
213
+ }, xe = (e) => T(T({
214
+ [b.deploymentEnvironmentName]: e.environment,
215
+ "rum.provider": "blueking",
216
+ [b.serviceName]: e.name
217
+ }, e.version ? { [b.serviceVersion]: e.version } : {}), {}, { "telemetry.sdk.language": "webjs" }), Se = (e) => ({
218
+ endpoint: E((e == null ? void 0 : e.endpoint) || ae),
219
+ traces: D(e, "traces"),
220
+ metrics: D(e, "metrics"),
221
+ logs: D(e, "logs")
222
+ }), Ce = (e) => ({ rate: le(e == null ? void 0 : e.rate) }), we = (e) => {
223
+ var t, n, r, i, a, o, s, c, l, u, d, f;
224
+ return {
225
+ getPageAttributes: (t = (n = e.attributes) == null ? void 0 : n.page) == null ? (() => ({
151
226
  "rum.page.host": typeof window > "u" ? "" : window.location.host,
152
227
  "rum.page.path": typeof window > "u" ? "" : window.location.pathname
153
- })) : _,
154
- getMetricAttributes: (y = (b = e.attributes) == null ? void 0 : b.metric) == null ? (() => ({})) : y,
155
- getErrorAttributes: (x = (S = e.attributes) == null ? void 0 : S.error) == null ? (() => ({})) : x,
156
- getCustomAttributes: (C = (w = e.attributes) == null ? void 0 : w.custom) == null ? (() => ({})) : C,
157
- redactAttributes: (T = (E = e.redact) == null ? void 0 : E.attributes) == null ? se : T,
158
- redactUrl: (D = (O = e.redact) == null ? void 0 : O.url) == null ? ce : D
159
- });
228
+ })) : t,
229
+ getMetricAttributes: (r = (i = e.attributes) == null ? void 0 : i.metric) == null ? (() => ({})) : r,
230
+ getErrorAttributes: (a = (o = e.attributes) == null ? void 0 : o.error) == null ? (() => ({})) : a,
231
+ getCustomAttributes: (s = (c = e.attributes) == null ? void 0 : c.custom) == null ? (() => ({})) : s,
232
+ getViewPathGroup: (t) => {
233
+ var n, r, i;
234
+ return (n = (r = e.route) == null || (i = r.getPathGroup) == null ? void 0 : i.call(r, t)) == null ? ye(t) : n;
235
+ },
236
+ redactAttributes: (l = (u = e.privacy) == null ? void 0 : u.redactAttributes) == null ? _e : l,
237
+ redactUrl: (d = (f = e.privacy) == null ? void 0 : f.redactUrl) == null ? ve : d
238
+ };
239
+ }, Te = (e) => {
240
+ var t, n, r, i, a, o;
241
+ let s = be(e.app);
242
+ return {
243
+ app: s,
244
+ autoStart: (t = e.autoStart) == null ? !0 : t,
245
+ debug: (n = e.debug) == null ? !1 : n,
246
+ enabled: (r = e.enabled) == null ? !0 : r,
247
+ hooks: we(e),
248
+ instrumentations: (i = e.instrumentations) == null ? [] : i,
249
+ metricIntervalMillis: oe,
250
+ plugins: (a = e.plugins) == null ? [] : a,
251
+ resourceAttributes: xe(s),
252
+ rum: ge(e.rum),
253
+ sampling: Ce(e.sampling),
254
+ spanBatch: e.spanBatch,
255
+ spanProcessor: (o = e.spanProcessor) == null ? "batch" : o,
256
+ transport: Se(e.transport),
257
+ user: e.user
258
+ };
160
259
  };
161
260
  //#endregion
162
261
  //#region \0@oxc-project+runtime@0.128.0/helpers/asyncToGenerator.js
163
- function ue(e, t, n, r, i, a, o) {
262
+ function Ee(e, t, n, r, i, a, o) {
164
263
  try {
165
264
  var s = e[a](o), c = s.value;
166
265
  } catch (e) {
@@ -169,16 +268,16 @@ function ue(e, t, n, r, i, a, o) {
169
268
  }
170
269
  s.done ? t(c) : Promise.resolve(c).then(r, i);
171
270
  }
172
- function F(e) {
271
+ function M(e) {
173
272
  return function() {
174
273
  var t = this, n = arguments;
175
274
  return new Promise(function(r, i) {
176
275
  var a = e.apply(t, n);
177
276
  function o(e) {
178
- ue(a, r, i, o, s, "next", e);
277
+ Ee(a, r, i, o, s, "next", e);
179
278
  }
180
279
  function s(e) {
181
- ue(a, r, i, o, s, "throw", e);
280
+ Ee(a, r, i, o, s, "throw", e);
182
281
  }
183
282
  o(void 0);
184
283
  });
@@ -186,13 +285,13 @@ function F(e) {
186
285
  }
187
286
  //#endregion
188
287
  //#region src/core/plugin.ts
189
- var de = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !== !1, fe = (e) => e, pe = class {
288
+ var De = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !== !1, Oe = (e) => e, ke = class {
190
289
  constructor(e) {
191
- D(this, "plugins", void 0), D(this, "startedPlugins", []), this.plugins = e;
290
+ C(this, "plugins", void 0), C(this, "startedPlugins", []), this.plugins = e;
192
291
  }
193
292
  flush() {
194
293
  var e = this;
195
- return F(function* () {
294
+ return M(function* () {
196
295
  yield Promise.all(e.startedPlugins.map((e) => Promise.resolve().then(() => {
197
296
  var t;
198
297
  return (t = e.flush) == null ? void 0 : t.call(e);
@@ -201,7 +300,7 @@ var de = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
201
300
  }
202
301
  shutdown() {
203
302
  var e = this;
204
- return F(function* () {
303
+ return M(function* () {
205
304
  let t = [...e.startedPlugins].reverse();
206
305
  for (let e of t) {
207
306
  var n;
@@ -212,8 +311,8 @@ var de = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
212
311
  }
213
312
  start(e) {
214
313
  var t = this;
215
- return F(function* () {
216
- for (let r of t.plugins) if (de(r, e.config)) try {
314
+ return M(function* () {
315
+ for (let r of t.plugins) if (De(r, e.config)) try {
217
316
  yield r.init(e), t.startedPlugins.push(r);
218
317
  } catch (t) {
219
318
  if (e.config.debug) {
@@ -223,35 +322,35 @@ var de = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
223
322
  }
224
323
  })();
225
324
  }
226
- }, me = () => typeof window > "u" ? "http://localhost" : window.location.origin, he = (e) => {
325
+ }, Ae = () => typeof window > "u" ? "http://localhost" : window.location.origin, je = (e) => {
227
326
  try {
228
- return new URL(e, me()).href;
327
+ return new URL(e, Ae()).href;
229
328
  } catch (t) {
230
329
  return e;
231
330
  }
232
- }, ge = (e) => e.length > 1 ? e.replace(/\/+$/, "") : e, _e = (e, t) => {
233
- let n = (e) => ge(e.replace(/[?#].*$/, ""));
331
+ }, Me = (e) => e.length > 1 ? e.replace(/\/+$/, "") : e, Ne = (e, t) => {
332
+ let n = (e) => Me(e.replace(/[?#].*$/, ""));
234
333
  return n(e) === n(t);
235
- }, ve = (e) => {
334
+ }, Pe = (e) => {
236
335
  try {
237
- return new URL(e, me()).origin === me();
336
+ return new URL(e, Ae()).origin === Ae();
238
337
  } catch (e) {
239
338
  return !1;
240
339
  }
241
- }, ye = (e, t) => {
242
- let n = he(t);
340
+ }, Fe = (e, t) => {
341
+ let n = je(t);
243
342
  return [
244
- e.traces.endpoint,
245
- e.metrics.endpoint,
246
- e.logs.endpoint
247
- ].some((e) => _e(n, he(e)));
248
- }, I = (e, t) => ye(e, t), be = (e, t) => ve(t), xe = ["http.url", "url.full"], Se = (e) => {
249
- for (let n of xe) {
343
+ e.transport.traces.endpoint,
344
+ e.transport.metrics.endpoint,
345
+ e.transport.logs.endpoint
346
+ ].some((e) => Ne(n, je(e)));
347
+ }, N = (e, t) => Fe(e, t), Ie = (e, t) => Pe(t), Le = ["http.url", "url.full"], Re = (e) => {
348
+ for (let n of Le) {
250
349
  var t;
251
350
  let r = (t = e.attributes) == null ? void 0 : t[n];
252
351
  if (typeof r == "string") return r;
253
352
  }
254
- }, Ce = class {
353
+ }, ze = class {
255
354
  constructor(e, t) {
256
355
  this.inner = e, this.config = t;
257
356
  }
@@ -259,8 +358,8 @@ var de = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
259
358
  return this.inner.forceFlush();
260
359
  }
261
360
  onEnd(e) {
262
- let t = Se(e);
263
- t && ye(this.config, t) || this.inner.onEnd(e);
361
+ let t = Re(e);
362
+ t && Fe(this.config, t) || this.inner.onEnd(e);
264
363
  }
265
364
  onStart(e, t) {
266
365
  this.inner.onStart(e, t);
@@ -268,7 +367,137 @@ var de = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
268
367
  shutdown() {
269
368
  return this.inner.shutdown();
270
369
  }
271
- }, we = "body", Te = 3e3, Ee = .8, De = [
370
+ }, Be = class {
371
+ constructor(e = {}, t) {
372
+ C(this, "attributes", {}), C(this, "setOptionalAttribute", (e, t) => {
373
+ if (t === void 0) {
374
+ delete this.attributes[e];
375
+ return;
376
+ }
377
+ this.attributes[e] = t;
378
+ }), C(this, "user", {}), C(this, "view", {}), C(this, "getAttributes", () => T({}, this.attributes)), C(this, "getUser", () => T({}, this.user)), C(this, "getView", () => T({}, this.view)), C(this, "setAttributes", (e) => {
379
+ for (let [t, n] of Object.entries(e)) {
380
+ if (n === void 0) {
381
+ delete this.attributes[t];
382
+ continue;
383
+ }
384
+ this.attributes[t] = n;
385
+ }
386
+ }), C(this, "setUser", (e) => {
387
+ if (this.user = T(T({}, this.user), e), "id" in e) {
388
+ if (e.id === void 0) {
389
+ delete this.attributes[b.userId];
390
+ return;
391
+ }
392
+ this.attributes[b.userId] = e.id;
393
+ }
394
+ }), C(this, "setView", (e) => {
395
+ this.view = T(T({}, this.view), e), this.setOptionalAttribute(b.viewId, e.id), this.setOptionalAttribute(b.viewUrl, e.url), this.setOptionalAttribute(b.viewUrlPathGroup, e.urlPathGroup), this.setOptionalAttribute(b.viewLoadingType, e.loadingType);
396
+ }), this.setAttributes(e), t && this.setUser(t);
397
+ }
398
+ }, P = {
399
+ abort: "abort",
400
+ error: "error",
401
+ success: "success",
402
+ timeout: "timeout",
403
+ warning: "warning"
404
+ }, F = {
405
+ action: "action",
406
+ custom: "custom",
407
+ document: "document",
408
+ error: "error",
409
+ http: "http",
410
+ longtask: "longtask",
411
+ resource: "resource",
412
+ route: "route",
413
+ vital: "vital"
414
+ }, Ve = (e) => e < 100 ? "<100ms" : e < 500 ? "100~500ms" : e < 2e3 ? "500ms~2s" : ">2s", He = (e) => `${Math.trunc(e / 100)}xx`, Ue = (e) => e === 408 || e === 504 ? P.timeout : typeof e == "number" && e >= 400 ? P.error : P.success, We = (e) => e === 408 || e === 504 ? "network_timeout" : typeof e != "number" || e < 400 ? "none" : e >= 500 ? "http_5xx" : "http_4xx", Ge = (e) => e === "good" ? P.success : P.warning, Ke = (e, t) => {
415
+ if (!e) return {};
416
+ try {
417
+ let n = new URL(e, typeof location > "u" ? "http://localhost" : location.href), r = t == null ? n.pathname : t;
418
+ return {
419
+ domain: n.host,
420
+ label: `${n.host}${r}`,
421
+ pathTemplate: r
422
+ };
423
+ } catch (n) {
424
+ return {
425
+ label: e,
426
+ pathTemplate: t == null ? e : t
427
+ };
428
+ }
429
+ }, I = ({ duration: e, errorType: t = "none", eventLabel: n, result: r = P.success, spanSubtype: i, spanType: a, targetLabel: o, targetValue: s, traceScene: c }) => T(T(T(T(T({
430
+ [b.spanType]: a,
431
+ [b.spanSubtype]: i,
432
+ [b.result]: r,
433
+ [b.errorType]: t
434
+ }, e === void 0 ? {} : { [b.durationBucket]: Ve(e) }), n === void 0 ? {} : { [b.eventLabel]: n }), o === void 0 ? {} : { [b.targetLabel]: o }), s === void 0 ? {} : { [b.targetValue]: s }), c === void 0 ? {} : { [b.traceScene]: c }), qe = ({ duration: e, method: t, statusCode: n, subtype: r, url: i, urlPathTemplate: a }) => {
435
+ let o = Ke(i, a);
436
+ return T(T(T(T(T({}, I({
437
+ duration: e,
438
+ errorType: We(n),
439
+ eventLabel: "API 调用",
440
+ result: Ue(n),
441
+ spanSubtype: r,
442
+ spanType: F.http,
443
+ targetLabel: o.label,
444
+ targetValue: n
445
+ })), t ? { "http.request.method": t.toUpperCase() } : {}), o.domain ? { [b.targetDomain]: o.domain } : {}), o.pathTemplate ? { [b.targetPathTemplate]: o.pathTemplate } : {}), typeof n == "number" ? {
446
+ "http.response.status_code": n,
447
+ [b.statusClass]: He(n)
448
+ } : {});
449
+ }, Je = ({ duration: e, initiatorType: t = "other", responseStatus: n, transferSize: r, url: i, urlPathTemplate: a }) => {
450
+ var o;
451
+ let s = Ke(i, a), c = typeof n == "number" ? Ue(n) : P.success;
452
+ return T(T(T(T({}, I({
453
+ duration: e,
454
+ errorType: typeof n == "number" ? We(n) : "none",
455
+ eventLabel: "静态资源",
456
+ result: c,
457
+ spanSubtype: t,
458
+ spanType: F.resource,
459
+ targetLabel: (o = s.label) == null ? i : o,
460
+ targetValue: r
461
+ })), s.domain ? { [b.targetDomain]: s.domain } : {}), s.pathTemplate ? { [b.targetPathTemplate]: s.pathTemplate } : {}), typeof n == "number" ? {
462
+ "http.response.status_code": n,
463
+ [b.statusClass]: He(n)
464
+ } : {});
465
+ }, Ye = (e) => e instanceof Element ? e : void 0, Xe = (e) => {
466
+ var t;
467
+ if (!e) return;
468
+ let n = ((t = e.textContent) == null ? void 0 : t.trim()) || e.getAttribute("aria-label") || e.getAttribute("title") || "";
469
+ return n ? n.slice(0, 32) : void 0;
470
+ }, Ze = (e) => {
471
+ let t = [];
472
+ return {
473
+ name: "action",
474
+ enabled: e.enabled,
475
+ init(n) {
476
+ if (typeof window > "u") return;
477
+ let r = {
478
+ capture: !0,
479
+ passive: !0
480
+ }, i = (e) => {
481
+ var t;
482
+ let r = Ye(e.target), i = Xe(r), a = r == null ? void 0 : r.tagName.toLowerCase();
483
+ n.startSpan(`action.${e.type}`, T(T(T(T({}, n.config.hooks.getPageAttributes()), I({
484
+ errorType: "none",
485
+ eventLabel: "用户操作",
486
+ spanSubtype: e.type,
487
+ spanType: F.action,
488
+ targetLabel: (t = i == null ? a : i) == null ? e.type : t
489
+ })), {}, { [b.actionType]: e.type }, i ? { [b.targetTextShort]: i } : {}), a ? { [b.targetTag]: a } : {})).end();
490
+ };
491
+ for (let n of e.enabled ? e.eventNames : []) window.addEventListener(n, i, r), t.push(() => window.removeEventListener(n, i, r));
492
+ },
493
+ shutdown() {
494
+ for (; t.length;) {
495
+ var e;
496
+ (e = t.pop()) == null || e();
497
+ }
498
+ }
499
+ };
500
+ }, Qe = "body", $e = 3e3, et = .8, tt = [
272
501
  "[data-loading=\"true\"]",
273
502
  "[aria-busy=\"true\"]",
274
503
  ".loading",
@@ -282,38 +511,38 @@ var de = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
282
511
  [.75, .25],
283
512
  [.25, .75],
284
513
  [.75, .75]
285
- ], Oe = (e) => {
514
+ ], nt = (e) => {
286
515
  if (!e) return "";
287
516
  let t = e.tagName.toLowerCase();
288
517
  return e.id ? `${t}#${e.id}` : t;
289
- }, ke = (e, t) => e ? t.some((t) => {
518
+ }, rt = (e, t) => e ? t.some((t) => {
290
519
  try {
291
520
  return e.matches(t) || !!e.closest(t);
292
521
  } catch (e) {
293
522
  return !1;
294
523
  }
295
- }) : !1, Ae = (e) => {
524
+ }) : !1, it = (e) => {
296
525
  if (typeof document > "u") return () => {};
297
526
  if (document.readyState === "complete" || document.readyState === "interactive") return e(), () => {};
298
527
  let t = () => {
299
528
  document.removeEventListener("DOMContentLoaded", t), e();
300
529
  };
301
530
  return document.addEventListener("DOMContentLoaded", t), () => document.removeEventListener("DOMContentLoaded", t);
302
- }, je = (e) => {
531
+ }, at = (e) => {
303
532
  let t, n, r = !1;
304
533
  return {
305
534
  name: "blank-screen",
306
- enabled: !!e,
535
+ enabled: e.enabled,
307
536
  init(i) {
308
- var a, s, c, l;
537
+ var a, s;
309
538
  if (typeof window > "u" || typeof document > "u") return;
310
- let u = typeof e == "object" ? e : {}, d = (a = u.rootSelector) == null ? we : a, f = (s = u.checkDelay) == null ? Te : s, p = (c = u.threshold) == null ? Ee : c, m = [...De, ...(l = u.ignoreSelectors) == null ? [] : l], h = i.meter.createCounter("browser.blank_screen.count", { description: "Number of suspected blank screen detections" }), g = () => {
539
+ let c = e.enabled ? (a = e.rootSelector) == null ? Qe : a : Qe, l = e.enabled ? e.checkDelay : $e, u = e.enabled ? e.threshold : et, d = [...tt, ...e.enabled ? (s = e.ignoreSelectors) == null ? [] : s : []], f = i.meter.createCounter("browser.blank_screen.count", { description: "Number of suspected blank screen detections" }), p = () => {
311
540
  try {
312
541
  var e, t;
313
- let n = document.querySelector(d), r = 0, a = 0;
542
+ let n = document.querySelector(c), r = 0, a = 0;
314
543
  for (let [e, t] of L) {
315
544
  let i = document.elementFromPoint(window.innerWidth * e, window.innerHeight * t);
316
- if (ke(i, m)) {
545
+ if (rt(i, d)) {
317
546
  a += 1;
318
547
  continue;
319
548
  }
@@ -321,22 +550,30 @@ var de = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
321
550
  }
322
551
  let s = L.length - a;
323
552
  if (s === 0) return;
324
- let c = r / s, l = c >= p, u = {
325
- "bk.rum.blank_screen.score": c,
326
- "bk.rum.blank_screen.threshold": p,
327
- "bk.rum.blank_screen.root": d,
328
- "bk.rum.blank_screen.detected": l,
329
- "bk.rum.blank_screen.sample_total": L.length,
330
- "bk.rum.blank_screen.sample_valid": s,
331
- "bk.rum.blank_screen.sample_loading": a,
332
- "bk.rum.blank_screen.center_element": Oe(document.elementFromPoint(window.innerWidth / 2, window.innerHeight / 2)),
333
- "bk.rum.blank_screen.dom_node_count": (e = (t = document.body) == null ? void 0 : t.getElementsByTagName("*").length) == null ? 0 : e
334
- };
335
- l && (h.add(1, i.applyRedact({ "bk.rum.blank_screen.root": d })), i.emitLog({
553
+ let l = r / s, p = l >= u, m = nt(document.elementFromPoint(window.innerWidth / 2, window.innerHeight / 2)), h = T(T({}, I({
554
+ errorType: p ? "blank_screen" : "none",
555
+ eventLabel: "白屏",
556
+ result: p ? P.error : P.success,
557
+ spanSubtype: "blank_screen",
558
+ spanType: F.error,
559
+ targetLabel: c,
560
+ targetValue: l
561
+ })), {}, {
562
+ "blank_screen.score": l,
563
+ "blank_screen.threshold": u,
564
+ "blank_screen.root": c,
565
+ "blank_screen.detected": p,
566
+ "blank_screen.sample_total": L.length,
567
+ "blank_screen.sample_valid": s,
568
+ "blank_screen.sample_loading": a,
569
+ "blank_screen.center_element": m,
570
+ "blank_screen.dom_node_count": (e = (t = document.body) == null ? void 0 : t.getElementsByTagName("*").length) == null ? 0 : e
571
+ });
572
+ p && (f.add(1, i.applyRedact({ "blank_screen.root": c })), i.emitLog({
336
573
  severityNumber: o.ERROR,
337
574
  severityText: "ERROR",
338
575
  body: "browser.blank_screen",
339
- attributes: u
576
+ attributes: h
340
577
  }));
341
578
  } catch (e) {
342
579
  if (i.config.debug) {
@@ -345,45 +582,90 @@ var de = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
345
582
  }
346
583
  }
347
584
  };
348
- n = Ae(() => {
349
- r || (t = window.setTimeout(g, f));
585
+ n = it(() => {
586
+ r || (t = window.setTimeout(p, l));
350
587
  });
351
588
  },
352
589
  shutdown() {
353
590
  r = !0, n == null || n(), n = void 0, t !== void 0 && typeof window < "u" && (window.clearTimeout(t), t = void 0);
354
591
  }
355
592
  };
356
- }, Me = ["http.url", "url.full"], Ne = (e) => ({ test: e }), Pe = (e, t) => {
357
- t.setAttributes(e.applyRedact(e.config.getPageAttributes()));
358
- for (let r of Me) {
359
- var n;
360
- let i = (n = t.attributes) == null ? void 0 : n[r];
361
- if (typeof i == "string") {
362
- let n = e.applyRedact({ [r]: e.config.redactUrl(i) })[r];
363
- typeof n == "string" && t.setAttribute(r, n);
593
+ }, ot = ["http.url", "url.full"], st = ["http.status_code", "http.response.status_code"], ct = ["http.method", "http.request.method"], lt = (e) => ({ test: e }), ut = (e, t, n) => {
594
+ var r;
595
+ t.setAttributes(e.applyRedact(e.config.hooks.getPageAttributes()));
596
+ let i;
597
+ for (let n of ot) {
598
+ var a;
599
+ let r = (a = t.attributes) == null ? void 0 : a[n];
600
+ if (typeof r == "string") {
601
+ let a = e.applyRedact({ [n]: e.config.hooks.redactUrl(r) })[n];
602
+ typeof a == "string" && (i = a, t.setAttribute(n, a));
364
603
  }
365
604
  }
366
- }, Fe = (e) => {
605
+ let o = st.map((e) => {
606
+ var n;
607
+ return (n = t.attributes) == null ? void 0 : n[e];
608
+ }).find((e) => typeof e == "number"), s = ct.map((e) => {
609
+ var n;
610
+ return (n = t.attributes) == null ? void 0 : n[e];
611
+ }).find((e) => typeof e == "string"), c = (r = i) == null ? ot.map((e) => {
612
+ var n;
613
+ return (n = t.attributes) == null ? void 0 : n[e];
614
+ }).find((e) => typeof e == "string") : r;
615
+ t.setAttributes(e.applyRedact(qe({
616
+ method: s,
617
+ statusCode: o,
618
+ subtype: n,
619
+ url: c,
620
+ urlPathTemplate: c ? e.config.hooks.getViewPathGroup(c) : void 0
621
+ })));
622
+ }, dt = (e, t, n) => {
623
+ t.setAttributes(e.applyRedact(T(T({}, e.config.hooks.getPageAttributes()), I({
624
+ errorType: "none",
625
+ eventLabel: "文档加载",
626
+ spanSubtype: n,
627
+ spanType: F.document,
628
+ targetLabel: e.config.hooks.getViewPathGroup(typeof location > "u" ? "" : location.href),
629
+ traceScene: "page_load"
630
+ }))));
631
+ }, ft = (e, t, n) => {
632
+ let r = e.config.hooks.redactUrl(n.name);
633
+ t.setAttributes(e.applyRedact(T(T(T({}, e.config.hooks.getPageAttributes()), Je({
634
+ duration: n.duration,
635
+ initiatorType: n.initiatorType || "other",
636
+ responseStatus: n.responseStatus,
637
+ transferSize: n.transferSize,
638
+ url: r,
639
+ urlPathTemplate: e.config.hooks.getViewPathGroup(n.name)
640
+ })), {}, { "url.full": r })));
641
+ }, pt = (e) => {
367
642
  let t = [];
368
643
  return {
369
644
  name: "official-instrumentations",
370
645
  enabled: !!(e.documentLoad || e.fetch || e.xhr || e.userInteraction),
371
646
  init(n) {
372
- return F(function* () {
373
- let r = [Ne((e) => I(n.config, e))], i = [Ne((e) => be(n.config, e))], [a, o, s, c] = yield Promise.all([
647
+ return M(function* () {
648
+ let r = [lt((e) => N(n.config, e))], i = [lt((e) => Ie(n.config, e))], [a, o, s, c] = yield Promise.all([
374
649
  e.documentLoad ? import("@opentelemetry/instrumentation-document-load") : Promise.resolve(null),
375
650
  e.fetch ? import("@opentelemetry/instrumentation-fetch") : Promise.resolve(null),
376
651
  e.xhr ? import("@opentelemetry/instrumentation-xml-http-request") : Promise.resolve(null),
377
652
  e.userInteraction ? import("@opentelemetry/instrumentation-user-interaction") : Promise.resolve(null)
378
653
  ]);
379
- if (a && t.push(new a.DocumentLoadInstrumentation({ semconvStabilityOptIn: "http" })), o && t.push(new o.FetchInstrumentation({
380
- applyCustomAttributesOnSpan: (e) => Pe(n, e),
654
+ if (a && t.push(new a.DocumentLoadInstrumentation({
655
+ semconvStabilityOptIn: "http",
656
+ applyCustomAttributesOnSpan: {
657
+ documentLoad: (e) => dt(n, e, "navigate"),
658
+ documentFetch: (e) => dt(n, e, "document_fetch"),
659
+ resourceFetch: (e, t) => ft(n, e, t)
660
+ }
661
+ })), o && t.push(new o.FetchInstrumentation({
662
+ applyCustomAttributesOnSpan: (e) => ut(n, e, "fetch"),
381
663
  ignoreUrls: r,
382
664
  propagateTraceHeaderCorsUrls: i,
383
665
  semconvStabilityOptIn: "http",
384
666
  ignoreNetworkEvents: !1
385
667
  })), s && t.push(new s.XMLHttpRequestInstrumentation({
386
- applyCustomAttributesOnSpan: (e) => Pe(n, e),
668
+ applyCustomAttributesOnSpan: (e) => ut(n, e, "xhr"),
387
669
  ignoreUrls: r,
388
670
  propagateTraceHeaderCorsUrls: i,
389
671
  semconvStabilityOptIn: "http",
@@ -428,24 +710,32 @@ var de = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
428
710
  count: o.count
429
711
  });
430
712
  } };
431
- }, Ie = 6e4, Le = 5, Re = /^https?:|^\/\//i, ze = (e, t) => {
432
- if (t) return Re.test(t) ? e(t) : t;
433
- }, Be = (e) => {
713
+ }, mt = 6e4, ht = 5, gt = /^https?:|^\/\//i, _t = (e, t) => {
714
+ if (t) return gt.test(t) ? e(t) : t;
715
+ }, vt = (e) => {
434
716
  let t;
435
717
  return {
436
718
  name: "csp-violation",
437
- enabled: !!e,
719
+ enabled: e.enabled,
438
720
  init(e) {
439
721
  if (typeof window > "u" || typeof document > "u") return;
440
- let n = z(Ie, Le), r = (t) => {
722
+ let n = z(mt, ht), r = (t) => {
441
723
  let r = R(`${t.violatedDirective}|${t.blockedURI}|${t.sourceFile}|${t.lineNumber}`), i = n.allow(r);
442
724
  if (!i.allowed) return;
443
- let a = ze(e.config.redactUrl, t.blockedURI), s = t.sourceFile ? e.config.redactUrl(t.sourceFile) : void 0, c = i.count === 1;
725
+ let a = _t(e.config.hooks.redactUrl, t.blockedURI), s = t.sourceFile ? e.config.hooks.redactUrl(t.sourceFile) : void 0, c = i.count === 1;
444
726
  e.emitLog({
445
727
  severityNumber: o.WARN,
446
728
  severityText: "WARN",
447
729
  body: "csp.violation",
448
- attributes: k(k({}, e.config.getPageAttributes()), {}, {
730
+ attributes: T(T(T({}, e.config.hooks.getPageAttributes()), I({
731
+ errorType: "csp",
732
+ eventLabel: "CSP 错误",
733
+ result: P.error,
734
+ spanSubtype: "csp",
735
+ spanType: F.error,
736
+ targetLabel: a == null ? t.effectiveDirective : a,
737
+ targetValue: t.statusCode
738
+ })), {}, {
449
739
  "csp.blocked_uri": a,
450
740
  "csp.violated_directive": t.violatedDirective,
451
741
  "csp.effective_directive": t.effectiveDirective,
@@ -455,7 +745,9 @@ var de = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
455
745
  "csp.column_number": t.columnNumber,
456
746
  "csp.status_code": t.statusCode,
457
747
  "csp.fingerprint": r,
458
- "csp.window_count": i.count
748
+ "csp.window_count": i.count,
749
+ [b.exceptionFingerprint]: r,
750
+ "error.source": "csp"
459
751
  }, c ? { "csp.original_policy": t.originalPolicy } : {})
460
752
  });
461
753
  };
@@ -465,7 +757,27 @@ var de = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
465
757
  t == null || t(), t = void 0;
466
758
  }
467
759
  };
468
- }, B = (e) => typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : `${e}-${Date.now()}-${Math.random().toString(16).slice(2)}`, Ve = "bk_ot_session_id", He = 250, Ue = () => navigator.connection, We = () => navigator.userAgentData, Ge = (e) => {
760
+ }, B = (e) => typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : `${e}-${Date.now()}-${Math.random().toString(16).slice(2)}`, yt = "BK_RUM_DEVICE_ID", bt = 250, xt = () => navigator.connection, St = () => navigator.userAgentData, Ct = (e) => {
761
+ for (let [t, n] of [
762
+ ["Edge", /Edg\/([\d.]+)/],
763
+ ["Chrome", /Chrome\/([\d.]+)/],
764
+ ["Firefox", /Firefox\/([\d.]+)/],
765
+ ["Safari", /Version\/([\d.]+).*Safari/]
766
+ ]) {
767
+ let r = e.match(n);
768
+ if (r != null && r[1]) return {
769
+ name: t,
770
+ version: r[1].split(".")[0]
771
+ };
772
+ }
773
+ return {
774
+ name: "Other",
775
+ version: void 0
776
+ };
777
+ }, wt = (e, t) => {
778
+ let n = `${t == null ? "" : t} ${e}`;
779
+ return /iphone|ipad|ipod/i.test(n) ? "iOS" : /android/i.test(n) ? "Android" : /mac/i.test(n) ? "macOS" : /win/i.test(n) ? "Windows" : /linux/i.test(n) ? "Linux" : "Other";
780
+ }, Tt = (e) => {
469
781
  let t = null;
470
782
  try {
471
783
  t = window.localStorage.getItem(e);
@@ -476,7 +788,7 @@ var de = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
476
788
  window.localStorage.setItem(e, n);
477
789
  } catch (e) {}
478
790
  return n;
479
- }, Ke = () => {
791
+ }, Et = () => {
480
792
  var e, t;
481
793
  return typeof window > "u" ? {} : {
482
794
  "browser.viewport.width": window.innerWidth,
@@ -484,8 +796,8 @@ var de = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
484
796
  "browser.screen.width": (e = window.screen) == null ? void 0 : e.width,
485
797
  "browser.screen.height": (t = window.screen) == null ? void 0 : t.height
486
798
  };
487
- }, qe = () => {
488
- let e = Ue();
799
+ }, Dt = () => {
800
+ let e = xt();
489
801
  return e ? {
490
802
  "network.effective_type": e.effectiveType,
491
803
  "network.connection_type": e.type,
@@ -493,39 +805,46 @@ var de = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
493
805
  "network.rtt": e.rtt,
494
806
  "network.save_data": e.saveData
495
807
  } : {};
496
- }, Je = () => {
808
+ }, Ot = () => {
497
809
  if (typeof navigator > "u") return {};
498
- let e = We();
810
+ let e = St(), t = navigator.userAgent, n = Ct(t), r = wt(t, e == null ? void 0 : e.platform), i = e != null && e.mobile || /mobi|android|iphone|ipad|ipod/i.test(t) ? "mobile" : "desktop";
499
811
  return {
500
812
  "device.memory": navigator.deviceMemory,
501
813
  "device.cpu_cores": navigator.hardwareConcurrency,
502
814
  "device.platform": e == null ? void 0 : e.platform,
503
- "device.mobile": e == null ? void 0 : e.mobile
815
+ "device.mobile": e == null ? void 0 : e.mobile,
816
+ [b.browserName]: n.name,
817
+ [b.browserVersion]: n.version,
818
+ [b.deviceType]: i,
819
+ [b.osName]: r,
820
+ "user_agent.name": n.name,
821
+ "user_agent.version": n.version,
822
+ "user_agent.os.name": r
504
823
  };
505
- }, Ye = (e, t) => {
824
+ }, kt = (e, t) => {
506
825
  let n;
507
826
  return () => {
508
827
  n !== void 0 && window.clearTimeout(n), n = window.setTimeout(() => {
509
828
  n = void 0, e();
510
829
  }, t);
511
830
  };
512
- }, Xe = (e) => {
831
+ }, At = (e) => {
513
832
  let t = [];
514
833
  return {
515
834
  name: "device",
516
- enabled: !!e,
835
+ enabled: e.enabled,
517
836
  init(n) {
518
837
  var r;
519
- let i = typeof e == "object" ? (r = e.storageKey) == null ? Ve : r : Ve, a = typeof window > "u" ? B("device") : Ge(i);
520
- if (n.setRuntimeAttributes(k(k(k({ "device.id": a }, Je()), Ke()), qe())), typeof window > "u") return;
521
- let o = Ye(() => {
522
- n.setRuntimeAttributes(Ke());
523
- }, He);
838
+ let i = e.enabled ? (r = e.storageKey) == null ? yt : r : yt, a = typeof window > "u" ? B("device") : Tt(i);
839
+ if (n.setRuntimeAttributes(T(T(T({ "device.id": a }, Ot()), Et()), Dt())), typeof window > "u") return;
840
+ let o = kt(() => {
841
+ n.setRuntimeAttributes(Et());
842
+ }, bt);
524
843
  window.addEventListener("resize", o), window.addEventListener("orientationchange", o), t.push(() => window.removeEventListener("resize", o), () => window.removeEventListener("orientationchange", o));
525
- let s = Ue();
844
+ let s = xt();
526
845
  if (s && typeof s.addEventListener == "function") {
527
846
  let e = () => {
528
- n.setRuntimeAttributes(qe());
847
+ n.setRuntimeAttributes(Dt());
529
848
  };
530
849
  s.addEventListener("change", e), t.push(() => {
531
850
  var t;
@@ -540,7 +859,7 @@ var de = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
540
859
  }
541
860
  }
542
861
  };
543
- }, Ze = 6e4, Qe = 5, $e = (e) => {
862
+ }, jt = 6e4, Mt = 5, Nt = (e) => {
544
863
  if (e instanceof Error) return e.message;
545
864
  if (typeof e == "string") return e;
546
865
  try {
@@ -548,22 +867,35 @@ var de = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
548
867
  } catch (t) {
549
868
  return String(e);
550
869
  }
551
- }, et = (e) => {
870
+ }, Pt = (e) => {
552
871
  var t;
553
872
  return e instanceof Error ? (t = e.stack) == null ? "" : t : "";
554
- }, V = ({ context: e, error: r, exceptionType: i, extra: s = {}, source: c, spanName: l, throttle: u }) => {
555
- let d = $e(r), f = et(r), p = R(`${c}|${d}|${f.slice(0, 256)}`), m = u.allow(p);
873
+ }, Ft = (e) => e.slice(0, 80), It = (e) => {
874
+ var t, n;
875
+ return (t = (n = e.split("\n").find((e) => e.trim().startsWith("at "))) == null ? void 0 : n.trim()) == null ? "" : t;
876
+ }, Lt = (e) => e === "unhandledrejection" ? "promise" : e === "resource" ? "resource_load" : "js", V = ({ context: e, error: r, exceptionType: i, extra: s = {}, source: c, spanName: l, throttle: u }) => {
877
+ let d = Nt(r), f = Pt(r), p = R(`${c}|${d}|${f.slice(0, 256)}`), m = u.allow(p);
556
878
  if (!m.allowed) return;
557
879
  let h = a.getActiveSpan(), g = r instanceof Error ? r : {
558
880
  message: d,
559
881
  name: i == null ? c : i
560
- }, _ = k(k(k({}, e.config.getPageAttributes()), e.config.getErrorAttributes()), {}, {
882
+ }, _ = T(T(T(T({}, e.config.hooks.getPageAttributes()), e.config.hooks.getErrorAttributes()), I({
883
+ errorType: Lt(c),
884
+ eventLabel: "错误",
885
+ result: P.error,
886
+ spanSubtype: Lt(c),
887
+ spanType: F.error,
888
+ targetLabel: r instanceof Error ? r.name : i == null ? c : i
889
+ })), {}, {
561
890
  "exception.message": d,
891
+ [b.exceptionMessageShort]: Ft(d),
562
892
  "exception.stacktrace": f,
893
+ [b.exceptionStackTopFrame]: It(f),
563
894
  "exception.type": r instanceof Error ? r.name : i == null ? c : i,
564
- "bk.rum.error.source": c,
565
- "bk.rum.error.fingerprint": p,
566
- "bk.rum.error.window_count": m.count
895
+ [b.exceptionFingerprint]: p,
896
+ "error.handled": !1,
897
+ "error.source": c,
898
+ "error.window_count": m.count
567
899
  }, s), v = () => e.emitLog({
568
900
  severityNumber: o.ERROR,
569
901
  severityText: "ERROR",
@@ -571,7 +903,7 @@ var de = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
571
903
  attributes: _
572
904
  });
573
905
  if (h) {
574
- h.recordException(g), h.setStatus({
906
+ h.setAttributes(e.applyRedact(_)), h.recordException(g), h.setStatus({
575
907
  code: t.ERROR,
576
908
  message: d
577
909
  }), v();
@@ -582,57 +914,56 @@ var de = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
582
914
  code: t.ERROR,
583
915
  message: d
584
916
  }), n.with(a.setSpan(n.active(), y), v), y.end();
585
- }, tt = (e) => {
917
+ }, Rt = (e) => {
586
918
  let t = [];
587
919
  return {
588
920
  name: "error",
589
- enabled: !!e,
921
+ enabled: e.enabled,
590
922
  init(n) {
591
- var r, i;
592
923
  if (typeof window > "u") return;
593
- let a = z(typeof e == "object" ? (r = e.windowMs) == null ? Ze : r : Ze, typeof e == "object" ? (i = e.maxPerWindow) == null ? Qe : i : Qe), o = (e) => {
924
+ let r = z(e.enabled ? e.windowMs : jt, e.enabled ? e.maxPerWindow : Mt), i = (e) => {
594
925
  var t;
595
- let r = !e.error && !e.filename && e.message === "Script error.";
926
+ let i = !e.error && !e.filename && e.message === "Script error.";
596
927
  V({
597
928
  context: n,
598
- throttle: a,
929
+ throttle: r,
599
930
  spanName: "browser.error",
600
931
  source: "window.error",
601
932
  error: (t = e.error) == null ? e.message : t,
602
- extra: k({
933
+ extra: T({
603
934
  "code.filepath": e.filename,
604
935
  "code.lineno": e.lineno,
605
936
  "code.column": e.colno
606
- }, r ? { "bk.rum.error.cross_origin": !0 } : {})
937
+ }, i ? { "error.cross_origin": !0 } : {})
607
938
  });
608
- }, s = (e) => {
939
+ }, a = (e) => {
609
940
  V({
610
941
  context: n,
611
- throttle: a,
942
+ throttle: r,
612
943
  spanName: "browser.unhandledrejection",
613
944
  source: "unhandledrejection",
614
945
  error: e.reason,
615
946
  exceptionType: e.reason instanceof Error ? e.reason.name : "UnhandledRejection"
616
947
  });
617
- }, c = (e) => {
948
+ }, o = (e) => {
618
949
  if (e instanceof ErrorEvent) return;
619
950
  let t = e.target;
620
951
  if (!(t instanceof Element)) return;
621
- let r = t, i = r.src || r.href || t.currentSrc || "";
952
+ let i = t, a = i.src || i.href || t.currentSrc || "";
622
953
  V({
623
954
  context: n,
624
- throttle: a,
955
+ throttle: r,
625
956
  spanName: "browser.resource_error",
626
957
  source: "resource",
627
- error: /* @__PURE__ */ Error(`Resource load failed: ${t.tagName.toLowerCase()} ${i}`),
958
+ error: /* @__PURE__ */ Error(`Resource load failed: ${t.tagName.toLowerCase()} ${a}`),
628
959
  exceptionType: "ResourceError",
629
960
  extra: {
630
- "url.full": n.config.redactUrl(i),
961
+ "url.full": n.config.hooks.redactUrl(a),
631
962
  "html.tag": t.tagName
632
963
  }
633
964
  });
634
965
  };
635
- window.addEventListener("error", o), window.addEventListener("unhandledrejection", s), window.addEventListener("error", c, !0), t.push(() => window.removeEventListener("error", o), () => window.removeEventListener("unhandledrejection", s), () => window.removeEventListener("error", c, !0));
966
+ window.addEventListener("error", i), window.addEventListener("unhandledrejection", a), window.addEventListener("error", o, !0), t.push(() => window.removeEventListener("error", i), () => window.removeEventListener("unhandledrejection", a), () => window.removeEventListener("error", o, !0));
636
967
  },
637
968
  shutdown() {
638
969
  for (; t.length;) {
@@ -641,13 +972,13 @@ var de = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
641
972
  }
642
973
  }
643
974
  };
644
- }, nt = 10 * 1024, rt = 10, H = /* @__PURE__ */ new WeakMap(), U = (e, t) => e.length <= t ? {
975
+ }, zt = 10 * 1024, Bt = 10, H = /* @__PURE__ */ new WeakMap(), U = (e, t) => e.length <= t ? {
645
976
  body: e,
646
977
  truncated: !1
647
978
  } : {
648
979
  body: e.slice(0, t),
649
980
  truncated: !0
650
- }, it = (e, t) => {
981
+ }, Vt = (e, t) => {
651
982
  if (!e) return;
652
983
  if (e instanceof Headers) return e.get(t) || void 0;
653
984
  let n = t.toLowerCase();
@@ -657,42 +988,30 @@ var de = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
657
988
  }
658
989
  let i = Object.keys(e).find((e) => e.toLowerCase() === n);
659
990
  return i ? e[i] : void 0;
660
- }, at = (e) => {
991
+ }, Ht = (e) => {
661
992
  let t = {};
662
993
  return e.forEach((e, n) => {
663
994
  t[n] = e instanceof File ? `[File name=${e.name} type=${e.type || "unknown"} size=${e.size}]` : e;
664
995
  }), JSON.stringify(t);
665
- }, ot = function() {
666
- var e = F(function* (e) {
667
- return e == null ? "" : typeof e == "string" ? e : e instanceof URLSearchParams ? e.toString() : e instanceof FormData ? at(e) : e instanceof Blob ? e.text() : e instanceof ArrayBuffer || ArrayBuffer.isView(e) ? new TextDecoder().decode(e) : e instanceof Document ? new XMLSerializer().serializeToString(e) : String(e);
996
+ }, Ut = function() {
997
+ var e = M(function* (e) {
998
+ return e == null ? "" : typeof e == "string" ? e : e instanceof URLSearchParams ? e.toString() : e instanceof FormData ? Ht(e) : e instanceof Blob ? e.text() : e instanceof ArrayBuffer || ArrayBuffer.isView(e) ? new TextDecoder().decode(e) : e instanceof Document ? new XMLSerializer().serializeToString(e) : String(e);
668
999
  });
669
1000
  return function(t) {
670
1001
  return e.apply(this, arguments);
671
1002
  };
672
- }(), st = function() {
673
- var e = F(function* (e, t, n) {
674
- let r = yield ot(e);
675
- if (r) return k(k({}, U(r, t)), {}, { contentType: n });
1003
+ }(), Wt = function() {
1004
+ var e = M(function* (e, t, n) {
1005
+ let r = yield Ut(e);
1006
+ if (r) return T(T({}, U(r, t)), {}, { contentType: n });
676
1007
  });
677
1008
  return function(t, n, r) {
678
1009
  return e.apply(this, arguments);
679
1010
  };
680
1011
  }(), W = function() {
681
- var e = F(function* (e, t, n) {
1012
+ var e = M(function* (e, t, n) {
682
1013
  try {
683
- return yield st(e, t, n);
684
- } catch (e) {
685
- return;
686
- }
687
- });
688
- return function(t, n, r) {
689
- return e.apply(this, arguments);
690
- };
691
- }(), ct = (e) => e instanceof Request ? e.url : String(e), lt = (e, t) => t != null && t.method ? t.method : e instanceof Request ? e.method : "GET", ut = function() {
692
- var e = F(function* (e, t, n) {
693
- if (t != null && t.body) return W(t.body, n, it(t.headers, "content-type"));
694
- if (e instanceof Request) try {
695
- return W(yield e.clone().text(), n, e.headers.get("content-type") || void 0);
1014
+ return yield Wt(e, t, n);
696
1015
  } catch (e) {
697
1016
  return;
698
1017
  }
@@ -700,13 +1019,13 @@ var de = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
700
1019
  return function(t, n, r) {
701
1020
  return e.apply(this, arguments);
702
1021
  };
703
- }(), dt = function() {
704
- var e = F(function* (e, t) {
1022
+ }(), Gt = (e) => e instanceof Request ? e.url : String(e), Kt = (e, t) => t != null && t.method ? t.method : e instanceof Request ? e.method : "GET", qt = (e, t, n) => t != null && t.body ? () => W(t.body, n, Vt(t.headers, "content-type")) : (e instanceof Request, () => Promise.resolve(void 0)), Jt = function() {
1023
+ var e = M(function* (e, t) {
705
1024
  try {
706
1025
  let n = e.headers.get("content-type") || void 0, r = e.headers.get("content-length");
707
1026
  if (r) {
708
1027
  let e = Number(r);
709
- if (Number.isFinite(e) && e > t * rt) return {
1028
+ if (Number.isFinite(e) && e > t * Bt) return {
710
1029
  body: "",
711
1030
  contentType: n,
712
1031
  truncated: !0
@@ -721,80 +1040,90 @@ var de = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
721
1040
  return function(t, n) {
722
1041
  return e.apply(this, arguments);
723
1042
  };
724
- }(), ft = (e, t) => {
725
- if (e.responseType === "" || e.responseType === "text") return k(k({}, U(e.responseText || "", t)), {}, { contentType: e.getResponseHeader("content-type") || void 0 });
726
- if (e.responseType === "json") return k(k({}, U(JSON.stringify(e.response), t)), {}, { contentType: e.getResponseHeader("content-type") || void 0 });
727
- }, pt = (e, t, n) => {
728
- if (n) return e.redact(k(k({}, t), {}, {
1043
+ }(), Yt = (e, t) => {
1044
+ if (e.responseType === "" || e.responseType === "text") return T(T({}, U(e.responseText || "", t)), {}, { contentType: e.getResponseHeader("content-type") || void 0 });
1045
+ if (e.responseType === "json") return T(T({}, U(JSON.stringify(e.response), t)), {}, { contentType: e.getResponseHeader("content-type") || void 0 });
1046
+ }, Xt = (e, t, n) => {
1047
+ if (n) return e.redact(T(T({}, t), {}, {
729
1048
  body: n.body,
730
1049
  truncated: n.truncated
731
1050
  }));
732
- }, G = ({ context: e, duration: t, error: n, method: r, request: i, response: a, status: s, url: c }) => {
733
- let l = e.config.rum.httpBody;
734
- if (!l) return;
735
- let u = !!n || typeof s == "number" && s >= 400, d = r.toUpperCase(), f = u ? pt(l, {
1051
+ }, G = ({ context: e, duration: t, error: n, method: r, request: i, response: a, status: s, subtype: c, url: l }) => {
1052
+ let u = e.config.rum.plugins.httpBody;
1053
+ if (!u.enabled) return;
1054
+ let d = !!n || typeof s == "number" && s >= 400, f = r.toUpperCase(), p = d ? Xt(u, {
736
1055
  contentType: i == null ? void 0 : i.contentType,
737
- method: d,
1056
+ method: f,
738
1057
  status: s,
739
1058
  type: "request",
740
- url: c
741
- }, i) : void 0, p = u ? pt(l, {
1059
+ url: l
1060
+ }, i) : void 0, m = d ? Xt(u, {
742
1061
  contentType: a == null ? void 0 : a.contentType,
743
- method: d,
1062
+ method: f,
744
1063
  status: s,
745
1064
  type: "response",
746
- url: c
747
- }, a) : void 0, m = k(k({}, e.config.getPageAttributes()), {}, {
1065
+ url: l
1066
+ }, a) : void 0, h = T(T(T({}, e.config.hooks.getPageAttributes()), qe({
1067
+ duration: t,
1068
+ method: f,
1069
+ statusCode: s,
1070
+ subtype: c,
1071
+ url: e.config.hooks.redactUrl(l),
1072
+ urlPathTemplate: e.config.hooks.getViewPathGroup(l)
1073
+ })), {}, {
748
1074
  "http.duration": t,
749
- "http.request.method": d,
750
- "url.full": e.config.redactUrl(c)
1075
+ "http.request.method": f,
1076
+ "url.full": e.config.hooks.redactUrl(l)
751
1077
  });
752
- if (typeof s == "number" && (m["http.response.status_code"] = s), f != null && (m["http.request.body"] = f), p != null && (m["http.response.body"] = p), u) {
753
- var h, g;
754
- m["bk.rum.http_body.request.truncated"] = (h = i == null ? void 0 : i.truncated) == null ? !1 : h, m["bk.rum.http_body.response.truncated"] = (g = a == null ? void 0 : a.truncated) == null ? !1 : g;
1078
+ if (typeof s == "number" && (h["http.response.status_code"] = s), p != null && (h["http.request.body"] = p), m != null && (h["http.response.body"] = m), d) {
1079
+ var g, _;
1080
+ h["http_body.request.truncated"] = (g = i == null ? void 0 : i.truncated) == null ? !1 : g, h["http_body.response.truncated"] = (_ = a == null ? void 0 : a.truncated) == null ? !1 : _;
755
1081
  }
756
1082
  if (n instanceof Error) {
757
- var _;
758
- m["exception.message"] = n.message, m["exception.type"] = n.name, m["exception.stacktrace"] = (_ = n.stack) == null ? "" : _;
1083
+ var v;
1084
+ h["exception.message"] = n.message, h["exception.type"] = n.name, h["exception.stacktrace"] = (v = n.stack) == null ? "" : v;
759
1085
  }
760
1086
  e.emitLog({
761
- severityNumber: u ? o.ERROR : o.INFO,
762
- severityText: u ? "ERROR" : "INFO",
763
- body: u ? "HTTP request completed with error" : "HTTP request completed",
764
- attributes: m
1087
+ severityNumber: d ? o.ERROR : o.INFO,
1088
+ severityText: d ? "ERROR" : "INFO",
1089
+ body: d ? "HTTP request completed with error" : "HTTP request completed",
1090
+ attributes: h
765
1091
  });
766
- }, mt = (e) => {
1092
+ }, Zt = (e) => {
767
1093
  let t = [];
768
1094
  return {
769
1095
  name: "http-body",
770
- enabled: !!e,
1096
+ enabled: e.enabled,
771
1097
  init(n) {
772
1098
  if (!e || typeof window > "u") return;
773
- let r = e.maxBodySize || nt, i = window.fetch;
1099
+ let r = e.enabled ? e.maxBodySize : zt, i = window.fetch;
774
1100
  if (typeof i == "function") {
775
1101
  let e = function() {
776
- var e = F(function* (e, t) {
777
- let a = ct(e);
778
- if (I(n.config, a)) return i(e, t);
779
- let o = lt(e, t), s = yield ut(e, t, r), c = performance.now();
1102
+ var e = M(function* (e, t) {
1103
+ let a = Gt(e);
1104
+ if (N(n.config, a)) return i(e, t);
1105
+ let o = Kt(e, t), s = qt(e, t, r), c = performance.now();
780
1106
  try {
781
- let l = yield i(e, t);
1107
+ let l = yield i(e, t), u = performance.now() - c, d = l.status >= 400;
782
1108
  return G({
783
1109
  context: n,
784
- duration: performance.now() - c,
1110
+ duration: u,
785
1111
  method: o,
786
- request: s,
787
- response: l.status >= 400 ? yield dt(l, r) : void 0,
1112
+ request: d ? yield s() : void 0,
1113
+ response: d ? yield Jt(l, r) : void 0,
788
1114
  status: l.status,
1115
+ subtype: "fetch",
789
1116
  url: a
790
1117
  }), l;
791
1118
  } catch (e) {
1119
+ let t = yield s();
792
1120
  throw G({
793
1121
  context: n,
794
1122
  duration: performance.now() - c,
795
1123
  error: e,
796
1124
  method: o,
797
- request: s,
1125
+ request: t,
1126
+ subtype: "fetch",
798
1127
  url: a
799
1128
  }), e;
800
1129
  }
@@ -827,7 +1156,7 @@ var de = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
827
1156
  let i = H.get(this);
828
1157
  if (i) {
829
1158
  var a;
830
- i.requestPromise = W(e, r, (a = i.requestHeaders) == null ? void 0 : a["content-type"]);
1159
+ i.requestBody = e, i.requestContentType = (a = i.requestHeaders) == null ? void 0 : a["content-type"];
831
1160
  }
832
1161
  return this.addEventListener("abort", () => {
833
1162
  let e = H.get(this);
@@ -836,18 +1165,19 @@ var de = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
836
1165
  let e = H.get(this);
837
1166
  e && (e.networkError = !0);
838
1167
  }, { once: !0 }), this.addEventListener("loadend", () => {
839
- F(function* () {
1168
+ M(function* () {
840
1169
  let e = H.get(t);
841
- if (!e || I(n.config, e.url) || e.aborted) return;
842
- let i = e.networkError || t.status >= 400 ? ft(t, r) : void 0, a = yield e.requestPromise;
1170
+ if (!e || N(n.config, e.url) || e.aborted) return;
1171
+ let i = e.networkError || t.status >= 400, a = i ? Yt(t, r) : void 0, o = i ? yield W(e.requestBody, r, e.requestContentType) : void 0;
843
1172
  G({
844
1173
  context: n,
845
1174
  duration: performance.now() - e.startTime,
846
1175
  error: e.networkError ? /* @__PURE__ */ Error("XHR network error") : void 0,
847
1176
  method: e.method,
848
- request: a,
849
- response: i,
1177
+ request: o,
1178
+ response: a,
850
1179
  status: t.status,
1180
+ subtype: "xhr",
851
1181
  url: e.url
852
1182
  });
853
1183
  })();
@@ -864,29 +1194,38 @@ var de = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
864
1194
  }
865
1195
  }
866
1196
  };
867
- }, ht = 50, gt = (e) => {
1197
+ }, Qt = 50, $t = (e) => {
868
1198
  let t;
869
1199
  return {
870
1200
  name: "long-task",
871
- enabled: !!e,
1201
+ enabled: e.enabled,
872
1202
  init(n) {
873
- var r, i;
1203
+ var r;
874
1204
  if (typeof PerformanceObserver > "u" || !((r = PerformanceObserver.supportedEntryTypes) != null && r.includes("longtask"))) return;
875
- let a = typeof e == "object" ? (i = e.threshold) == null ? ht : i : ht, o = n.meter.createCounter("browser.long_task.count", { description: "Number of long tasks observed (duration >= threshold)" }), s = n.meter.createHistogram("browser.long_task.duration", {
1205
+ let i = e.enabled ? e.threshold : Qt, a = n.meter.createCounter("browser.long_task.count", { description: "Number of long tasks observed (duration >= threshold)" }), o = n.meter.createHistogram("browser.long_task.duration", {
876
1206
  unit: "ms",
877
1207
  description: "Duration of long tasks"
878
1208
  });
879
1209
  try {
880
1210
  t = new PerformanceObserver((e) => {
881
- let t = n.applyRedact(k(k({}, n.config.getPageAttributes()), n.config.getMetricAttributes()));
882
- for (let n of e.getEntries()) {
883
- var r, i;
884
- if (n.duration < a) continue;
885
- let e = (r = n.attribution) == null ? void 0 : r[0], c = k(k({}, t), {}, {
886
- "long_task.name": n.name,
887
- "long_task.attribution": (i = e == null ? void 0 : e.name) == null ? "unknown" : i
888
- });
889
- o.add(1, c), s.record(n.duration, c);
1211
+ let t = n.applyRedact(T(T({}, n.config.hooks.getPageAttributes()), n.config.hooks.getMetricAttributes()));
1212
+ for (let h of e.getEntries()) {
1213
+ var r, s, c, l, u, d, f, p, m;
1214
+ if (h.duration < i) continue;
1215
+ let e = (r = h.attribution) == null ? void 0 : r[0], g = T(T({}, t), {}, { [b.longtaskAttributionScript]: (s = (c = e == null ? void 0 : e.containerSrc) == null ? e == null ? void 0 : e.name : c) == null ? "unknown" : s }), _ = h.duration > 100 ? P.warning : P.success;
1216
+ n.startSpan("browser.long_task", T(T(T({}, t), I({
1217
+ duration: h.duration,
1218
+ errorType: _ === P.warning ? "longtask_blocking" : "none",
1219
+ eventLabel: "长任务",
1220
+ result: _,
1221
+ spanSubtype: (l = e == null ? void 0 : e.name) == null ? "unknown" : l,
1222
+ spanType: F.longtask,
1223
+ targetLabel: (u = (d = (f = e == null ? void 0 : e.containerSrc) == null ? e == null ? void 0 : e.containerName : f) == null ? e == null ? void 0 : e.name : d) == null ? "unknown" : u,
1224
+ targetValue: h.duration
1225
+ })), {}, {
1226
+ [b.longtaskBlockingDuration]: h.duration,
1227
+ [b.longtaskAttributionScript]: (p = (m = e == null ? void 0 : e.containerSrc) == null ? e == null ? void 0 : e.name : m) == null ? "unknown" : p
1228
+ }), { startTime: performance.timeOrigin + h.startTime }).end(performance.timeOrigin + h.startTime + h.duration), a.add(1, g), o.record(h.duration, g);
890
1229
  }
891
1230
  }), t.observe({
892
1231
  type: "longtask",
@@ -909,11 +1248,11 @@ var de = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
909
1248
  toUrl: n
910
1249
  };
911
1250
  for (let e of Array.from(K)) e(r);
912
- }, _t = () => {
1251
+ }, en = () => {
913
1252
  Q("popstate", q || Z());
914
- }, vt = () => {
1253
+ }, tn = () => {
915
1254
  Q("hashchange", q || Z());
916
- }, yt = () => {
1255
+ }, nn = () => {
917
1256
  X || typeof window > "u" || typeof history > "u" || (X = !0, q = Z(), J = history.pushState, Y = history.replaceState, history.pushState = function(e, t, n) {
918
1257
  let r = q || Z(), i = J == null ? void 0 : J.apply(this, [
919
1258
  e,
@@ -928,32 +1267,53 @@ var de = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
928
1267
  n
929
1268
  ]);
930
1269
  return Q("replaceState", r), i;
931
- }, window.addEventListener("popstate", _t), window.addEventListener("hashchange", vt));
932
- }, bt = () => {
933
- !X || typeof window > "u" || typeof history > "u" || (J && (history.pushState = J), Y && (history.replaceState = Y), window.removeEventListener("popstate", _t), window.removeEventListener("hashchange", vt), J = void 0, Y = void 0, X = !1, q = "");
934
- }, xt = (e) => typeof window > "u" || typeof history > "u" ? () => {} : (yt(), K.add(e), () => {
935
- K.delete(e), K.size === 0 && bt();
936
- }), St = () => typeof location > "u" ? "" : location.href, Ct = (e) => {
1270
+ }, window.addEventListener("popstate", en), window.addEventListener("hashchange", tn));
1271
+ }, rn = () => {
1272
+ !X || typeof window > "u" || typeof history > "u" || (J && (history.pushState = J), Y && (history.replaceState = Y), window.removeEventListener("popstate", en), window.removeEventListener("hashchange", tn), J = void 0, Y = void 0, X = !1, q = "");
1273
+ }, an = (e) => typeof window > "u" || typeof history > "u" ? () => {} : (nn(), K.add(e), () => {
1274
+ K.delete(e), K.size === 0 && rn();
1275
+ }), on = () => typeof location > "u" ? "" : location.href, sn = (e) => {
937
1276
  let t = [];
938
1277
  return {
939
1278
  name: "page-view",
940
- enabled: !!e,
1279
+ enabled: e.enabled,
941
1280
  init(e) {
942
1281
  if (typeof window > "u") return;
943
- let n = "", r = (t, r = n) => {
944
- let i = St();
945
- if (i === n) return;
946
- n = i;
947
- let a = t === "load";
948
- e.startSpan("browser.page_view", k(k({}, e.config.getPageAttributes()), {}, {
949
- "url.full": e.config.redactUrl(i),
950
- "url.previous": e.config.redactUrl(r),
951
- "bk.rum.event.source": t
952
- }, a ? { "document.referrer": e.config.redactUrl(document.referrer || "") } : {})).end();
953
- }, i = xt((e) => {
954
- r(e.source, e.fromUrl);
1282
+ let n = "", r, i = (t, i = n) => {
1283
+ let a = on();
1284
+ if (a === n) return;
1285
+ r == null || r.setAttribute("view.end_reason", t), r == null || r.end(), n = a;
1286
+ let o = B("view"), s = e.config.hooks.getViewPathGroup(a), c = t === "load" ? "initial_load" : "route_change", l = e.config.hooks.redactUrl(a), u = e.config.hooks.redactUrl(i);
1287
+ e.setView({
1288
+ id: o,
1289
+ loadingType: c,
1290
+ url: l,
1291
+ urlPathGroup: s
1292
+ });
1293
+ let d = t === "load", f = T(T(T({}, e.config.hooks.getPageAttributes()), I({
1294
+ errorType: "none",
1295
+ eventLabel: d ? "文档加载" : "路由切换",
1296
+ spanSubtype: d ? "navigate" : t,
1297
+ spanType: d ? F.document : F.route,
1298
+ targetLabel: s,
1299
+ traceScene: d ? "page_load" : "route_change"
1300
+ })), {}, {
1301
+ [b.viewId]: o,
1302
+ [b.viewUrl]: l,
1303
+ [b.viewUrlPathGroup]: s,
1304
+ [b.viewLoadingType]: c,
1305
+ "url.previous": u,
1306
+ "event.source": t
1307
+ }, d ? { "document.referrer": e.config.hooks.redactUrl(document.referrer || "") } : {});
1308
+ r = e.startSpan("browser.view", f), e.startSpan("browser.page_view", T({}, f)).end();
1309
+ }, a = an((e) => {
1310
+ i(e.source, e.fromUrl);
955
1311
  });
956
- r("load"), t.push(i);
1312
+ i("load");
1313
+ let o = () => {
1314
+ r == null || r.setAttribute("view.end_reason", "shutdown"), r == null || r.end(), r = void 0;
1315
+ };
1316
+ window.addEventListener("pagehide", o), t.push(a, () => window.removeEventListener("pagehide", o), o);
957
1317
  },
958
1318
  shutdown() {
959
1319
  for (; t.length;) {
@@ -962,11 +1322,57 @@ var de = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
962
1322
  }
963
1323
  }
964
1324
  };
965
- }, wt = (e) => {
1325
+ }, cn = (e) => e.transferSize === 0 && e.decodedBodySize > 0 ? !0 : void 0, ln = (e) => {
1326
+ let t, n = /* @__PURE__ */ new Set();
1327
+ return {
1328
+ name: "resource",
1329
+ enabled: e.enabled,
1330
+ init(e) {
1331
+ var r;
1332
+ if (typeof PerformanceObserver > "u" || !((r = PerformanceObserver.supportedEntryTypes) != null && r.includes("resource"))) return;
1333
+ let i = (t) => {
1334
+ if (!t.name || N(e.config, t.name)) return;
1335
+ let r = `${t.name}|${t.startTime}`;
1336
+ if (n.has(r)) return;
1337
+ n.add(r);
1338
+ let i = e.config.hooks.redactUrl(t.name), a = t.duration;
1339
+ e.startSpan("browser.resource", T(T(T({}, e.config.hooks.getPageAttributes()), Je({
1340
+ duration: a,
1341
+ initiatorType: t.initiatorType || "other",
1342
+ responseStatus: t.responseStatus,
1343
+ transferSize: t.transferSize,
1344
+ url: i,
1345
+ urlPathTemplate: e.config.hooks.getViewPathGroup(t.name)
1346
+ })), {}, {
1347
+ "url.full": i,
1348
+ [b.transferSize]: t.transferSize,
1349
+ [b.cacheHit]: cn(t),
1350
+ [b.nextHopProtocol]: t.nextHopProtocol,
1351
+ initiator_type: t.initiatorType || "other",
1352
+ "resource.encoded_body_size": t.encodedBodySize,
1353
+ "resource.decoded_body_size": t.decodedBodySize
1354
+ }), { startTime: performance.timeOrigin + t.startTime }).end(performance.timeOrigin + t.startTime + a);
1355
+ };
1356
+ try {
1357
+ t = new PerformanceObserver((e) => {
1358
+ for (let t of e.getEntries()) i(t);
1359
+ }), t.observe({
1360
+ type: "resource",
1361
+ buffered: !0
1362
+ });
1363
+ } catch (e) {
1364
+ t = void 0;
1365
+ }
1366
+ },
1367
+ shutdown() {
1368
+ t == null || t.disconnect(), t = void 0, n.clear();
1369
+ }
1370
+ };
1371
+ }, un = (e) => {
966
1372
  let t = [], n = !1;
967
1373
  return {
968
1374
  name: "route-timing",
969
- enabled: !!e,
1375
+ enabled: e.enabled,
970
1376
  init(e) {
971
1377
  if (typeof window > "u" || typeof history > "u") return;
972
1378
  let r = e.meter.createHistogram("browser.route_change.duration", {
@@ -976,15 +1382,24 @@ var de = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
976
1382
  if (n) return;
977
1383
  let o = performance.now(), s = performance.timeOrigin + o, c = () => {
978
1384
  if (n || typeof document < "u" && document.visibilityState === "hidden") return;
979
- let c = performance.now() - o, l = e.applyRedact(k(k(k({}, e.config.getPageAttributes()), e.config.getMetricAttributes()), {}, { "route.change.source": t }));
980
- r.record(c, l), e.startSpan("browser.route_change", k(k({}, l), {}, {
981
- "url.full": e.config.redactUrl(a),
982
- "url.previous": e.config.redactUrl(i),
983
- "route.change.duration_ms": c
1385
+ let c = performance.now() - o, l = c > 500 ? P.warning : P.success, u = e.applyRedact(T(T(T({}, e.config.hooks.getPageAttributes()), e.config.hooks.getMetricAttributes()), {}, { "route.change.source": t }));
1386
+ r.record(c, u), e.startSpan("browser.route_change", T(T(T({}, u), I({
1387
+ duration: c,
1388
+ errorType: l === P.warning ? "slow" : "none",
1389
+ eventLabel: "路由切换",
1390
+ result: l,
1391
+ spanSubtype: t,
1392
+ spanType: F.route,
1393
+ targetLabel: e.config.hooks.getViewPathGroup(a),
1394
+ targetValue: c,
1395
+ traceScene: "route_change"
1396
+ })), {}, {
1397
+ "url.full": e.config.hooks.redactUrl(a),
1398
+ "url.previous": e.config.hooks.redactUrl(i)
984
1399
  }), { startTime: s }).end();
985
1400
  };
986
1401
  requestAnimationFrame(() => requestAnimationFrame(() => setTimeout(c, 0)));
987
- }, a = xt((e) => {
1402
+ }, a = an((e) => {
988
1403
  e.fromUrl !== e.toUrl && i(e.source, e.fromUrl, e.toUrl);
989
1404
  });
990
1405
  t.push(a);
@@ -996,32 +1411,32 @@ var de = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
996
1411
  }
997
1412
  }
998
1413
  };
999
- }, Tt = 1800 * 1e3, Et = 1440 * 60 * 1e3, Dt = 6e4, Ot = 5e3, kt = [
1414
+ }, dn = 1800 * 1e3, fn = 1440 * 60 * 1e3, pn = 6e4, mn = 5e3, hn = [
1000
1415
  "click",
1001
1416
  "keydown",
1002
1417
  "scroll",
1003
1418
  "mousemove",
1004
1419
  "touchstart"
1005
- ], At = (e, t) => typeof e == "number" && Number.isFinite(e) && e > 0 && e <= t + Ot, jt = (e, t) => {
1420
+ ], gn = (e, t) => typeof e == "number" && Number.isFinite(e) && e > 0 && e <= t + mn, _n = (e, t) => {
1006
1421
  if (!e) return null;
1007
1422
  try {
1008
1423
  let n = JSON.parse(e);
1009
- if (typeof (n == null ? void 0 : n.id) == "string" && At(n.ts, t) && At(n.startedAt, t)) return n;
1424
+ if (typeof (n == null ? void 0 : n.id) == "string" && gn(n.ts, t) && gn(n.startedAt, t)) return n;
1010
1425
  } catch (e) {}
1011
1426
  return null;
1012
- }, Mt = (e, t) => {
1427
+ }, vn = (e, t) => {
1013
1428
  if (typeof window > "u") return null;
1014
1429
  let n = null;
1015
1430
  try {
1016
1431
  n = window.localStorage.getItem(e);
1017
1432
  } catch (e) {}
1018
- let r = jt(n, t);
1433
+ let r = _n(n, t);
1019
1434
  if (r) return r;
1020
1435
  try {
1021
1436
  n = window.sessionStorage.getItem(e);
1022
1437
  } catch (e) {}
1023
- return r = jt(n, t), r;
1024
- }, Nt = (e, t) => {
1438
+ return r = _n(n, t), r;
1439
+ }, yn = (e, t) => {
1025
1440
  if (typeof window > "u") return;
1026
1441
  let n = JSON.stringify(t);
1027
1442
  try {
@@ -1030,13 +1445,13 @@ var de = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
1030
1445
  try {
1031
1446
  window.localStorage.setItem(e, n);
1032
1447
  } catch (e) {}
1033
- }, Pt = (e, t, n) => {
1034
- let r = Date.now(), i = Mt(e, r);
1448
+ }, bn = (e, t, n) => {
1449
+ let r = Date.now(), i = vn(e, r);
1035
1450
  if (i) {
1036
1451
  let a = r - i.ts >= t, o = r - i.startedAt >= n;
1037
1452
  if (!a && !o) {
1038
- let t = k(k({}, i), {}, { ts: r });
1039
- return Nt(e, t), {
1453
+ let t = T(T({}, i), {}, { ts: r });
1454
+ return yn(e, t), {
1040
1455
  id: t.id,
1041
1456
  rotated: !1
1042
1457
  };
@@ -1046,7 +1461,7 @@ var de = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
1046
1461
  startedAt: r,
1047
1462
  ts: r
1048
1463
  };
1049
- return Nt(e, c), {
1464
+ return yn(e, c), {
1050
1465
  id: c.id,
1051
1466
  prevId: i.id,
1052
1467
  reason: s,
@@ -1058,12 +1473,12 @@ var de = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
1058
1473
  startedAt: r,
1059
1474
  ts: r
1060
1475
  };
1061
- return Nt(e, a), {
1476
+ return yn(e, a), {
1062
1477
  id: a.id,
1063
1478
  reason: "init",
1064
1479
  rotated: !0
1065
1480
  };
1066
- }, Ft = (e) => {
1481
+ }, xn = (e) => {
1067
1482
  let t = "";
1068
1483
  try {
1069
1484
  t = new URL(e).host;
@@ -1071,62 +1486,72 @@ var de = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
1071
1486
  t = e;
1072
1487
  }
1073
1488
  return `bk_ot_session__${R(t || "default")}`;
1074
- }, It = (e, t) => {
1075
- !t.rotated || !t.reason || e.emitLog({
1489
+ }, Sn = (e, t) => {
1490
+ if (!t.rotated || !t.reason) return;
1491
+ let n = Date.now();
1492
+ e.emitLog({
1076
1493
  severityNumber: o.INFO,
1077
1494
  severityText: "INFO",
1078
1495
  body: t.reason === "init" ? "session.start" : "session.rotate",
1079
- attributes: k(k({}, e.config.getPageAttributes()), {}, {
1080
- "session.id": t.id,
1496
+ attributes: T(T({}, e.config.hooks.getPageAttributes()), {}, {
1497
+ [b.sessionHasReplay]: !1,
1498
+ [b.sessionId]: t.id,
1499
+ [b.sessionStartTime]: n,
1081
1500
  "session.rotate.reason": t.reason
1082
1501
  }, t.prevId ? { "session.previous_id": t.prevId } : {})
1083
1502
  });
1084
- }, Lt = (e) => {
1503
+ }, Cn = (e) => {
1085
1504
  let t = [];
1086
1505
  return {
1087
1506
  name: "session",
1088
- enabled: !!e,
1507
+ enabled: e.enabled,
1089
1508
  init(n) {
1090
- var r, i, a;
1091
- let o = typeof e == "object" ? e : void 0, s = (r = o == null ? void 0 : o.storageKey) == null ? Ft(n.config.endpoint) : r, c = (i = o == null ? void 0 : o.inactivityMs) == null ? Tt : i, l = (a = o == null ? void 0 : o.maxLifetimeMs) == null ? Et : a, u = "", d = () => {
1509
+ var r;
1510
+ let i = e.enabled ? (r = e.storageKey) == null ? xn(n.config.transport.endpoint) : r : xn(n.config.transport.endpoint), a = e.enabled ? e.inactivityMs : dn, o = e.enabled ? e.maxLifetimeMs : fn, s = "", c = () => {
1092
1511
  if (typeof window > "u") {
1093
- u || (u = B("session"), n.setRuntimeAttributes({ "session.id": u }));
1512
+ s || (s = B("session"), n.setRuntimeAttributes({
1513
+ [b.sessionHasReplay]: !1,
1514
+ [b.sessionId]: s
1515
+ }));
1094
1516
  return;
1095
1517
  }
1096
- let e = Pt(s, c, l);
1097
- n.setRuntimeAttributes({ "session.id": e.id }), e.id !== u && (u = e.id, It(n, e));
1518
+ let e = bn(i, a, o);
1519
+ n.setRuntimeAttributes({
1520
+ [b.sessionHasReplay]: !1,
1521
+ [b.sessionId]: e.id
1522
+ }), e.id !== s && (s = e.id, Sn(n, e));
1098
1523
  };
1099
- if (d(), typeof window > "u" || typeof document > "u") return;
1100
- let f = Date.now(), p = () => {
1524
+ if (c(), typeof window > "u" || typeof document > "u") return;
1525
+ let l = Date.now(), u = () => {
1101
1526
  let e = Date.now();
1102
- e - f < Dt || (f = e, d());
1103
- }, m = {
1527
+ e - l < pn || (l = e, c());
1528
+ }, d = {
1104
1529
  capture: !0,
1105
1530
  passive: !0
1106
1531
  };
1107
- kt.forEach((e) => {
1108
- window.addEventListener(e, p, m);
1532
+ hn.forEach((e) => {
1533
+ window.addEventListener(e, u, d);
1109
1534
  }), t.push(() => {
1110
- kt.forEach((e) => {
1111
- window.removeEventListener(e, p, m);
1535
+ hn.forEach((e) => {
1536
+ window.removeEventListener(e, u, d);
1112
1537
  });
1113
1538
  });
1114
- let h = () => {
1115
- document.visibilityState === "visible" && d();
1539
+ let f = () => {
1540
+ document.visibilityState === "visible" && c();
1116
1541
  };
1117
- document.addEventListener("visibilitychange", h), t.push(() => document.removeEventListener("visibilitychange", h));
1118
- let g = (e) => {
1119
- if (e.storageArea !== window.localStorage || e.key !== s || !e.newValue) return;
1120
- let t = Date.now(), r = jt(e.newValue, t);
1121
- if (!(!r || r.id === u)) {
1122
- u = r.id;
1542
+ document.addEventListener("visibilitychange", f), t.push(() => document.removeEventListener("visibilitychange", f));
1543
+ let p = (e) => {
1544
+ if (e.storageArea !== window.localStorage || e.key !== i || !e.newValue) return;
1545
+ let t = Date.now(), r = _n(e.newValue, t);
1546
+ if (!(!r || r.id === s)) {
1547
+ s = r.id;
1123
1548
  try {
1124
- window.sessionStorage.setItem(s, e.newValue);
1549
+ window.sessionStorage.setItem(i, e.newValue);
1125
1550
  } catch (e) {}
1126
- n.setRuntimeAttributes({ "session.id": r.id });
1551
+ n.setRuntimeAttributes({ [b.sessionId]: r.id });
1127
1552
  }
1128
1553
  };
1129
- window.addEventListener("storage", g), t.push(() => window.removeEventListener("storage", g));
1554
+ window.addEventListener("storage", p), t.push(() => window.removeEventListener("storage", p));
1130
1555
  },
1131
1556
  shutdown() {
1132
1557
  for (; t.length;) {
@@ -1135,48 +1560,48 @@ var de = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
1135
1560
  }
1136
1561
  }
1137
1562
  };
1138
- }, Rt = "unknown", zt = (e) => e ? e.replace(/_/g, "-") : Rt, Bt = () => {
1139
- if (typeof performance > "u") return Rt;
1563
+ }, wn = "unknown", Tn = (e) => e ? e.replace(/_/g, "-") : wn, En = () => {
1564
+ if (typeof performance > "u") return wn;
1140
1565
  let e = performance.getEntriesByType("navigation")[0];
1141
- return zt(e == null ? void 0 : e.type);
1142
- }, Vt = (e, t) => {
1566
+ return Tn(e == null ? void 0 : e.type);
1567
+ }, Dn = (e, t) => {
1143
1568
  var n;
1144
1569
  return {
1145
1570
  "rum.navigation.type": (n = e.navigationType) == null ? t : n,
1146
- "web_vital.name": e.name,
1147
- "web_vital.rating": e.rating
1571
+ [b.vitalMetric]: e.name.toLowerCase(),
1572
+ [b.vitalRating]: e.rating
1148
1573
  };
1149
- }, Ht = (e, t) => {
1574
+ }, On = (e, t) => {
1150
1575
  var n;
1151
1576
  let r = (n = e.attribution) == null ? {} : n, i = {}, a = (e) => r[e], o = (e, t, n) => {
1152
1577
  t != null && (typeof t == "string" || typeof t == "number" || typeof t == "boolean") && (i[e] = typeof t == "string" && n ? n(t) : t);
1153
1578
  };
1154
1579
  switch (e.name) {
1155
1580
  case "LCP":
1156
- o("web_vital.lcp.url", a("url"), t), o("web_vital.lcp.target", a("target")), o("web_vital.lcp.element_render_delay", a("elementRenderDelay")), o("web_vital.lcp.resource_load_duration", a("resourceLoadDuration")), o("web_vital.lcp.time_to_first_byte", a("timeToFirstByte"));
1581
+ o("vital.lcp.url", a("url"), t), o("vital.lcp.target", a("target")), o("vital.lcp.element_render_delay", a("elementRenderDelay")), o("vital.lcp.resource_load_duration", a("resourceLoadDuration")), o("vital.lcp.time_to_first_byte", a("timeToFirstByte"));
1157
1582
  break;
1158
1583
  case "CLS":
1159
- o("web_vital.cls.largest_shift_target", a("largestShiftTarget")), o("web_vital.cls.largest_shift_value", a("largestShiftValue")), o("web_vital.cls.load_state", a("loadState"));
1584
+ o("vital.cls.largest_shift_target", a("largestShiftTarget")), o("vital.cls.largest_shift_value", a("largestShiftValue")), o("vital.cls.load_state", a("loadState"));
1160
1585
  break;
1161
1586
  case "INP":
1162
- o("web_vital.inp.interaction_target", a("interactionTarget")), o("web_vital.inp.interaction_type", a("interactionType")), o("web_vital.inp.input_delay", a("inputDelay")), o("web_vital.inp.processing_duration", a("processingDuration")), o("web_vital.inp.presentation_delay", a("presentationDelay"));
1587
+ o("vital.inp.interaction_target", a("interactionTarget")), o("vital.inp.interaction_type", a("interactionType")), o("vital.inp.input_delay", a("inputDelay")), o("vital.inp.processing_duration", a("processingDuration")), o("vital.inp.presentation_delay", a("presentationDelay"));
1163
1588
  break;
1164
1589
  case "FCP":
1165
- o("web_vital.fcp.time_to_first_byte", a("timeToFirstByte")), o("web_vital.fcp.load_state", a("loadState"));
1590
+ o("vital.fcp.time_to_first_byte", a("timeToFirstByte")), o("vital.fcp.load_state", a("loadState"));
1166
1591
  break;
1167
1592
  case "TTFB":
1168
- o("web_vital.ttfb.waiting_duration", a("waitingDuration")), o("web_vital.ttfb.dns_duration", a("dnsDuration")), o("web_vital.ttfb.connection_duration", a("connectionDuration")), o("web_vital.ttfb.request_duration", a("requestDuration"));
1593
+ o("vital.ttfb.waiting_duration", a("waitingDuration")), o("vital.ttfb.dns_duration", a("dnsDuration")), o("vital.ttfb.connection_duration", a("connectionDuration")), o("vital.ttfb.request_duration", a("requestDuration"));
1169
1594
  break;
1170
1595
  default: break;
1171
1596
  }
1172
1597
  return i;
1173
- }, Ut = (e) => {
1598
+ }, kn = (e) => {
1174
1599
  let t = !1;
1175
1600
  return {
1176
1601
  name: "web-vitals",
1177
- enabled: !!e,
1602
+ enabled: e.enabled,
1178
1603
  init(e) {
1179
- return F(function* () {
1604
+ return M(function* () {
1180
1605
  if (typeof window > "u") return;
1181
1606
  let n;
1182
1607
  try {
@@ -1189,22 +1614,34 @@ var de = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
1189
1614
  return;
1190
1615
  }
1191
1616
  if (t) return;
1192
- let { onCLS: i, onFCP: a, onINP: o, onLCP: s, onTTFB: c } = n, l = Bt(), u = e.meter.createHistogram("browser.web_vital.cls", {
1617
+ let { onCLS: i, onFCP: a, onINP: o, onLCP: s, onTTFB: c } = n, l = En(), u = e.meter.createHistogram("browser.web_vital.cls", {
1193
1618
  unit: "1",
1194
1619
  description: "Cumulative Layout Shift"
1195
1620
  }), d = e.meter.createHistogram("browser.web_vital.duration", {
1196
1621
  unit: "ms",
1197
1622
  description: "Web Vitals duration metrics, including FCP, INP, LCP and TTFB"
1198
1623
  }), f = (t) => {
1199
- e.startSpan("browser.web_vital", k(k(k(k({}, e.config.getPageAttributes()), e.config.getMetricAttributes()), Vt(t, l)), {}, {
1200
- "web_vital.id": t.id,
1201
- "web_vital.value": t.value
1202
- }, Ht(t, e.config.redactUrl))).end();
1624
+ let n = t.name.toLowerCase();
1625
+ e.startSpan("browser.web_vital", T(T(T(T(T({}, e.config.hooks.getPageAttributes()), e.config.hooks.getMetricAttributes()), Dn(t, l)), I({
1626
+ duration: t.name === "CLS" ? void 0 : t.value,
1627
+ errorType: t.rating === "good" ? "none" : "slow",
1628
+ eventLabel: "Web 指标",
1629
+ result: Ge(t.rating),
1630
+ spanSubtype: n,
1631
+ spanType: F.vital,
1632
+ targetLabel: n,
1633
+ targetValue: t.value
1634
+ })), {}, {
1635
+ [b.vitalMetric]: n,
1636
+ [b.vitalValue]: t.value,
1637
+ [b.vitalRating]: t.rating,
1638
+ "vital.id": t.id
1639
+ }, On(t, e.config.hooks.redactUrl))).end();
1203
1640
  }, p = (n) => {
1204
- t || !Number.isFinite(n.value) || (d.record(n.value, e.applyRedact(k(k(k({}, e.config.getPageAttributes()), e.config.getMetricAttributes()), Vt(n, l)))), f(n));
1641
+ t || !Number.isFinite(n.value) || (d.record(n.value, e.applyRedact(T(T(T({}, e.config.hooks.getPageAttributes()), e.config.hooks.getMetricAttributes()), Dn(n, l)))), f(n));
1205
1642
  };
1206
1643
  i((n) => {
1207
- t || !Number.isFinite(n.value) || (u.record(n.value, e.applyRedact(k(k(k({}, e.config.getPageAttributes()), e.config.getMetricAttributes()), Vt(n, l)))), f(n));
1644
+ t || !Number.isFinite(n.value) || (u.record(n.value, e.applyRedact(T(T(T({}, e.config.hooks.getPageAttributes()), e.config.hooks.getMetricAttributes()), Dn(n, l)))), f(n));
1208
1645
  }), a(p), o(p), s(p), c(p);
1209
1646
  })();
1210
1647
  },
@@ -1212,7 +1649,7 @@ var de = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
1212
1649
  t = !0;
1213
1650
  }
1214
1651
  };
1215
- }, Wt = 64 * 1024, Gt = 6e4, Kt = 5, qt = (e) => e == null ? 0 : typeof e == "string" ? e.length > Wt || typeof TextEncoder > "u" ? e.length : new TextEncoder().encode(e).byteLength : e instanceof ArrayBuffer || ArrayBuffer.isView(e) ? e.byteLength : typeof Blob < "u" && e instanceof Blob ? e.size : 0, Jt = (e, t) => {
1652
+ }, An = 64 * 1024, jn = 6e4, Mn = 5, Nn = (e) => e == null ? 0 : typeof e == "string" ? e.length > An || typeof TextEncoder > "u" ? e.length : new TextEncoder().encode(e).byteLength : e instanceof ArrayBuffer || ArrayBuffer.isView(e) ? e.byteLength : typeof Blob < "u" && e instanceof Blob ? e.size : 0, Pn = (e, t) => {
1216
1653
  let n = {
1217
1654
  "network.protocol.name": "websocket",
1218
1655
  "url.full": t(e)
@@ -1225,61 +1662,92 @@ var de = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
1225
1662
  metricAttributes: r,
1226
1663
  spanAttributes: n
1227
1664
  };
1228
- }, Yt = (e, n) => {
1229
- let { bytesCounter: r, connectDurationHistogram: i, context: a, errorCounter: s, errorThrottle: c, isDisposed: l, messageCounter: u, url: d } = n, { metricAttributes: f, spanAttributes: p } = Jt(d, a.config.redactUrl), m = a.startSpan("websocket.connect", p), h = performance.now(), g = !1, _ = (e) => {
1230
- if (g) return;
1231
- g = !0;
1232
- let n = performance.now() - h;
1233
- e === "error" && m.setStatus({
1665
+ }, Fn = (e, n) => {
1666
+ var r;
1667
+ let { bytesCounter: i, connectDurationHistogram: a, context: s, errorCounter: c, errorThrottle: l, isDisposed: u, messageCounter: d, url: f } = n, { metricAttributes: p, spanAttributes: m } = Pn(f, s.config.hooks.redactUrl), h = (r = m["server.address"]) == null ? m["url.full"] : r, g = s.startSpan("websocket.connect", T(T(T({}, m), I({
1668
+ errorType: "none",
1669
+ eventLabel: "WebSocket",
1670
+ spanSubtype: "websocket",
1671
+ spanType: F.custom,
1672
+ targetLabel: h
1673
+ })), m["server.address"] ? { [b.targetDomain]: m["server.address"] } : {})), _ = performance.now(), v = !1, y = (e) => {
1674
+ if (v) return;
1675
+ v = !0;
1676
+ let n = performance.now() - _;
1677
+ e === "error" && g.setStatus({
1234
1678
  code: t.ERROR,
1235
1679
  message: "websocket connect failed"
1236
- }), m.setAttribute("websocket.connect.duration_ms", n), m.end(), e === "opened" && !l() && i.record(n, f);
1680
+ }), g.setAttributes(I({
1681
+ duration: n,
1682
+ errorType: e === "error" ? "network" : "none",
1683
+ eventLabel: "WebSocket",
1684
+ result: e === "error" ? P.error : P.success,
1685
+ spanSubtype: "websocket",
1686
+ spanType: F.custom,
1687
+ targetLabel: h,
1688
+ targetValue: n
1689
+ })), g.end(), e === "opened" && !u() && a.record(n, p);
1237
1690
  };
1238
1691
  e.addEventListener("open", () => {
1239
- l() || _("opened");
1692
+ u() || y("opened");
1240
1693
  }), e.addEventListener("message", (e) => {
1241
- if (l()) return;
1242
- let t = k(k({}, f), {}, { "websocket.direction": "in" });
1243
- u.add(1, t), r.add(qt(e.data), t);
1694
+ if (u()) return;
1695
+ let t = T(T({}, p), {}, { "websocket.direction": "in" });
1696
+ d.add(1, t), i.add(Nn(e.data), t);
1244
1697
  }), e.addEventListener("error", () => {
1245
- if (l()) return;
1246
- let e = g ? "runtime" : "connect";
1247
- s.add(1, k(k({}, f), {}, { "websocket.error.phase": e })), _("error");
1248
- let t = c.allow(`ws:error:${d}`);
1249
- t.allowed && a.emitLog({
1698
+ if (u()) return;
1699
+ let e = v ? "runtime" : "connect";
1700
+ c.add(1, T(T({}, p), {}, { "websocket.error.phase": e })), y("error");
1701
+ let t = l.allow(`ws:error:${f}`);
1702
+ t.allowed && s.emitLog({
1250
1703
  severityNumber: o.ERROR,
1251
1704
  severityText: "ERROR",
1252
1705
  body: "websocket.error",
1253
- attributes: k(k({}, p), {}, {
1706
+ attributes: T(T(T({}, m), I({
1707
+ errorType: "network",
1708
+ eventLabel: "WebSocket 错误",
1709
+ result: P.error,
1710
+ spanSubtype: "websocket",
1711
+ spanType: F.custom,
1712
+ targetLabel: h
1713
+ })), {}, {
1254
1714
  "websocket.error.phase": e,
1255
1715
  "websocket.error.window_count": t.count
1256
1716
  })
1257
1717
  });
1258
1718
  }), e.addEventListener("close", (e) => {
1259
- l() || (g || _("error"), a.emitLog({
1719
+ u() || (v || y("error"), s.emitLog({
1260
1720
  severityNumber: o.INFO,
1261
1721
  severityText: "INFO",
1262
1722
  body: "websocket.close",
1263
- attributes: k(k({}, p), {}, {
1723
+ attributes: T(T(T({}, m), I({
1724
+ errorType: e.wasClean ? "none" : "network",
1725
+ eventLabel: "WebSocket 关闭",
1726
+ result: e.wasClean ? P.success : P.warning,
1727
+ spanSubtype: "websocket",
1728
+ spanType: F.custom,
1729
+ targetLabel: h,
1730
+ targetValue: e.code
1731
+ })), {}, {
1264
1732
  "websocket.close.code": e.code,
1265
1733
  "websocket.close.reason": e.reason,
1266
1734
  "websocket.close.was_clean": e.wasClean
1267
1735
  })
1268
1736
  }));
1269
1737
  });
1270
- let v = e.send.bind(e);
1738
+ let ee = e.send.bind(e);
1271
1739
  e.send = (e) => {
1272
- if (!l()) {
1273
- let t = k(k({}, f), {}, { "websocket.direction": "out" });
1274
- u.add(1, t), r.add(qt(e), t);
1740
+ if (!u()) {
1741
+ let t = T(T({}, p), {}, { "websocket.direction": "out" });
1742
+ d.add(1, t), i.add(Nn(e), t);
1275
1743
  }
1276
- return v(e);
1744
+ return ee(e);
1277
1745
  };
1278
- }, Xt = (e) => {
1746
+ }, In = (e) => {
1279
1747
  let t, n, r = !1;
1280
1748
  return {
1281
1749
  name: "websocket",
1282
- enabled: !!e,
1750
+ enabled: e.enabled,
1283
1751
  init(e) {
1284
1752
  if (typeof window > "u" || window.WebSocket === void 0) return;
1285
1753
  let i = window.WebSocket;
@@ -1290,12 +1758,12 @@ var de = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
1290
1758
  }), s = e.meter.createCounter("browser.websocket.error.count", { description: "Total number of WebSocket error events" }), c = e.meter.createHistogram("browser.websocket.connect.duration", {
1291
1759
  unit: "ms",
1292
1760
  description: "WebSocket connection establishment duration (only successful connects)"
1293
- }), l = z(Gt, Kt), u = () => r;
1761
+ }), l = z(jn, Mn), u = () => r;
1294
1762
  n = new Proxy(i, { construct(t, n, i) {
1295
1763
  let d = Reflect.construct(t, n, i);
1296
1764
  if (r) return d;
1297
1765
  let f = n[0] == null ? "" : String(n[0]);
1298
- return !f || I(e.config, f) || Yt(d, {
1766
+ return !f || N(e.config, f) || Fn(d, {
1299
1767
  bytesCounter: o,
1300
1768
  connectDurationHistogram: c,
1301
1769
  context: e,
@@ -1311,55 +1779,68 @@ var de = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
1311
1779
  r = !0, typeof window < "u" && t && window.WebSocket === n && (window.WebSocket = t), n = void 0, t = void 0;
1312
1780
  }
1313
1781
  };
1314
- }, $ = "__bk_ot_sampled__", Zt = /* @__PURE__ */ new Map(), Qt = (e) => Zt.get(e), $t = (e, t) => (Zt.set(e, t), t), en = ({ sampleRate: e }) => {
1315
- if (e <= 0) return !1;
1316
- if (e >= 1) return !0;
1782
+ }, $ = "BK_RUM_SAMPLING", Ln = /* @__PURE__ */ new Map(), Rn = (e) => Ln.get(e), zn = (e, t) => (Ln.set(e, t), t), Bn = ({ sampling: e }) => {
1783
+ if (e.rate <= 0) return !1;
1784
+ if (e.rate >= 1) return !0;
1317
1785
  try {
1318
1786
  let t = sessionStorage.getItem($);
1319
1787
  if (t) return t === "1";
1320
- let n = Math.random() < e;
1321
- return sessionStorage.setItem($, n ? "1" : "0"), $t($, n), n;
1788
+ let n = Math.random() < e.rate;
1789
+ return sessionStorage.setItem($, n ? "1" : "0"), zn($, n), n;
1322
1790
  } catch (t) {
1323
- let n = Qt($);
1324
- return typeof n == "boolean" ? n : $t($, Math.random() < e);
1791
+ let n = Rn($);
1792
+ return typeof n == "boolean" ? n : zn($, Math.random() < e.rate);
1325
1793
  }
1326
- }, tn = (e) => ({
1794
+ }, Vn = (e) => ({
1327
1795
  url: e.endpoint,
1328
1796
  headers: e.headers,
1329
1797
  concurrencyLimit: e.concurrencyLimit,
1330
1798
  timeoutMillis: e.timeoutMillis
1331
- }), nn = "bk-rum", rn = (e, t, n) => n ? new Proxy(e, { get(e, n, r) {
1799
+ }), Hn = "bk-rum", Un = (e, t, n) => n ? new Proxy(e, { get(e, n, r) {
1332
1800
  if (n === "export") return (n, r) => {
1333
1801
  var i;
1334
1802
  return (i = globalThis.console) == null || i.log(`[bk-ot][${t}]`, n), e.export(n, r);
1335
1803
  };
1336
1804
  let i = Reflect.get(e, n, r);
1337
1805
  return typeof i == "function" ? i.bind(e) : i;
1338
- } }) : e, an = (e) => [Fe(e.commonInstrumentations)], on = (e) => [
1339
- Xe(e.rum.device),
1340
- mt(e.rum.httpBody),
1341
- Lt(e.rum.session),
1342
- Ct(e.rum.pageView),
1343
- tt(e.rum.error),
1344
- Ut(e.rum.webVitals),
1345
- je(e.rum.blankScreen),
1346
- Xt(e.rum.websocket),
1347
- gt(e.rum.longTask),
1348
- Be(e.rum.cspViolation),
1349
- wt(e.rum.routeTiming)
1350
- ], sn = class {
1806
+ } }) : e, Wn = (e) => [pt(e.rum.instrumentations)], Gn = (e) => [
1807
+ Ze(e.rum.plugins.action),
1808
+ At(e.rum.plugins.device),
1809
+ Zt(e.rum.plugins.httpBody),
1810
+ Cn(e.rum.plugins.session),
1811
+ sn(e.rum.plugins.pageView),
1812
+ Rt(e.rum.plugins.error),
1813
+ kn(e.rum.plugins.webVitals),
1814
+ ln(e.rum.plugins.resource),
1815
+ at(e.rum.plugins.blankScreen),
1816
+ In(e.rum.plugins.websocket),
1817
+ $t(e.rum.plugins.longTask),
1818
+ vt(e.rum.plugins.cspViolation),
1819
+ un(e.rum.plugins.routeTiming)
1820
+ ], Kn = class {
1351
1821
  assertBeforeStart(e) {
1352
1822
  if (this.phase !== "idle") throw Error(`[bk-ot] ${e}() must be called before start(); set autoStart: false before registration.`);
1353
1823
  }
1354
1824
  constructor(o) {
1355
- var w = this;
1356
- D(this, "loggerProvider", void 0), D(this, "meterProvider", void 0), D(this, "phase", "idle"), D(this, "pluginManager", void 0), D(this, "plugins", void 0), D(this, "registeredInstrumentations", void 0), D(this, "runtimeAttributes", void 0), D(this, "sampled", void 0), D(this, "teardownCallbacks", []), D(this, "tracerProvider", void 0), D(this, "applyRedact", (e) => this.config.redactAttributes(e)), D(this, "config", void 0), D(this, "emitLog", (e) => {
1825
+ var x = this;
1826
+ C(this, "loggerProvider", void 0), C(this, "meterProvider", void 0), C(this, "phase", "idle"), C(this, "pluginManager", void 0), C(this, "plugins", void 0), C(this, "registeredInstrumentations", void 0), C(this, "runtimeContext", void 0), C(this, "sampled", void 0), C(this, "teardownCallbacks", []), C(this, "tracerProvider", void 0), C(this, "applyRedact", (e) => this.config.hooks.redactAttributes(e)), C(this, "config", void 0), C(this, "emitLog", (e) => {
1357
1827
  var t;
1358
- let n = k(k({}, e), {}, { attributes: this.applyRedact(k(k({}, this.getRuntimeAttributes()), (t = e.attributes) == null ? {} : t)) });
1828
+ let n = T(T({}, e), {}, { attributes: this.applyRedact(T(T({}, this.getRuntimeAttributes()), (t = e.attributes) == null ? {} : t)) });
1359
1829
  this.logger.emit(n);
1360
- }), D(this, "flush", F(function* () {
1361
- yield w.pluginManager.flush(), yield w.tracerProvider.forceFlush(), yield w.meterProvider.forceFlush(), yield w.loggerProvider.forceFlush();
1362
- })), D(this, "getRuntimeAttributes", () => k({}, this.runtimeAttributes)), D(this, "logger", void 0), D(this, "meter", void 0), D(this, "reportCustomEvent", ({ attributes: e = {}, error: n, name: r }) => {
1830
+ }), C(this, "flush", M(function* () {
1831
+ yield x.pluginManager.flush(), yield x.tracerProvider.forceFlush(), yield x.meterProvider.forceFlush(), yield x.loggerProvider.forceFlush();
1832
+ })), C(this, "getRuntimeAttributes", () => this.runtimeContext.getAttributes()), C(this, "logger", void 0), C(this, "meter", void 0), C(this, "reportAction", ({ attributes: e = {}, targetTag: t, targetText: n, type: r }) => {
1833
+ var i;
1834
+ if (!this.sampled) return;
1835
+ let a = n == null ? void 0 : n.slice(0, 32);
1836
+ this.startSpan(`action.${r}`, T(T(T(T(T({}, this.config.hooks.getPageAttributes()), I({
1837
+ errorType: "none",
1838
+ eventLabel: "用户操作",
1839
+ spanSubtype: r,
1840
+ spanType: F.action,
1841
+ targetLabel: (i = a == null ? t : a) == null ? r : i
1842
+ })), {}, { [b.actionType]: r }, a ? { [b.targetTextShort]: a } : {}), t ? { [b.targetTag]: t } : {}), e)).end();
1843
+ }), C(this, "reportCustomEvent", ({ attributes: e = {}, error: n, name: r }) => {
1363
1844
  if (!this.sampled) {
1364
1845
  if (this.config.debug) {
1365
1846
  var i;
@@ -1367,84 +1848,95 @@ var de = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
1367
1848
  }
1368
1849
  return;
1369
1850
  }
1370
- let a = this.startSpan(`custom.${r}`, k(k(k(k({}, this.config.getPageAttributes()), this.config.getCustomAttributes()), e), {}, { "rum.custom.name": r }));
1851
+ let a = this.startSpan(`custom.${r}`, T(T(T(T(T({}, this.config.hooks.getPageAttributes()), this.config.hooks.getCustomAttributes()), I({
1852
+ errorType: n ? "custom" : "none",
1853
+ eventLabel: "自定义事件",
1854
+ result: n ? P.error : P.success,
1855
+ spanSubtype: r,
1856
+ spanType: F.custom,
1857
+ targetLabel: r
1858
+ })), e), {}, { "rum.custom.name": r }));
1371
1859
  n && (a.recordException(n), a.setStatus({
1372
1860
  code: t.ERROR,
1373
1861
  message: n.message
1374
1862
  })), a.end();
1375
- }), D(this, "setRuntimeAttributes", (e) => {
1376
- Object.assign(this.runtimeAttributes, e);
1377
- }), D(this, "shutdown", F(function* () {
1378
- if (w.phase !== "stopped") {
1379
- for (yield w.flush(); w.teardownCallbacks.length;) {
1863
+ }), C(this, "setRuntimeAttributes", (e) => {
1864
+ this.runtimeContext.setAttributes(e);
1865
+ }), C(this, "setUser", (e) => {
1866
+ this.runtimeContext.setUser(e);
1867
+ }), C(this, "setView", (e) => {
1868
+ this.runtimeContext.setView(e);
1869
+ }), C(this, "shutdown", M(function* () {
1870
+ if (x.phase !== "stopped") {
1871
+ for (yield x.flush(); x.teardownCallbacks.length;) {
1380
1872
  var e;
1381
- (e = w.teardownCallbacks.pop()) == null || e();
1873
+ (e = x.teardownCallbacks.pop()) == null || e();
1382
1874
  }
1383
- for (yield w.pluginManager.shutdown(); w.registeredInstrumentations.length;) {
1875
+ for (yield x.pluginManager.shutdown(); x.registeredInstrumentations.length;) {
1384
1876
  var t, i;
1385
- (t = w.registeredInstrumentations.pop()) == null || (i = t.disable) == null || i.call(t);
1877
+ (t = x.registeredInstrumentations.pop()) == null || (i = t.disable) == null || i.call(t);
1386
1878
  }
1387
- yield w.tracerProvider.shutdown(), yield w.meterProvider.shutdown(), yield w.loggerProvider.shutdown(), a.disable(), r.disable(), n.disable(), w.phase = "stopped";
1879
+ yield x.tracerProvider.shutdown(), yield x.meterProvider.shutdown(), yield x.loggerProvider.shutdown(), a.disable(), r.disable(), n.disable(), x.phase = "stopped";
1388
1880
  }
1389
- })), D(this, "start", F(function* () {
1390
- if (!(w.phase === "started" || w.phase === "starting")) {
1391
- if (w.phase === "stopped") throw Error("[bk-ot] instance has been shut down and cannot be restarted; create a new instance instead.");
1392
- if (!w.config.enabled) {
1393
- w.phase = "started";
1881
+ })), C(this, "start", M(function* () {
1882
+ if (!(x.phase === "started" || x.phase === "starting")) {
1883
+ if (x.phase === "stopped") throw Error("[bk-ot] instance has been shut down and cannot be restarted; create a new instance instead.");
1884
+ if (!x.config.enabled) {
1885
+ x.phase = "started";
1394
1886
  return;
1395
1887
  }
1396
- w.phase = "starting", i.setGlobalPropagator(new l()), w.tracerProvider.register({ contextManager: new c() }), r.setGlobalMeterProvider(w.meterProvider), s.setGlobalLoggerProvider(w.loggerProvider);
1888
+ x.phase = "starting", i.setGlobalPropagator(new l()), x.tracerProvider.register({ contextManager: new c() }), r.setGlobalMeterProvider(x.meterProvider), s.setGlobalLoggerProvider(x.loggerProvider);
1397
1889
  try {
1398
- if (w.registeredInstrumentations.length && p({
1399
- instrumentations: w.registeredInstrumentations,
1400
- meterProvider: w.meterProvider,
1401
- tracerProvider: w.tracerProvider
1402
- }), yield w.pluginManager.start(w), typeof window < "u" && typeof document < "u") {
1890
+ if (x.registeredInstrumentations.length && p({
1891
+ instrumentations: x.registeredInstrumentations,
1892
+ meterProvider: x.meterProvider,
1893
+ tracerProvider: x.tracerProvider
1894
+ }), yield x.pluginManager.start(x), typeof window < "u" && typeof document < "u") {
1403
1895
  let e = () => {
1404
- w.flush();
1896
+ x.flush();
1405
1897
  }, t = () => {
1406
- document.visibilityState === "hidden" && w.flush();
1898
+ document.visibilityState === "hidden" && x.flush();
1407
1899
  };
1408
- window.addEventListener("pagehide", e), document.addEventListener("visibilitychange", t), w.teardownCallbacks.push(() => window.removeEventListener("pagehide", e), () => document.removeEventListener("visibilitychange", t));
1900
+ window.addEventListener("pagehide", e), document.addEventListener("visibilitychange", t), x.teardownCallbacks.push(() => window.removeEventListener("pagehide", e), () => document.removeEventListener("visibilitychange", t));
1409
1901
  }
1410
1902
  } catch (i) {
1411
- for (; w.teardownCallbacks.length;) {
1903
+ for (; x.teardownCallbacks.length;) {
1412
1904
  var e;
1413
- (e = w.teardownCallbacks.pop()) == null || e();
1905
+ (e = x.teardownCallbacks.pop()) == null || e();
1414
1906
  }
1415
- yield w.pluginManager.shutdown();
1416
- for (let e of w.registeredInstrumentations) {
1907
+ yield x.pluginManager.shutdown();
1908
+ for (let e of x.registeredInstrumentations) {
1417
1909
  var t;
1418
1910
  (t = e.disable) == null || t.call(e);
1419
1911
  }
1420
- throw a.disable(), r.disable(), n.disable(), w.phase = "idle", i;
1912
+ throw a.disable(), r.disable(), n.disable(), x.phase = "idle", i;
1421
1913
  }
1422
- w.phase = "started";
1914
+ x.phase = "started";
1423
1915
  }
1424
- })), D(this, "startSpan", (t, n = {}, r) => this.tracer.startSpan(t, {
1916
+ })), C(this, "startSpan", (t, n = {}, r) => this.tracer.startSpan(t, {
1425
1917
  kind: e.INTERNAL,
1426
1918
  startTime: r == null ? void 0 : r.startTime,
1427
- attributes: this.applyRedact(k(k({}, this.getRuntimeAttributes()), n))
1428
- })), D(this, "tracer", void 0), D(this, "use", (e) => (this.assertBeforeStart("use"), this.sampled && this.plugins.push(e), this)), D(this, "useInstrumentation", (e) => (this.assertBeforeStart("useInstrumentation"), this.config.enabled && this.registeredInstrumentations.push(e), this)), this.config = le(o), this.sampled = this.config.enabled && en(this.config);
1429
- let T = m(this.config.resourceAttributes), E = rn(new f(tn(this.config.traces)), "traces", this.config.debug), O = rn(new d(tn(this.config.metrics)), "metrics", this.config.debug), A = rn(new u(tn(this.config.logs)), "logs", this.config.debug), ee = new Ce(this.config.spanProcessor === "simple" ? new x(E) : new y(E, this.config.spanBatch), this.config), j = new v({
1430
- exporter: O,
1919
+ attributes: this.applyRedact(T(T({}, this.getRuntimeAttributes()), n))
1920
+ })), C(this, "tracer", void 0), C(this, "use", (e) => (this.assertBeforeStart("use"), this.sampled && this.plugins.push(e), this)), C(this, "useInstrumentation", (e) => (this.assertBeforeStart("useInstrumentation"), this.config.enabled && this.registeredInstrumentations.push(e), this)), this.config = Te(o), this.sampled = this.config.enabled && Bn(this.config);
1921
+ let S = m(this.config.resourceAttributes), ie = Un(new f(Vn(this.config.transport.traces)), "traces", this.config.debug), w = Un(new d(Vn(this.config.transport.metrics)), "metrics", this.config.debug), ae = Un(new u(Vn(this.config.transport.logs)), "logs", this.config.debug), oe = new ze(this.config.spanProcessor === "simple" ? new te(ie) : new y(ie, this.config.spanBatch), this.config), se = new v({
1922
+ exporter: w,
1431
1923
  exportIntervalMillis: this.config.metricIntervalMillis
1432
- }), M = new h(A);
1433
- this.tracerProvider = new C({
1434
- resource: T,
1435
- sampler: new b({ root: new S(+!!this.sampled) }),
1436
- spanProcessors: [ee]
1924
+ }), E = new h(ae);
1925
+ this.tracerProvider = new re({
1926
+ resource: S,
1927
+ sampler: new ee({ root: new ne(+!!this.sampled) }),
1928
+ spanProcessors: [oe]
1437
1929
  }), this.meterProvider = new _({
1438
- resource: T,
1439
- readers: [j]
1930
+ resource: S,
1931
+ readers: [se]
1440
1932
  }), this.loggerProvider = new g({
1441
- resource: T,
1442
- processors: [M]
1443
- }), this.tracer = this.tracerProvider.getTracer(nn), this.meter = this.meterProvider.getMeter(nn), this.logger = this.loggerProvider.getLogger(nn), this.runtimeAttributes = { "bk.rum.sampled": this.sampled }, this.registeredInstrumentations = this.config.enabled ? [...this.config.instrumentations] : [], this.plugins = [...this.config.enabled ? an(this.config) : [], ...this.sampled ? [...on(this.config), ...this.config.plugins] : []], this.pluginManager = new pe(this.plugins), this.config.autoStart && this.start().catch((e) => {
1933
+ resource: S,
1934
+ processors: [E]
1935
+ }), this.tracer = this.tracerProvider.getTracer(Hn), this.meter = this.meterProvider.getMeter(Hn), this.logger = this.loggerProvider.getLogger(Hn), this.runtimeContext = new Be({ "rum.sampled": this.sampled }, this.config.user), this.registeredInstrumentations = this.config.enabled ? [...this.config.instrumentations] : [], this.plugins = [...this.config.enabled ? Wn(this.config) : [], ...this.sampled ? [...Gn(this.config), ...this.config.plugins] : []], this.pluginManager = new ke(this.plugins), this.config.autoStart && this.start().catch((e) => {
1444
1936
  var t;
1445
1937
  (t = globalThis.console) == null || t.warn("[bk-ot] auto start failed:", e);
1446
1938
  });
1447
1939
  }
1448
1940
  };
1449
1941
  //#endregion
1450
- export { sn as BkOpenTelemetry, Ce as FilteringSpanProcessor, je as createBlankScreenPlugin, Fe as createCommonInstrumentationsPlugin, Be as createCspViolationPlugin, Xe as createDevicePlugin, tt as createErrorPlugin, mt as createHttpBodyPlugin, gt as createLongTaskPlugin, Ct as createPageViewPlugin, fe as createPlugin, wt as createRouteTimingPlugin, Lt as createSessionPlugin, Xt as createWebSocketPlugin, Ut as createWebVitalsPlugin, le as normalizeConfig };
1942
+ export { Kn as BkOpenTelemetry, ze as FilteringSpanProcessor, b as RUM_ATTRIBUTES, P as RUM_SPAN_RESULT, F as RUM_SPAN_TYPE, Be as RumRuntimeContext, I as buildRumSpanAttributes, Ze as createActionPlugin, at as createBlankScreenPlugin, pt as createCommonInstrumentationsPlugin, vt as createCspViolationPlugin, At as createDevicePlugin, Rt as createErrorPlugin, Zt as createHttpBodyPlugin, $t as createLongTaskPlugin, sn as createPageViewPlugin, Oe as createPlugin, ln as createResourcePlugin, un as createRouteTimingPlugin, Cn as createSessionPlugin, In as createWebSocketPlugin, kn as createWebVitalsPlugin, Ve as getDurationBucket, Te as resolveConfig };