@blueking/open-telemetry 0.0.13 → 0.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +170 -554
  2. package/dist/bk-rum.global.js +9 -9
  3. package/dist/bk-rum.global.js.map +1 -1
  4. package/dist/core/action-activity.d.ts +28 -0
  5. package/dist/core/config.d.ts +113 -93
  6. package/dist/core/page-activity.d.ts +14 -0
  7. package/dist/core/plugin.d.ts +23 -6
  8. package/dist/core/processor.d.ts +25 -4
  9. package/dist/core/request-timing.d.ts +5 -0
  10. package/dist/core/runtime-context.d.ts +51 -3
  11. package/dist/core/sampling.d.ts +5 -1
  12. package/dist/core/sdk.d.ts +29 -10
  13. package/dist/core/url.d.ts +4 -1
  14. package/dist/index.d.ts +12 -14
  15. package/dist/index.js +2184 -1175
  16. package/dist/index.js.map +1 -1
  17. package/dist/plugins/action.d.ts +6 -2
  18. package/dist/plugins/activity.d.ts +6 -0
  19. package/dist/plugins/blank-screen.d.ts +17 -0
  20. package/dist/plugins/common.d.ts +11 -3
  21. package/dist/plugins/device.d.ts +2 -0
  22. package/dist/plugins/long-task.d.ts +3 -12
  23. package/dist/plugins/page-view.d.ts +1 -0
  24. package/dist/plugins/request-body.d.ts +14 -0
  25. package/dist/plugins/resource.d.ts +17 -1
  26. package/dist/plugins/session-state.d.ts +18 -0
  27. package/dist/plugins/session.d.ts +4 -4
  28. package/dist/plugins/web-vitals.d.ts +74 -0
  29. package/dist/schema/attributes.d.ts +31 -10
  30. package/dist/schema/span.d.ts +4 -12
  31. package/package.json +3 -7
  32. package/skills/bk-rum-otele/SKILL.md +34 -33
  33. package/skills/bk-rum-otele/evals/evals.json +1 -1
  34. package/skills/bk-rum-otele/references/api.md +45 -13
  35. package/skills/bk-rum-otele/references/concepts.md +38 -112
  36. package/skills/bk-rum-otele/references/configuration.md +135 -228
  37. package/skills/bk-rum-otele/references/custom-plugin.md +8 -5
  38. package/skills/bk-rum-otele/references/data-model.md +13 -8
  39. package/skills/bk-rum-otele/references/framework-integration.md +25 -17
  40. package/skills/bk-rum-otele/references/getting-started.md +27 -87
  41. package/skills/bk-rum-otele/references/plugins.md +165 -99
  42. package/skills/bk-rum-otele/references/privacy.md +42 -33
  43. package/skills/bk-rum-otele/references/telemetry-reference.md +73 -44
  44. package/skills/bk-rum-otele/references/troubleshooting.md +72 -38
  45. package/dist/plugins/http-body.d.ts +0 -3
  46. package/dist/plugins/route-timing.d.ts +0 -2
package/dist/index.js CHANGED
@@ -1,38 +1,54 @@
1
- import { SpanKind as e, SpanStatusCode as t, context as n, metrics as r, propagation as i, trace as a } from "@opentelemetry/api";
2
- import { SeverityNumber as o, logs as s } from "@opentelemetry/api-logs";
3
- import { ZoneContextManager as c } from "@opentelemetry/context-zone";
4
- import { W3CTraceContextPropagator as l } from "@opentelemetry/core";
5
- import { OTLPLogExporter as u } from "@opentelemetry/exporter-logs-otlp-http";
6
- import { OTLPMetricExporter as d } from "@opentelemetry/exporter-metrics-otlp-http";
7
- import { OTLPTraceExporter as f } from "@opentelemetry/exporter-trace-otlp-http";
8
- import { registerInstrumentations as p } from "@opentelemetry/instrumentation";
9
- import { resourceFromAttributes as m } from "@opentelemetry/resources";
10
- import { BatchLogRecordProcessor as h, LoggerProvider as g } from "@opentelemetry/sdk-logs";
11
- import { MeterProvider as _, PeriodicExportingMetricReader as v } from "@opentelemetry/sdk-metrics";
12
- import { BatchSpanProcessor as y, ParentBasedSampler as b, SimpleSpanProcessor as ee, TraceIdRatioBasedSampler as te } from "@opentelemetry/sdk-trace-base";
13
- import { WebTracerProvider as ne } from "@opentelemetry/sdk-trace-web";
1
+ import { ExportResultCode as e, W3CTraceContextPropagator as t, hrTimeToMilliseconds as n, timeInputToHrTime as r } from "@opentelemetry/core";
2
+ import { AggregationTemporality as i, MeterProvider as a, PeriodicExportingMetricReader as o } from "@opentelemetry/sdk-metrics";
3
+ import { SpanKind as s, SpanStatusCode as c, context as l, propagation as u, trace as d } from "@opentelemetry/api";
4
+ import { ZoneContextManager as f } from "@opentelemetry/context-zone";
5
+ import { OTLPLogExporter as p } from "@opentelemetry/exporter-logs-otlp-http";
6
+ import { AggregationTemporalityPreference as m, OTLPMetricExporter as h } from "@opentelemetry/exporter-metrics-otlp-http";
7
+ import { OTLPTraceExporter as g } from "@opentelemetry/exporter-trace-otlp-http";
8
+ import { registerInstrumentations as _ } from "@opentelemetry/instrumentation";
9
+ import { resourceFromAttributes as v } from "@opentelemetry/resources";
10
+ import { BatchLogRecordProcessor as y, LoggerProvider as b } from "@opentelemetry/sdk-logs";
11
+ import { BatchSpanProcessor as x, SamplingDecision as S, SimpleSpanProcessor as C } from "@opentelemetry/sdk-trace-base";
12
+ import { WebTracerProvider as ee } from "@opentelemetry/sdk-trace-web";
13
+ import { SeverityNumber as w } from "@opentelemetry/api-logs";
14
14
  //#region src/schema/attributes.ts
