Files
discord-decomp/_bundle/BrowserMetricsAggregator.js
T
2026-11-01 12:12:55 +02:00

84 lines
2.4 KiB
JavaScript

// Metro module 6472 (f6473).
import * as _classCallCheck from "./_classCallCheck";
import * as __createClass from "./_createClass";
import { DEFAULT_BROWSER_FLUSH_INTERVAL, SET_METRIC_TYPE } from "./Module6465";
import { timestampInSeconds } from "./Module6382";
import { sanitizeMetricKey, sanitizeTags, sanitizeUnit, getBucketKey } from "./Module6469";
import { METRIC_MAP } from "./CounterMetric";
import { updateMetricSummaryOnActiveSpan } from "./spanTimeInputToSeconds";
import { captureAggregateMetrics } from "./createMetricEnvelope";
let env4172 = {};
const BrowserMetricsAggregator = function BrowserMetricsAggregator(a0) {
"use strict";
_classCallCheck(this, BrowserMetricsAggregator);
this._client = a0;
this._buckets = new Map();
this._interval = setInterval(() => this.flush(), DEFAULT_BROWSER_FLUSH_INTERVAL);
};
exports.BrowserMetricsAggregator = __createClass(BrowserMetricsAggregator, [{
key: "add",
value: function add(a0, a1, a2) {
"use strict";
let r61;
let r6 = arguments[3];
if (r6 === void 0) {
r6 = "none";
}
let r9 = arguments[4];
if (r9 === void 0) {
r9 = {};
}
let r5 = arguments[5];
if (r5 === void 0) {
r5 = timestampInSeconds();
}
const timestamp2 = Math.floor(r5);
const name = sanitizeMetricKey(a1);
const tags = sanitizeTags(r9);
const unit = sanitizeUnit(r6);
const bucketKey = getBucketKey(a0, name, unit, tags);
const r12 = this._buckets.get(bucketKey);
const r11 = r12 ? a0 === SET_METRIC_TYPE ? r12.metric.weight : 0 : 0;
let r53 = a2;
if (r12) {
r12.metric.add(a2);
const timestamp = r12.timestamp;
r61 = r12;
if (timestamp < timestamp2) {
r12.timestamp = timestamp2;
r61 = r12;
}
} else {
r61 = {
metric: new METRIC_MAP[a0](a2),
timestamp: timestamp2,
metricType: a0,
name,
unit,
tags
};
this._buckets.set(bucketKey, r61);
}
if (typeof a2 === "string") {
r53 = r61.metric.weight - r11;
}
updateMetricSummaryOnActiveSpan(a0, name, r53, unit, r9, bucketKey);
}
}, {
key: "flush",
value: function flush() {
"use strict";
if (this._buckets.size !== 0) {
captureAggregateMetrics(this._client, Array.from(this._buckets.values()));
this._buckets.clear();
}
}
}, {
key: "close",
value: function close() {
"use strict";
clearInterval(this._interval);
this.flush();
}
}]);