15
- var x = {
15
+ var T = {
16
+ actionErrorCount: "action.error.count",
17
+ actionFrustrationCount: "action.frustration.count",
18
+ actionFrustrationType: "action.frustration.type",
19
+ actionId: "action.id",
20
+ actionLoadingTime: "action.loading_time",
21
+ actionLongTaskCount: "action.long_task.count",
22
+ actionName: "action.name",
23
+ actionResourceCount: "action.resource.count",
24
+ actionTargetName: "action.target.name",
25
+ actionTargetTag: "action.target.tag",
16
26
  actionType: "action.type",
17
27
  deploymentEnvironmentName: "deployment.environment.name",
18
- browserName: "browser_name",
19
- browserVersion: "browser_version",
20
- cacheHit: "cache_hit",
21
- deviceType: "device_type",
28
+ browserName: "browser.name",
29
+ browserVersion: "browser.version",
30
+ cacheHit: "resource.cache.hit",
31
+ deviceType: "device.type",
22
32
  durationBucket: "duration_bucket",
23
33
  errorType: "error_type",
24
34
  eventLabel: "event_label",
25
35
  exceptionFingerprint: "exception.fingerprint",
26
36
  exceptionMessageShort: "exception.message_short",
27
37
  exceptionStackTopFrame: "exception.stack_top_frame",
28
- longtaskAttributionScript: "longtask.attribution_script",
29
- longtaskBlockingDuration: "longtask.blocking_duration",
38
+ longTaskBlockingDuration: "long_task.blocking_duration",
39
+ longTaskCulprit: "long_task.culprit",
40
+ longTaskDuration: "long_task.duration",
41
+ longTaskEntryType: "long_task.entry_type",
42
+ longTaskId: "long_task.id",
43
+ longTaskIsFrozenFrame: "long_task.is_frozen_frame",
44
+ longTaskScriptCount: "long_task.script.count",
45
+ longTaskStartTime: "long_task.start_time",
30
46
  networkEffectiveType: "network.effective_type",
31
- nextHopProtocol: "next_hop_protocol",
47
+ nextHopProtocol: "resource.protocol",
32
48
  result: "result",
33
49
  serviceName: "service.name",
34
50
  serviceVersion: "service.version",
35
- osName: "os_name",
51
+ osName: "os.name",
36
52
  sessionHasReplay: "session.has_replay",
37
53
  sessionId: "session.id",
38
54
  sessionStartTime: "session.start_time",
@@ -42,8 +58,6 @@ var x = {
42
58
  targetDomain: "target_domain",
43
59
  targetLabel: "target_label",
44
60
  targetPathTemplate: "target_path_template",
45
- targetTag: "target.tag",
46
- targetTextShort: "target.text_short",
47
61
  targetValue: "target_value",
48
62
  traceScene: "trace_scene",
49
63
  transferSize: "transfer_size",
@@ -51,43 +65,50 @@ var x = {
51
65
  vitalMetric: "vital.metric",
52
66
  vitalRating: "vital.rating",
53
67
  vitalValue: "vital.value",
68
+ viewDomComplete: "view.dom_complete",
69
+ viewDomContentLoaded: "view.dom_content_loaded",
70
+ viewDomInteractive: "view.dom_interactive",
71
+ viewFirstByte: "view.first_byte",
54
72
  viewId: "view.id",
73
+ viewLoadEvent: "view.load_event",
74
+ viewLoadingTime: "view.loading_time",
55
75
  viewLoadingType: "view.loading_type",
76
+ viewName: "view.name",
56
77
  viewUrl: "view.url",
57
78
  viewUrlPathGroup: "view.url_path_group"
58
79
  };
59
80
  //#endregion
60
81
  //#region \0@oxc-project+runtime@0.128.0/helpers/typeof.js
61
- function S(e) {
82
+ function E(e) {
62
83
  "@babel/helpers - typeof";
63
- return S = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(e) {
84
+ return E = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(e) {
64
85
  return typeof e;
65
86
  } : function(e) {
66
87
  return e && typeof Symbol == "function" && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e;
67
- }, S(e);
88
+ }, E(e);
68
89
  }
69
90
  //#endregion
70
91
  //#region \0@oxc-project+runtime@0.128.0/helpers/toPrimitive.js
71
- function re(e, t) {
72
- if (S(e) != "object" || !e) return e;
92
+ function te(e, t) {
93
+ if (E(e) != "object" || !e) return e;
73
94
  var n = e[Symbol.toPrimitive];
74
95
  if (n !== void 0) {
75
96
  var r = n.call(e, t || "default");
76
- if (S(r) != "object") return r;
97
+ if (E(r) != "object") return r;
77
98
  throw TypeError("@@toPrimitive must return a primitive value.");
78
99
  }
79
100
  return (t === "string" ? String : Number)(e);
80
101
  }
81
102
  //#endregion
82
103
  //#region \0@oxc-project+runtime@0.128.0/helpers/toPropertyKey.js
83
- function C(e) {
84
- var t = re(e, "string");
85
- return S(t) == "symbol" ? t : t + "";
104
+ function ne(e) {
105
+ var t = te(e, "string");
106
+ return E(t) == "symbol" ? t : t + "";
86
107
  }
87
108
  //#endregion
88
109
  //#region \0@oxc-project+runtime@0.128.0/helpers/defineProperty.js
89
- function w(e, t, n) {
90
- return (t = C(t)) in e ? Object.defineProperty(e, t, {
110
+ function D(e, t, n) {
111
+ return (t = ne(t)) in e ? Object.defineProperty(e, t, {
91
112
  value: n,
92
113
  enumerable: !0,
93
114
  configurable: !0,
@@ -96,7 +117,7 @@ function w(e, t, n) {
96
117
  }
97
118
  //#endregion
98
119
  //#region \0@oxc-project+runtime@0.128.0/helpers/objectSpread2.js
99
- function T(e, t) {
120
+ function re(e, t) {
100
121
  var n = Object.keys(e);
101
122
  if (Object.getOwnPropertySymbols) {
102
123
  var r = Object.getOwnPropertySymbols(e);
@@ -106,12 +127,12 @@ function T(e, t) {
106
127
  }
107
128
  return n;
108
129
  }
109
- function E(e) {
130
+ function O(e) {
110
131
  for (var t = 1; t < arguments.length; t++) {
111
132
  var n = arguments[t] == null ? {} : arguments[t];
112
- t % 2 ? T(Object(n), !0).forEach(function(t) {
113
- w(e, t, n[t]);
114
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(n)) : T(Object(n)).forEach(function(t) {
133
+ t % 2 ? re(Object(n), !0).forEach(function(t) {
134
+ D(e, t, n[t]);
135
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(n)) : re(Object(n)).forEach(function(t) {
115
136
  Object.defineProperty(e, t, Object.getOwnPropertyDescriptor(n, t));
116
137
  });
117
138
  }
@@ -119,81 +140,130 @@ function E(e) {
119
140
  }
120
141
  //#endregion
121
142
  //#region src/core/config.ts
122
- var D = "http://localhost:4318", ie = 60 * 1e3, ae = "unknown_service", O = (e) => e.replace(/\/+$/, ""), oe = {
143
+ var ie = 60 * 1e3, ae = (e) => e.trim().replace(/\/+$/, ""), oe = {
123
144
  traces: "rum",
124
145
  metrics: "metrics",
125
146
  logs: "logs"
126
- }, se = (e, t) => `${O(e || D)}/${oe[t]}`, k = (e, t) => {
127
- var n, r, i, a, o;
128
- 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 ? E(E(E({}, 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;
147
+ }, se = (e, t) => `${ae(e == null ? "" : e)}/v1/${oe[t]}`, ce = (e, t) => {
148
+ var n, r, i;
149
+ let a = (n = e.signals) == null ? void 0 : n[t];
150
+ if (a === !1) return !1;
151
+ let o = a == null ? void 0 : a.endpoint, s = e.token || e.headers || a != null && a.headers ? O(O(O({}, e.token ? { Authorization: `Bearer ${e.token}` } : {}), (r = e.headers) == null ? {} : r), (i = a == null ? void 0 : a.headers) == null ? {} : i) : void 0;
129
152
  return {
130
- concurrencyLimit: s == null ? void 0 : s.concurrencyLimit,
131
- endpoint: c ? O(c) : se((o = s == null ? void 0 : s.endpoint) == null ? e == null ? void 0 : e.endpoint : o, t),
132
- headers: l,
133
- timeoutMillis: s == null ? void 0 : s.timeoutMillis
153
+ concurrencyLimit: a == null ? void 0 : a.concurrencyLimit,
154
+ endpoint: o ? ae(o) : se(e.endpoint, t),
155
+ headers: s,
156
+ timeoutMillis: a == null ? void 0 : a.timeoutMillis
134
157
  };
135
- }, ce = (e) => typeof e != "number" || !Number.isFinite(e) ? 1 : Math.max(0, Math.min(1, e)), le = (e) => e, ue = (e) => e, de = (e) => {
158
+ }, le = (e) => typeof e != "number" || !Number.isFinite(e) ? 1 : Math.max(0, Math.min(1, e)), ue = (e) => e, de = (e) => {
159
+ try {
160
+ let t = new URL(e, typeof location > "u" ? "http://localhost" : location.href);
161
+ return t.username = "", t.password = "", t.search = "", t.hash = "", t.href;
162
+ } catch (t) {
163
+ return e.replace(/[?#].*$/, "");
164
+ }
165
+ }, fe = (e) => {
136
166
  try {
137
167
  return new URL(e, typeof location > "u" ? "http://localhost" : location.href).pathname || "/";
138
168
  } catch (t) {
139
169
  return e || "/";
140
170
  }
141
- }, fe = (e) => {
142
- var t, n;
171
+ }, pe = (e) => {
172
+ var t;
143
173
  return {
144
- environment: (t = e == null ? void 0 : e.environment) == null ? "production" : t,
145
- name: (n = e == null ? void 0 : e.name) == null ? ae : n,
146
- version: e == null ? void 0 : e.version
174
+ environment: (t = e.environment) == null ? "production" : t,
175
+ name: e.name,
176
+ version: e.version
147
177
  };
148
- }, pe = (e) => E(E({
149
- [x.deploymentEnvironmentName]: e.environment,
178
+ }, me = (e) => O(O({
179
+ [T.deploymentEnvironmentName]: e.environment,
150
180
  "rum.provider": "blueking",
151
- [x.serviceName]: e.name
152
- }, e.version ? { [x.serviceVersion]: e.version } : {}), {}, { "telemetry.sdk.language": "webjs" }), me = (e) => ({
153
- endpoint: O((e == null ? void 0 : e.endpoint) || D),
154
- traces: k(e, "traces"),
155
- metrics: k(e, "metrics"),
156
- logs: k(e, "logs")
157
- }), he = (e) => ({ rate: ce(e == null ? void 0 : e.rate) }), ge = (e) => {
158
- var t, n, r, i, a, o, s, c, l, u, d, f;
181
+ "rum.schema.version": "1",
182
+ [T.serviceName]: e.name
183
+ }, e.version ? { [T.serviceVersion]: e.version } : {}), {}, {
184
+ "telemetry.sdk.language": "webjs",
185
+ "telemetry.sdk.name": "@blueking/open-telemetry"
186
+ }), he = (e) => {
187
+ var t, n;
188
+ let r = ce(e, "traces"), i = ce(e, "metrics"), a = ce(e, "logs");
189
+ return {
190
+ endpoint: ae((t = e.endpoint) == null ? "" : t) || ((n = [
191
+ r,
192
+ i,
193
+ a
194
+ ].find((e) => e !== !1)) == null ? void 0 : n.endpoint) || "",
195
+ traces: r,
196
+ metrics: i,
197
+ logs: a
198
+ };
199
+ }, ge = (e) => {
200
+ if (!e) throw Error("[bk-ot] transport is required.");
201
+ let t = [
202
+ "traces",
203
+ "metrics",
204
+ "logs"
205
+ ].filter((t) => {
206
+ var n;
207
+ return ((n = e.signals) == null ? void 0 : n[t]) !== !1;
208
+ });
209
+ if (!t.length) throw Error("[bk-ot] at least one transport signal must be enabled.");
210
+ for (let i of t) {
211
+ var n, r;
212
+ let t = (n = e.signals) == null ? void 0 : n[i], a = t ? t.endpoint : void 0;
213
+ if (!(a != null && a.trim()) && !((r = e.endpoint) != null && r.trim())) throw Error(`[bk-ot] transport.signals.${i}.endpoint or transport.endpoint is required.`);
214
+ }
215
+ }, _e = (e) => {
216
+ var t, n, r, i, a, o, s, c, l, u, d, f, p;
159
217
  return {
160
- getPageAttributes: (t = (n = e.attributes) == null ? void 0 : n.page) == null ? (() => ({
218
+ beforeSend: (t = e.tracking) == null ? void 0 : t.beforeSend,
219
+ getPageAttributes: (n = (r = e.context) == null || (r = r.attributes) == null ? void 0 : r.page) == null ? (() => ({
161
220
  "rum.page.host": typeof window > "u" ? "" : window.location.host,
162
221
  "rum.page.path": typeof window > "u" ? "" : window.location.pathname
163
- })) : t,
164
- getMetricAttributes: (r = (i = e.attributes) == null ? void 0 : i.metric) == null ? (() => ({})) : r,
165
- getErrorAttributes: (a = (o = e.attributes) == null ? void 0 : o.error) == null ? (() => ({})) : a,
166
- getCustomAttributes: (s = (c = e.attributes) == null ? void 0 : c.custom) == null ? (() => ({})) : s,
222
+ })) : n,
223
+ getMetricAttributes: (i = (a = e.context) == null || (a = a.attributes) == null ? void 0 : a.metric) == null ? (() => ({})) : i,
224
+ getErrorAttributes: (o = (s = e.context) == null || (s = s.attributes) == null ? void 0 : s.error) == null ? (() => ({})) : o,
225
+ getCustomAttributes: (c = (l = e.context) == null || (l = l.attributes) == null ? void 0 : l.custom) == null ? (() => ({})) : c,
167
226
  getViewPathGroup: (t) => {
168
- var n, r, i;
169
- return (n = (r = e.route) == null || (i = r.getPathGroup) == null ? void 0 : i.call(r, t)) == null ? de(t) : n;
227
+ var n, r, i, a;
228
+ return (n = typeof ((r = e.tracking) == null ? void 0 : r.view) == "object" ? (i = (a = e.tracking.view).getPathGroup) == null ? void 0 : i.call(a, t) : void 0) == null ? fe(t) : n;
170
229
  },
171
- redactAttributes: (l = (u = e.privacy) == null ? void 0 : u.redactAttributes) == null ? le : l,
172
- redactUrl: (d = (f = e.privacy) == null ? void 0 : f.redactUrl) == null ? ue : d
230
+ redactAttributes: (u = (d = e.privacy) == null ? void 0 : d.redactAttributes) == null ? ue : u,
231
+ redactUrl: (f = (p = e.privacy) == null ? void 0 : p.redactUrl) == null ? de : f
173
232
  };
174
- }, _e = (e) => {
175
- var t, n, r, i, a, o;
176
- let s = fe(e.app);
233
+ }, ve = (e) => {
234
+ var t, n, r, i, a, o, s, c, l, u, d, f, p, m, h, g, _, v;
235
+ if (!(!((t = e.application) == null || (t = t.name) == null) && t.trim())) throw Error("[bk-ot] application.name is required.");
236
+ ge(e.transport);
237
+ let y = pe(e.application), b = typeof ((n = e.tracking) == null ? void 0 : n.view) == "object" ? e.tracking.view : void 0, x = (r = e.transport.signals) == null ? void 0 : r.traces, S = (i = e.transport.signals) == null ? void 0 : i.metrics;
177
238
  return {
178
- app: s,
179
- autoStart: (t = e.autoStart) == null ? !0 : t,
180
- debug: (n = e.debug) == null ? !1 : n,
181
- enabled: (r = e.enabled) == null ? !0 : r,
182
- hooks: ge(e),
183
- instrumentations: (i = e.instrumentations) == null ? {} : i,
184
- metricIntervalMillis: ie,
185
- plugins: (a = e.plugins) == null ? {} : a,
186
- resourceAttributes: pe(s),
187
- sampling: he(e.sampling),
188
- spanBatch: e.spanBatch,
189
- spanProcessor: (o = e.spanProcessor) == null ? "batch" : o,
190
- transport: me(e.transport),
191
- user: e.user
239
+ application: y,
240
+ autoStart: (a = e.autoStart) == null ? !0 : a,
241
+ debug: (o = e.debug) == null ? !1 : o,
242
+ enabled: (s = e.enabled) == null ? !0 : s,
243
+ extensions: {
244
+ instrumentations: [...(c = (l = e.extensions) == null ? void 0 : l.instrumentations) == null ? [] : c],
245
+ plugins: [...(u = (d = e.extensions) == null ? void 0 : d.plugins) == null ? [] : u]
246
+ },
247
+ hooks: _e(e),
248
+ metricIntervalMillis: S ? (f = S.intervalMillis) == null ? ie : f : ie,
249
+ resourceAttributes: me(y),
250
+ session: O(O({}, e.session), {}, { sampleRate: le((p = e.session) == null ? void 0 : p.sampleRate) }),
251
+ spanBatch: x ? x.batch : void 0,
252
+ spanProcessor: x ? (m = x.processor) == null ? "batch" : m : "batch",
253
+ tracking: (h = e.tracking) == null ? {} : h,
254
+ trackingConsent: (g = (_ = e.privacy) == null ? void 0 : _.trackingConsent) == null ? "granted" : g,
255
+ transport: he(e.transport),
256
+ user: (v = e.context) == null ? void 0 : v.user,
257
+ view: {
258
+ excludedActivityUrls: b == null ? void 0 : b.excludedActivityUrls,
259
+ loadingTime: (b == null ? void 0 : b.loadingTime) !== !1,
260
+ tracking: (b == null ? void 0 : b.tracking) === "manual" ? "manual" : "auto"
261
+ }
192
262
  };
193
263
  };
194
264
  //#endregion
195
265
  //#region \0@oxc-project+runtime@0.128.0/helpers/asyncToGenerator.js
196
- function ve(e, t, n, r, i, a, o) {
266
+ function ye(e, t, n, r, i, a, o) {
197
267
  try {
198
268
  var s = e[a](o), c = s.value;
199
269
  } catch (e) {
@@ -202,16 +272,16 @@ function ve(e, t, n, r, i, a, o) {
202
272
  }
203
273
  s.done ? t(c) : Promise.resolve(c).then(r, i);
204
274
  }
205
- function A(e) {
275
+ function k(e) {
206
276
  return function() {
207
277
  var t = this, n = arguments;
208
278
  return new Promise(function(r, i) {
209
279
  var a = e.apply(t, n);
210
280
  function o(e) {
211
- ve(a, r, i, o, s, "next", e);
281
+ ye(a, r, i, o, s, "next", e);
212
282
  }
213
283
  function s(e) {
214
- ve(a, r, i, o, s, "throw", e);
284
+ ye(a, r, i, o, s, "throw", e);
215
285
  }
216
286
  o(void 0);
217
287
  });
@@ -219,13 +289,13 @@ function A(e) {
219
289
  }
220
290
  //#endregion
221
291
  //#region src/core/plugin.ts
222
- var ye = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !== !1, be = (e) => e, xe = class {
292
+ var be = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !== !1, xe = (e) => e, Se = class {
223
293
  constructor(e) {
224
- w(this, "plugins", void 0), w(this, "startedPlugins", []), this.plugins = e;
294
+ D(this, "plugins", void 0), D(this, "startedPlugins", []), this.plugins = e;
225
295
  }
226
296
  flush() {
227
297
  var e = this;
228
- return A(function* () {
298
+ return k(function* () {
229
299
  yield Promise.all(e.startedPlugins.map((e) => Promise.resolve().then(() => {
230
300
  var t;
231
301
  return (t = e.flush) == null ? void 0 : t.call(e);
@@ -234,7 +304,7 @@ var ye = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
234
304
  }
235
305
  shutdown() {
236
306
  var e = this;
237
- return A(function* () {
307
+ return k(function* () {
238
308
  let t = [...e.startedPlugins].reverse();
239
309
  for (let e of t) {
240
310
  var n;
@@ -245,8 +315,8 @@ var ye = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
245
315
  }
246
316
  start(e) {
247
317
  var t = this;
248
- return A(function* () {
249
- for (let r of t.plugins) if (ye(r, e.config)) try {
318
+ return k(function* () {
319
+ for (let r of t.plugins) if (be(r, e.config)) try {
250
320
  yield r.init(e), t.startedPlugins.push(r);
251
321
  } catch (t) {
252
322
  if (e.config.debug) {
@@ -256,64 +326,207 @@ var ye = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
256
326
  }
257
327
  })();
258
328
  }
259
- }, Se = () => typeof window > "u" ? "http://localhost" : window.location.origin, j = (e) => {
329
+ }, A = "bk.rum.sampled", Ce = (e) => {
330
+ let t = 2166136261;
331
+ for (let n = 0; n < e.length; n += 1) t = Math.imul(t ^ e.charCodeAt(n), 16777619);
332
+ return t += t << 13, t ^= t >>> 7, t += t << 3, t ^= t >>> 17, t += t << 5, (t >>> 0) / 4294967296;
333
+ }, we = ({ application: e, session: t }, n) => t.sampleRate <= 0 ? !1 : t.sampleRate >= 1 ? !0 : Ce(`${e.name}\0${n}`) < t.sampleRate, Te = () => typeof window > "u" ? "http://localhost" : window.location.origin, j = (e) => {
260
334
  try {
261
- return new URL(e, Se()).href;
335
+ return new URL(e, Te()).href;
262
336
  } catch (t) {
263
337
  return e;
264
338
  }
265
- }, Ce = (e) => e.length > 1 ? e.replace(/\/+$/, "") : e, we = (e, t) => {
266
- let n = (e) => Ce(e.replace(/[?#].*$/, ""));
339
+ }, Ee = (e) => e.length > 1 ? e.replace(/\/+$/, "") : e, De = (e, t) => {
340
+ let n = (e) => Ee(e.replace(/[?#].*$/, ""));
267
341
  return n(e) === n(t);
268
- }, Te = (e) => {
269
- try {
270
- return new URL(e, Se()).origin === Se();
271
- } catch (e) {
272
- return !1;
273
- }
274
- }, Ee = (e, t) => {
342
+ }, Oe = (e, t) => {
275
343
  let n = j(t);
276
344
  return [
277
- e.transport.traces.endpoint,
278
- e.transport.metrics.endpoint,
279
- e.transport.logs.endpoint
280
- ].some((e) => we(n, j(e)));
281
- }, M = (e, t) => Ee(e, t), De = (e, t) => e === "all" ? !0 : typeof e == "function" ? e(t) : (Array.isArray(e) ? e : [e]).some((e) => typeof e == "string" ? t.includes(e) : e.test(t)), Oe = (e, t) => {
282
- if (Te(t)) return !0;
283
- let n = e.instrumentations.propagateTraceHeaderUrls;
284
- return n ? De(n, j(t)) : !1;
285
- }, ke = ["http.url", "url.full"], Ae = (e) => {
286
- for (let n of ke) {
345
+ e.transport.traces,
346
+ e.transport.metrics,
347
+ e.transport.logs
348
+ ].filter((e) => e !== !1).some((e) => De(n, j(e.endpoint)));
349
+ }, ke = (e, t) => Oe(e, t), Ae = (e, t) => typeof e == "function" ? e(t) : typeof e == "string" ? t.includes(e) : (e.lastIndex = 0, e.test(t)), M = (e, t) => (Array.isArray(e) ? e : e ? [e] : []).some((e) => Ae(e, t)), je = (e) => typeof e.tracking.request == "object" ? e.tracking.request : void 0, Me = (e, t) => {
350
+ var n;
351
+ return ke(e, t) || M((n = je(e)) == null ? void 0 : n.excludedUrls, j(t));
352
+ }, Ne = (e, t) => {
353
+ var n;
354
+ return e.transport.traces !== !1 && M((n = je(e)) == null ? void 0 : n.allowedTracingUrls, j(t));
355
+ };
356
+ //#endregion
357
+ //#region \0@oxc-project+runtime@0.128.0/helpers/objectWithoutPropertiesLoose.js
358
+ function Pe(e, t) {
359
+ if (e == null) return {};
360
+ var n = {};
361
+ for (var r in e) if ({}.hasOwnProperty.call(e, r)) {
362
+ if (t.includes(r)) continue;
363
+ n[r] = e[r];
364
+ }
365
+ return n;
366
+ }
367
+ //#endregion
368
+ //#region \0@oxc-project+runtime@0.128.0/helpers/objectWithoutProperties.js
369
+ function Fe(e, t) {
370
+ if (e == null) return {};
371
+ var n, r, i = Pe(e, t);
372
+ if (Object.getOwnPropertySymbols) {
373
+ var a = Object.getOwnPropertySymbols(e);
374
+ for (r = 0; r < a.length; r++) n = a[r], t.includes(n) || {}.propertyIsEnumerable.call(e, n) && (i[n] = e[n]);
375
+ }
376
+ return i;
377
+ }
378
+ //#endregion
379
+ //#region src/core/processor.ts
380
+ var Ie = ["http.url", "url.full"], Le = "bk.rum.request.discard", Re = (e) => {
381
+ for (let n of Ie) {
287
382
  var t;
288
383
  let r = (t = e.attributes) == null ? void 0 : t[n];
289
384
  if (typeof r == "string") return r;
290
385
  }
291
- }, je = class {
386
+ }, ze = (e) => {
387
+ let t = e == null ? void 0 : e[T.sessionId];
388
+ return typeof t == "string" && t.length > 0;
389
+ }, Be = (e) => {
390
+ let t = e == null ? void 0 : e[T.viewId];
391
+ return typeof t == "string" && t.length > 0;
392
+ }, Ve = (e) => (e == null ? void 0 : e["bk.rum.sampled"]) === !0 && ze(e) && Be(e), He = class {
292
393
  constructor(e, t) {
293
394
  this.inner = e, this.config = t;
294
395
  }
396
+ enabled(e) {
397
+ var t, n, r;
398
+ return (t = (n = (r = this.inner).enabled) == null ? void 0 : n.call(r, e)) == null ? !0 : t;
399
+ }
400
+ forceFlush() {
401
+ return this.inner.forceFlush();
402
+ }
403
+ onEmit(e, t) {
404
+ var n;
405
+ let r = e.body === "session.start" || e.body === "session.rotate";
406
+ if (Ve(e.attributes) || r && ((n = e.attributes) == null ? void 0 : n["bk.rum.sampled"]) === !0 && ze(e.attributes)) {
407
+ delete e.attributes[A];
408
+ try {
409
+ var i, a, o, s, c;
410
+ if (((i = this.config) == null || (o = (a = i.hooks).beforeSend) == null ? void 0 : o.call(a, {
411
+ attributes: e.attributes,
412
+ name: (s = e.eventName) == null ? String((c = e.body) == null ? "" : c) : s,
413
+ signal: "log"
414
+ })) === !1) return;
415
+ } catch (e) {
416
+ var l, u;
417
+ (l = this.config) != null && l.debug && ((u = globalThis.console) == null || u.warn("[bk-ot] tracking.beforeSend failed:", e));
418
+ }
419
+ this.inner.onEmit(e, t);
420
+ }
421
+ }
422
+ shutdown() {
423
+ return this.inner.shutdown();
424
+ }
425
+ }, Ue = class {
426
+ constructor(e, t, n) {
427
+ this.inner = e, this.config = t, this.getRuntimeAttributes = n;
428
+ }
295
429
  forceFlush() {
296
430
  return this.inner.forceFlush();
297
431
  }
298
432
  onEnd(e) {
299
- let t = Ae(e);
300
- t && Ee(this.config, t) || this.inner.onEnd(e);
433
+ let t = Re(e);
434
+ if (!(e.attributes["bk.rum.request.discard"] === !0 || t && Oe(this.config, t) || !Ve(e.attributes))) {
435
+ delete e.attributes[A];
436
+ try {
437
+ var n, r;
438
+ if (((n = this.config.hooks) == null || (r = n.beforeSend) == null ? void 0 : r.call(n, {
439
+ attributes: e.attributes,
440
+ name: e.name,
441
+ signal: "span"
442
+ })) === !1) return;
443
+ } catch (e) {
444
+ var i;
445
+ this.config.debug && ((i = globalThis.console) == null || i.warn("[bk-ot] tracking.beforeSend failed:", e));
446
+ }
447
+ this.inner.onEnd(e);
448
+ }
301
449
  }
302
450
  onStart(e, t) {
303
- this.inner.onStart(e, t);
451
+ var n;
452
+ let r = (n = e.attributes) == null ? {} : n, i = {};
453
+ for (let [e, t] of Object.entries(this.getRuntimeAttributes())) r[e] === void 0 && t !== void 0 && (i[e] = t);
454
+ e.setAttributes(i), this.inner.onStart(e, t);
304
455
  }
305
456
  shutdown() {
306
457
  return this.inner.shutdown();
307
458
  }
308
- }, Me = class {
459
+ }, We = (e) => O(O({}, e), {}, { dataPoints: e.dataPoints.filter((e) => e.attributes[A] === !0).map((e) => {
460
+ let t = e.attributes, { [A]: n } = t, r = Fe(t, [A].map(ne));
461
+ return O(O({}, e), {}, { attributes: r });
462
+ }) }), Ge = class {
463
+ constructor(e) {
464
+ this.inner = e;
465
+ }
466
+ export(t, n) {
467
+ let r = O(O({}, t), {}, { scopeMetrics: t.scopeMetrics.map((e) => O(O({}, e), {}, { metrics: e.metrics.map(We).filter((e) => e.dataPoints.length > 0) })).filter((e) => e.metrics.length > 0) });
468
+ if (r.scopeMetrics.length === 0) {
469
+ n({ code: e.SUCCESS });
470
+ return;
471
+ }
472
+ this.inner.export(r, n);
473
+ }
474
+ forceFlush() {
475
+ return this.inner.forceFlush();
476
+ }
477
+ selectAggregationTemporality(e) {
478
+ var t, n, r;
479
+ return (t = (n = (r = this.inner).selectAggregationTemporality) == null ? void 0 : n.call(r, e)) == null ? i.CUMULATIVE : t;
480
+ }
481
+ shutdown() {
482
+ return this.inner.shutdown();
483
+ }
484
+ }, Ke = new Set([...Object.values(T), A]), qe = class {
309
485
  constructor(e = {}, t) {
310
- w(this, "attributes", {}), w(this, "setOptionalAttribute", (e, t) => {
486
+ D(this, "actionHistory", []), D(this, "attributes", {}), D(this, "queuedViewCommands", []), D(this, "recordAssociation", (e, t, n, r) => {
487
+ let i = e.at(-1);
488
+ if (i && i.endedAt === void 0 && (i.endedAt = Math.max(i.startedAt, n)), r) {
489
+ let r = {};
490
+ for (let e of t) {
491
+ let t = this.attributes[e];
492
+ t !== void 0 && (r[e] = t);
493
+ }
494
+ e.push({
495
+ attributes: r,
496
+ startedAt: n
497
+ });
498
+ }
499
+ e.length > 100 && e.splice(0, e.length - 100);
500
+ }), D(this, "sessionHistory", []), D(this, "sessionLifecycleListeners", /* @__PURE__ */ new Set()), D(this, "setOptionalAttribute", (e, t) => {
311
501
  if (t === void 0) {
312
502
  delete this.attributes[e];
313
503
  return;
314
504
  }
315
505
  this.attributes[e] = t;
316
- }), w(this, "user", {}), w(this, "view", {}), w(this, "getAttributes", () => E({}, this.attributes)), w(this, "getUser", () => E({}, this.user)), w(this, "getView", () => E({}, this.view)), w(this, "setAttributes", (e) => {
506
+ }), D(this, "user", {}), D(this, "view", {}), D(this, "viewAttributeKeys", /* @__PURE__ */ new Set()), D(this, "viewChangeListeners", /* @__PURE__ */ new Set()), D(this, "viewCommandListeners", /* @__PURE__ */ new Set()), D(this, "viewHistory", []), D(this, "viewScopedAttributeKeys", /* @__PURE__ */ new Set()), D(this, "dispatchViewCommand", (e) => {
507
+ if (this.viewCommandListeners.size === 0) {
508
+ this.queuedViewCommands.push(e);
509
+ return;
510
+ }
511
+ this.viewCommandListeners.forEach((t) => t(e));
512
+ }), D(this, "getAttributes", () => O({}, this.attributes)), D(this, "getAttributesAt", (e) => {
513
+ if (!Number.isFinite(e)) return this.getAttributes();
514
+ let t = this.getAttributes(), n = (n, r) => {
515
+ for (let e of r) delete t[e];
516
+ let i = [...n].reverse().find((t) => t.startedAt <= e && (t.endedAt === void 0 || e < t.endedAt));
517
+ i && Object.assign(t, i.attributes);
518
+ };
519
+ return n(this.sessionHistory, [
520
+ T.sessionId,
521
+ T.sessionHasReplay,
522
+ A
523
+ ]), n(this.viewHistory, this.viewScopedAttributeKeys), n(this.actionHistory, [T.actionId]), t;
524
+ }), D(this, "getUser", () => O({}, this.user)), D(this, "getView", () => O({}, this.view)), D(this, "isSessionActive", () => typeof this.attributes[T.sessionId] == "string"), D(this, "isViewActive", () => typeof this.attributes[T.viewId] == "string"), D(this, "notifySessionLifecycle", (e) => {
525
+ this.sessionLifecycleListeners.forEach((t) => t(e));
526
+ }), D(this, "onSessionLifecycle", (e) => (this.sessionLifecycleListeners.add(e), () => this.sessionLifecycleListeners.delete(e))), D(this, "onViewChange", (e) => (this.viewChangeListeners.add(e), this.view.id && e(this.getView()), () => this.viewChangeListeners.delete(e))), D(this, "onViewCommand", (e) => {
527
+ for (this.viewCommandListeners.add(e); this.queuedViewCommands.length;) e(this.queuedViewCommands.shift());
528
+ return () => this.viewCommandListeners.delete(e);
529
+ }), D(this, "setAttributes", (e, t = Date.now()) => {
317
530
  for (let [t, n] of Object.entries(e)) {
318
531
  if (n === void 0) {
319
532
  delete this.attributes[t];
@@ -321,35 +534,52 @@ var ye = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
321
534
  }
322
535
  this.attributes[t] = n;
323
536
  }
324
- }), w(this, "setUser", (e) => {
325
- if (this.user = E(E({}, this.user), e), "id" in e) {
537
+ if (T.sessionId in e && this.recordAssociation(this.sessionHistory, [
538
+ T.sessionId,
539
+ T.sessionHasReplay,
540
+ A
541
+ ], t, typeof this.attributes[T.sessionId] == "string"), T.actionId in e) {
542
+ let e = this.attributes[T.actionId];
543
+ this.recordAssociation(this.actionHistory, [T.actionId], t, Array.isArray(e) ? e.length > 0 : typeof e == "string");
544
+ }
545
+ }), D(this, "setUser", (e) => {
546
+ if (this.user = O(O({}, this.user), e), "id" in e) {
326
547
  if (e.id === void 0) {
327
- delete this.attributes[x.userId];
548
+ delete this.attributes[T.userId];
328
549
  return;
329
550
  }
330
- this.attributes[x.userId] = e.id;
551
+ this.attributes[T.userId] = e.id;
331
552
  }
332
- }), w(this, "setView", (e) => {
333
- this.view = E(E({}, this.view), e), this.setOptionalAttribute(x.viewId, e.id), this.setOptionalAttribute(x.viewUrl, e.url), this.setOptionalAttribute(x.viewUrlPathGroup, e.urlPathGroup), this.setOptionalAttribute(x.viewLoadingType, e.loadingType);
553
+ }), D(this, "setView", (e, t = ((t) => (t = e.startedAt) == null ? Date.now() : t)()) => {
554
+ var n;
555
+ this.viewAttributeKeys.forEach((e) => delete this.attributes[e]), this.viewAttributeKeys.clear();
556
+ let r = {};
557
+ for (let [t, i] of Object.entries((n = e.attributes) == null ? {} : n)) i === void 0 || Ke.has(t) || (r[t] = i, this.attributes[t] = i, this.viewAttributeKeys.add(t), this.viewScopedAttributeKeys.add(t));
558
+ this.view = O(O({}, e), {}, { attributes: r }), this.setOptionalAttribute(T.viewId, e.id), this.setOptionalAttribute(T.viewUrl, e.url), this.setOptionalAttribute(T.viewUrlPathGroup, e.urlPathGroup), this.setOptionalAttribute(T.viewLoadingType, e.loadingType), this.setOptionalAttribute(T.viewName, e.name), [
559
+ T.viewId,
560
+ T.viewUrl,
561
+ T.viewUrlPathGroup,
562
+ T.viewLoadingType,
563
+ T.viewName
564
+ ].forEach((e) => this.viewScopedAttributeKeys.add(e)), this.recordAssociation(this.viewHistory, this.viewScopedAttributeKeys, t, typeof e.id == "string" && e.id.length > 0), this.viewChangeListeners.forEach((e) => e(this.getView()));
334
565
  }), this.setAttributes(e), t && this.setUser(t);
335
566
  }
336
- }, N = {
567
+ }, N = (e) => typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : `${e}-${Date.now()}-${Math.random().toString(16).slice(2)}`, P = {
337
568
  abort: "abort",
338
569
  error: "error",
339
570
  success: "success",
340
571
  timeout: "timeout",
341
572
  warning: "warning"
342
- }, P = {
573
+ }, F = {
343
574
  action: "action",
344
575
  custom: "custom",
345
576
  document: "document",
346
577
  error: "error",
347
- http: "http",
348
578
  longtask: "longtask",
349
579
  resource: "resource",
350
580
  route: "route",
351
581
  vital: "vital"
352
- }, Ne = (e) => e < 100 ? "<100ms" : e < 500 ? "100~500ms" : e < 2e3 ? "500ms~2s" : ">2s", Pe = (e) => `${Math.trunc(e / 100)}xx`, Fe = (e) => e === 408 || e === 504 ? N.timeout : typeof e == "number" && e >= 400 ? N.error : N.success, Ie = (e) => e === 408 || e === 504 ? "network_timeout" : typeof e != "number" || e < 400 ? "none" : e >= 500 ? "http_5xx" : "http_4xx", Le = (e) => e === "good" ? N.success : N.warning, Re = (e, t) => {
582
+ }, Je = (e) => e < 100 ? "<100ms" : e < 500 ? "100~500ms" : e < 2e3 ? "500ms~2s" : ">2s", Ye = (e) => `${Math.trunc(e / 100)}xx`, Xe = (e) => e === 408 || e === 504 ? P.timeout : typeof e == "number" && e >= 400 ? P.error : P.success, Ze = (e) => e === 408 || e === 504 ? "network_timeout" : typeof e != "number" || e < 400 ? "none" : e >= 500 ? "http_5xx" : "http_4xx", Qe = (e) => e === "good" ? P.success : P.warning, $e = (e, t) => {
353
583
  if (!e) return {};
354
584
  try {
355
585
  let n = new URL(e, typeof location > "u" ? "http://localhost" : location.href), r = t == null ? n.pathname : t;
@@ -364,114 +594,371 @@ var ye = (e, t) => typeof e.enabled == "function" ? e.enabled(t) : e.enabled !==
364
594
  pathTemplate: t == null ? e : t
365
595
  };
366
596
  }
367
- }, F = ({ duration: e, errorType: t = "none", eventLabel: n, result: r = N.success, spanSubtype: i, spanType: a, targetLabel: o, targetValue: s, traceScene: c }) => E(E(E(E(E({
368
- [x.spanType]: a,
369
- [x.spanSubtype]: i,
370
- [x.result]: r,
371
- [x.errorType]: t
372
- }, e === void 0 ? {} : { [x.durationBucket]: Ne(e) }), n === void 0 ? {} : { [x.eventLabel]: n }), o === void 0 ? {} : { [x.targetLabel]: o }), s === void 0 ? {} : { [x.targetValue]: s }), c === void 0 ? {} : { [x.traceScene]: c }), ze = ({ duration: e, method: t, statusCode: n, subtype: r, url: i, urlPathTemplate: a }) => {
373
- let o = Re(i, a);
374
- return E(E(E(E(E({}, F({
375
- duration: e,
376
- errorType: Ie(n),
377
- eventLabel: "API 调用",
378
- result: Fe(n),
379
- spanSubtype: r,
380
- spanType: P.http,
381
- targetLabel: o.label,
382
- targetValue: n
383
- })), t ? { "http.request.method": t.toUpperCase() } : {}), o.domain ? { [x.targetDomain]: o.domain } : {}), o.pathTemplate ? { [x.targetPathTemplate]: o.pathTemplate } : {}), typeof n == "number" ? {
384
- "http.response.status_code": n,
385
- [x.statusClass]: Pe(n)
386
- } : {});
387
- }, Be = ({ duration: e, initiatorType: t = "other", responseStatus: n, transferSize: r, url: i, urlPathTemplate: a }) => {
388
- var o;
389
- let s = Re(i, a), c = typeof n == "number" ? Fe(n) : N.success;
390
- return E(E(E(E({}, F({
597
+ }, I = ({ duration: e, errorType: t = "none", eventLabel: n, result: r = P.success, spanSubtype: i, spanType: a, targetLabel: o, targetValue: s, traceScene: c }) => O(O(O(O(O({
598
+ [T.spanType]: a,
599
+ [T.spanSubtype]: i,
600
+ [T.result]: r,
601
+ [T.errorType]: t
602
+ }, e === void 0 ? {} : { [T.durationBucket]: Je(e) }), n === void 0 ? {} : { [T.eventLabel]: n }), o === void 0 ? {} : { [T.targetLabel]: o }), s === void 0 ? {} : { [T.targetValue]: s }), c === void 0 ? {} : { [T.traceScene]: c }), et = ({ duration: e, initiatorType: t = "other", method: n, networkError: r = !1, responseStatus: i, transferSize: a, url: o, urlPathTemplate: s }) => {
603
+ var c;
604
+ let l = $e(o, s), u = t === "fetch" || t === "xhr", d = r ? P.error : typeof i == "number" ? Xe(i) : P.success, f = n == null ? void 0 : n.toUpperCase();
605
+ return O(O(O(O(O(O(O({}, I({
391
606
  duration: e,
392
- errorType: typeof n == "number" ? Ie(n) : "none",
393
- eventLabel: "静态资源",
394
- result: c,
607
+ errorType: r ? "network" : typeof i == "number" ? Ze(i) : "none",
608
+ eventLabel: u ? "请求资源" : "静态资源",
609
+ result: d,
395
610
  spanSubtype: t,
396
- spanType: P.resource,
397
- targetLabel: (o = s.label) == null ? i : o,
398
- targetValue: r
399
- })), s.domain ? { [x.targetDomain]: s.domain } : {}), s.pathTemplate ? { [x.targetPathTemplate]: s.pathTemplate } : {}), typeof n == "number" ? {
400
- "http.response.status_code": n,
401
- [x.statusClass]: Pe(n)
402
- } : {});
403
- }, Ve = [
404
- "click",
405
- "submit",
406
- "keydown"
407
- ], He = (e) => e instanceof Element ? e : void 0, Ue = (e) => {
611
+ spanType: F.resource,
612
+ targetLabel: (c = l.label) == null ? o : c,
613
+ targetValue: u ? i : a
614
+ })), l.domain ? { [T.targetDomain]: l.domain } : {}), l.pathTemplate ? { [T.targetPathTemplate]: l.pathTemplate } : {}), {}, {
615
+ "resource.type": t,
616
+ "resource.url": o
617
+ }, e === void 0 ? {} : { "resource.duration": e }), f ? {
618
+ "http.request.method": f,
619
+ "resource.method": f
620
+ } : {}), typeof a == "number" ? { "resource.size": a } : {}), typeof i == "number" ? O({
621
+ "http.response.status_code": i,
622
+ "resource.status_code": i
623
+ }, i > 0 ? { [T.statusClass]: Ye(i) } : {}) : {});
624
+ }, tt = 100, nt = 100, rt = 1e3, it = 100, at = 1e4, ot = "data-bk-action-name", st = 100, ct = 10, L = (e) => e.replace(/\s+/g, " ").trim().slice(0, st), R = (e) => {
408
625
  var t;
409
- if (!e) return;
410
- let n = ((t = e.textContent) == null ? void 0 : t.trim()) || e.getAttribute("aria-label") || e.getAttribute("title") || "";
411
- return n ? n.slice(0, 32) : void 0;
412
- }, We = (e = {}) => {
626
+ if (e.parentElement) return e.parentElement;
627
+ let n = (t = e.getRootNode) == null ? void 0 : t.call(e);
628
+ return typeof ShadowRoot < "u" && n instanceof ShadowRoot ? n.host : null;
629
+ }, lt = (e, t) => {
630
+ let n = e;
631
+ for (; n;) {
632
+ let e = n.getAttribute(t);
633
+ if (e) return L(e);
634
+ n = R(n);
635
+ }
636
+ }, ut = (e) => {
637
+ var t;
638
+ return e.isContentEditable ? "" : L((t = e.textContent) == null ? "" : t);
639
+ }, dt = (e) => {
640
+ var t, n;
641
+ let r = e, i = (t = r.labels) == null ? void 0 : t[0];
642
+ if (i) {
643
+ let e = ut(i);
644
+ if (e) return e;
645
+ }
646
+ let a = e.tagName.toLowerCase(), o = (n = e.getAttribute("type")) == null ? void 0 : n.toLowerCase();
647
+ if (a === "input" && [
648
+ "button",
649
+ "reset",
650
+ "submit"
651
+ ].includes(o == null ? "" : o)) {
652
+ var s;
653
+ let e = L((s = r.value) == null ? "" : s);
654
+ if (e) return e;
655
+ }
656
+ if (a === "button" || a === "label" || e.getAttribute("role") === "button") {
657
+ let t = ut(e);
658
+ if (t) return t;
659
+ }
660
+ for (let t of [
661
+ "aria-label",
662
+ "alt",
663
+ "name",
664
+ "title",
665
+ "placeholder"
666
+ ]) {
667
+ var c;
668
+ let n = L((c = e.getAttribute(t)) == null ? "" : c);
669
+ if (n) return n;
670
+ }
671
+ }, ft = (e, t = ot, n = !1) => {
672
+ let r = lt(e, t);
673
+ if (r) return r;
674
+ if (!n) return e.tagName.toLowerCase();
675
+ let i = e, a = 0;
676
+ for (; i && a <= ct;) {
677
+ let e = i.tagName.toLowerCase();
678
+ if (e === "body" || e === "html" || e === "head") break;
679
+ let t = dt(i);
680
+ if (t) return t;
681
+ if (e === "form") break;
682
+ i = R(i), a += 1;
683
+ }
684
+ for (i = e, a = 0; i && a <= ct;) {
685
+ let e = i.tagName.toLowerCase();
686
+ if (e === "body" || e === "html" || e === "head") break;
687
+ let t = ut(i);
688
+ if (t) return t;
689
+ if (e === "form") break;
690
+ i = R(i), a += 1;
691
+ }
692
+ return e.tagName.toLowerCase();
693
+ }, pt = (e) => {
413
694
  var t;
414
- let n = [], r = (t = e.eventNames) == null ? Ve : t;
695
+ let n = (t = e.composedPath) == null ? void 0 : t.call(e)[0];
696
+ return n instanceof Element ? n : e.target instanceof Element ? e.target : void 0;
697
+ }, mt = (e) => {
698
+ let t = e.timeStamp;
699
+ return !Number.isFinite(t) || t <= 0 ? Date.now() : t > 0xe8d4a51000 ? t : typeof performance > "u" ? Date.now() : performance.timeOrigin + t;
700
+ }, ht = (e, t) => typeof e == "number" && Number.isFinite(e) && e > 0 ? e : t, gt = (e) => {
701
+ let t = e;
702
+ if (t.tagName.toLowerCase() === "label" && t.hasAttribute("for")) {
703
+ var n;
704
+ t = document.getElementById((n = t.getAttribute("for")) == null ? "" : n);
705
+ }
706
+ for (; t;) {
707
+ let e = t.tagName.toLowerCase();
708
+ if (t.hasAttribute("contenteditable") || e === "canvas" || e === "select" || e === "textarea" || e === "a" && t.hasAttribute("href")) return !0;
709
+ if (e === "input") {
710
+ var r, i;
711
+ return ![
712
+ "button",
713
+ "checkbox",
714
+ "radio",
715
+ "range",
716
+ "reset",
717
+ "submit"
718
+ ].includes((r = (i = t.getAttribute("type")) == null ? void 0 : i.toLowerCase()) == null ? "text" : r);
719
+ }
720
+ t = R(t);
721
+ }
722
+ return !1;
723
+ }, _t = (e = {}) => {
724
+ let t = [], n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Set(), i = e.actionNameAttribute || ot, a = ht(e.maxDuration, at), o = [], s, c = () => {
725
+ s == null || s.setRuntimeAttributes({ [T.actionId]: n.size ? [...n.keys()] : void 0 });
726
+ }, l = (e) => !e.hadActivity && !e.userActivity.input && !e.userActivity.scroll && !e.userActivity.selection && !gt(e.target), u = (e) => {
727
+ var t;
728
+ if (!r.delete(e) || !s || !e.completed || e.discardedByRage) return;
729
+ clearTimeout(e.reportTimer), e.counts.error && e.frustrations.add("error_click"), ((t = e.rageSources) == null ? [e] : t).some(l) && e.frustrations.add("dead_click");
730
+ let n = [
731
+ "rage_click",
732
+ "dead_click",
733
+ "error_click"
734
+ ].filter((t) => e.frustrations.has(t)), { endTime: i, hasLoadingTime: a } = e.completed, o = Math.max(0, i - e.startTime), c = e.counts.error > 0 || n.length > 0, u = s.startSpan("action.click", O(O(O(O(O({}, s.config.hooks.getPageAttributes()), I({
735
+ duration: a ? o : void 0,
736
+ errorType: e.counts.error ? "js" : n.length ? "frustration" : "none",
737
+ eventLabel: "用户操作",
738
+ result: c ? P.warning : P.success,
739
+ spanSubtype: "click",
740
+ spanType: F.action,
741
+ targetLabel: e.targetName,
742
+ targetValue: a ? o : void 0,
743
+ traceScene: "user_action"
744
+ })), e.runtimeAttributes), {}, {
745
+ [T.actionId]: e.id,
746
+ [T.actionType]: "click",
747
+ [T.actionName]: `Click on ${e.targetName}`,
748
+ [T.actionTargetName]: e.targetName,
749
+ [T.actionTargetTag]: e.targetTag,
750
+ [T.actionResourceCount]: e.counts.resource,
751
+ [T.actionErrorCount]: e.counts.error,
752
+ [T.actionLongTaskCount]: e.counts.longTask,
753
+ [T.actionFrustrationCount]: n.length
754
+ }, n.length ? { [T.actionFrustrationType]: n } : {}), a ? { [T.actionLoadingTime]: o } : {}), { startTime: e.startTime });
755
+ u.setAttributes(O(O({}, e.runtimeAttributes), {}, { [T.actionId]: e.id })), u.end(a ? i : e.startTime);
756
+ }, d = (e, t, i) => {
757
+ if (!n.delete(e.id) || !s) return;
758
+ clearTimeout(e.validationTimer), clearTimeout(e.quietTimer), clearTimeout(e.maxDurationTimer), c(), e.completed = {
759
+ endTime: t,
760
+ hasLoadingTime: i
761
+ }, r.add(e);
762
+ let a = Math.max(0, e.startTime + rt - Date.now());
763
+ e.reportTimer = setTimeout(() => u(e), a);
764
+ }, f = () => {
765
+ [...r].forEach(u);
766
+ }, p = (e) => {
767
+ if (clearTimeout(e.quietTimer), !e.hadActivity || e.pendingRequests.size) return;
768
+ let t = Math.max(0, e.lastActivityTime + nt - Date.now());
769
+ e.quietTimer = setTimeout(() => d(e, e.lastActivityTime, !0), t);
770
+ }, m = (e, t) => {
771
+ e.hadActivity = !0, e.lastActivityTime = Math.max(e.lastActivityTime, t), p(e);
772
+ }, h = (e, t) => t >= e.startTime && t <= e.startTime + a, g = (e) => {
773
+ for (let i of n.values()) {
774
+ if (e.type === "request_start") {
775
+ var t;
776
+ if (e.url && M(s == null || (t = s.config.view) == null ? void 0 : t.excludedActivityUrls, e.url) || !h(i, e.time)) continue;
777
+ i.pendingRequests.add(e.id), m(i, e.time);
778
+ continue;
779
+ }
780
+ if (e.type === "request_end") {
781
+ if (!i.pendingRequests.delete(e.id)) continue;
782
+ i.counts.resource += 1, m(i, e.time);
783
+ continue;
784
+ }
785
+ if (e.type === "long_task" || e.type === "resource") {
786
+ var r;
787
+ if (e.type === "resource" && e.url && M(s == null || (r = s.config.view) == null ? void 0 : r.excludedActivityUrls, e.url) || e.startTime > i.startTime + a || (e.type === "resource" ? e.startTime < i.startTime : e.endTime < i.startTime)) continue;
788
+ i.counts[e.type === "long_task" ? "longTask" : "resource"] += 1, m(i, e.endTime);
789
+ continue;
790
+ }
791
+ if (e.type === "dom_mutation" || e.type === "window_open") {
792
+ h(i, e.time) && m(i, e.time);
793
+ continue;
794
+ }
795
+ e.type === "error" && h(i, e.time) && (i.counts.error += 1, m(i, e.time));
796
+ }
797
+ }, _ = (e = Date.now()) => {
798
+ [...n.values()].forEach((t) => d(t, e, t.hadActivity));
799
+ }, v = (e, t) => {
800
+ let n = "clientX" in t && typeof t.clientX == "number" ? t.clientX : 0, r = "clientY" in t && typeof t.clientY == "number" ? t.clientY : 0;
801
+ o = o.filter((t) => e.startTime - t.action.startTime <= rt);
802
+ let i = o.at(-1), a = o.some((e) => e.action.userActivity.scroll || e.action.userActivity.selection), s = (i == null ? void 0 : i.target) === e.target && Math.hypot(i.x - n, i.y - r) <= it;
803
+ if ((a || i && !s) && (o = []), o.push({
804
+ action: e,
805
+ target: e.target,
806
+ x: n,
807
+ y: r
808
+ }), o.length >= 3 && e.startTime - o[o.length - 3].action.startTime <= rt) {
809
+ let t = o.slice(-3).map((e) => e.action);
810
+ t.slice(0, -1).forEach((e) => {
811
+ e.discardedByRage = !0;
812
+ }), e.frustrations.add("rage_click"), e.rageSources = t, o = [];
813
+ }
814
+ };
415
815
  return {
416
816
  name: "action",
417
- init(e) {
418
- if (typeof window > "u") return;
419
- let t = {
817
+ init(l) {
818
+ if (typeof window > "u" || typeof document > "u") return;
819
+ s = l;
820
+ let u = {
420
821
  capture: !0,
421
822
  passive: !0
422
- }, i = (t) => {
423
- var n;
424
- let r = He(t.target), i = Ue(r), a = r == null ? void 0 : r.tagName.toLowerCase();
425
- e.startSpan(`action.${t.type}`, E(E(E(E({}, e.config.hooks.getPageAttributes()), F({
426
- errorType: "none",
427
- eventLabel: "用户操作",
428
- spanSubtype: t.type,
429
- spanType: P.action,
430
- targetLabel: (n = i == null ? a : i) == null ? t.type : n
431
- })), {}, { [x.actionType]: t.type }, i ? { [x.targetTextShort]: i } : {}), a ? { [x.targetTag]: a } : {})).end();
823
+ }, p = (t) => {
824
+ if ("button" in t && typeof t.button == "number" && t.button !== 0) return;
825
+ let r = pt(t);
826
+ if (!r) return;
827
+ let o = mt(t), s = N("action"), u = {
828
+ counts: {
829
+ error: 0,
830
+ longTask: 0,
831
+ resource: 0
832
+ },
833
+ frustrations: /* @__PURE__ */ new Set(),
834
+ hadActivity: !1,
835
+ id: s,
836
+ lastActivityTime: o,
837
+ maxDurationTimer: setTimeout(() => d(u, o + a, !0), a),
838
+ pendingRequests: /* @__PURE__ */ new Set(),
839
+ runtimeAttributes: l.getRuntimeAttributes(),
840
+ startTime: o,
841
+ target: r,
842
+ targetName: ft(r, i, e.nameCollection === "text"),
843
+ targetTag: r.tagName.toLowerCase(),
844
+ userActivity: {
845
+ input: !1,
846
+ scroll: !1,
847
+ selection: !1
848
+ },
849
+ validationTimer: setTimeout(() => {
850
+ u.hadActivity || d(u, u.startTime, !1);
851
+ }, tt)
852
+ };
853
+ n.set(s, u), v(u, t), c();
432
854
  };
433
- for (let e of r) window.addEventListener(e, i, t), n.push(() => window.removeEventListener(e, i, t));
855
+ window.addEventListener("click", p, u), t.push(() => window.removeEventListener("click", p, u));
856
+ let m = l.onActivity(g), h = l.onSessionLifecycle((e) => {
857
+ e.type === "expired" && (_(e.expiredAt), f());
858
+ });
859
+ t.push(m, h);
860
+ let y = () => {
861
+ document.visibilityState === "hidden" && (_(), f());
862
+ }, b = () => {
863
+ _(), f();
864
+ };
865
+ window.addEventListener("pagehide", b), document.addEventListener("visibilitychange", y), t.push(() => window.removeEventListener("pagehide", b), () => document.removeEventListener("visibilitychange", y));
866
+ let x = (e) => {
867
+ new Set([
868
+ ...n.values(),
869
+ ...r,
870
+ ...o.map((e) => e.action)
871
+ ]).forEach((t) => {
872
+ if (t.userActivity[e] = !0, e !== "input" && t.frustrations.delete("rage_click")) {
873
+ var n;
874
+ (n = t.rageSources) == null || n.slice(0, -1).forEach((e) => {
875
+ e.discardedByRage = !1;
876
+ }), t.rageSources = void 0;
877
+ }
878
+ });
879
+ }, S = () => x("input"), C = () => x("scroll"), ee = () => x("selection");
880
+ window.addEventListener("input", S, u), window.addEventListener("scroll", C, u), document.addEventListener("selectionchange", ee, u), t.push(() => window.removeEventListener("input", S, u), () => window.removeEventListener("scroll", C, u), () => document.removeEventListener("selectionchange", ee, u));
434
881
  },
435
882
  shutdown() {
436
- for (; n.length;) {
883
+ for (_(), f(); t.length;) {
437
884
  var e;
438
- (e = n.pop()) == null || e();
885
+ (e = t.pop()) == null || e();
439
886
  }
887
+ o = [], s = void 0;
440
888
  }
441
889
  };
442
- };
443
- //#endregion
444
- //#region \0@oxc-project+runtime@0.128.0/helpers/objectWithoutPropertiesLoose.js
445
- function Ge(e, t) {
446
- if (e == null) return {};
447
- var n = {};
448
- for (var r in e) if ({}.hasOwnProperty.call(e, r)) {
449
- if (t.includes(r)) continue;
450
- n[r] = e[r];
451
- }
452
- return n;
453
- }
454
- //#endregion
455
- //#region \0@oxc-project+runtime@0.128.0/helpers/objectWithoutProperties.js
456
- function Ke(e, t) {
457
- if (e == null) return {};
458
- var n, r, i = Ge(e, t);
459
- if (Object.getOwnPropertySymbols) {
460
- var a = Object.getOwnPropertySymbols(e);
461
- for (r = 0; r < a.length; r++) n = a[r], t.includes(n) || {}.propertyIsEnumerable.call(e, n) && (i[n] = e[n]);
462
- }
463
- return i;
464
- }
465
- //#endregion
466
- //#region src/core/telemetry-attributes.ts
467
- var qe = (e) => typeof e == "string" && e.length > 0 ? e : void 0, Je = (e) => {
468
- let t = qe(e);
469
- return t ? { [x.viewUrlPathGroup]: t } : {};
470
- }, I = (e) => Je(e[x.viewUrlPathGroup]), L = (e, t) => {
471
- var n;
472
- let r = x.viewUrlPathGroup, { [r]: i } = e;
473
- return E(E({}, Ke(e, [r].map(C))), Je((n = qe(i)) == null ? t : n));
474
- }, Ye = "body", Xe = 3e3, Ze = .8, Qe = [
890
+ }, vt = "data-bk-excluded-activity-mutations", yt = (e) => {
891
+ let t = e.type === "characterData" ? e.target.parentElement : e.target;
892
+ return t instanceof Element && !!t.closest("[data-bk-excluded-activity-mutations]");
893
+ }, bt = () => {
894
+ let e, t = [];
895
+ return {
896
+ name: "activity",
897
+ init(n) {
898
+ if (typeof document < "u" && typeof MutationObserver < "u" && (e = new MutationObserver((e) => {
899
+ e.length && !e.every(yt) && n.notifyActivity({
900
+ time: Date.now(),
901
+ type: "dom_mutation"
902
+ });
903
+ }), e.observe(document, {
904
+ attributes: !0,
905
+ characterData: !0,
906
+ childList: !0,
907
+ subtree: !0
908
+ })), !(typeof window > "u") && typeof window.open == "function") {
909
+ let e = window.open, r = ((...t) => (n.notifyActivity({
910
+ time: Date.now(),
911
+ type: "window_open"
912
+ }), Reflect.apply(e, window, t)));
913
+ window.open = r, t.push(() => {
914
+ window.open === r && (window.open = e);
915
+ });
916
+ }
917
+ },
918
+ shutdown() {
919
+ var n;
920
+ for (e == null || e.disconnect(), e = void 0; t.length;) (n = t.pop()) == null || n();
921
+ }
922
+ };
923
+ }, xt = (e, t) => !!(t && M(e.config.view.excludedActivityUrls, t)), St = (e, t, n) => {
924
+ let r = /* @__PURE__ */ new Set(), i = !1, a = !1, o = t, s, c = (e) => {
925
+ i || (i = !0, clearTimeout(f), clearTimeout(s), d(), n(e));
926
+ }, l = () => {
927
+ clearTimeout(s), !(!a || r.size) && (s = setTimeout(() => c({
928
+ endTime: o,
929
+ hadActivity: !0
930
+ }), Math.max(0, o + 100 - Date.now())));
931
+ }, u = (e) => {
932
+ a = !0, o = Math.max(o, e), l();
933
+ }, d = e.onActivity((n) => {
934
+ if (!(n.type === "error" || n.type === "long_task")) {
935
+ if (n.type === "request_start") {
936
+ if (n.time < t || xt(e, n.url)) return;
937
+ r.add(n.id), u(n.time);
938
+ return;
939
+ }
940
+ if (n.type === "request_end") {
941
+ if (!r.delete(n.id)) return;
942
+ u(n.time);
943
+ return;
944
+ }
945
+ if (n.type === "resource") {
946
+ if (n.endTime < t || xt(e, n.url)) return;
947
+ u(n.endTime);
948
+ return;
949
+ }
950
+ n.time >= t && u(n.time);
951
+ }
952
+ }), f = setTimeout(() => {
953
+ a || c({ hadActivity: !1 });
954
+ }, 100);
955
+ return () => {
956
+ i || (i = !0, clearTimeout(f), clearTimeout(s), d());
957
+ };
958
+ }, Ct = (e) => typeof e == "string" && e.length > 0 ? e : void 0, wt = (e) => {
959
+ let t = Ct(e);
960
+ return t ? { [T.viewUrlPathGroup]: t } : {};
961
+ }, z = (e) => O(O({}, wt(e[T.viewUrlPathGroup])), {}, { [A]: e[A] === !0 }), Tt = 1e3, Et = 200, Dt = "body", Ot = .8, kt = [
475
962
  "[data-loading=\"true\"]",
476
963
  "[aria-busy=\"true\"]",
477
964
  ".loading",
@@ -479,196 +966,570 @@ var qe = (e) => typeof e == "string" && e.length > 0 ? e : void 0, Je = (e) => {
479
966
  ".spinner",
480
967
  ".skeleton",
481
968
  ".bk-loading"
482
- ], R = [
969
+ ], B = [
970
+ [.2, .2],
971
+ [.5, .2],
972
+ [.8, .2],
973
+ [.2, .5],
483
974
  [.5, .5],
484
- [.25, .25],
485
- [.75, .25],
486
- [.25, .75],
487
- [.75, .75]
488
- ], $e = (e, t) => typeof e == "number" && Number.isFinite(e) && e >= 0 ? e : t, et = (e, t) => typeof e != "number" || !Number.isFinite(e) ? t : Math.max(0, Math.min(1, e)), tt = (e) => {
975
+ [.8, .5],
976
+ [.2, .8],
977
+ [.5, .8],
978
+ [.8, .8]
979
+ ], At = (e, t) => typeof e == "number" && Number.isFinite(e) && e >= 0 ? e : t, jt = (e, t) => typeof e == "number" && Number.isFinite(e) ? Math.max(0, Math.min(1, e)) : t, Mt = (e) => {
489
980
  if (!e) return "";
490
981
  let t = e.tagName.toLowerCase();
491
982
  return e.id ? `${t}#${e.id}` : t;
492
- }, nt = (e, t) => e ? t.some((t) => {
983
+ }, Nt = (e, t) => t.some((t) => {
493
984
  try {
494
985
  return e.matches(t) || !!e.closest(t);
495
986
  } catch (e) {
496
987
  return !1;
497
988
  }
498
- }) : !1, rt = (e) => {
499
- if (typeof document > "u") return () => {};
500
- if (document.readyState === "complete" || document.readyState === "interactive") return e(), () => {};
501
- let t = () => {
502
- document.removeEventListener("DOMContentLoaded", t), e();
989
+ }), Pt = (e) => {
990
+ if (typeof getComputedStyle != "function") return !0;
991
+ let t = getComputedStyle(e);
992
+ return t.display !== "none" && t.visibility !== "hidden" && Number(t.opacity || 1) > 0;
993
+ }, Ft = (e, t) => {
994
+ if (typeof document.elementsFromPoint == "function") return document.elementsFromPoint(e, t);
995
+ let n = document.elementFromPoint(e, t);
996
+ return n ? [n] : [];
997
+ }, It = (e, t) => {
998
+ let n = document.querySelector(e);
999
+ if (!n) return {
1000
+ centerElement: Mt(Ft(window.innerWidth / 2, window.innerHeight / 2)[0]),
1001
+ emptyCount: B.length,
1002
+ ignoredCount: 0,
1003
+ reason: "missing_root",
1004
+ rootFound: !1,
1005
+ score: 1,
1006
+ validCount: B.length
503
1007
  };
504
- return document.addEventListener("DOMContentLoaded", t), () => document.removeEventListener("DOMContentLoaded", t);
505
- }, it = (e = {}) => {
506
- var t, n;
507
- let r, i, a = !1, o = {
508
- checkDelay: $e(e.checkDelay, Xe),
509
- ignoreSelectors: (t = e.ignoreSelectors) == null ? [] : t,
510
- rootSelector: (n = e.rootSelector) == null ? Ye : n,
511
- threshold: et(e.threshold, Ze)
1008
+ let r = 0, i = 0, a = "";
1009
+ for (let [e, o] of B) {
1010
+ let s = Ft(window.innerWidth * e, window.innerHeight * o);
1011
+ if (e === .5 && o === .5 && (a = Mt(s[0])), s.some((e) => Nt(e, t))) {
1012
+ i += 1;
1013
+ continue;
1014
+ }
1015
+ s.some((e) => e !== n && e !== document.body && e !== document.documentElement && n.contains(e) && Pt(e)) || (r += 1);
1016
+ }
1017
+ let o = B.length - i;
1018
+ return {
1019
+ centerElement: a,
1020
+ emptyCount: r,
1021
+ ignoredCount: i,
1022
+ reason: "empty_viewport",
1023
+ rootFound: !0,
1024
+ score: o ? r / o : 0,
1025
+ validCount: o
512
1026
  };
1027
+ }, Lt = (e = {}) => {
1028
+ var t;
1029
+ let n = At(e.checkDelay, Tt), r = At(e.confirmationDelay, Et), i = e.rootSelector || Dt, a = jt(e.threshold, Ot), o = [...kt, ...(t = e.ignoreSelectors) == null ? [] : t], s, c, l, u, d = () => {}, f;
513
1030
  return {
514
1031
  name: "blank-screen",
515
1032
  init(e) {
516
1033
  if (typeof window > "u" || typeof document > "u") return;
517
- let { checkDelay: t, rootSelector: n, threshold: s } = o, c = [...Qe, ...o.ignoreSelectors], l = e.meter.createCounter("browser.blank_screen.count", { description: "Number of suspected blank screen detections" }), u = () => {
1034
+ let t = e.meter.createCounter("browser.blank_screen.count", { description: "Number of confirmed blank screens" }), p = () => {
1035
+ clearTimeout(u), u = void 0;
1036
+ }, m = (n, r) => {
1037
+ s !== n || c === n || (c = n, t.add(1, e.applyRedact(O(O(O({}, e.config.hooks.getMetricAttributes()), z(e.getRuntimeAttributes())), {}, {
1038
+ "blank_screen.reason": r.reason,
1039
+ "blank_screen.root_selector": i
1040
+ }))), e.startSpan("browser.blank_screen", O(O({}, I({
1041
+ errorType: "blank_screen",
1042
+ eventLabel: "白屏",
1043
+ result: P.error,
1044
+ spanSubtype: r.reason,
1045
+ spanType: F.error,
1046
+ targetLabel: i,
1047
+ targetValue: r.score
1048
+ })), {}, {
1049
+ "blank_screen.center_element": r.centerElement,
1050
+ "blank_screen.empty_ratio": r.score,
1051
+ "blank_screen.empty_sample_count": r.emptyCount,
1052
+ "blank_screen.ignored_sample_count": r.ignoredCount,
1053
+ "blank_screen.reason": r.reason,
1054
+ "blank_screen.root_found": r.rootFound,
1055
+ "blank_screen.root_selector": i,
1056
+ "blank_screen.sample_count": B.length,
1057
+ "blank_screen.valid_sample_count": r.validCount
1058
+ })).end());
1059
+ }, h = (t) => {
1060
+ if (s !== t || c === t || document.visibilityState === "hidden") return;
1061
+ let n;
518
1062
  try {
519
- var t, r;
520
- let i = document.querySelector(n), a = 0, o = 0;
521
- for (let [e, t] of R) {
522
- let n = document.elementFromPoint(window.innerWidth * e, window.innerHeight * t);
523
- if (nt(n, c)) {
524
- o += 1;
525
- continue;
526
- }
527
- (n === i || n === document.body || n === document.documentElement) && (a += 1);
528
- }
529
- let u = R.length - o;
530
- if (u === 0) return;
531
- let d = a / u, f = d >= s, p = tt(document.elementFromPoint(window.innerWidth / 2, window.innerHeight / 2)), m = E(E({}, F({
532
- errorType: f ? "blank_screen" : "none",
533
- eventLabel: "白屏",
534
- result: f ? N.error : N.success,
535
- spanSubtype: "blank_screen",
536
- spanType: P.error,
537
- targetLabel: n,
538
- targetValue: d
539
- })), {}, {
540
- "blank_screen.score": d,
541
- "blank_screen.threshold": s,
542
- "blank_screen.root": n,
543
- "blank_screen.detected": f,
544
- "blank_screen.sample_total": R.length,
545
- "blank_screen.sample_valid": u,
546
- "blank_screen.sample_loading": o,
547
- "blank_screen.center_element": p,
548
- "blank_screen.dom_node_count": (t = (r = document.body) == null ? void 0 : r.getElementsByTagName("*").length) == null ? 0 : t
549
- });
550
- f && (l.add(1, e.applyRedact(E(E(E({}, e.config.hooks.getMetricAttributes()), I(e.getRuntimeAttributes())), {}, { "blank_screen.root": n }))), e.startSpan("browser.blank_screen", m).end());
1063
+ n = It(i, o);
551
1064
  } catch (t) {
552
- if (e.config.debug) {
553
- var i;
554
- (i = globalThis.console) == null || i.warn("[bk-ot][blank-screen] detection failed:", t);
555
- }
1065
+ var l;
1066
+ e.config.debug && ((l = globalThis.console) == null || l.warn("[bk-ot][blank-screen] detection failed:", t));
1067
+ return;
556
1068
  }
1069
+ !n.validCount || n.score < a || (u = setTimeout(() => {
1070
+ if (s !== t || document.visibilityState === "hidden") return;
1071
+ let n;
1072
+ try {
1073
+ n = It(i, o);
1074
+ } catch (t) {
1075
+ var r;
1076
+ e.config.debug && ((r = globalThis.console) == null || r.warn("[bk-ot][blank-screen] confirmation failed:", t));
1077
+ return;
1078
+ }
1079
+ n.validCount && n.score >= a && m(t, n);
1080
+ }, r));
1081
+ }, g = (e) => {
1082
+ p(), document.visibilityState !== "hidden" && (u = setTimeout(() => h(e), n));
557
1083
  };
558
- i = rt(() => {
559
- a || (r = window.setTimeout(u, t));
1084
+ d = e.onViewChange((t) => {
1085
+ if (t.id !== s && (p(), l == null || l(), l = void 0, s = t.id, c = void 0, t.id)) {
1086
+ let n = t.id;
1087
+ l = St(e, Date.now(), () => {
1088
+ l = void 0, g(n);
1089
+ });
1090
+ }
560
1091
  });
1092
+ let _ = () => {
1093
+ document.visibilityState === "hidden" ? p() : s && c !== s && g(s);
1094
+ };
1095
+ document.addEventListener("visibilitychange", _), f = () => document.removeEventListener("visibilitychange", _);
561
1096
  },
562
1097
  shutdown() {
563
- a = !0, i == null || i(), i = void 0, r !== void 0 && typeof window < "u" && (window.clearTimeout(r), r = void 0);
1098
+ clearTimeout(u), u = void 0, d(), l == null || l(), l = void 0, f == null || f(), f = void 0, s = void 0, c = void 0;
564
1099
  }
565
1100
  };
566
- }, at = ["http.url", "url.full"], ot = ["http.status_code", "http.response.status_code"], st = ["http.method", "http.request.method"], ct = (e) => ({ test: e }), z = (e) => typeof location > "u" ? void 0 : e.config.hooks.getViewPathGroup(location.href), lt = (e, t, n) => {
567
- var r;
568
- t.setAttributes(e.applyRedact(E(E({}, L(e.getRuntimeAttributes(), z(e))), e.config.hooks.getPageAttributes())));
569
- let i;
570
- for (let n of at) {
571
- var a;
572
- let r = (a = t.attributes) == null ? void 0 : a[n];
573
- if (typeof r == "string") {
574
- let a = e.applyRedact({ [n]: e.config.hooks.redactUrl(r) })[n];
575
- typeof a == "string" && (i = a, t.setAttribute(n, a));
1101
+ }, Rt = 100, zt = 200, V = [], Bt = (e) => e.replace(/#.*$/, ""), Vt = (e) => {
1102
+ let t = V.indexOf(e);
1103
+ t >= 0 && V.splice(t, 1), e.timer !== void 0 && clearTimeout(e.timer);
1104
+ }, H = (e, t) => {
1105
+ let n = e.callback;
1106
+ Vt(e), e.callback = void 0, n == null || n(t);
1107
+ }, Ht = (e) => {
1108
+ let t = performance.timeOrigin + e.startTime, n = V.filter((n) => !n.entry && Bt(n.url) === Bt(e.name) && t >= n.startTime - 50).sort((e, n) => Math.abs(e.startTime - t) - Math.abs(n.startTime - t))[0];
1109
+ n && (n.entry = e, n.callback && H(n, e));
1110
+ }, Ut = (e, t = Date.now()) => {
1111
+ let n = {
1112
+ startTime: t,
1113
+ url: e
1114
+ };
1115
+ return V.push(n), V.length > Rt && H(V[0]), {
1116
+ cancel: () => H(n),
1117
+ complete: (e) => {
1118
+ if (n.callback = e, n.entry) {
1119
+ H(n, n.entry);
1120
+ return;
1121
+ }
1122
+ n.timer = setTimeout(() => H(n), zt);
576
1123
  }
1124
+ };
1125
+ }, Wt = 10 * 1024, Gt = [
1126
+ /^text\//i,
1127
+ /json/i,
1128
+ "application/x-www-form-urlencoded",
1129
+ "application/graphql"
1130
+ ], Kt = (e) => typeof e == "number" && Number.isFinite(e) && e > 0 ? Math.floor(e) : Wt, qt = (e, t, n) => e ? t.some((t) => typeof t == "string" ? e.toLowerCase().includes(t.toLowerCase()) : (t.lastIndex = 0, t.test(e))) : n, Jt = (e) => {
1131
+ try {
1132
+ var t;
1133
+ return e ? (t = new Headers(e).get("content-type")) == null ? void 0 : t : void 0;
1134
+ } catch (e) {
1135
+ return;
577
1136
  }
578
- let o = ot.map((e) => {
579
- var n;
580
- return (n = t.attributes) == null ? void 0 : n[e];
581
- }).find((e) => typeof e == "number"), s = st.map((e) => {
582
- var n;
583
- return (n = t.attributes) == null ? void 0 : n[e];
584
- }).find((e) => typeof e == "string"), c = (r = i) == null ? at.map((e) => {
1137
+ }, Yt = function() {
1138
+ var e = k(function* (e, t) {
1139
+ let n = e.getReader(), r = new TextDecoder(), i = "";
1140
+ try {
1141
+ for (; i.length <= t;) {
1142
+ let { done: e, value: t } = yield n.read();
1143
+ if (e) {
1144
+ i += r.decode();
1145
+ break;
1146
+ }
1147
+ i += r.decode(t, { stream: !0 });
1148
+ }
1149
+ i.length > t && (yield n.cancel().catch(() => void 0));
1150
+ } finally {
1151
+ n.releaseLock();
1152
+ }
1153
+ return i;
1154
+ });
1155
+ return function(t, n) {
1156
+ return e.apply(this, arguments);
1157
+ };
1158
+ }(), Xt = function() {
1159
+ var e = k(function* (e, t) {
1160
+ if (typeof e == "string") return e;
1161
+ if (typeof URLSearchParams < "u" && e instanceof URLSearchParams) return e.toString();
1162
+ if (typeof Blob < "u" && e instanceof Blob) return Yt(e.stream(), t);
1163
+ });
1164
+ return function(t, n) {
1165
+ return e.apply(this, arguments);
1166
+ };
1167
+ }(), Zt = function() {
1168
+ var e = k(function* (e, t) {
1169
+ if (typeof Request < "u" && e instanceof Request) {
1170
+ var n;
1171
+ let r = (n = e.headers.get("content-type")) == null ? void 0 : n, i = e.clone();
1172
+ return {
1173
+ contentType: r,
1174
+ text: i.body ? yield Yt(i.body, t) : ""
1175
+ };
1176
+ }
1177
+ return {
1178
+ contentType: Jt(e.headers),
1179
+ text: yield Xt(e.body, t)
1180
+ };
1181
+ });
1182
+ return function(t, n) {
1183
+ return e.apply(this, arguments);
1184
+ };
1185
+ }(), Qt = (e) => {
1186
+ if (typeof Request > "u" || !(e instanceof Request)) return e;
1187
+ try {
1188
+ return e.clone();
1189
+ } catch (e) {
1190
+ return;
1191
+ }
1192
+ }, $t = function() {
1193
+ var e = k(function* (e, t) {
585
1194
  var n;
586
- return (n = t.attributes) == null ? void 0 : n[e];
587
- }).find((e) => typeof e == "string") : r;
588
- t.setAttributes(e.applyRedact(ze({
589
- method: s,
590
- statusCode: o,
591
- subtype: n,
592
- url: c,
593
- urlPathTemplate: c ? e.config.hooks.getViewPathGroup(c) : void 0
594
- })));
595
- }, ut = (e, t, n) => {
596
- let r = z(e);
597
- t.setAttributes(e.applyRedact(E(E(E({}, L(e.getRuntimeAttributes(), r)), e.config.hooks.getPageAttributes()), F({
598
- errorType: "none",
599
- eventLabel: "文档加载",
600
- spanSubtype: n,
601
- spanType: P.document,
602
- targetLabel: r,
603
- traceScene: "page_load"
604
- }))));
605
- }, dt = (e, t, n) => {
606
- let r = e.config.hooks.redactUrl(n.name);
607
- t.setAttributes(e.applyRedact(E(E(E(E({}, L(e.getRuntimeAttributes(), z(e))), e.config.hooks.getPageAttributes()), Be({
608
- duration: n.duration,
609
- initiatorType: n.initiatorType || "other",
610
- responseStatus: n.responseStatus,
611
- transferSize: n.transferSize,
612
- url: r,
613
- urlPathTemplate: e.config.hooks.getViewPathGroup(n.name)
614
- })), {}, { "url.full": r })));
615
- }, ft = (e = {}) => {
616
- var t, n, r, i;
617
- let a = [], o = {
618
- documentLoad: (t = e.documentLoad) == null ? !0 : t,
619
- fetch: (n = e.fetch) == null ? !0 : n,
620
- xhr: (r = e.xhr) == null ? !0 : r,
621
- userInteraction: (i = e.userInteraction) == null ? !0 : i
1195
+ if (!e) return {};
1196
+ let r = (n = e.headers.get("content-type")) == null ? void 0 : n, i = e.clone();
1197
+ return {
1198
+ contentType: r,
1199
+ text: i.body ? yield Yt(i.body, t) : ""
1200
+ };
1201
+ });
1202
+ return function(t, n) {
1203
+ return e.apply(this, arguments);
1204
+ };
1205
+ }(), en = (e) => {
1206
+ var t;
1207
+ let n = (t = e.getResponseHeader("content-type")) == null ? void 0 : t;
1208
+ return e.responseType === "" || e.responseType === "text" ? {
1209
+ contentType: n,
1210
+ text: e.responseText
1211
+ } : e.responseType === "json" ? {
1212
+ contentType: n,
1213
+ text: JSON.stringify(e.response)
1214
+ } : { contentType: n };
1215
+ }, tn = (e, t, n, r, i) => {
1216
+ if (i === void 0) return;
1217
+ let a = Kt(e.maxSize), o = i.length > a, s = {
1218
+ body: i.slice(0, a * 2),
1219
+ contentType: r,
1220
+ kind: n,
1221
+ method: t.resource.method,
1222
+ statusCode: t.resource.statusCode,
1223
+ truncated: o,
1224
+ type: t.resource.type,
1225
+ url: t.resource.url
1226
+ }, c = e.redact(s);
1227
+ if (c !== void 0) return {
1228
+ body: c.slice(0, a),
1229
+ contentType: r,
1230
+ truncated: o || c.length > a
1231
+ };
1232
+ }, nn = function() {
1233
+ var e = k(function* ({ bodyConfig: e, domainContext: t, event: n, fetchRequest: r, runtimeContext: i, span: a }) {
1234
+ var o, s;
1235
+ let c = n.resource.statusCode, u = c === void 0 || c === 0 || c >= 400;
1236
+ if (((o = e.capture) == null ? "errors" : o) === "errors" && !u) return;
1237
+ let f = Kt(e.maxSize) * 2, p = (s = e.allowedContentTypes) == null ? Gt : s, m = {}, h = {};
1238
+ try {
1239
+ t.type === "fetch" ? [m, h] = yield Promise.all([Zt(r == null ? t.request : r, f), $t(t.response, f)]) : (m = { text: yield Xt(t.requestBody, f) }, h = en(t.xhr));
1240
+ } catch (e) {
1241
+ return;
1242
+ }
1243
+ let g, _;
1244
+ try {
1245
+ g = qt(m.contentType, p, !0) ? tn(e, n, "request", m.contentType, m.text) : void 0, _ = qt(h.contentType, p, !1) ? tn(e, n, "response", h.contentType, h.text) : void 0;
1246
+ } catch (e) {
1247
+ return;
1248
+ }
1249
+ if (!g && !_) return;
1250
+ let v = a.spanContext();
1251
+ i.emitLog({
1252
+ attributes: O(O(O({}, n.attributes), {}, {
1253
+ "span.id": v.spanId,
1254
+ "trace.id": v.traceId
1255
+ }, g ? {
1256
+ "request.body": g.body,
1257
+ "request.body.content_type": g.contentType,
1258
+ "request.body.truncated": g.truncated
1259
+ } : {}), _ ? {
1260
+ "response.body": _.body,
1261
+ "response.body.content_type": _.contentType,
1262
+ "response.body.truncated": _.truncated
1263
+ } : {}),
1264
+ body: "browser.request.body",
1265
+ context: d.setSpan(l.active(), a),
1266
+ eventName: "browser.request.body",
1267
+ severityNumber: u ? w.ERROR : w.INFO,
1268
+ severityText: u ? "ERROR" : "INFO"
1269
+ });
1270
+ });
1271
+ return function(t) {
1272
+ return e.apply(this, arguments);
622
1273
  };
1274
+ }(), rn = (e) => e.deliveryType === "cache" || e.transferSize === 0 && e.decodedBodySize > 0 ? !0 : void 0, an = (...e) => e.every((t, n) => n === 0 || e[n - 1] <= t), U = (e, t, n, r, i) => {
1275
+ an(n, r, i) && (e[`resource.${t}.start`] = r - n, e[`resource.${t}.duration`] = i - r);
1276
+ }, on = (e) => {
1277
+ let t = {}, n = [
1278
+ e.startTime,
1279
+ e.fetchStart,
1280
+ e.domainLookupStart,
1281
+ e.domainLookupEnd,
1282
+ e.connectStart,
1283
+ e.connectEnd,
1284
+ e.requestStart,
1285
+ e.responseStart,
1286
+ e.responseEnd
1287
+ ];
1288
+ return !n.every(Number.isFinite) || !an(...n) ? t : (U(t, "first_byte", e.startTime, e.requestStart, e.responseStart), U(t, "download", e.startTime, e.responseStart, e.responseEnd), e.workerStart > 0 && e.workerStart < e.fetchStart && U(t, "worker", e.startTime, e.workerStart, e.fetchStart), e.fetchStart < e.domainLookupEnd && U(t, "dns", e.startTime, e.domainLookupStart, e.domainLookupEnd), e.fetchStart < e.connectEnd && (U(t, "connect", e.startTime, e.connectStart, e.connectEnd), e.connectStart <= e.secureConnectionStart && e.secureConnectionStart <= e.connectEnd && U(t, "ssl", e.startTime, e.secureConnectionStart, e.connectEnd)), e.redirectEnd > e.startTime && an(e.startTime, e.redirectStart, e.redirectEnd, e.fetchStart) && U(t, "redirect", e.startTime, e.redirectStart, e.redirectEnd), t);
1289
+ }, sn = (e) => e.duration === 0 && e.responseEnd > e.startTime ? e.responseEnd - e.startTime : e.duration, cn = (e) => {
1290
+ let t = typeof e.deliveryType == "string" ? e.deliveryType || "other" : void 0;
1291
+ return O(O(O(O({
1292
+ [T.transferSize]: e.transferSize,
1293
+ [T.cacheHit]: rn(e),
1294
+ [T.nextHopProtocol]: e.nextHopProtocol
1295
+ }, on(e)), t ? { "resource.delivery_type": t } : {}), e.renderBlockingStatus ? { "resource.render_blocking_status": e.renderBlockingStatus } : {}), {}, {
1296
+ "resource.encoded_body_size": e.encodedBodySize,
1297
+ "resource.decoded_body_size": e.decodedBodySize
1298
+ });
1299
+ }, ln = (e = !0) => {
1300
+ let t;
623
1301
  return {
624
- name: "official-instrumentations",
625
- enabled: !!(o.documentLoad || o.fetch || o.xhr || o.userInteraction),
1302
+ name: "resource",
1303
+ init(n) {
1304
+ var r;
1305
+ if (typeof PerformanceObserver > "u" || !((r = PerformanceObserver.supportedEntryTypes) != null && r.includes("resource"))) return;
1306
+ let i = (t) => {
1307
+ if (!t.name || ke(n.config, t.name)) return;
1308
+ if (t.initiatorType === "fetch" || t.initiatorType === "xmlhttprequest") {
1309
+ Ht(t);
1310
+ return;
1311
+ }
1312
+ if (t.duration < 0) return;
1313
+ let r = n.config.hooks.redactUrl(t.name), i = sn(t), a = performance.timeOrigin + t.startTime, o = a + i;
1314
+ e && n.startSpan("browser.resource", O(O(O({}, n.config.hooks.getPageAttributes()), et({
1315
+ duration: i,
1316
+ initiatorType: t.initiatorType || "other",
1317
+ responseStatus: t.responseStatus,
1318
+ transferSize: t.transferSize,
1319
+ url: r,
1320
+ urlPathTemplate: n.config.hooks.getViewPathGroup(t.name)
1321
+ })), {}, {
1322
+ "url.full": r,
1323
+ initiator_type: t.initiatorType || "other"
1324
+ }, cn(t)), { startTime: a }).end(o), n.notifyActivity({
1325
+ endTime: o,
1326
+ startTime: a,
1327
+ type: "resource",
1328
+ url: t.name
1329
+ });
1330
+ };
1331
+ try {
1332
+ t = new PerformanceObserver((e) => {
1333
+ for (let t of e.getEntries()) i(t);
1334
+ }), t.observe({
1335
+ type: "resource",
1336
+ buffered: !0
1337
+ });
1338
+ } catch (e) {
1339
+ t = void 0;
1340
+ }
1341
+ },
1342
+ shutdown() {
1343
+ t == null || t.disconnect(), t = void 0;
1344
+ }
1345
+ };
1346
+ }, un = (e) => typeof e.config.tracking.request == "object" ? e.config.tracking.request : void 0, dn = (e) => {
1347
+ if (e.type === "xhr") return e.xhr.status;
1348
+ if (e.response) return e.response.status;
1349
+ if (typeof e.error == "object" && e.error && "status" in e.error) {
1350
+ let t = e.error.status;
1351
+ return typeof t == "number" ? t : void 0;
1352
+ }
1353
+ }, fn = (e) => typeof e == "string" || e instanceof URL ? j(String(e)) : j(e.url), pn = (e, t) => {
1354
+ var n;
1355
+ return ((n = t == null ? void 0 : t.method) == null ? typeof Request < "u" && e instanceof Request ? e.method : "GET" : n).toUpperCase();
1356
+ }, mn = (e, t) => typeof Request < "u" && e instanceof Request ? e : t == null ? {} : t, hn = (e, t, n) => {
1357
+ var r;
1358
+ let i = typeof Request < "u" && e instanceof Request ? e.headers : void 0, a = new Headers((r = t == null ? void 0 : t.headers) == null ? i : r);
1359
+ return u.inject(d.setSpan(l.active(), n), a, { set: (e, t, n) => e.set(t, n) }), O(O({}, t), {}, { headers: a });
1360
+ }, gn = (e, t) => {
1361
+ let n = {};
1362
+ u.inject(d.setSpan(l.active(), t), n);
1363
+ for (let [t, r] of Object.entries(n)) e.setRequestHeader(t, r);
1364
+ }, _n = (e, t) => ke(e.config, t) || M(e.config.view.excludedActivityUrls, t), vn = (e, t) => {
1365
+ if (_n(e, t)) return () => {};
1366
+ let n = N("request");
1367
+ e.notifyActivity({
1368
+ id: n,
1369
+ time: Date.now(),
1370
+ type: "request_start",
1371
+ url: t
1372
+ });
1373
+ let r = !1;
1374
+ return () => {
1375
+ r || (r = !0, e.notifyActivity({
1376
+ id: n,
1377
+ time: Date.now(),
1378
+ type: "request_end"
1379
+ }));
1380
+ };
1381
+ }, yn = (e, t) => e.config.transport.traces === !1 ? {
1382
+ cancel() {},
1383
+ complete(e) {
1384
+ e();
1385
+ }
1386
+ } : Ut(t), bn = (e, t, n) => {
1387
+ var r;
1388
+ return e.startSpan("browser.resource", O(O(O({}, e.config.hooks.getPageAttributes()), et({
1389
+ initiatorType: t,
1390
+ method: n.method,
1391
+ url: (r = n.url) == null ? "" : r,
1392
+ urlPathTemplate: n.url ? e.config.hooks.getViewPathGroup(n.url) : void 0
1393
+ })), n.url ? { "resource.url": e.config.hooks.redactUrl(n.url) } : {}), { kind: s.CLIENT });
1394
+ }, xn = (e, t, n, r, i = {}, a) => {
1395
+ var o;
1396
+ let s = i.url, l = s ? e.config.hooks.redactUrl(s) : void 0, u = dn(r), d = i.method, f = {
1397
+ attributes: O(O(O({}, e.config.hooks.getPageAttributes()), et({
1398
+ initiatorType: n,
1399
+ method: d,
1400
+ networkError: r.type === "fetch" ? !r.response : r.xhr.status === 0,
1401
+ responseStatus: u,
1402
+ url: l == null ? "" : l,
1403
+ urlPathTemplate: s ? e.config.hooks.getViewPathGroup(s) : void 0
1404
+ })), l ? {
1405
+ "resource.url": l,
1406
+ "url.full": l
1407
+ } : {}),
1408
+ resource: {
1409
+ method: d,
1410
+ statusCode: u,
1411
+ type: n,
1412
+ url: l
1413
+ },
1414
+ type: "resource"
1415
+ }, p = !0;
1416
+ try {
1417
+ var m, h;
1418
+ p = (m = un(e)) == null || (h = m.beforeSend) == null ? void 0 : h.call(m, f, r);
1419
+ } catch (t) {
1420
+ var g;
1421
+ e.config.debug && ((g = globalThis.console) == null || g.warn("[bk-ot] request.beforeSend failed:", t));
1422
+ }
1423
+ if (t.setAttributes(e.applyRedact(f.attributes)), p === !1) {
1424
+ t.setAttribute(Le, !0);
1425
+ return;
1426
+ }
1427
+ ((u == null ? 0 : u) >= 400 || u === 0 || r.type === "fetch" && r.error) && t.setStatus({ code: c.ERROR });
1428
+ let _ = e.config.transport.logs === !1 || (o = un(e)) == null ? void 0 : o.body;
1429
+ _ && nn({
1430
+ bodyConfig: _,
1431
+ domainContext: r,
1432
+ event: f,
1433
+ fetchRequest: a,
1434
+ runtimeContext: e,
1435
+ span: t
1436
+ });
1437
+ }, Sn = (e) => {
1438
+ let t = [], n = /* @__PURE__ */ new Set();
1439
+ return {
1440
+ name: "request",
1441
+ enabled: e !== !1,
626
1442
  init(e) {
627
- return A(function* () {
628
- let t = [ct((t) => M(e.config, t))], n = [ct((t) => Oe(e.config, t))], [r, i, s, c] = yield Promise.all([
629
- o.documentLoad ? import("@opentelemetry/instrumentation-document-load") : Promise.resolve(null),
630
- o.fetch ? import("@opentelemetry/instrumentation-fetch") : Promise.resolve(null),
631
- o.xhr ? import("@opentelemetry/instrumentation-xml-http-request") : Promise.resolve(null),
632
- o.userInteraction ? import("@opentelemetry/instrumentation-user-interaction") : Promise.resolve(null)
633
- ]);
634
- if (r && a.push(new r.DocumentLoadInstrumentation({
635
- semconvStabilityOptIn: "http",
636
- applyCustomAttributesOnSpan: {
637
- documentLoad: (t) => ut(e, t, "navigate"),
638
- documentFetch: (t) => ut(e, t, "document_fetch"),
639
- resourceFetch: (t, n) => dt(e, t, n)
640
- }
641
- })), i && a.push(new i.FetchInstrumentation({
642
- applyCustomAttributesOnSpan: (t) => lt(e, t, "fetch"),
643
- ignoreUrls: t,
644
- propagateTraceHeaderCorsUrls: n,
645
- semconvStabilityOptIn: "http",
646
- ignoreNetworkEvents: !1
647
- })), s && a.push(new s.XMLHttpRequestInstrumentation({
648
- applyCustomAttributesOnSpan: (t) => lt(e, t, "xhr"),
649
- ignoreUrls: t,
650
- propagateTraceHeaderCorsUrls: n,
651
- semconvStabilityOptIn: "http",
652
- ignoreNetworkEvents: !1
653
- })), c) {
654
- let e = o.userInteraction !== null && typeof o.userInteraction == "object" ? { eventNames: o.userInteraction.eventNames } : void 0;
655
- a.push(new c.UserInteractionInstrumentation(e));
1443
+ if (!(typeof window > "u")) {
1444
+ if (typeof window.fetch == "function") {
1445
+ let r = window.fetch, i = /* @__PURE__ */ function() {
1446
+ var t = k(function* (t, i) {
1447
+ var a;
1448
+ let o = fn(t);
1449
+ if (Me(e.config, o)) return r.call(this, t, i);
1450
+ let s = {
1451
+ method: pn(t, i),
1452
+ url: o
1453
+ }, c = bn(e, "fetch", s), l = yn(e, o), u = vn(e, o), d = mn(t, i), f = e.config.transport.logs !== !1 && (a = un(e)) != null && a.body ? Qt(d) : void 0, p = Ne(e.config, o) ? hn(t, i, c) : i, m = !1, h = (t) => {
1454
+ m || (m = !0, n.delete(g), t && c.setAttributes(e.applyRedact(cn(t))), c.end());
1455
+ }, g = () => {
1456
+ l.cancel(), h();
1457
+ };
1458
+ n.add(g);
1459
+ try {
1460
+ let n = yield r.call(this, t, p);
1461
+ return xn(e, c, "fetch", {
1462
+ request: d,
1463
+ response: n,
1464
+ type: "fetch"
1465
+ }, s, f), l.complete(h), n;
1466
+ } catch (t) {
1467
+ throw xn(e, c, "fetch", {
1468
+ error: t,
1469
+ request: d,
1470
+ type: "fetch"
1471
+ }, s, f), t instanceof Error && c.recordException(t), l.complete(h), t;
1472
+ } finally {
1473
+ u();
1474
+ }
1475
+ });
1476
+ return function(e, n) {
1477
+ return t.apply(this, arguments);
1478
+ };
1479
+ }();
1480
+ window.fetch = i, t.push(() => {
1481
+ window.fetch === i && (window.fetch = r);
1482
+ });
1483
+ }
1484
+ if (typeof XMLHttpRequest < "u") {
1485
+ let r = /* @__PURE__ */ new WeakMap(), i = XMLHttpRequest.prototype.open, a = XMLHttpRequest.prototype.send, o = function(e, t, n = !0, a, o) {
1486
+ return r.set(this, {
1487
+ method: e.toUpperCase(),
1488
+ url: j(String(t))
1489
+ }), i.call(this, e, String(t), n, a, o);
1490
+ }, s = function(t) {
1491
+ var i;
1492
+ let o = (i = r.get(this)) == null ? {} : i;
1493
+ if (!o.url || Me(e.config, o.url)) return a.call(this, t);
1494
+ let s = bn(e, "xhr", o), c = yn(e, o.url), l = vn(e, o.url);
1495
+ Ne(e.config, o.url) && gn(this, s);
1496
+ let u = !1, d = () => {
1497
+ c.cancel(), !u && (u = !0, n.delete(d), l(), s.end());
1498
+ };
1499
+ n.add(d);
1500
+ let f = () => {
1501
+ u || (xn(e, s, "xhr", {
1502
+ requestBody: t,
1503
+ type: "xhr",
1504
+ xhr: this
1505
+ }, o), l(), c.complete((t) => {
1506
+ u || (u = !0, n.delete(d), t && s.setAttributes(e.applyRedact(cn(t))), s.end());
1507
+ }));
1508
+ };
1509
+ this.addEventListener("loadend", f, { once: !0 });
1510
+ try {
1511
+ return a.call(this, t);
1512
+ } catch (e) {
1513
+ throw e instanceof Error && s.recordException(e), f(), e;
1514
+ }
1515
+ };
1516
+ XMLHttpRequest.prototype.open = o, XMLHttpRequest.prototype.send = s, t.push(() => {
1517
+ XMLHttpRequest.prototype.open === o && (XMLHttpRequest.prototype.open = i), XMLHttpRequest.prototype.send === s && (XMLHttpRequest.prototype.send = a);
1518
+ });
656
1519
  }
657
- p({ instrumentations: a });
658
- })();
1520
+ }
659
1521
  },
660
1522
  shutdown() {
661
- for (; a.length;) {
662
- var e, t;
663
- (e = a.pop()) == null || (t = e.disable) == null || t.call(e);
664
- }
1523
+ var e;
1524
+ for (let e of [...n]) e();
1525
+ for (; t.length;) (e = t.pop()) == null || e();
665
1526
  }
666
1527
  };
667
- }, pt = (e) => {
1528
+ }, W = (e) => {
668
1529
  let t = 5381;
669
1530
  for (let n = 0; n < e.length; n++) t = t * 33 ^ e.charCodeAt(n);
670
1531
  return (t >>> 0).toString(36);
671
- }, mt = (e, t) => {
1532
+ }, Cn = (e, t) => {
672
1533
  let n = /* @__PURE__ */ new Map(), r = 0, i = (t) => {
673
1534
  if (!(t - r < e)) {
674
1535
  r = t;
@@ -690,24 +1551,24 @@ var qe = (e) => typeof e == "string" && e.length > 0 ? e : void 0, Je = (e) => {
690
1551
  count: o.count
691
1552
  });
692
1553
  } };
693
- }, ht = 6e4, gt = 5, _t = /^https?:|^\/\//i, vt = (e, t) => {
694
- if (t) return _t.test(t) ? e(t) : t;
695
- }, yt = () => {
1554
+ }, wn = 6e4, Tn = 5, En = /^https?:|^\/\//i, Dn = (e, t) => {
1555
+ if (t) return En.test(t) ? e(t) : t;
1556
+ }, On = () => {
696
1557
  let e;
697
1558
  return {
698
1559
  name: "csp-violation",
699
1560
  init(t) {
700
1561
  if (typeof window > "u" || typeof document > "u") return;
701
- let n = mt(ht, gt), r = (e) => {
702
- let r = pt(`${e.violatedDirective}|${e.blockedURI}|${e.sourceFile}|${e.lineNumber}`), i = n.allow(r);
1562
+ let n = Cn(wn, Tn), r = (e) => {
1563
+ let r = W(`${e.violatedDirective}|${e.blockedURI}|${e.sourceFile}|${e.lineNumber}`), i = n.allow(r);
703
1564
  if (!i.allowed) return;
704
- let a = vt(t.config.hooks.redactUrl, e.blockedURI), o = e.sourceFile ? t.config.hooks.redactUrl(e.sourceFile) : void 0, s = i.count === 1;
705
- t.startSpan("csp.violation", E(E(E({}, t.config.hooks.getPageAttributes()), F({
1565
+ let a = Dn(t.config.hooks.redactUrl, e.blockedURI), o = e.sourceFile ? t.config.hooks.redactUrl(e.sourceFile) : void 0, s = i.count === 1;
1566
+ t.startSpan("csp.violation", O(O(O({}, t.config.hooks.getPageAttributes()), I({
706
1567
  errorType: "csp",
707
1568
  eventLabel: "CSP 错误",
708
- result: N.error,
1569
+ result: P.error,
709
1570
  spanSubtype: "csp",
710
- spanType: P.error,
1571
+ spanType: F.error,
711
1572
  targetLabel: a == null ? e.effectiveDirective : a,
712
1573
  targetValue: e.statusCode
713
1574
  })), {}, {
@@ -721,7 +1582,7 @@ var qe = (e) => typeof e == "string" && e.length > 0 ? e : void 0, Je = (e) => {
721
1582
  "csp.status_code": e.statusCode,
722
1583
  "csp.fingerprint": r,
723
1584
  "csp.window_count": i.count,
724
- [x.exceptionFingerprint]: r,
1585
+ [T.exceptionFingerprint]: r,
725
1586
  "error.source": "csp"
726
1587
  }, s ? { "csp.original_policy": e.originalPolicy } : {})).end();
727
1588
  };
@@ -731,7 +1592,7 @@ var qe = (e) => typeof e == "string" && e.length > 0 ? e : void 0, Je = (e) => {
731
1592
  e == null || e(), e = void 0;
732
1593
  }
733
1594
  };
734
- }, B = (e) => typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : `${e}-${Date.now()}-${Math.random().toString(16).slice(2)}`, bt = "BK_RUM_DEVICE_ID", xt = 250, St = () => navigator.connection, Ct = () => navigator.userAgentData, wt = (e) => {
1595
+ }, kn = "BK_RUM_DEVICE_ID", An = 250, jn = () => navigator.connection, Mn = () => navigator.userAgentData, Nn = (e) => {
735
1596
  for (let [t, n] of [
736
1597
  ["Edge", /Edg\/([\d.]+)/],
737
1598
  ["Chrome", /Chrome\/([\d.]+)/],
@@ -748,21 +1609,21 @@ var qe = (e) => typeof e == "string" && e.length > 0 ? e : void 0, Je = (e) => {
748
1609
  name: "Other",
749
1610
  version: void 0
750
1611
  };
751
- }, Tt = (e, t) => {
1612
+ }, Pn = (e, t) => {
752
1613
  let n = `${t == null ? "" : t} ${e}`;
753
1614
  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";
754
- }, Et = (e) => {
1615
+ }, Fn = (e) => {
755
1616
  let t = null;
756
1617
  try {
757
1618
  t = window.localStorage.getItem(e);
758
1619
  } catch (e) {}
759
1620
  if (t) return t;
760
- let n = B("device");
1621
+ let n = N("device");
761
1622
  try {
762
1623
  window.localStorage.setItem(e, n);
763
1624
  } catch (e) {}
764
1625
  return n;
765
- }, Dt = () => {
1626
+ }, In = () => {
766
1627
  var e, t;
767
1628
  return typeof window > "u" ? {} : {
768
1629
  "browser.viewport.width": window.innerWidth,
@@ -770,8 +1631,8 @@ var qe = (e) => typeof e == "string" && e.length > 0 ? e : void 0, Je = (e) => {
770
1631
  "browser.screen.width": (e = window.screen) == null ? void 0 : e.width,
771
1632
  "browser.screen.height": (t = window.screen) == null ? void 0 : t.height
772
1633
  };
773
- }, Ot = () => {
774
- let e = St();
1634
+ }, Ln = () => {
1635
+ let e = jn();
775
1636
  return e ? {
776
1637
  "network.effective_type": e.effectiveType,
777
1638
  "network.connection_type": e.type,
@@ -779,60 +1640,57 @@ var qe = (e) => typeof e == "string" && e.length > 0 ? e : void 0, Je = (e) => {
779
1640
  "network.rtt": e.rtt,
780
1641
  "network.save_data": e.saveData
781
1642
  } : {};
782
- }, kt = () => {
1643
+ }, Rn = () => {
783
1644
  if (typeof navigator > "u") return {};
784
- let e = Ct(), t = navigator.userAgent, n = wt(t), r = Tt(t, e == null ? void 0 : e.platform), i = e != null && e.mobile || /mobi|android|iphone|ipad|ipod/i.test(t) ? "mobile" : "desktop";
1645
+ let e = Mn(), t = navigator.userAgent, n = Nn(t), r = Pn(t, e == null ? void 0 : e.platform), i = e != null && e.mobile || /mobi|android|iphone|ipad|ipod/i.test(t) ? "mobile" : "desktop";
785
1646
  return {
786
1647
  "device.memory": navigator.deviceMemory,
787
1648
  "device.cpu_cores": navigator.hardwareConcurrency,
788
1649
  "device.platform": e == null ? void 0 : e.platform,
789
1650
  "device.mobile": e == null ? void 0 : e.mobile,
790
- [x.browserName]: n.name,
791
- [x.browserVersion]: n.version,
792
- [x.deviceType]: i,
793
- [x.osName]: r,
794
- "user_agent.name": n.name,
795
- "user_agent.version": n.version,
796
- "user_agent.os.name": r
1651
+ [T.browserName]: n.name,
1652
+ [T.browserVersion]: n.version,
1653
+ [T.deviceType]: i,
1654
+ [T.osName]: r
797
1655
  };
798
- }, At = (e, t) => {
1656
+ }, zn = (e, t) => {
799
1657
  let n;
800
1658
  return () => {
801
1659
  n !== void 0 && window.clearTimeout(n), n = window.setTimeout(() => {
802
1660
  n = void 0, e();
803
1661
  }, t);
804
1662
  };
805
- }, jt = (e = {}) => {
806
- var t;
807
- let n = [], r = (t = e.storageKey) == null ? bt : t;
1663
+ }, Bn = (e = {}) => {
1664
+ let t = [];
808
1665
  return {
809
1666
  name: "device",
810
- init(e) {
811
- let t = typeof window > "u" ? B("device") : Et(r);
812
- if (e.setRuntimeAttributes(E(E(E({ "device.id": t }, kt()), Dt()), Ot())), typeof window > "u") return;
813
- let i = At(() => {
814
- e.setRuntimeAttributes(Dt());
815
- }, xt);
816
- window.addEventListener("resize", i), window.addEventListener("orientationchange", i), n.push(() => window.removeEventListener("resize", i), () => window.removeEventListener("orientationchange", i));
817
- let a = St();
818
- if (a && typeof a.addEventListener == "function") {
819
- let t = () => {
820
- e.setRuntimeAttributes(Ot());
1667
+ init(n) {
1668
+ var r;
1669
+ let i = (r = e.storageKey) == null ? `${kn}_${W(n.config.application.name)}` : r, a = typeof window > "u" || e.persistentId !== !0 ? N("device") : Fn(i);
1670
+ if (n.setRuntimeAttributes(O(O(O({ "device.id": a }, Rn()), In()), Ln())), typeof window > "u") return;
1671
+ let o = zn(() => {
1672
+ n.setRuntimeAttributes(In());
1673
+ }, An);
1674
+ window.addEventListener("resize", o), window.addEventListener("orientationchange", o), t.push(() => window.removeEventListener("resize", o), () => window.removeEventListener("orientationchange", o));
1675
+ let s = jn();
1676
+ if (s && typeof s.addEventListener == "function") {
1677
+ let e = () => {
1678
+ n.setRuntimeAttributes(Ln());
821
1679
  };
822
- a.addEventListener("change", t), n.push(() => {
823
- var e;
824
- (e = a.removeEventListener) == null || e.call(a, "change", t);
1680
+ s.addEventListener("change", e), t.push(() => {
1681
+ var t;
1682
+ (t = s.removeEventListener) == null || t.call(s, "change", e);
825
1683
  });
826
1684
  }
827
1685
  },
828
1686
  shutdown() {
829
- for (; n.length;) {
1687
+ for (; t.length;) {
830
1688
  var e;
831
- (e = n.pop()) == null || e();
1689
+ (e = t.pop()) == null || e();
832
1690
  }
833
1691
  }
834
1692
  };
835
- }, Mt = 6e4, Nt = 5, Pt = (e, t) => typeof e == "number" && Number.isFinite(e) && e > 0 ? e : t, Ft = (e) => {
1693
+ }, Vn = 6e4, Hn = 5, Un = (e, t) => typeof e == "number" && Number.isFinite(e) && e > 0 ? e : t, Wn = (e) => {
836
1694
  if (e instanceof Error) return e.message;
837
1695
  if (typeof e == "string") return e;
838
1696
  try {
@@ -840,63 +1698,67 @@ var qe = (e) => typeof e == "string" && e.length > 0 ? e : void 0, Je = (e) => {
840
1698
  } catch (t) {
841
1699
  return String(e);
842
1700
  }
843
- }, It = (e) => {
1701
+ }, Gn = (e) => {
844
1702
  var t;
845
1703
  return e instanceof Error ? (t = e.stack) == null ? "" : t : "";
846
- }, Lt = (e) => e.slice(0, 80), Rt = (e) => {
1704
+ }, Kn = (e) => e.slice(0, 80), qn = (e) => {
847
1705
  var t, n;
848
1706
  return (t = (n = e.split("\n").find((e) => e.trim().startsWith("at "))) == null ? void 0 : n.trim()) == null ? "" : t;
849
- }, zt = (e) => e === "unhandledrejection" ? "promise" : e === "resource" ? "resource_load" : "js", Bt = ({ context: e, error: n, exceptionType: r, extra: i = {}, source: a, spanName: o, throttle: s }) => {
850
- let c = Ft(n), l = It(n), u = pt(`${a}|${c}|${l.slice(0, 256)}`), d = s.allow(u);
1707
+ }, Jn = (e) => e === "unhandledrejection" ? "promise" : e === "resource" ? "resource_load" : "js", Yn = ({ context: e, error: t, exceptionType: n, extra: r = {}, source: i, spanName: a, throttle: o }) => {
1708
+ let s = Wn(t), l = Gn(t), u = W(`${i}|${s}|${l.slice(0, 256)}`), d = o.allow(u);
851
1709
  if (!d.allowed) return;
852
- let f = n instanceof Error ? n : {
853
- message: c,
854
- name: r == null ? a : r
855
- }, p = E(E(E(E({}, e.config.hooks.getPageAttributes()), e.config.hooks.getErrorAttributes()), F({
856
- errorType: zt(a),
1710
+ e.notifyActivity({
1711
+ time: Date.now(),
1712
+ type: "error"
1713
+ });
1714
+ let f = t instanceof Error ? t : {
1715
+ message: s,
1716
+ name: n == null ? i : n
1717
+ }, p = O(O(O(O({}, e.config.hooks.getPageAttributes()), e.config.hooks.getErrorAttributes()), I({
1718
+ errorType: Jn(i),
857
1719
  eventLabel: "错误",
858
- result: N.error,
859
- spanSubtype: zt(a),
860
- spanType: P.error,
861
- targetLabel: n instanceof Error ? n.name : r == null ? a : r
1720
+ result: P.error,
1721
+ spanSubtype: Jn(i),
1722
+ spanType: F.error,
1723
+ targetLabel: t instanceof Error ? t.name : n == null ? i : n
862
1724
  })), {}, {
863
- "exception.message": c,
864
- [x.exceptionMessageShort]: Lt(c),
1725
+ "exception.message": s,
1726
+ [T.exceptionMessageShort]: Kn(s),
865
1727
  "exception.stacktrace": l,
866
- [x.exceptionStackTopFrame]: Rt(l),
867
- "exception.type": n instanceof Error ? n.name : r == null ? a : r,
868
- [x.exceptionFingerprint]: u,
1728
+ [T.exceptionStackTopFrame]: qn(l),
1729
+ "exception.type": t instanceof Error ? t.name : n == null ? i : n,
1730
+ [T.exceptionFingerprint]: u,
869
1731
  "error.handled": !1,
870
- "error.source": a,
1732
+ "error.source": i,
871
1733
  "error.window_count": d.count
872
- }, i), m = e.startSpan(o, p);
1734
+ }, r), m = e.startSpan(a, p);
873
1735
  m.recordException(f), m.setStatus({
874
- code: t.ERROR,
875
- message: c
1736
+ code: c.ERROR,
1737
+ message: s
876
1738
  }), m.end();
877
- }, Vt = (e = {}) => {
878
- let t = [], n = Pt(e.windowMs, Mt), r = Pt(e.maxPerWindow, Nt);
1739
+ }, Xn = (e = {}) => {
1740
+ let t = [], n = Un(e.windowMs, Vn), r = Un(e.maxPerWindow, Hn);
879
1741
  return {
880
1742
  name: "error",
881
1743
  init(e) {
882
1744
  if (typeof window > "u") return;
883
- let i = mt(n, r), a = (t) => {
1745
+ let i = Cn(n, r), a = (t) => {
884
1746
  var n;
885
1747
  let r = !t.error && !t.filename && t.message === "Script error.";
886
- Bt({
1748
+ Yn({
887
1749
  context: e,
888
1750
  throttle: i,
889
1751
  spanName: "browser.error",
890
1752
  source: "window.error",
891
1753
  error: (n = t.error) == null ? t.message : n,
892
- extra: E({
1754
+ extra: O({
893
1755
  "code.filepath": t.filename,
894
1756
  "code.lineno": t.lineno,
895
1757
  "code.column": t.colno
896
1758
  }, r ? { "error.cross_origin": !0 } : {})
897
1759
  });
898
1760
  }, o = (t) => {
899
- Bt({
1761
+ Yn({
900
1762
  context: e,
901
1763
  throttle: i,
902
1764
  spanName: "browser.unhandledrejection",
@@ -909,7 +1771,7 @@ var qe = (e) => typeof e == "string" && e.length > 0 ? e : void 0, Je = (e) => {
909
1771
  let n = t.target;
910
1772
  if (!(n instanceof Element)) return;
911
1773
  let r = n, a = r.src || r.href || n.currentSrc || "";
912
- Bt({
1774
+ Yn({
913
1775
  context: e,
914
1776
  throttle: i,
915
1777
  spanName: "browser.resource_error",
@@ -931,350 +1793,313 @@ var qe = (e) => typeof e == "string" && e.length > 0 ? e : void 0, Je = (e) => {
931
1793
  }
932
1794
  }
933
1795
  };
934
- }, Ht = 10 * 1024, Ut = 10, Wt = (e) => e.body, Gt = (e, t) => typeof e == "number" && Number.isFinite(e) && e > 0 ? e : t, V = /* @__PURE__ */ new WeakMap(), Kt = (e, t) => e.length <= t ? {
935
- body: e,
936
- truncated: !1
937
- } : {
938
- body: e.slice(0, t),
939
- truncated: !0
940
- }, qt = (e, t) => {
941
- if (!e) return;
942
- if (e instanceof Headers) return e.get(t) || void 0;
943
- let n = t.toLowerCase();
944
- if (Array.isArray(e)) {
945
- var r;
946
- return (r = e.find(([e]) => e.toLowerCase() === n)) == null ? void 0 : r[1];
947
- }
948
- let i = Object.keys(e).find((e) => e.toLowerCase() === n);
949
- return i ? e[i] : void 0;
950
- }, Jt = (e) => {
951
- let t = {};
952
- return e.forEach((e, n) => {
953
- t[n] = e instanceof File ? `[File name=${e.name} type=${e.type || "unknown"} size=${e.size}]` : e;
954
- }), JSON.stringify(t);
955
- }, Yt = function() {
956
- var e = A(function* (e) {
957
- return e == null ? "" : typeof e == "string" ? e : e instanceof URLSearchParams ? e.toString() : e instanceof FormData ? Jt(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);
958
- });
959
- return function(t) {
960
- return e.apply(this, arguments);
961
- };
962
- }(), Xt = function() {
963
- var e = A(function* (e, t, n) {
964
- let r = yield Yt(e);
965
- if (r) return E(E({}, Kt(r, t)), {}, { contentType: n });
966
- });
967
- return function(t, n, r) {
968
- return e.apply(this, arguments);
969
- };
970
- }(), H = function() {
971
- var e = A(function* (e, t, n) {
972
- try {
973
- return yield Xt(e, t, n);
974
- } catch (e) {
975
- return;
976
- }
977
- });
978
- return function(t, n, r) {
979
- return e.apply(this, arguments);
980
- };
981
- }(), Zt = (e) => e instanceof Request ? e.url : String(e), Qt = (e, t) => t != null && t.method ? t.method : e instanceof Request ? e.method : "GET", $t = (e, t, n) => t != null && t.body ? () => H(t.body, n, qt(t.headers, "content-type")) : (e instanceof Request, () => Promise.resolve(void 0)), en = function() {
982
- var e = A(function* (e, t) {
983
- try {
984
- let n = e.headers.get("content-type") || void 0, r = e.headers.get("content-length");
985
- if (r) {
986
- let e = Number(r);
987
- if (Number.isFinite(e) && e > t * Ut) return {
988
- body: "",
989
- contentType: n,
990
- truncated: !0
991
- };
992
- }
993
- let i = e.clone();
994
- return H(i.body ? yield i.text() : "", t, n);
995
- } catch (e) {
996
- return;
997
- }
998
- });
999
- return function(t, n) {
1000
- return e.apply(this, arguments);
1001
- };
1002
- }(), tn = (e, t) => {
1003
- if (e.responseType === "" || e.responseType === "text") return E(E({}, Kt(e.responseText || "", t)), {}, { contentType: e.getResponseHeader("content-type") || void 0 });
1004
- if (e.responseType === "json") return E(E({}, Kt(JSON.stringify(e.response), t)), {}, { contentType: e.getResponseHeader("content-type") || void 0 });
1005
- }, nn = (e, t, n) => {
1006
- if (n) return e.redact(E(E({}, t), {}, {
1007
- body: n.body,
1008
- truncated: n.truncated
1009
- }));
1010
- }, U = ({ config: e, context: t, duration: n, error: r, method: i, request: a, response: s, status: c, subtype: l, url: u }) => {
1011
- let d = !!r || typeof c == "number" && c >= 400, f = i.toUpperCase(), p = d ? nn(e, {
1012
- contentType: a == null ? void 0 : a.contentType,
1013
- method: f,
1014
- status: c,
1015
- type: "request",
1016
- url: u
1017
- }, a) : void 0, m = d ? nn(e, {
1018
- contentType: s == null ? void 0 : s.contentType,
1019
- method: f,
1020
- status: c,
1021
- type: "response",
1022
- url: u
1023
- }, s) : void 0, h = E(E(E({}, t.config.hooks.getPageAttributes()), ze({
1024
- duration: n,
1025
- method: f,
1026
- statusCode: c,
1027
- subtype: l,
1028
- url: t.config.hooks.redactUrl(u),
1029
- urlPathTemplate: t.config.hooks.getViewPathGroup(u)
1030
- })), {}, {
1031
- "http.duration": n,
1032
- "http.request.method": f,
1033
- "url.full": t.config.hooks.redactUrl(u)
1034
- });
1035
- if (typeof c == "number" && (h["http.response.status_code"] = c), p != null && (h["http.request.body"] = p), m != null && (h["http.response.body"] = m), d) {
1036
- var g, _;
1037
- h["http_body.request.truncated"] = (g = a == null ? void 0 : a.truncated) == null ? !1 : g, h["http_body.response.truncated"] = (_ = s == null ? void 0 : s.truncated) == null ? !1 : _;
1038
- }
1039
- if (r instanceof Error) {
1040
- var v;
1041
- h["exception.message"] = r.message, h["exception.type"] = r.name, h["exception.stacktrace"] = (v = r.stack) == null ? "" : v;
1042
- }
1043
- t.emitLog({
1044
- severityNumber: d ? o.ERROR : o.INFO,
1045
- severityText: d ? "ERROR" : "INFO",
1046
- body: d ? "HTTP request completed with error" : "HTTP request completed",
1047
- attributes: h
1048
- });
1049
- }, rn = (e = {}) => {
1050
- var t;
1051
- let n = [], r = {
1052
- maxBodySize: Gt(e.maxBodySize, Ht),
1053
- redact: (t = e.redact) == null ? Wt : t
1054
- };
1055
- return {
1056
- name: "http-body",
1057
- init(e) {
1058
- if (typeof window > "u") return;
1059
- let { maxBodySize: t } = r, i = window.fetch;
1060
- if (typeof i == "function") {
1061
- let a = function() {
1062
- var n = A(function* (n, a) {
1063
- let o = Zt(n);
1064
- if (M(e.config, o)) return i(n, a);
1065
- let s = Qt(n, a), c = $t(n, a, t), l = performance.now();
1066
- try {
1067
- let u = yield i(n, a), d = performance.now() - l, f = u.status >= 400;
1068
- return U({
1069
- config: r,
1070
- context: e,
1071
- duration: d,
1072
- method: s,
1073
- request: f ? yield c() : void 0,
1074
- response: f ? yield en(u, t) : void 0,
1075
- status: u.status,
1076
- subtype: "fetch",
1077
- url: o
1078
- }), u;
1079
- } catch (t) {
1080
- let n = yield c();
1081
- throw U({
1082
- config: r,
1083
- context: e,
1084
- duration: performance.now() - l,
1085
- error: t,
1086
- method: s,
1087
- request: n,
1088
- subtype: "fetch",
1089
- url: o
1090
- }), t;
1091
- }
1092
- });
1093
- return function(e, t) {
1094
- return n.apply(this, arguments);
1095
- };
1096
- }();
1097
- window.fetch = a, n.push(() => {
1098
- window.fetch === a && (window.fetch = i);
1099
- });
1100
- }
1101
- let a = XMLHttpRequest.prototype.open, o = XMLHttpRequest.prototype.send, s = XMLHttpRequest.prototype.setRequestHeader, c = function(e, t, ...n) {
1102
- var r;
1103
- return V.set(this, {
1104
- method: e,
1105
- startTime: performance.now(),
1106
- url: String(t)
1107
- }), a.call(this, e, t, (r = n[0]) == null ? !0 : r, n[1], n[2]);
1108
- }, l = function(e, t) {
1109
- let n = V.get(this);
1110
- if (n) {
1111
- var r;
1112
- let i = e.toLowerCase(), a = (r = n.requestHeaders) == null ? {} : r, o = a[i];
1113
- a[i] = o ? `${o}, ${t}` : t, n.requestHeaders = a;
1114
- }
1115
- return s.call(this, e, t);
1116
- }, u = function(n) {
1117
- var i = this;
1118
- let a = V.get(this);
1119
- if (a) {
1120
- var s;
1121
- a.requestBody = n, a.requestContentType = (s = a.requestHeaders) == null ? void 0 : s["content-type"];
1122
- }
1123
- return this.addEventListener("abort", () => {
1124
- let e = V.get(this);
1125
- e && (e.aborted = !0);
1126
- }, { once: !0 }), this.addEventListener("error", () => {
1127
- let e = V.get(this);
1128
- e && (e.networkError = !0);
1129
- }, { once: !0 }), this.addEventListener("loadend", () => {
1130
- A(function* () {
1131
- let n = V.get(i);
1132
- if (!n || M(e.config, n.url) || n.aborted) return;
1133
- let a = n.networkError || i.status >= 400, o = a ? tn(i, t) : void 0, s = a ? yield H(n.requestBody, t, n.requestContentType) : void 0;
1134
- U({
1135
- config: r,
1136
- context: e,
1137
- duration: performance.now() - n.startTime,
1138
- error: n.networkError ? /* @__PURE__ */ Error("XHR network error") : void 0,
1139
- method: n.method,
1140
- request: s,
1141
- response: o,
1142
- status: i.status,
1143
- subtype: "xhr",
1144
- url: n.url
1145
- });
1146
- })();
1147
- }, { once: !0 }), o.call(this, n);
1148
- };
1149
- XMLHttpRequest.prototype.open = c, XMLHttpRequest.prototype.setRequestHeader = l, XMLHttpRequest.prototype.send = u, n.push(() => {
1150
- XMLHttpRequest.prototype.open === c && (XMLHttpRequest.prototype.open = a), XMLHttpRequest.prototype.setRequestHeader === l && (XMLHttpRequest.prototype.setRequestHeader = s), XMLHttpRequest.prototype.send === u && (XMLHttpRequest.prototype.send = o);
1151
- });
1152
- },
1153
- shutdown() {
1154
- for (; n.length;) {
1155
- var e;
1156
- (e = n.pop()) == null || e();
1157
- }
1158
- }
1159
- };
1160
- }, an = 50, on = (e, t) => typeof e == "number" && Number.isFinite(e) && e >= 0 ? e : t, sn = (e = {}) => {
1161
- let t, n = on(e.threshold, an);
1796
+ }, Zn = 50, Qn = 100, $n = 700, er = (e, t) => typeof e == "number" && Number.isFinite(e) && e >= 0 ? e : t, tr = (e) => Number.isFinite(e) ? e : void 0, nr = (e, t) => {
1797
+ var n;
1798
+ let r = (n = e.attribution) == null ? void 0 : n[0];
1799
+ return r != null && r.containerSrc ? t(r.containerSrc) : (r == null ? void 0 : r.containerName) || (r == null ? void 0 : r.name) || e.name || "unknown";
1800
+ }, rr = (e, t) => ({
1801
+ "long_task.script.duration": e.duration,
1802
+ "long_task.script.execution_start": e.executionStart,
1803
+ "long_task.script.forced_style_and_layout_duration": e.forcedStyleAndLayoutDuration,
1804
+ "long_task.script.invoker": e.invoker,
1805
+ "long_task.script.invoker_type": e.invokerType,
1806
+ "long_task.script.pause_duration": e.pauseDuration,
1807
+ "long_task.script.source_char_position": e.sourceCharPosition,
1808
+ "long_task.script.source_function_name": e.sourceFunctionName,
1809
+ "long_task.script.source_url": e.sourceURL ? t(e.sourceURL) : "",
1810
+ "long_task.script.start_time": e.startTime,
1811
+ "long_task.script.window_attribution": e.windowAttribution
1812
+ }), ir = (e = {}) => {
1813
+ let t = er(e.threshold, Zn), n = Math.max(t, er(e.warningThreshold, Qn)), r, i, a = [];
1162
1814
  return {
1163
1815
  name: "long-task",
1164
1816
  init(e) {
1165
- var r;
1166
- if (typeof PerformanceObserver > "u" || !((r = PerformanceObserver.supportedEntryTypes) != null && r.includes("longtask"))) return;
1167
- let i = e.meter.createCounter("browser.long_task.count", { description: "Number of long tasks observed (duration >= threshold)" }), a = e.meter.createHistogram("browser.long_task.duration", {
1168
- unit: "ms",
1169
- description: "Duration of long tasks"
1170
- });
1817
+ var o;
1818
+ if (typeof PerformanceObserver > "u" || typeof performance > "u") return;
1819
+ let s = (o = PerformanceObserver.supportedEntryTypes) == null ? [] : o, c = s.includes("long-animation-frame") ? "long-animation-frame" : s.includes("longtask") ? "longtask" : void 0;
1820
+ if (!c) return;
1821
+ let l = e.meter.createCounter("browser.long_task.count", { description: "Number of long tasks and long animation frames" }), u = e.meter.createHistogram("browser.long_task.duration", {
1822
+ description: "Duration of long tasks and long animation frames",
1823
+ unit: "ms"
1824
+ }), d = e.meter.createHistogram("browser.long_task.blocking_duration", {
1825
+ description: "Blocking duration of long animation frames",
1826
+ unit: "ms"
1827
+ }), f = (r) => {
1828
+ var i, a, o;
1829
+ if (!Number.isFinite(r.duration) || r.duration < t) return;
1830
+ let s = r.entryType === "long-animation-frame", c = s ? r : void 0, f = (i = c == null ? void 0 : c.scripts) == null ? [] : i, p = f.reduce((e, t) => !e || t.duration > e.duration ? t : e, void 0), m = N("long-task"), h = performance.timeOrigin + r.startTime, g = h + r.duration, _ = r.duration >= n ? P.warning : P.success, v = s ? "long-animation-frame" : "long-task", y = p != null && p.sourceURL ? e.config.hooks.redactUrl(p.sourceURL) : void 0, b = s ? void 0 : nr(r, e.config.hooks.redactUrl), x = y || (p == null ? void 0 : p.sourceFunctionName) || b || "unknown", S = e.startSpan("browser.long_task", O(O(O(O(O(O(O(O({}, e.config.hooks.getPageAttributes()), I({
1831
+ duration: r.duration,
1832
+ errorType: _ === P.warning ? "main_thread_blocked" : "none",
1833
+ eventLabel: s ? "长动画帧" : "长任务",
1834
+ result: _,
1835
+ spanSubtype: v,
1836
+ spanType: F.longtask,
1837
+ targetLabel: x,
1838
+ targetValue: (a = c == null ? void 0 : c.blockingDuration) == null ? r.duration : a
1839
+ })), {}, {
1840
+ [T.longTaskBlockingDuration]: (o = c == null ? void 0 : c.blockingDuration) == null ? r.duration : o,
1841
+ [T.longTaskDuration]: r.duration,
1842
+ [T.longTaskEntryType]: v,
1843
+ [T.longTaskId]: m,
1844
+ [T.longTaskIsFrozenFrame]: r.duration >= $n,
1845
+ [T.longTaskScriptCount]: f.length
1846
+ }, b ? { [T.longTaskCulprit]: b } : {}), p ? {
1847
+ [T.longTaskCulprit]: x,
1848
+ "long_task.culprit.duration": p.duration,
1849
+ "long_task.culprit.forced_style_and_layout_duration": p.forcedStyleAndLayoutDuration,
1850
+ "long_task.culprit.function_name": p.sourceFunctionName,
1851
+ "long_task.culprit.invoker_type": p.invokerType
1852
+ } : {}), tr(c == null ? void 0 : c.firstUIEventTimestamp) === void 0 ? {} : { "long_task.first_ui_event_timestamp": c.firstUIEventTimestamp }), tr(c == null ? void 0 : c.renderStart) === void 0 ? {} : { "long_task.render_start": c.renderStart }), tr(c == null ? void 0 : c.styleAndLayoutStart) === void 0 ? {} : { "long_task.style_and_layout_start": c.styleAndLayoutStart }), c ? { [T.longTaskStartTime]: c.startTime } : {}), { startTime: h });
1853
+ f.forEach((t) => {
1854
+ S.addEvent("long_task.script", e.applyRedact(rr(t, e.config.hooks.redactUrl)), performance.timeOrigin + t.startTime);
1855
+ }), S.end(g), e.notifyActivity({
1856
+ endTime: g,
1857
+ startTime: h,
1858
+ type: "long_task"
1859
+ });
1860
+ let C = e.applyRedact(O(O(O({}, e.config.hooks.getMetricAttributes()), z(e.getRuntimeAttributes())), {}, { [T.longTaskEntryType]: v }));
1861
+ l.add(1, C), u.record(r.duration, C), c && d.record(c.blockingDuration, C);
1862
+ }, p = (e) => e.forEach((e) => f(e));
1171
1863
  try {
1172
- t = new PerformanceObserver((t) => {
1173
- let r = e.applyRedact(E(E(E({}, e.config.hooks.getPageAttributes()), e.config.hooks.getMetricAttributes()), I(e.getRuntimeAttributes())));
1174
- for (let h of t.getEntries()) {
1175
- var o, s, c, l, u, d, f, p, m;
1176
- if (h.duration < n) continue;
1177
- let t = (o = h.attribution) == null ? void 0 : o[0], g = E(E({}, r), {}, { [x.longtaskAttributionScript]: (s = (c = t == null ? void 0 : t.containerSrc) == null ? t == null ? void 0 : t.name : c) == null ? "unknown" : s }), _ = h.duration > 100 ? N.warning : N.success;
1178
- e.startSpan("browser.long_task", E(E(E({}, r), F({
1179
- duration: h.duration,
1180
- errorType: _ === N.warning ? "longtask_blocking" : "none",
1181
- eventLabel: "长任务",
1182
- result: _,
1183
- spanSubtype: (l = t == null ? void 0 : t.name) == null ? "unknown" : l,
1184
- spanType: P.longtask,
1185
- targetLabel: (u = (d = (f = t == null ? void 0 : t.containerSrc) == null ? t == null ? void 0 : t.containerName : f) == null ? t == null ? void 0 : t.name : d) == null ? "unknown" : u,
1186
- targetValue: h.duration
1187
- })), {}, {
1188
- [x.longtaskBlockingDuration]: h.duration,
1189
- [x.longtaskAttributionScript]: (p = (m = t == null ? void 0 : t.containerSrc) == null ? t == null ? void 0 : t.name : m) == null ? "unknown" : p
1190
- }), { startTime: performance.timeOrigin + h.startTime }).end(performance.timeOrigin + h.startTime + h.duration), i.add(1, g), a.record(h.duration, g);
1191
- }
1192
- }), t.observe({
1193
- type: "longtask",
1864
+ let e = !0;
1865
+ r = new PerformanceObserver((t) => {
1866
+ let n = t.getEntries();
1867
+ e ? (a.push(...n), i || (i = setTimeout(() => {
1868
+ let e = a;
1869
+ a = [], i = void 0, p(e);
1870
+ }))) : p(n);
1871
+ }), r.observe({
1872
+ type: c,
1194
1873
  buffered: !0
1195
- });
1874
+ }), e = !1;
1196
1875
  } catch (e) {
1197
- t = void 0;
1876
+ r = void 0;
1198
1877
  }
1199
1878
  },
1200
1879
  shutdown() {
1201
- t == null || t.disconnect(), t = void 0;
1880
+ r == null || r.disconnect(), r = void 0, clearTimeout(i), i = void 0, a = [];
1202
1881
  }
1203
1882
  };
1204
- }, W = /* @__PURE__ */ new Set(), G = "", K, q, J = !1, Y = () => typeof location > "u" ? "" : location.href, X = (e, t) => {
1883
+ }, G = /* @__PURE__ */ new Set(), K = "", q, J, ar = !1, Y = () => typeof location > "u" ? "" : location.href, or = (e, t) => {
1205
1884
  let n = Y();
1206
- G = n;
1885
+ K = n;
1207
1886
  let r = {
1208
1887
  fromUrl: t,
1209
1888
  source: e,
1210
1889
  toUrl: n
1211
1890
  };
1212
- for (let e of Array.from(W)) e(r);
1213
- }, cn = () => {
1214
- X("popstate", G || Y());
1215
- }, ln = () => {
1216
- X("hashchange", G || Y());
1217
- }, un = () => {
1218
- J || typeof window > "u" || typeof history > "u" || (J = !0, G = Y(), K = history.pushState, q = history.replaceState, history.pushState = function(e, t, n) {
1219
- let r = G || Y(), i = K == null ? void 0 : K.apply(this, [
1891
+ for (let e of Array.from(G)) e(r);
1892
+ }, sr = () => {
1893
+ or("popstate", K || Y());
1894
+ }, cr = () => {
1895
+ or("hashchange", K || Y());
1896
+ }, lr = () => {
1897
+ ar || typeof window > "u" || typeof history > "u" || (ar = !0, K = Y(), q = history.pushState, J = history.replaceState, history.pushState = function(e, t, n) {
1898
+ let r = K || Y(), i = q == null ? void 0 : q.apply(this, [
1220
1899
  e,
1221
1900
  t,
1222
1901
  n
1223
1902
  ]);
1224
- return X("pushState", r), i;
1903
+ return or("pushState", r), i;
1225
1904
  }, history.replaceState = function(e, t, n) {
1226
- let r = G || Y(), i = q == null ? void 0 : q.apply(this, [
1905
+ let r = K || Y(), i = J == null ? void 0 : J.apply(this, [
1227
1906
  e,
1228
1907
  t,
1229
1908
  n
1230
1909
  ]);
1231
- return X("replaceState", r), i;
1232
- }, window.addEventListener("popstate", cn), window.addEventListener("hashchange", ln));
1233
- }, dn = () => {
1234
- !J || typeof window > "u" || typeof history > "u" || (K && (history.pushState = K), q && (history.replaceState = q), window.removeEventListener("popstate", cn), window.removeEventListener("hashchange", ln), K = void 0, q = void 0, J = !1, G = "");
1235
- }, fn = (e) => typeof window > "u" || typeof history > "u" ? () => {} : (un(), W.add(e), () => {
1236
- W.delete(e), W.size === 0 && dn();
1237
- }), pn = () => typeof location > "u" ? "" : location.href, mn = () => {
1910
+ return or("replaceState", r), i;
1911
+ }, window.addEventListener("popstate", sr), window.addEventListener("hashchange", cr));
1912
+ }, ur = () => {
1913
+ !ar || typeof window > "u" || typeof history > "u" || (q && (history.pushState = q), J && (history.replaceState = J), window.removeEventListener("popstate", sr), window.removeEventListener("hashchange", cr), q = void 0, J = void 0, ar = !1, K = "");
1914
+ }, dr = (e) => typeof window > "u" || typeof history > "u" ? () => {} : (lr(), G.add(e), () => {
1915
+ G.delete(e), G.size === 0 && ur();
1916
+ }), fr = ["span", "stopLoadingTime"], pr = new Set([...Object.values(T), A]), mr = () => typeof location > "u" ? "" : location.href, hr = () => {
1917
+ if (typeof performance > "u") return {};
1918
+ let e = performance.getEntriesByType("navigation")[0];
1919
+ if (!e) return {};
1920
+ let t = {}, n = (e, n) => {
1921
+ Number.isFinite(n) && n > 0 && (t[e] = n);
1922
+ };
1923
+ return n(T.viewFirstByte, e.responseStart), n(T.viewDomInteractive, e.domInteractive), n(T.viewDomContentLoaded, e.domContentLoadedEventEnd), n(T.viewDomComplete, e.domComplete), n(T.viewLoadEvent, e.loadEventEnd), t;
1924
+ }, gr = (e) => {
1925
+ let t = e.indexOf("?");
1926
+ return t < 0 ? e : e.slice(0, t);
1927
+ }, _r = (e) => {
1928
+ let t = e.slice(1);
1929
+ if (!t || typeof document > "u" || typeof document.getElementById != "function") return !1;
1930
+ try {
1931
+ return !!document.getElementById(decodeURIComponent(t));
1932
+ } catch (e) {
1933
+ return !!document.getElementById(t);
1934
+ }
1935
+ }, vr = (e, t) => {
1936
+ try {
1937
+ let n = typeof location > "u" ? "http://localhost" : location.href, r = new URL(e, n), i = new URL(t, n);
1938
+ return r.pathname !== i.pathname || !_r(i.hash) && gr(r.hash) !== gr(i.hash);
1939
+ } catch (n) {
1940
+ return e !== t;
1941
+ }
1942
+ }, yr = () => {
1238
1943
  let e = [];
1239
1944
  return {
1240
1945
  name: "page-view",
1241
1946
  init(t) {
1242
1947
  if (typeof window > "u") return;
1243
- let n = "", r, i = (e, i = n) => {
1244
- let a = pn();
1245
- if (a === n) return;
1246
- r == null || r.setAttribute("view.end_reason", e), r == null || r.end(), n = a;
1247
- let o = B("view"), s = t.config.hooks.getViewPathGroup(a), c = e === "load" ? "initial_load" : "route_change", l = t.config.hooks.redactUrl(a), u = t.config.hooks.redactUrl(i);
1248
- t.setView({
1249
- id: o,
1250
- loadingType: c,
1251
- url: l,
1252
- urlPathGroup: s
1948
+ let n, r, i = t.config.view.loadingTime ? t.meter.createHistogram("browser.view.loading_time", {
1949
+ description: "Time from view start until network and DOM activity become idle",
1950
+ unit: "ms"
1951
+ }) : void 0, a = (e = Date.now()) => t.setView({}, e), o = (e, n, r = Date.now(), i) => {
1952
+ e.documentVersion += 1, t.emitLog({
1953
+ attributes: O(O(O(O(O({}, t.config.hooks.getPageAttributes()), e.attributes), e.snapshotAttributes), {}, {
1954
+ "event.type": "view",
1955
+ "view.document_version": e.documentVersion,
1956
+ "view.duration": Math.max(0, r - e.startedAt),
1957
+ "view.is_active": n !== "final",
1958
+ "view.snapshot.type": n
1959
+ }, i ? { "view.end_reason": i } : {}), e.loadingTime === void 0 ? {} : {
1960
+ [T.viewLoadingTime]: e.loadingTime,
1961
+ "view.loading_time.source": e.loadingTimeSource
1962
+ }),
1963
+ body: "browser.view",
1964
+ eventName: "browser.view",
1965
+ severityNumber: w.INFO,
1966
+ severityText: "INFO",
1967
+ timestamp: r
1968
+ });
1969
+ }, s = (e, r = !0, s = Date.now()) => {
1970
+ var c;
1971
+ if (!n) {
1972
+ r && a(s);
1973
+ return;
1974
+ }
1975
+ let l = O({}, n);
1976
+ (c = n.stopLoadingTime) == null || c.call(n), n.loadingTime !== void 0 && (i == null || i.record(n.loadingTime, t.applyRedact(O(O(O({}, t.config.hooks.getMetricAttributes()), z(t.getRuntimeAttributes())), {}, { "view.loading_type": n.loadingType })))), o(n, "final", s, e), n.span.setAttribute("view.end_reason", e), n.span.end(s), n = void 0, r && a(s);
1977
+ let { span: u, stopLoadingTime: d } = l;
1978
+ return Fe(l, fr);
1979
+ }, c = (e, t, r) => {
1980
+ if (n !== e || !Number.isFinite(t) || t < 0) return;
1981
+ let i = O(O({}, e.loadingType === "initial_load" ? hr() : {}), {}, {
1982
+ [T.viewLoadingTime]: t,
1983
+ "view.loading_time.source": r
1253
1984
  });
1254
- let d = e === "load", f = E(E(E({}, t.config.hooks.getPageAttributes()), F({
1985
+ e.span.setAttributes(i), Object.assign(e.snapshotAttributes, i), e.loadingTime = t, e.loadingTimeSource = r, o(e, "update");
1986
+ }, l = (e) => {
1987
+ if (!t.config.view.loadingTime || document.visibilityState === "hidden") return;
1988
+ let r = !1, i, a = e.loadingType !== "initial_load", o, s, l = !1, u, d = () => {
1989
+ var t;
1990
+ if (l || !r || !a || n !== e) return;
1991
+ let s = [i, o].filter((e) => e !== void 0);
1992
+ s.length && c(e, Math.max(...s), "auto"), (t = e.stopLoadingTime) == null || t.call(e), e.stopLoadingTime = void 0;
1993
+ }, f = () => {
1994
+ var t, n;
1995
+ let r = (t = (n = performance).getEntriesByType) == null ? void 0 : t.call(n, "navigation")[0];
1996
+ return r != null && r.loadEventEnd ? (o = Math.max(0, performance.timeOrigin + r.loadEventEnd - e.startedAt), a = !0, !0) : !1;
1997
+ };
1998
+ if (!a && !f()) {
1999
+ let t = () => {
2000
+ setTimeout(() => {
2001
+ n === e && (f(), a = !0, d());
2002
+ });
2003
+ };
2004
+ window.addEventListener("load", t, { once: !0 }), s = () => window.removeEventListener("load", t);
2005
+ }
2006
+ let p = St(t, e.startedAt, (t) => {
2007
+ r = !0, t.hadActivity && (i = Math.max(0, t.endTime - e.startedAt)), d();
2008
+ }), m = () => {
2009
+ var t;
2010
+ document.visibilityState === "hidden" && (l = !0, (t = e.stopLoadingTime) == null || t.call(e), e.stopLoadingTime = void 0);
2011
+ };
2012
+ document.addEventListener("visibilitychange", m), u = () => document.removeEventListener("visibilitychange", m), e.stopLoadingTime = () => {
2013
+ p(), s == null || s(), s = void 0, u == null || u(), u = void 0;
2014
+ }, d();
2015
+ }, u = (e) => {
2016
+ let n = t.applyRedact(e == null ? {} : e);
2017
+ return Object.fromEntries(Object.entries(n).filter(([e, t]) => t !== void 0 && !pr.has(e)));
2018
+ }, d = (e, r, i, a = ((e) => (e = n == null ? void 0 : n.rawUrl) == null ? "" : e)()) => {
2019
+ var c, d;
2020
+ if (!t.isSessionActive()) return;
2021
+ let f = (c = e.url) == null ? mr() : c, p = t.config.hooks.getViewPathGroup(f), m = (d = e.name) == null ? p : d, h = u(e.attributes);
2022
+ s(r, !1);
2023
+ let g = N("view"), _ = t.config.hooks.redactUrl(f), v = t.config.hooks.redactUrl(a), y = i === "initial_load", b = y && typeof performance < "u" ? performance.timeOrigin : Date.now(), x = y ? hr() : {};
2024
+ t.setView({
2025
+ attributes: h,
2026
+ id: g,
2027
+ loadingType: i,
2028
+ name: m,
2029
+ startedAt: b,
2030
+ url: _,
2031
+ urlPathGroup: p
2032
+ }, b);
2033
+ let S = O(O(O(O(O({}, h), t.config.hooks.getPageAttributes()), x), I({
1255
2034
  errorType: "none",
1256
- eventLabel: d ? "文档加载" : "路由切换",
1257
- spanSubtype: d ? "navigate" : e,
1258
- spanType: d ? P.document : P.route,
1259
- targetLabel: s,
1260
- traceScene: d ? "page_load" : "route_change"
2035
+ eventLabel: y ? "文档加载" : "路由切换",
2036
+ spanSubtype: y ? "navigate" : r,
2037
+ spanType: y ? F.document : F.route,
2038
+ targetLabel: p,
2039
+ traceScene: y ? "page_load" : "route_change"
1261
2040
  })), {}, {
1262
- [x.viewId]: o,
1263
- [x.viewUrl]: l,
1264
- [x.viewUrlPathGroup]: s,
1265
- [x.viewLoadingType]: c,
1266
- "url.previous": u,
1267
- "event.source": e
1268
- }, d ? { "document.referrer": t.config.hooks.redactUrl(document.referrer || "") } : {});
1269
- r = t.startSpan("browser.view", f), t.startSpan("browser.page_view", E({}, f)).end();
1270
- }, a = fn((e) => {
1271
- i(e.source, e.fromUrl);
2041
+ [T.viewId]: g,
2042
+ [T.viewName]: m,
2043
+ [T.viewUrl]: _,
2044
+ [T.viewUrlPathGroup]: p,
2045
+ [T.viewLoadingType]: i,
2046
+ "url.previous": v,
2047
+ "event.source": r
2048
+ }, y ? { "document.referrer": t.config.hooks.redactUrl(document.referrer || "") } : {});
2049
+ n = {
2050
+ attributes: h,
2051
+ documentVersion: 0,
2052
+ id: g,
2053
+ loadingType: i,
2054
+ name: m,
2055
+ rawUrl: f,
2056
+ snapshotAttributes: S,
2057
+ span: t.startSpan("browser.view", S, { startTime: b }),
2058
+ startedAt: b,
2059
+ url: _,
2060
+ urlPathGroup: p
2061
+ }, o(n, "create", b), l(n);
2062
+ }, f = t.onViewCommand((e) => {
2063
+ if (e.type === "start") {
2064
+ d(e.options, "manual", n ? "route_change" : "initial_load");
2065
+ return;
2066
+ }
2067
+ if (n) {
2068
+ if (e.type === "set_loading_time") {
2069
+ var r;
2070
+ (r = n.stopLoadingTime) == null || r.call(n), n.stopLoadingTime = void 0, c(n, Math.max(0, e.time - n.startedAt), "manual");
2071
+ return;
2072
+ }
2073
+ n.name = e.name, n.span.setAttribute(T.viewName, e.name), n.snapshotAttributes[T.viewName] = e.name, t.setView({
2074
+ attributes: n.attributes,
2075
+ id: n.id,
2076
+ loadingType: n.loadingType,
2077
+ name: n.name,
2078
+ startedAt: n.startedAt,
2079
+ url: n.url,
2080
+ urlPathGroup: n.urlPathGroup
2081
+ }), o(n, "update");
2082
+ }
2083
+ }), p = () => {};
2084
+ t.config.view.tracking === "auto" && (n || d({}, "load", "initial_load"), p = dr((e) => {
2085
+ vr(e.fromUrl, e.toUrl) && d({}, e.source, "route_change", e.fromUrl);
2086
+ }));
2087
+ let m = (e) => {
2088
+ e.persisted || s("pagehide");
2089
+ }, h = (e) => {
2090
+ e.persisted && t.config.view.tracking === "auto" && d({}, "bfCache", "bf_cache", n == null ? void 0 : n.rawUrl);
2091
+ }, g = t.onSessionLifecycle((e) => {
2092
+ if (e.type === "expired") {
2093
+ r = s("session_expired", !0, e.expiredAt);
2094
+ return;
2095
+ }
2096
+ r && (d({
2097
+ attributes: r.attributes,
2098
+ name: r.name,
2099
+ url: r.rawUrl
2100
+ }, "sessionRenewal", "session_renewal", r.rawUrl), r = void 0);
1272
2101
  });
1273
- i("load");
1274
- let o = () => {
1275
- r == null || r.setAttribute("view.end_reason", "shutdown"), r == null || r.end(), r = void 0;
1276
- };
1277
- window.addEventListener("pagehide", o), e.push(a, () => window.removeEventListener("pagehide", o), o);
2102
+ window.addEventListener("pagehide", m), window.addEventListener("pageshow", h), e.push(p, g, f, () => window.removeEventListener("pagehide", m), () => window.removeEventListener("pageshow", h), () => s("shutdown"));
1278
2103
  },
1279
2104
  shutdown() {
1280
2105
  for (; e.length;) {
@@ -1283,253 +2108,248 @@ var qe = (e) => typeof e == "string" && e.length > 0 ? e : void 0, Je = (e) => {
1283
2108
  }
1284
2109
  }
1285
2110
  };
1286
- }, hn = (e) => e.transferSize === 0 && e.decodedBodySize > 0 ? !0 : void 0, gn = () => {
1287
- let e, t = /* @__PURE__ */ new Set();
1288
- return {
1289
- name: "resource",
1290
- init(n) {
1291
- var r;
1292
- if (typeof PerformanceObserver > "u" || !((r = PerformanceObserver.supportedEntryTypes) != null && r.includes("resource"))) return;
1293
- let i = (e) => {
1294
- if (!e.name || M(n.config, e.name)) return;
1295
- let r = `${e.name}|${e.startTime}`;
1296
- if (t.has(r)) return;
1297
- t.add(r);
1298
- let i = n.config.hooks.redactUrl(e.name), a = e.duration;
1299
- n.startSpan("browser.resource", E(E(E({}, n.config.hooks.getPageAttributes()), Be({
1300
- duration: a,
1301
- initiatorType: e.initiatorType || "other",
1302
- responseStatus: e.responseStatus,
1303
- transferSize: e.transferSize,
1304
- url: i,
1305
- urlPathTemplate: n.config.hooks.getViewPathGroup(e.name)
1306
- })), {}, {
1307
- "url.full": i,
1308
- [x.transferSize]: e.transferSize,
1309
- [x.cacheHit]: hn(e),
1310
- [x.nextHopProtocol]: e.nextHopProtocol,
1311
- initiator_type: e.initiatorType || "other",
1312
- "resource.encoded_body_size": e.encodedBodySize,
1313
- "resource.decoded_body_size": e.decodedBodySize
1314
- }), { startTime: performance.timeOrigin + e.startTime }).end(performance.timeOrigin + e.startTime + a);
1315
- };
1316
- try {
1317
- e = new PerformanceObserver((e) => {
1318
- for (let t of e.getEntries()) i(t);
1319
- }), e.observe({
1320
- type: "resource",
1321
- buffered: !0
1322
- });
1323
- } catch (t) {
1324
- e = void 0;
1325
- }
1326
- },
1327
- shutdown() {
1328
- e == null || e.disconnect(), e = void 0, t.clear();
1329
- }
1330
- };
1331
- }, _n = () => {
1332
- let e = [], t = !1;
1333
- return {
1334
- name: "route-timing",
1335
- init(n) {
1336
- if (typeof window > "u" || typeof history > "u") return;
1337
- let r = n.meter.createHistogram("browser.route_change.duration", {
1338
- unit: "ms",
1339
- description: "Estimated SPA route change duration (route start to next idle)"
1340
- }), i = (e, i, a) => {
1341
- if (t) return;
1342
- let o = performance.now(), s = performance.timeOrigin + o, c = () => {
1343
- if (t || typeof document < "u" && document.visibilityState === "hidden") return;
1344
- let c = performance.now() - o, l = c > 500 ? N.warning : N.success, u = n.applyRedact(E(E(E(E({}, n.config.hooks.getPageAttributes()), n.config.hooks.getMetricAttributes()), I(n.getRuntimeAttributes())), {}, { "route.change.source": e }));
1345
- r.record(c, u), n.startSpan("browser.route_change", E(E(E({}, u), F({
1346
- duration: c,
1347
- errorType: l === N.warning ? "slow" : "none",
1348
- eventLabel: "路由切换",
1349
- result: l,
1350
- spanSubtype: e,
1351
- spanType: P.route,
1352
- targetLabel: n.config.hooks.getViewPathGroup(a),
1353
- targetValue: c,
1354
- traceScene: "route_change"
1355
- })), {}, {
1356
- "url.full": n.config.hooks.redactUrl(a),
1357
- "url.previous": n.config.hooks.redactUrl(i)
1358
- }), { startTime: s }).end();
1359
- };
1360
- requestAnimationFrame(() => requestAnimationFrame(() => setTimeout(c, 0)));
1361
- }, a = fn((e) => {
1362
- e.fromUrl !== e.toUrl && i(e.source, e.fromUrl, e.toUrl);
1363
- });
1364
- e.push(a);
1365
- },
1366
- shutdown() {
1367
- for (t = !0; e.length;) {
1368
- var n;
1369
- (n = e.pop()) == null || n();
1370
- }
1371
- }
1372
- };
1373
- }, vn = 1800 * 1e3, yn = 1440 * 60 * 1e3, bn = 6e4, xn = 5e3, Sn = [
1374
- "click",
1375
- "keydown",
1376
- "scroll",
1377
- "mousemove",
1378
- "touchstart"
1379
- ], Cn = (e, t) => typeof e == "number" && Number.isFinite(e) && e > 0 ? e : t, wn = (e, t) => typeof e == "number" && Number.isFinite(e) && e > 0 && e <= t + xn, Tn = (e, t) => {
2111
+ }, br = 5e3, xr = (e) => typeof e == "number" && Number.isFinite(e) && e > 0, Sr = (e, t, n, r) => ({
2112
+ expiresAt: Math.min(t + n, t + r),
2113
+ id: e,
2114
+ startedAt: t,
2115
+ status: "active"
2116
+ }), X = (e, t, n) => {
2117
+ if (t >= e.startedAt + n) return "maxLifetime";
2118
+ if (t >= e.expiresAt) return "inactivity";
2119
+ }, Cr = (e, t, n, r) => O(O({}, e), {}, { expiresAt: Math.min(t + n, e.startedAt + r) }), wr = (e, t, n) => {
1380
2120
  if (!e) return null;
1381
2121
  try {
1382
- let n = JSON.parse(e);
1383
- if (typeof (n == null ? void 0 : n.id) == "string" && wn(n.ts, t) && wn(n.startedAt, t)) return n;
2122
+ let r = JSON.parse(e);
2123
+ if (r.status === "active" && typeof r.id == "string" && r.id.length > 0 && xr(r.startedAt) && r.startedAt <= t + br && xr(r.expiresAt) && r.expiresAt >= r.startedAt && r.expiresAt <= r.startedAt + n || r.status === "expired" && typeof r.previousId == "string" && r.previousId.length > 0 && (r.reason === "inactivity" || r.reason === "maxLifetime") && xr(r.expiredAt) && r.expiredAt <= t + br) return r;
1384
2124
  } catch (e) {}
1385
2125
  return null;
1386
- }, En = (e, t) => {
1387
- if (typeof window > "u") return null;
1388
- let n = null;
1389
- try {
1390
- n = window.localStorage.getItem(e);
1391
- } catch (e) {}
1392
- let r = Tn(n, t);
1393
- if (r) return r;
1394
- try {
1395
- n = window.sessionStorage.getItem(e);
1396
- } catch (e) {}
1397
- return r = Tn(n, t), r;
1398
- }, Dn = (e, t) => {
1399
- if (typeof window > "u") return;
1400
- let n = JSON.stringify(t);
1401
- try {
1402
- window.sessionStorage.setItem(e, n);
1403
- } catch (e) {}
1404
- try {
1405
- window.localStorage.setItem(e, n);
1406
- } catch (e) {}
1407
- }, On = (e, t, n) => {
1408
- let r = Date.now(), i = En(e, r);
1409
- if (i) {
1410
- let a = r - i.ts >= t, o = r - i.startedAt >= n;
1411
- if (!a && !o) {
1412
- let t = E(E({}, i), {}, { ts: r });
1413
- return Dn(e, t), {
1414
- id: t.id,
1415
- rotated: !1
1416
- };
2126
+ }, Tr = 900 * 1e3, Z = 14400 * 1e3, Er = 1e3, Dr = 6e4, Or = [
2127
+ "click",
2128
+ "keydown",
2129
+ "scroll",
2130
+ "touchstart"
2131
+ ], kr = /* @__PURE__ */ new Map(), Ar = (e) => {
2132
+ let t = typeof window < "u", n = () => {
2133
+ var n;
2134
+ if (t) try {
2135
+ return window.localStorage.getItem(e);
2136
+ } catch (e) {
2137
+ t = !1;
1417
2138
  }
1418
- let s = a ? "inactivity" : "maxLifetime", c = {
1419
- id: B("session"),
1420
- startedAt: r,
1421
- ts: r
1422
- };
1423
- return Dn(e, c), {
1424
- id: c.id,
1425
- prevId: i.id,
1426
- reason: s,
1427
- rotated: !0
1428
- };
1429
- }
1430
- let a = {
1431
- id: B("session"),
1432
- startedAt: r,
1433
- ts: r
2139
+ return (n = kr.get(e)) == null ? null : n;
1434
2140
  };
1435
- return Dn(e, a), {
1436
- id: a.id,
1437
- reason: "init",
1438
- rotated: !0
2141
+ return n(), {
2142
+ isLocalStorage: () => t,
2143
+ read: n,
2144
+ write: (n) => {
2145
+ let r = JSON.stringify(n);
2146
+ if (kr.set(e, r), t) try {
2147
+ window.localStorage.setItem(e, r);
2148
+ } catch (e) {
2149
+ t = !1;
2150
+ }
2151
+ }
1439
2152
  };
1440
- }, kn = (e) => {
1441
- let t = "";
2153
+ }, jr = (e, t) => {
2154
+ let n = "";
1442
2155
  try {
1443
- t = new URL(e).host;
1444
- } catch (n) {
1445
- t = e;
1446
- }
1447
- return `bk_ot_session__${pt(t || "default")}`;
1448
- }, An = (e, t) => {
1449
- if (!t.rotated || !t.reason) return;
1450
- let n = Date.now();
1451
- e.emitLog({
1452
- severityNumber: o.INFO,
2156
+ n = new URL(e).host;
2157
+ } catch (t) {
2158
+ n = e;
2159
+ }
2160
+ return `bk_ot_session__${W(`${t}\0${n || "default"}`)}`;
2161
+ }, Mr = (e, t) => {
2162
+ t.reason && e.emitLog({
2163
+ severityNumber: w.INFO,
1453
2164
  severityText: "INFO",
1454
2165
  body: t.reason === "init" ? "session.start" : "session.rotate",
1455
- attributes: E(E({}, e.config.hooks.getPageAttributes()), {}, {
1456
- [x.sessionHasReplay]: !1,
1457
- [x.sessionId]: t.id,
1458
- [x.sessionStartTime]: n,
2166
+ attributes: O(O({}, e.config.hooks.getPageAttributes()), {}, {
2167
+ [T.sessionHasReplay]: !1,
2168
+ [T.sessionId]: t.record.id,
2169
+ [T.sessionStartTime]: t.record.startedAt,
1459
2170
  "session.rotate.reason": t.reason
1460
- }, t.prevId ? { "session.previous_id": t.prevId } : {})
2171
+ }, t.previousId ? { "session.previous_id": t.previousId } : {})
1461
2172
  });
1462
- }, jn = (e = {}) => {
1463
- let t = [], n = Cn(e.inactivityMs, vn), r = Cn(e.maxLifetimeMs, yn);
2173
+ }, Nr = (e = {}) => {
2174
+ let t = [];
1464
2175
  return {
1465
2176
  name: "session",
1466
- init(i) {
1467
- var a;
1468
- let o = (a = e.storageKey) == null ? kn(i.config.transport.endpoint) : a, s = "", c = () => {
1469
- if (typeof window > "u") {
1470
- s || (s = B("session"), i.setRuntimeAttributes({
1471
- [x.sessionHasReplay]: !1,
1472
- [x.sessionId]: s
1473
- }));
2177
+ init(n) {
2178
+ var r;
2179
+ if (typeof window > "u" || typeof document > "u") {
2180
+ n.setRuntimeAttributes({
2181
+ [T.sessionHasReplay]: !1,
2182
+ [T.sessionId]: N("session")
2183
+ });
2184
+ return;
2185
+ }
2186
+ let i = (r = e.storageKey) == null ? jr(n.config.transport.endpoint, n.config.application.name) : r, a = Ar(i), o = typeof performance < "u" && Number.isFinite(performance.timeOrigin) ? performance.timeOrigin : Date.now(), s, c, l = (e = Date.now()) => wr(a.read(), e, Z), u = () => {
2187
+ c !== void 0 && (clearTimeout(c), c = void 0);
2188
+ }, d = (e, t = Date.now()) => {
2189
+ let r = s;
2190
+ r && (n.notifySessionLifecycle({
2191
+ expiredAt: t,
2192
+ id: r,
2193
+ reason: e,
2194
+ type: "expired"
2195
+ }), u(), s = void 0, n.setRuntimeAttributes({
2196
+ [T.sessionHasReplay]: void 0,
2197
+ [T.sessionId]: void 0
2198
+ }, t), n.flush());
2199
+ }, f = () => {
2200
+ let e = Date.now(), t = l(e);
2201
+ if (!t) {
2202
+ d("external", e);
2203
+ return;
2204
+ }
2205
+ if (t.status === "expired") {
2206
+ d(t.reason, t.expiredAt);
2207
+ return;
2208
+ }
2209
+ if (t.id !== s) {
2210
+ d("external", e);
2211
+ return;
2212
+ }
2213
+ let n = X(t, e, Z);
2214
+ if (!n) {
2215
+ p(t);
2216
+ return;
2217
+ }
2218
+ let r = {
2219
+ expiredAt: e,
2220
+ previousId: t.id,
2221
+ reason: n,
2222
+ status: "expired"
2223
+ };
2224
+ a.write(r), d(n, e);
2225
+ }, p = (e) => {
2226
+ u();
2227
+ let t = Math.min(e.expiresAt, e.startedAt + Z);
2228
+ c = setTimeout(f, Math.max(0, t - Date.now()));
2229
+ }, m = (e, t) => {
2230
+ let r = e.id !== s;
2231
+ s = e.id, n.setRuntimeAttributes({
2232
+ [T.sessionHasReplay]: !1,
2233
+ [T.sessionId]: e.id
2234
+ }, Math.min(e.startedAt, o)), p(e), r && t && n.notifySessionLifecycle({
2235
+ id: e.id,
2236
+ previousId: t.previousId,
2237
+ reason: t.reason,
2238
+ startedAt: e.startedAt,
2239
+ type: "renewed"
2240
+ });
2241
+ }, h = (e = !1) => {
2242
+ let t = Date.now(), r = l(t);
2243
+ if ((r == null ? void 0 : r.status) === "active" && !X(r, t, Z)) {
2244
+ let e = Cr(r, t, Tr, Z);
2245
+ a.write(e), m(e, s ? void 0 : { reason: "shared" });
2246
+ return;
2247
+ }
2248
+ let i = (r == null ? void 0 : r.status) === "expired" ? r.previousId : r == null ? void 0 : r.id, o = (r == null ? void 0 : r.status) === "expired" ? r.reason : r ? X(r, t, Z) : e ? "init" : void 0, c = Sr(N("session"), t, Tr, Z);
2249
+ a.write(c), m(c, {
2250
+ previousId: i,
2251
+ reason: o == null ? "init" : o
2252
+ }), Mr(n, {
2253
+ previousId: i,
2254
+ reason: o == null ? "init" : o,
2255
+ record: c
2256
+ });
2257
+ }, g = () => {
2258
+ if (!s) return;
2259
+ let e = Date.now(), t = l(e);
2260
+ if ((t == null ? void 0 : t.status) !== "active" || t.id !== s || X(t, e, Z)) {
2261
+ f();
1474
2262
  return;
1475
2263
  }
1476
- let e = On(o, n, r);
1477
- i.setRuntimeAttributes({
1478
- [x.sessionHasReplay]: !1,
1479
- [x.sessionId]: e.id
1480
- }), e.id !== s && (s = e.id, An(i, e));
2264
+ let n = Cr(t, e, Tr, Z);
2265
+ a.write(n), m(n);
1481
2266
  };
1482
- if (c(), typeof window > "u" || typeof document > "u") return;
1483
- let l = Date.now(), u = () => {
2267
+ h(!0);
2268
+ let _ = 0, v = () => {
1484
2269
  let e = Date.now();
1485
- e - l < bn || (l = e, c());
1486
- }, d = {
2270
+ e - _ < Er || (_ = e, h());
2271
+ }, y = {
1487
2272
  capture: !0,
1488
2273
  passive: !0
1489
2274
  };
1490
- Sn.forEach((e) => {
1491
- window.addEventListener(e, u, d);
1492
- }), t.push(() => {
1493
- Sn.forEach((e) => {
1494
- window.removeEventListener(e, u, d);
1495
- });
2275
+ Or.forEach((e) => window.addEventListener(e, v, y)), t.push(() => {
2276
+ Or.forEach((e) => window.removeEventListener(e, v, y));
1496
2277
  });
1497
- let f = () => {
1498
- document.visibilityState === "visible" && c();
2278
+ let b = () => {
2279
+ document.visibilityState === "visible" && g();
1499
2280
  };
1500
- document.addEventListener("visibilitychange", f), t.push(() => document.removeEventListener("visibilitychange", f));
1501
- let p = (e) => {
1502
- if (e.storageArea !== window.localStorage || e.key !== o || !e.newValue) return;
1503
- let t = Date.now(), n = Tn(e.newValue, t);
1504
- if (!(!n || n.id === s)) {
1505
- s = n.id;
1506
- try {
1507
- window.sessionStorage.setItem(o, e.newValue);
1508
- } catch (e) {}
1509
- i.setRuntimeAttributes({ [x.sessionId]: n.id });
2281
+ document.addEventListener("visibilitychange", b);
2282
+ let x = window.setInterval(b, Dr);
2283
+ t.push(() => {
2284
+ document.removeEventListener("visibilitychange", b), window.clearInterval(x);
2285
+ });
2286
+ let S = (e) => {
2287
+ if (!a.isLocalStorage() || e.storageArea !== window.localStorage || e.key !== i) return;
2288
+ let t = Date.now(), n = wr(e.newValue, t, Z);
2289
+ if ((n == null ? void 0 : n.status) === "active" && n.id === s && !X(n, t, Z)) {
2290
+ p(n);
2291
+ return;
1510
2292
  }
2293
+ d((n == null ? void 0 : n.status) === "expired" ? n.reason : "external", (n == null ? void 0 : n.status) === "expired" ? n.expiredAt : t);
1511
2294
  };
1512
- window.addEventListener("storage", p), t.push(() => window.removeEventListener("storage", p));
2295
+ window.addEventListener("storage", S), t.push(() => window.removeEventListener("storage", S)), t.push(u);
1513
2296
  },
1514
2297
  shutdown() {
1515
- for (; t.length;) {
1516
- var e;
1517
- (e = t.pop()) == null || e();
1518
- }
2298
+ for (var e; t.length;) (e = t.pop()) == null || e();
1519
2299
  }
1520
2300
  };
1521
- }, Mn = "unknown", Nn = (e) => e ? e.replace(/_/g, "-") : Mn, Pn = () => {
1522
- if (typeof performance > "u") return Mn;
2301
+ }, Pr = "unknown", Fr = 10, Ir = 6e4, Lr = 5e3, Rr = 1e3, zr = (e) => e ? e.replace(/_/g, "-") : Pr, Br = () => {
2302
+ if (typeof performance > "u") return Pr;
1523
2303
  let e = performance.getEntriesByType("navigation")[0];
1524
- return Nn(e == null ? void 0 : e.type);
1525
- }, Fn = (e, t) => {
2304
+ return zr(e == null ? void 0 : e.type);
2305
+ }, Vr = (e, t) => {
2306
+ let [n, r] = e === "CLS" ? [.1, .25] : [200, 500];
2307
+ return t <= n ? "good" : t <= r ? "needs-improvement" : "poor";
2308
+ }, Hr = (e) => {
2309
+ var t, n, r;
2310
+ if (!(typeof Element > "u" || !(e instanceof Element))) return (t = (n = (r = e.getAttribute("data-bk-action-name")) == null ? e.getAttribute("aria-label") : r) == null ? e.getAttribute("name") : n) == null ? e.tagName.toLowerCase() : t;
2311
+ }, Ur = () => {
2312
+ if (typeof performance > "u") return;
2313
+ let e = performance.interactionCount;
2314
+ return typeof e == "number" && Number.isFinite(e) ? e : void 0;
2315
+ }, Wr = (e, t) => {
2316
+ var n, r;
2317
+ let i = (n = t.value) == null ? 0 : n;
2318
+ if (!(t.hadRecentInput || !Number.isFinite(i))) {
2319
+ if (e.clsWindowStart === void 0 || t.startTime - ((r = e.clsWindowEnd) == null ? t.startTime : r) >= Rr || t.startTime - e.clsWindowStart >= Lr) {
2320
+ var a;
2321
+ e.clsWindowStart = t.startTime, e.clsWindowValue = i, e.clsWindowLargestShiftValue = i, e.clsWindowLargestShiftTarget = Hr((a = t.sources) == null || (a = a[0]) == null ? void 0 : a.node);
2322
+ } else if (e.clsWindowValue += i, i > e.clsWindowLargestShiftValue) {
2323
+ var o;
2324
+ e.clsWindowLargestShiftValue = i, e.clsWindowLargestShiftTarget = Hr((o = t.sources) == null || (o = o[0]) == null ? void 0 : o.node);
2325
+ }
2326
+ e.clsWindowEnd = t.startTime, e.clsWindowValue > e.cls && (e.cls = Math.round(e.clsWindowValue * 1e4) / 1e4, e.largestShiftValue = e.clsWindowLargestShiftValue, e.largestShiftTarget = e.clsWindowLargestShiftTarget);
2327
+ }
2328
+ }, Gr = (e, t) => {
2329
+ var n, r;
2330
+ if (!t.interactionId || !Number.isFinite(t.duration)) return;
2331
+ e.interactionIdMin = Math.min(e.interactionIdMin, t.interactionId), e.interactionIdMax = Math.max(e.interactionIdMax, t.interactionId);
2332
+ let i = (n = t.processingStart) == null ? t.startTime : n, a = (r = t.processingEnd) == null ? i : r, o = {
2333
+ duration: Math.min(t.duration, Ir),
2334
+ inputDelay: Math.max(0, i - t.startTime),
2335
+ interactionId: t.interactionId,
2336
+ interactionTarget: Hr(t.target),
2337
+ interactionType: t.name,
2338
+ presentationDelay: Math.max(0, t.startTime + t.duration - a),
2339
+ processingDuration: Math.max(0, a - i)
2340
+ }, s = e.inpCandidates.findIndex((e) => e.interactionId === t.interactionId);
2341
+ s >= 0 ? o.duration > e.inpCandidates[s].duration && (e.inpCandidates[s] = o) : e.inpCandidates.push(o), e.inpCandidates.sort((e, t) => t.duration - e.duration).splice(Fr);
2342
+ }, Kr = (e) => {
2343
+ let t = Ur(), n = t !== void 0 && e.interactionCountAtStart !== void 0 ? Math.max(0, t - e.interactionCountAtStart) : e.interactionIdMin === Infinity ? 0 : (e.interactionIdMax - e.interactionIdMin) / 7 + 1;
2344
+ if (e.inpCandidates.length) return e.inpCandidates[Math.min(e.inpCandidates.length - 1, Math.floor(n / 50))];
2345
+ }, qr = (e, t) => {
1526
2346
  var n;
1527
2347
  return {
1528
2348
  "rum.navigation.type": (n = e.navigationType) == null ? t : n,
1529
- [x.vitalMetric]: e.name.toLowerCase(),
1530
- [x.vitalRating]: e.rating
2349
+ [T.vitalMetric]: e.name.toLowerCase(),
2350
+ [T.vitalRating]: e.rating
1531
2351
  };
1532
- }, In = (e, t) => {
2352
+ }, Jr = (e, t) => {
1533
2353
  var n;
1534
2354
  let r = (n = e.attribution) == null ? {} : n, i = {}, a = (e) => r[e], o = (e, t, n) => {
1535
2355
  t != null && (typeof t == "string" || typeof t == "number" || typeof t == "boolean") && (i[e] = typeof t == "string" && n ? n(t) : t);
@@ -1553,60 +2373,125 @@ var qe = (e) => typeof e == "string" && e.length > 0 ? e : void 0, Je = (e) => {
1553
2373
  default: break;
1554
2374
  }
1555
2375
  return i;
1556
- }, Ln = () => {
1557
- let e = !1;
2376
+ }, Yr = () => {
2377
+ let e, t = !1;
1558
2378
  return {
1559
2379
  name: "web-vitals",
1560
- init(t) {
1561
- return A(function* () {
2380
+ init(n) {
2381
+ return k(function* () {
1562
2382
  if (typeof window > "u") return;
1563
- let n;
2383
+ let r;
1564
2384
  try {
1565
- n = yield import("web-vitals/attribution");
2385
+ r = yield import("web-vitals/attribution");
1566
2386
  } catch (e) {
1567
- if (t.config.debug) {
1568
- var r;
1569
- (r = globalThis.console) == null || r.warn("[bk-ot] web-vitals load failed:", e);
2387
+ if (n.config.debug) {
2388
+ var i;
2389
+ (i = globalThis.console) == null || i.warn("[bk-ot] web-vitals load failed:", e);
1570
2390
  }
1571
2391
  return;
1572
2392
  }
1573
- if (e) return;
1574
- let { onCLS: i, onFCP: a, onINP: o, onLCP: s, onTTFB: c } = n, l = Pn(), u = t.meter.createHistogram("browser.web_vital.cls", {
2393
+ if (t) return;
2394
+ let { onFCP: a, onLCP: o, onTTFB: s } = r, c = Br(), l = n.meter.createHistogram("browser.web_vital.cls", {
1575
2395
  unit: "1",
1576
2396
  description: "Cumulative Layout Shift"
1577
- }), d = t.meter.createHistogram("browser.web_vital.duration", {
2397
+ }), u = n.meter.createHistogram("browser.web_vital.duration", {
1578
2398
  unit: "ms",
1579
2399
  description: "Web Vitals duration metrics, including FCP, INP, LCP and TTFB"
1580
- }), f = (e) => {
1581
- let n = e.name.toLowerCase();
1582
- t.startSpan("browser.web_vital", E(E(E(E(E({}, t.config.hooks.getPageAttributes()), t.config.hooks.getMetricAttributes()), Fn(e, l)), F({
2400
+ }), d = (e, t, r) => {
2401
+ let i = e.name.toLowerCase();
2402
+ n.startSpan("browser.web_vital", O(O(O(O(O({}, n.config.hooks.getPageAttributes()), t), qr(e, c)), I({
1583
2403
  duration: e.name === "CLS" ? void 0 : e.value,
1584
2404
  errorType: e.rating === "good" ? "none" : "slow",
1585
2405
  eventLabel: "Web 指标",
1586
- result: Le(e.rating),
1587
- spanSubtype: n,
1588
- spanType: P.vital,
1589
- targetLabel: n,
2406
+ result: Qe(e.rating),
2407
+ spanSubtype: i,
2408
+ spanType: F.vital,
2409
+ targetLabel: i,
1590
2410
  targetValue: e.value
1591
2411
  })), {}, {
1592
- [x.vitalMetric]: n,
1593
- [x.vitalValue]: e.value,
1594
- [x.vitalRating]: e.rating,
2412
+ [T.vitalMetric]: i,
2413
+ [T.vitalValue]: e.value,
2414
+ [T.vitalRating]: e.rating,
1595
2415
  "vital.id": e.id
1596
- }, In(e, t.config.hooks.redactUrl))).end();
1597
- }, p = (n) => {
1598
- e || !Number.isFinite(n.value) || (d.record(n.value, t.applyRedact(E(E(E(E({}, t.config.hooks.getPageAttributes()), t.config.hooks.getMetricAttributes()), I(t.getRuntimeAttributes())), Fn(n, l)))), f(n));
2416
+ }, Jr(e, n.config.hooks.redactUrl)), r === void 0 ? void 0 : { contextTime: r }).end();
2417
+ }, f = (e) => {
2418
+ if (t || !Number.isFinite(e.value)) return;
2419
+ let r = e.entries[0], i = r && typeof performance < "u" ? performance.timeOrigin + r.startTime : void 0, a = i === void 0 ? n.getRuntimeAttributes() : n.getRuntimeAttributesAt(i);
2420
+ u.record(e.value, n.applyRedact(O(O(O({}, n.config.hooks.getMetricAttributes()), z(a)), qr(e, c)))), d(e, a, i);
2421
+ }, p, m, h, g = (e, t, r) => {
2422
+ let i = n.applyRedact(O(O(O({}, n.config.hooks.getMetricAttributes()), z(t)), qr(e, c)));
2423
+ e.name === "CLS" ? l.record(e.value, i) : u.record(e.value, i), d(e, t, r);
2424
+ }, _ = () => {
2425
+ let e = p;
2426
+ if (!e) return;
2427
+ g({
2428
+ attribution: {
2429
+ largestShiftTarget: e.largestShiftTarget,
2430
+ largestShiftValue: e.largestShiftValue
2431
+ },
2432
+ entries: [],
2433
+ id: N("vital"),
2434
+ name: "CLS",
2435
+ navigationType: c,
2436
+ rating: Vr("CLS", e.cls),
2437
+ value: e.cls
2438
+ }, e.runtimeAttributes, e.startedAt);
2439
+ let t = Kr(e);
2440
+ t && g({
2441
+ attribution: {
2442
+ inputDelay: t.inputDelay,
2443
+ interactionTarget: t.interactionTarget,
2444
+ interactionType: t.interactionType,
2445
+ presentationDelay: t.presentationDelay,
2446
+ processingDuration: t.processingDuration
2447
+ },
2448
+ entries: [],
2449
+ id: N("vital"),
2450
+ name: "INP",
2451
+ navigationType: c,
2452
+ rating: Vr("INP", t.duration),
2453
+ value: t.duration
2454
+ }, e.runtimeAttributes, e.startedAt);
2455
+ }, v = n.onViewChange((e) => {
2456
+ var t;
2457
+ _(), p = e.id ? {
2458
+ cls: 0,
2459
+ clsWindowLargestShiftValue: 0,
2460
+ clsWindowValue: 0,
2461
+ interactionCountAtStart: Ur(),
2462
+ interactionIdMax: 0,
2463
+ interactionIdMin: Infinity,
2464
+ inpCandidates: [],
2465
+ largestShiftValue: 0,
2466
+ runtimeAttributes: n.getRuntimeAttributes(),
2467
+ startedAt: (t = e.startedAt) == null ? Date.now() : t
2468
+ } : void 0;
2469
+ });
2470
+ if (typeof PerformanceObserver < "u") {
2471
+ var y, b;
2472
+ (y = PerformanceObserver.supportedEntryTypes) != null && y.includes("layout-shift") && (h = new PerformanceObserver((e) => {
2473
+ if (p) for (let t of e.getEntries()) performance.timeOrigin + t.startTime < p.startedAt || Wr(p, t);
2474
+ }), h.observe({
2475
+ buffered: !0,
2476
+ type: "layout-shift"
2477
+ })), (b = PerformanceObserver.supportedEntryTypes) != null && b.includes("event") && (m = new PerformanceObserver((e) => {
2478
+ if (p) for (let t of e.getEntries()) performance.timeOrigin + t.startTime < p.startedAt || !t.interactionId || !Number.isFinite(t.duration) || Gr(p, t);
2479
+ }), m.observe({
2480
+ buffered: !0,
2481
+ durationThreshold: 40,
2482
+ type: "event"
2483
+ }));
2484
+ }
2485
+ a(f), o(f), s(f), e = () => {
2486
+ _(), p = void 0, v(), h == null || h.disconnect(), m == null || m.disconnect();
1599
2487
  };
1600
- i((n) => {
1601
- e || !Number.isFinite(n.value) || (u.record(n.value, t.applyRedact(E(E(E(E({}, t.config.hooks.getPageAttributes()), t.config.hooks.getMetricAttributes()), I(t.getRuntimeAttributes())), Fn(n, l)))), f(n));
1602
- }), a(p), o(p), s(p), c(p);
1603
2488
  })();
1604
2489
  },
1605
2490
  shutdown() {
1606
- e = !0;
2491
+ t = !0, e == null || e(), e = void 0;
1607
2492
  }
1608
2493
  };
1609
- }, Rn = 64 * 1024, zn = 6e4, Bn = 5, Vn = (e) => e == null ? 0 : typeof e == "string" ? e.length > Rn || 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, Hn = (e, t) => {
2494
+ }, Xr = 64 * 1024, Zr = 6e4, Qr = 5, $r = (e) => e == null ? 0 : typeof e == "string" ? e.length > Xr || 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, ei = (e, t) => {
1610
2495
  let n = {
1611
2496
  "network.protocol.name": "websocket",
1612
2497
  "url.full": t(e)
@@ -1619,71 +2504,71 @@ var qe = (e) => typeof e == "string" && e.length > 0 ? e : void 0, Je = (e) => {
1619
2504
  metricAttributes: r,
1620
2505
  spanAttributes: n
1621
2506
  };
1622
- }, Un = (e, n) => {
1623
- var r;
1624
- let { bytesCounter: i, connectDurationHistogram: a, context: s, errorCounter: c, errorThrottle: l, isDisposed: u, messageCounter: d, url: f } = n, { metricAttributes: p, spanAttributes: m } = Hn(f, s.config.hooks.redactUrl), h = s.applyRedact(E(E({}, s.config.hooks.getMetricAttributes()), p)), g = (r = m["server.address"]) == null ? m["url.full"] : r, _ = s.startSpan("websocket.connect", E(E(E({}, m), F({
2507
+ }, ti = (e, t) => {
2508
+ var n;
2509
+ let { bytesCounter: r, connectDurationHistogram: i, context: a, errorCounter: o, errorThrottle: s, isDisposed: l, messageCounter: u, url: d } = t, { metricAttributes: f, spanAttributes: p } = ei(d, a.config.hooks.redactUrl), m = a.applyRedact(O(O(O({}, a.config.hooks.getMetricAttributes()), z(a.getRuntimeAttributes())), f)), h = (n = p["server.address"]) == null ? p["url.full"] : n, g = a.startSpan("websocket.connect", O(O(O({}, p), I({
1625
2510
  errorType: "none",
1626
2511
  eventLabel: "WebSocket",
1627
2512
  spanSubtype: "websocket",
1628
- spanType: P.custom,
1629
- targetLabel: g
1630
- })), m["server.address"] ? { [x.targetDomain]: m["server.address"] } : {})), v = performance.now(), y = !1, b = (e) => {
1631
- if (y) return;
1632
- y = !0;
1633
- let n = performance.now() - v;
1634
- e === "error" && _.setStatus({
1635
- code: t.ERROR,
2513
+ spanType: F.custom,
2514
+ targetLabel: h
2515
+ })), p["server.address"] ? { [T.targetDomain]: p["server.address"] } : {})), _ = performance.now(), v = !1, y = (e) => {
2516
+ if (v) return;
2517
+ v = !0;
2518
+ let t = performance.now() - _;
2519
+ e === "error" && g.setStatus({
2520
+ code: c.ERROR,
1636
2521
  message: "websocket connect failed"
1637
- }), _.setAttributes(F({
1638
- duration: n,
2522
+ }), g.setAttributes(I({
2523
+ duration: t,
1639
2524
  errorType: e === "error" ? "network" : "none",
1640
2525
  eventLabel: "WebSocket",
1641
- result: e === "error" ? N.error : N.success,
2526
+ result: e === "error" ? P.error : P.success,
1642
2527
  spanSubtype: "websocket",
1643
- spanType: P.custom,
1644
- targetLabel: g,
1645
- targetValue: n
1646
- })), _.end(), e === "opened" && !u() && a.record(n, h);
2528
+ spanType: F.custom,
2529
+ targetLabel: h,
2530
+ targetValue: t
2531
+ })), g.end(), e === "opened" && !l() && i.record(t, m);
1647
2532
  };
1648
2533
  e.addEventListener("open", () => {
1649
- u() || b("opened");
2534
+ l() || y("opened");
1650
2535
  }), e.addEventListener("message", (e) => {
1651
- if (u()) return;
1652
- let t = E(E({}, h), {}, { "websocket.direction": "in" });
1653
- d.add(1, t), i.add(Vn(e.data), t);
2536
+ if (l()) return;
2537
+ let t = O(O({}, m), {}, { "websocket.direction": "in" });
2538
+ u.add(1, t), r.add($r(e.data), t);
1654
2539
  }), e.addEventListener("error", () => {
1655
- if (u()) return;
1656
- let e = y ? "runtime" : "connect";
1657
- c.add(1, E(E({}, h), {}, { "websocket.error.phase": e })), b("error");
1658
- let t = l.allow(`ws:error:${f}`);
1659
- t.allowed && s.emitLog({
1660
- severityNumber: o.ERROR,
2540
+ if (l()) return;
2541
+ let e = v ? "runtime" : "connect";
2542
+ o.add(1, O(O({}, m), {}, { "websocket.error.phase": e })), y("error");
2543
+ let t = s.allow(`ws:error:${d}`);
2544
+ t.allowed && a.emitLog({
2545
+ severityNumber: w.ERROR,
1661
2546
  severityText: "ERROR",
1662
2547
  body: "websocket.error",
1663
- attributes: E(E(E({}, m), F({
2548
+ attributes: O(O(O({}, p), I({
1664
2549
  errorType: "network",
1665
2550
  eventLabel: "WebSocket 错误",
1666
- result: N.error,
2551
+ result: P.error,
1667
2552
  spanSubtype: "websocket",
1668
- spanType: P.custom,
1669
- targetLabel: g
2553
+ spanType: F.custom,
2554
+ targetLabel: h
1670
2555
  })), {}, {
1671
2556
  "websocket.error.phase": e,
1672
2557
  "websocket.error.window_count": t.count
1673
2558
  })
1674
2559
  });
1675
2560
  }), e.addEventListener("close", (e) => {
1676
- u() || (y || b("error"), s.emitLog({
1677
- severityNumber: o.INFO,
2561
+ l() || (v || y("error"), a.emitLog({
2562
+ severityNumber: w.INFO,
1678
2563
  severityText: "INFO",
1679
2564
  body: "websocket.close",
1680
- attributes: E(E(E({}, m), F({
2565
+ attributes: O(O(O({}, p), I({
1681
2566
  errorType: e.wasClean ? "none" : "network",
1682
2567
  eventLabel: "WebSocket 关闭",
1683
- result: e.wasClean ? N.success : N.warning,
2568
+ result: e.wasClean ? P.success : P.warning,
1684
2569
  spanSubtype: "websocket",
1685
- spanType: P.custom,
1686
- targetLabel: g,
2570
+ spanType: F.custom,
2571
+ targetLabel: h,
1687
2572
  targetValue: e.code
1688
2573
  })), {}, {
1689
2574
  "websocket.close.code": e.code,
@@ -1692,15 +2577,15 @@ var qe = (e) => typeof e == "string" && e.length > 0 ? e : void 0, Je = (e) => {
1692
2577
  })
1693
2578
  }));
1694
2579
  });
1695
- let ee = e.send.bind(e);
2580
+ let b = e.send.bind(e);
1696
2581
  e.send = (e) => {
1697
- if (!u()) {
1698
- let t = E(E({}, h), {}, { "websocket.direction": "out" });
1699
- d.add(1, t), i.add(Vn(e), t);
2582
+ if (!l()) {
2583
+ let t = O(O({}, m), {}, { "websocket.direction": "out" });
2584
+ u.add(1, t), r.add($r(e), t);
1700
2585
  }
1701
- return ee(e);
2586
+ return b(e);
1702
2587
  };
1703
- }, Wn = () => {
2588
+ }, ni = () => {
1704
2589
  let e, t, n = !1;
1705
2590
  return {
1706
2591
  name: "websocket",
@@ -1714,12 +2599,12 @@ var qe = (e) => typeof e == "string" && e.length > 0 ? e : void 0, Je = (e) => {
1714
2599
  }), s = r.meter.createCounter("browser.websocket.error.count", { description: "Total number of WebSocket error events" }), c = r.meter.createHistogram("browser.websocket.connect.duration", {
1715
2600
  unit: "ms",
1716
2601
  description: "WebSocket connection establishment duration (only successful connects)"
1717
- }), l = mt(zn, Bn), u = () => n;
2602
+ }), l = Cn(Zr, Qr), u = () => n;
1718
2603
  t = new Proxy(i, { construct(e, t, i) {
1719
2604
  let d = Reflect.construct(e, t, i);
1720
2605
  if (n) return d;
1721
2606
  let f = t[0] == null ? "" : String(t[0]);
1722
- return !f || M(r.config, f) || Un(d, {
2607
+ return !f || ke(r.config, f) || ti(d, {
1723
2608
  bytesCounter: o,
1724
2609
  connectDurationHistogram: c,
1725
2610
  context: r,
@@ -1735,164 +2620,288 @@ var qe = (e) => typeof e == "string" && e.length > 0 ? e : void 0, Je = (e) => {
1735
2620
  n = !0, typeof window < "u" && e && window.WebSocket === t && (window.WebSocket = e), t = void 0, e = void 0;
1736
2621
  }
1737
2622
  };
1738
- }, Z = "BK_RUM_SAMPLING", Gn = /* @__PURE__ */ new Map(), Kn = (e) => Gn.get(e), qn = (e, t) => (Gn.set(e, t), t), Jn = ({ sampling: e }) => {
1739
- if (e.rate <= 0) return !1;
1740
- if (e.rate >= 1) return !0;
1741
- try {
1742
- let t = sessionStorage.getItem(Z);
1743
- if (t) return t === "1";
1744
- let n = Math.random() < e.rate;
1745
- return sessionStorage.setItem(Z, n ? "1" : "0"), qn(Z, n), n;
1746
- } catch (t) {
1747
- let n = Kn(Z);
1748
- return typeof n == "boolean" ? n : qn(Z, Math.random() < e.rate);
2623
+ }, ri = class {
2624
+ constructor() {
2625
+ D(this, "listeners", /* @__PURE__ */ new Set()), D(this, "notify", (e) => {
2626
+ this.listeners.forEach((t) => t(e));
2627
+ }), D(this, "subscribe", (e) => (this.listeners.add(e), () => this.listeners.delete(e)));
1749
2628
  }
1750
- }, Yn = (e) => ({
2629
+ }, ii = (e) => ({
1751
2630
  url: e.endpoint,
1752
2631
  headers: e.headers,
1753
2632
  concurrencyLimit: e.concurrencyLimit,
1754
2633
  timeoutMillis: e.timeoutMillis
1755
- }), Xn = "bk-rum", Q = (e, t, n) => n ? new Proxy(e, { get(e, n, r) {
2634
+ }), ai = "bk-rum", oi = class {
2635
+ constructor(e) {
2636
+ this.isSampled = e;
2637
+ }
2638
+ shouldSample() {
2639
+ return { decision: this.isSampled() ? S.RECORD_AND_SAMPLED : S.NOT_RECORD };
2640
+ }
2641
+ toString() {
2642
+ return "RumSessionSampler";
2643
+ }
2644
+ }, Q, si = () => {
2645
+ if (Q) Q.users += 1;
2646
+ else {
2647
+ let e = new f().enable(), n = l.setGlobalContextManager(e);
2648
+ n || e.disable(), Q = {
2649
+ contextManager: n ? e : void 0,
2650
+ ownsContext: n,
2651
+ ownsPropagator: u.setGlobalPropagator(new t()),
2652
+ users: 1
2653
+ };
2654
+ }
2655
+ let e = !1;
2656
+ return () => {
2657
+ e || !Q || (e = !0, --Q.users, !(Q.users > 0) && (Q.ownsContext && l.disable(), Q.ownsPropagator && u.disable(), Q = void 0));
2658
+ };
2659
+ }, ci = (e, t, n) => n ? new Proxy(e, { get(e, n, r) {
1756
2660
  if (n === "export") return (n, r) => {
1757
2661
  var i;
1758
2662
  return (i = globalThis.console) == null || i.log(`[bk-ot][${t}]`, n), e.export(n, r);
1759
2663
  };
1760
2664
  let i = Reflect.get(e, n, r);
1761
2665
  return typeof i == "function" ? i.bind(e) : i;
1762
- } }) : e, Zn = (e) => [ft(e.instrumentations)], Qn = (e, t) => e === void 0 ? t : e !== !1, $n = (e) => typeof e == "object" && e ? e : void 0, $ = (e, t, n) => Qn(e, t) ? [n($n(e))] : [], er = (e) => [
1763
- ...$(e.device, !0, jt),
1764
- ...$(e.session, !0, jn),
1765
- ...$(e.pageView, !0, mn),
1766
- ...$(e.httpBody, !1, rn),
1767
- ...$(e.error, !0, Vt),
1768
- ...$(e.webVitals, !0, Ln),
1769
- ...$(e.resource, !0, gn),
1770
- ...$(e.blankScreen, !0, it),
1771
- ...$(e.action, !1, We),
1772
- ...$(e.websocket, !1, Wn),
1773
- ...$(e.longTask, !1, sn),
1774
- ...$(e.cspViolation, !1, yt),
1775
- ...$(e.routeTiming, !1, _n)
1776
- ], tr = class {
2666
+ } }) : e, li = (e) => [Sn(e.tracking.request)], ui = (e) => [
2667
+ Nr(e.session),
2668
+ ...$(e.tracking.device, !0, Bn),
2669
+ bt(),
2670
+ yr(),
2671
+ ln(di(e.tracking.resource, !0))
2672
+ ], di = (e, t) => e === void 0 ? t : e !== !1, fi = (e) => typeof e == "object" && e ? e : void 0, $ = (e, t, n) => di(e, t) ? [n(fi(e))] : [], pi = (e) => [
2673
+ ...$(e.error, !0, Xn),
2674
+ ...$(e.webVitals, !0, Yr),
2675
+ ...$(e.blankScreen, !0, Lt),
2676
+ ...$(e.action, !0, _t),
2677
+ ...$(e.websocket, !1, ni),
2678
+ ...$(e.longTask, !1, ir),
2679
+ ...$(e.cspViolation, !1, On)
2680
+ ], mi = class {
1777
2681
  assertBeforeStart(e) {
1778
2682
  if (this.phase !== "idle") throw Error(`[bk-ot] ${e}() must be called before start(); set autoStart: false before registration.`);
1779
2683
  }
1780
- constructor(o) {
1781
- var S = this, re, C;
1782
- w(this, "loggerProvider", void 0), w(this, "meterProvider", void 0), w(this, "phase", "idle"), w(this, "pluginManager", void 0), w(this, "plugins", void 0), w(this, "registeredInstrumentations", void 0), w(this, "runtimeContext", void 0), w(this, "sampled", void 0), w(this, "teardownCallbacks", []), w(this, "tracerProvider", void 0), w(this, "applyRedact", (e) => this.config.hooks.redactAttributes(e)), w(this, "config", void 0), w(this, "emitLog", (e) => {
2684
+ createPluginContext() {
2685
+ return {
2686
+ applyRedact: this.applyRedact,
2687
+ config: this.config,
2688
+ emitLog: this.emitLog,
2689
+ flush: this.flush,
2690
+ getRuntimeAttributes: this.getRuntimeAttributes,
2691
+ getRuntimeAttributesAt: this.getRuntimeAttributesAt,
2692
+ isSampled: this.isSampled,
2693
+ isSessionActive: this.isSessionActive,
2694
+ isViewActive: this.isViewActive,
2695
+ logger: this.logger,
2696
+ meter: this.meter,
2697
+ notifySessionLifecycle: this.notifySessionLifecycle,
2698
+ notifyActivity: this.activityObserver.notify,
2699
+ onActivity: this.activityObserver.subscribe,
2700
+ onSessionLifecycle: this.onSessionLifecycle,
2701
+ onViewCommand: this.runtimeContext.onViewCommand,
2702
+ onViewChange: this.runtimeContext.onViewChange,
2703
+ registerInstrumentations: this.registerInstrumentations,
2704
+ setRuntimeAttributes: this.setRuntimeAttributes,
2705
+ setUser: this.setUser,
2706
+ setView: this.runtimeContext.setView,
2707
+ startSpan: this.startSpan,
2708
+ tracer: this.tracer
2709
+ };
2710
+ }
2711
+ createPluginManager() {
2712
+ var e;
2713
+ return new Se([
2714
+ ...ui(this.config),
2715
+ ...li(this.config),
2716
+ ...pi(this.config.tracking),
2717
+ ...(e = this.config.extensions.plugins) == null ? [] : e
2718
+ ]);
2719
+ }
2720
+ constructor(e) {
2721
+ var t = this;
2722
+ D(this, "activityObserver", new ri()), D(this, "flushProviders", k(function* () {
2723
+ yield t.tracerProvider.forceFlush(), yield t.meterProvider.forceFlush(), yield t.loggerProvider.forceFlush();
2724
+ })), D(this, "loggerProvider", void 0), D(this, "meterProvider", void 0), D(this, "phase", "idle"), D(this, "pluginManager", void 0), D(this, "registeredInstrumentations", void 0), D(this, "releaseOtelGlobals", void 0), D(this, "runtimeContext", void 0), D(this, "sampled", !1), D(this, "startCollection", k(function* () {
2725
+ if (t.pluginManager || !t.config.enabled || t.config.trackingConsent !== "granted") return;
2726
+ t.config.transport.traces !== !1 && (t.releaseOtelGlobals = si());
2727
+ let e = t.createPluginManager();
2728
+ t.pluginManager = e;
2729
+ try {
2730
+ var n;
2731
+ yield e.start(t.createPluginContext()), t.registerInstrumentations((n = t.config.extensions.instrumentations) == null ? [] : n);
2732
+ } catch (n) {
2733
+ var r, i, a;
2734
+ for (yield e.shutdown(), t.pluginManager = void 0; t.registeredInstrumentations.length;) (r = t.registeredInstrumentations.pop()) == null || (i = r.disable) == null || i.call(r);
2735
+ throw (a = t.releaseOtelGlobals) == null || a.call(t), t.releaseOtelGlobals = void 0, n;
2736
+ }
2737
+ })), D(this, "stopCollection", function() {
2738
+ var e = k(function* (e) {
2739
+ var n, r, i;
2740
+ let a = t.pluginManager;
2741
+ if (a) {
2742
+ for (yield a.shutdown(), t.pluginManager = void 0; t.registeredInstrumentations.length;) (n = t.registeredInstrumentations.pop()) == null || (r = n.disable) == null || r.call(n);
2743
+ t.setRuntimeAttributes({
2744
+ [T.sessionHasReplay]: void 0,
2745
+ [T.sessionId]: void 0
2746
+ }), e && (yield t.flushProviders()), (i = t.releaseOtelGlobals) == null || i.call(t), t.releaseOtelGlobals = void 0;
2747
+ }
2748
+ });
2749
+ return function(t) {
2750
+ return e.apply(this, arguments);
2751
+ };
2752
+ }()), D(this, "teardownCallbacks", []), D(this, "tracerProvider", void 0), D(this, "applyRedact", (e) => this.config.hooks.redactAttributes(e)), D(this, "config", void 0), D(this, "emitLog", (e) => {
1783
2753
  var t;
1784
- let n = E(E({}, e), {}, { attributes: this.applyRedact(E(E({}, this.getRuntimeAttributes()), (t = e.attributes) == null ? {} : t)) });
1785
- this.logger.emit(n);
1786
- }), w(this, "flush", A(function* () {
1787
- yield S.pluginManager.flush(), yield S.tracerProvider.forceFlush(), yield S.meterProvider.forceFlush(), yield S.loggerProvider.forceFlush();
1788
- })), w(this, "getRuntimeAttributes", () => this.runtimeContext.getAttributes()), w(this, "logger", void 0), w(this, "meter", void 0), w(this, "reportAction", ({ attributes: e = {}, targetTag: t, targetText: n, type: r }) => {
1789
- var i;
1790
- if (!this.sampled) return;
1791
- let a = n == null ? void 0 : n.slice(0, 32);
1792
- this.startSpan(`action.${r}`, E(E(E(E(E({}, this.config.hooks.getPageAttributes()), F({
2754
+ let i = e.timestamp ? n(r(e.timestamp)) : void 0, a = O(O({}, e), {}, { attributes: this.applyRedact(O(O({}, i === void 0 ? this.getRuntimeAttributes() : this.getRuntimeAttributesAt(i)), (t = e.attributes) == null ? {} : t)) });
2755
+ this.logger.emit(a);
2756
+ }), D(this, "flush", k(function* () {
2757
+ var e;
2758
+ yield (e = t.pluginManager) == null ? void 0 : e.flush(), yield t.flushProviders();
2759
+ })), D(this, "getRuntimeAttributes", () => this.runtimeContext.getAttributes()), D(this, "getRuntimeAttributesAt", (e) => this.runtimeContext.getAttributesAt(e)), D(this, "isSampled", () => this.sampled), D(this, "isSessionActive", () => this.runtimeContext.isSessionActive()), D(this, "isViewActive", () => this.runtimeContext.isViewActive()), D(this, "logger", void 0), D(this, "meter", void 0), D(this, "notifySessionLifecycle", (e) => {
2760
+ this.runtimeContext.notifySessionLifecycle(e);
2761
+ }), D(this, "onSessionLifecycle", (e) => this.runtimeContext.onSessionLifecycle(e)), D(this, "registerInstrumentations", (e) => {
2762
+ e.length && (_({
2763
+ instrumentations: e,
2764
+ meterProvider: this.meterProvider,
2765
+ tracerProvider: this.tracerProvider
2766
+ }), this.registeredInstrumentations.push(...e));
2767
+ }), D(this, "reportAction", ({ attributes: e = {}, name: t }) => {
2768
+ if (!this.isSampled()) return;
2769
+ let n = N("action");
2770
+ this.startSpan("action.custom", O(O(O(O({}, this.config.hooks.getPageAttributes()), e), I({
1793
2771
  errorType: "none",
1794
2772
  eventLabel: "用户操作",
1795
- spanSubtype: r,
1796
- spanType: P.action,
1797
- targetLabel: (i = a == null ? t : a) == null ? r : i
1798
- })), {}, { [x.actionType]: r }, a ? { [x.targetTextShort]: a } : {}), t ? { [x.targetTag]: t } : {}), e)).end();
1799
- }), w(this, "reportCustomEvent", ({ attributes: e = {}, error: n, name: r }) => {
1800
- if (!this.sampled) {
2773
+ spanSubtype: "custom",
2774
+ spanType: F.action,
2775
+ targetLabel: t,
2776
+ traceScene: "user_action"
2777
+ })), {}, {
2778
+ [T.actionId]: n,
2779
+ [T.actionName]: t,
2780
+ [T.actionType]: "custom"
2781
+ })).end();
2782
+ }), D(this, "reportCustomEvent", ({ attributes: e = {}, error: t, name: n }) => {
2783
+ if (!this.isSampled()) {
1801
2784
  if (this.config.debug) {
1802
- var i;
1803
- (i = globalThis.console) == null || i.warn("[bk-ot] custom event dropped (not sampled):", r);
2785
+ var r;
2786
+ (r = globalThis.console) == null || r.warn("[bk-ot] custom event dropped (not sampled):", n);
1804
2787
  }
1805
2788
  return;
1806
2789
  }
1807
- let a = this.startSpan(`custom.${r}`, E(E(E(E(E({}, this.config.hooks.getPageAttributes()), this.config.hooks.getCustomAttributes()), F({
1808
- errorType: n ? "custom" : "none",
2790
+ let i = this.startSpan(`custom.${n}`, O(O(O(O(O({}, this.config.hooks.getPageAttributes()), this.config.hooks.getCustomAttributes()), I({
2791
+ errorType: t ? "custom" : "none",
1809
2792
  eventLabel: "自定义事件",
1810
- result: n ? N.error : N.success,
1811
- spanSubtype: r,
1812
- spanType: P.custom,
1813
- targetLabel: r
1814
- })), e), {}, { "rum.custom.name": r }));
1815
- n && (a.recordException(n), a.setStatus({
1816
- code: t.ERROR,
1817
- message: n.message
1818
- })), a.end();
1819
- }), w(this, "setRuntimeAttributes", (e) => {
1820
- this.runtimeContext.setAttributes(e);
1821
- }), w(this, "setUser", (e) => {
2793
+ result: t ? P.error : P.success,
2794
+ spanSubtype: n,
2795
+ spanType: F.custom,
2796
+ targetLabel: n
2797
+ })), e), {}, { "rum.custom.name": n }));
2798
+ t && (i.recordException(t), i.setStatus({
2799
+ code: c.ERROR,
2800
+ message: t.message
2801
+ })), i.end();
2802
+ }), D(this, "setRuntimeAttributes", (e, t) => {
2803
+ let n = O({}, e);
2804
+ if (T.sessionId in e) {
2805
+ let t = e[T.sessionId];
2806
+ this.sampled = this.config.enabled && typeof t == "string" && t.length > 0 ? we(this.config, t) : !1, n[A] = this.sampled;
2807
+ }
2808
+ this.runtimeContext.setAttributes(n, t);
2809
+ }), D(this, "setTrackingConsent", function() {
2810
+ var e = k(function* (e) {
2811
+ t.config.trackingConsent !== e && (t.config.trackingConsent = e, t.phase === "started" && (e === "granted" ? yield t.startCollection() : yield t.stopCollection(!0)));
2812
+ });
2813
+ return function(t) {
2814
+ return e.apply(this, arguments);
2815
+ };
2816
+ }()), D(this, "setUser", (e) => {
1822
2817
  this.runtimeContext.setUser(e);
1823
- }), w(this, "setView", (e) => {
1824
- this.runtimeContext.setView(e);
1825
- }), w(this, "shutdown", A(function* () {
1826
- if (S.phase !== "stopped") {
1827
- for (yield S.flush(); S.teardownCallbacks.length;) {
2818
+ }), D(this, "setViewLoadingTime", () => {
2819
+ this.isSampled() && this.runtimeContext.dispatchViewCommand({
2820
+ time: Date.now(),
2821
+ type: "set_loading_time"
2822
+ });
2823
+ }), D(this, "setViewName", (e) => {
2824
+ this.isSampled() && this.runtimeContext.dispatchViewCommand({
2825
+ name: e,
2826
+ type: "set_name"
2827
+ });
2828
+ }), D(this, "shutdown", k(function* () {
2829
+ if (t.phase !== "stopped") {
2830
+ for (yield t.stopCollection(!1), yield t.flushProviders(); t.teardownCallbacks.length;) {
1828
2831
  var e;
1829
- (e = S.teardownCallbacks.pop()) == null || e();
2832
+ (e = t.teardownCallbacks.pop()) == null || e();
1830
2833
  }
1831
- for (yield S.pluginManager.shutdown(); S.registeredInstrumentations.length;) {
1832
- var t, i;
1833
- (t = S.registeredInstrumentations.pop()) == null || (i = t.disable) == null || i.call(t);
1834
- }
1835
- yield S.tracerProvider.shutdown(), yield S.meterProvider.shutdown(), yield S.loggerProvider.shutdown(), a.disable(), r.disable(), n.disable(), S.phase = "stopped";
2834
+ yield t.tracerProvider.shutdown(), yield t.meterProvider.shutdown(), yield t.loggerProvider.shutdown(), t.phase = "stopped";
1836
2835
  }
1837
- })), w(this, "start", A(function* () {
1838
- if (!(S.phase === "started" || S.phase === "starting")) {
1839
- if (S.phase === "stopped") throw Error("[bk-ot] instance has been shut down and cannot be restarted; create a new instance instead.");
1840
- if (!S.config.enabled) {
1841
- S.phase = "started";
2836
+ })), D(this, "start", k(function* () {
2837
+ if (!(t.phase === "started" || t.phase === "starting")) {
2838
+ if (t.phase === "stopped") throw Error("[bk-ot] instance has been shut down and cannot be restarted; create a new instance instead.");
2839
+ if (!t.config.enabled) {
2840
+ t.phase = "started";
1842
2841
  return;
1843
2842
  }
1844
- S.phase = "starting", i.setGlobalPropagator(new l()), S.tracerProvider.register({ contextManager: new c() }), r.setGlobalMeterProvider(S.meterProvider), s.setGlobalLoggerProvider(S.loggerProvider);
2843
+ t.phase = "starting";
1845
2844
  try {
1846
- if (S.registeredInstrumentations.length && p({
1847
- instrumentations: S.registeredInstrumentations,
1848
- meterProvider: S.meterProvider,
1849
- tracerProvider: S.tracerProvider
1850
- }), yield S.pluginManager.start(S), typeof window < "u" && typeof document < "u") {
2845
+ if (yield t.startCollection(), typeof window < "u" && typeof document < "u") {
1851
2846
  let e = () => {
1852
- S.flush();
1853
- }, t = () => {
1854
- document.visibilityState === "hidden" && S.flush();
2847
+ t.flush();
2848
+ }, n = () => {
2849
+ document.visibilityState === "hidden" && t.flush();
1855
2850
  };
1856
- window.addEventListener("pagehide", e), document.addEventListener("visibilitychange", t), S.teardownCallbacks.push(() => window.removeEventListener("pagehide", e), () => document.removeEventListener("visibilitychange", t));
2851
+ window.addEventListener("pagehide", e), document.addEventListener("visibilitychange", n), t.teardownCallbacks.push(() => window.removeEventListener("pagehide", e), () => document.removeEventListener("visibilitychange", n));
1857
2852
  }
1858
- } catch (i) {
1859
- for (; S.teardownCallbacks.length;) {
2853
+ } catch (n) {
2854
+ for (; t.teardownCallbacks.length;) {
1860
2855
  var e;
1861
- (e = S.teardownCallbacks.pop()) == null || e();
1862
- }
1863
- yield S.pluginManager.shutdown();
1864
- for (let e of S.registeredInstrumentations) {
1865
- var t;
1866
- (t = e.disable) == null || t.call(e);
2856
+ (e = t.teardownCallbacks.pop()) == null || e();
1867
2857
  }
1868
- throw a.disable(), r.disable(), n.disable(), S.phase = "idle", i;
2858
+ throw yield t.stopCollection(!1), t.phase = "idle", n;
1869
2859
  }
1870
- S.phase = "started";
2860
+ t.phase = "started";
1871
2861
  }
1872
- })), w(this, "startSpan", (t, n = {}, r) => this.tracer.startSpan(t, {
1873
- kind: e.INTERNAL,
1874
- startTime: r == null ? void 0 : r.startTime,
1875
- attributes: this.applyRedact(E(E({}, this.getRuntimeAttributes()), n))
1876
- })), w(this, "tracer", void 0), w(this, "use", (e) => (this.assertBeforeStart("use"), this.sampled && this.plugins.push(e), this)), w(this, "useInstrumentation", (e) => (this.assertBeforeStart("useInstrumentation"), this.config.enabled && this.registeredInstrumentations.push(e), this)), this.config = _e(o), this.sampled = this.config.enabled && Jn(this.config);
1877
- let T = m(this.config.resourceAttributes), D = Q(new f(Yn(this.config.transport.traces)), "traces", this.config.debug), ie = Q(new d(Yn(this.config.transport.metrics)), "metrics", this.config.debug), ae = Q(new u(Yn(this.config.transport.logs)), "logs", this.config.debug), O = new je(this.config.spanProcessor === "simple" ? new ee(D) : new y(D, this.config.spanBatch), this.config), oe = new v({
1878
- exporter: ie,
2862
+ })), D(this, "startSpan", (e, t = {}, n) => {
2863
+ var r, i;
2864
+ let a = (r = n == null ? void 0 : n.contextTime) == null ? typeof (n == null ? void 0 : n.startTime) == "number" ? n.startTime : void 0 : r, o = a === void 0 ? this.getRuntimeAttributes() : this.runtimeContext.getAttributesAt(a);
2865
+ return this.tracer.startSpan(e, {
2866
+ kind: (i = n == null ? void 0 : n.kind) == null ? s.INTERNAL : i,
2867
+ startTime: n == null ? void 0 : n.startTime,
2868
+ attributes: this.applyRedact(O(O({}, o), t))
2869
+ });
2870
+ }), D(this, "startView", (e = {}) => {
2871
+ this.isSampled() && this.runtimeContext.dispatchViewCommand({
2872
+ options: e,
2873
+ type: "start"
2874
+ });
2875
+ }), D(this, "tracer", void 0), D(this, "use", (e) => {
2876
+ var t;
2877
+ return this.assertBeforeStart("use"), (t = this.config.extensions.plugins) == null || t.push(e), this;
2878
+ }), D(this, "useInstrumentation", (e) => {
2879
+ var t;
2880
+ return this.assertBeforeStart("useInstrumentation"), this.config.enabled && ((t = this.config.extensions.instrumentations) == null || t.push(e)), this;
2881
+ }), this.config = ve(e), this.runtimeContext = new qe({ [A]: !1 }, this.config.user);
2882
+ let i = v(this.config.resourceAttributes), l = (() => {
2883
+ if (this.config.transport.traces === !1) return [];
2884
+ let e = ci(new g(ii(this.config.transport.traces)), "traces", this.config.debug);
2885
+ return [new Ue(this.config.spanProcessor === "simple" ? new C(e) : new x(e, this.config.spanBatch), this.config, () => this.applyRedact(O(O({}, this.runtimeContext.getAttributes()), this.config.hooks.getPageAttributes())))];
2886
+ })(), u = this.config.transport.metrics === !1 ? [] : [new o({
2887
+ exporter: new Ge(ci(new h(O(O({}, ii(this.config.transport.metrics)), {}, { temporalityPreference: m.DELTA })), "metrics", this.config.debug)),
1879
2888
  exportIntervalMillis: this.config.metricIntervalMillis
1880
- }), se = new h(ae);
1881
- this.tracerProvider = new ne({
1882
- resource: T,
1883
- sampler: new b({ root: new te(+!!this.sampled) }),
1884
- spanProcessors: [O]
1885
- }), this.meterProvider = new _({
1886
- resource: T,
1887
- readers: [oe]
1888
- }), this.loggerProvider = new g({
1889
- resource: T,
1890
- processors: [se]
1891
- }), this.tracer = this.tracerProvider.getTracer(Xn), this.meter = this.meterProvider.getMeter(Xn), this.logger = this.loggerProvider.getLogger(Xn), this.runtimeContext = new Me({ "rum.sampled": this.sampled }, this.config.user), this.registeredInstrumentations = this.config.enabled ? [...(re = this.config.instrumentations.custom) == null ? [] : re] : [], this.plugins = [...this.config.enabled ? Zn(this.config) : [], ...this.sampled ? [...er(this.config.plugins), ...(C = this.config.plugins.custom) == null ? [] : C] : []], this.pluginManager = new xe(this.plugins), this.config.autoStart && this.start().catch((e) => {
2889
+ })], d = this.config.transport.logs === !1 ? [] : [new He(new y(ci(new p(ii(this.config.transport.logs)), "logs", this.config.debug)), this.config)];
2890
+ this.tracerProvider = new ee({
2891
+ resource: i,
2892
+ sampler: new oi(() => this.config.transport.traces !== !1 && this.isSampled()),
2893
+ spanProcessors: l
2894
+ }), this.meterProvider = new a({
2895
+ resource: i,
2896
+ readers: u
2897
+ }), this.loggerProvider = new b({
2898
+ resource: i,
2899
+ processors: d
2900
+ }), this.tracer = this.tracerProvider.getTracer(ai), this.meter = this.meterProvider.getMeter(ai), this.logger = this.loggerProvider.getLogger(ai), this.registeredInstrumentations = [], this.config.autoStart && this.start().catch((e) => {
1892
2901
  var t;
1893
2902
  (t = globalThis.console) == null || t.warn("[bk-ot] auto start failed:", e);
1894
2903
  });
1895
2904
  }
1896
2905
  };
1897
2906
  //#endregion
1898
- export { tr as BkOpenTelemetry, je as FilteringSpanProcessor, x as RUM_ATTRIBUTES, N as RUM_SPAN_RESULT, P as RUM_SPAN_TYPE, Me as RumRuntimeContext, F as buildRumSpanAttributes, We as createActionPlugin, it as createBlankScreenPlugin, ft as createCommonInstrumentationsPlugin, yt as createCspViolationPlugin, jt as createDevicePlugin, Vt as createErrorPlugin, rn as createHttpBodyPlugin, sn as createLongTaskPlugin, mn as createPageViewPlugin, be as createPlugin, gn as createResourcePlugin, _n as createRouteTimingPlugin, jn as createSessionPlugin, Wn as createWebSocketPlugin, Ln as createWebVitalsPlugin, Ne as getDurationBucket, _e as resolveConfig };
2907
+ export { mi as BkOpenTelemetry, vt as EXCLUDED_ACTIVITY_MUTATIONS_ATTRIBUTE, He as FilteringLogRecordProcessor, Ge as FilteringMetricExporter, Ue as FilteringSpanProcessor, T as RUM_ATTRIBUTES, P as RUM_SPAN_RESULT, F as RUM_SPAN_TYPE, qe as RumRuntimeContext, I as buildRumSpanAttributes, _t as createActionPlugin, Lt as createBlankScreenPlugin, Sn as createCommonInstrumentationsPlugin, On as createCspViolationPlugin, Bn as createDevicePlugin, Xn as createErrorPlugin, ir as createLongTaskPlugin, xe as createPlugin, ln as createResourcePlugin, Nr as createSessionPlugin, ni as createWebSocketPlugin, Yr as createWebVitalsPlugin, Je as getDurationBucket, ve as resolveConfig };