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

184 lines
6.2 KiB
JavaScript

// Metro module 885 (f886).
import { _getTraceInfoFromScope } from "./Module881";
import { _getSpanForScope } from "./Module844";
import { timestampInSeconds } from "./dateTimestampInSeconds";
import { serializeAttributes } from "./isAttributeObject";
import { getCurrentScope, getClient, getIsolationScope } from "./Module848";
import { DEBUG_BUILD } from "./Module823";
import { debug } from "./consoleSandbox";
import { getCombinedScopeData } from "./mergeScopeData";
import { createMetricEnvelope } from "./Module886";
import { getGlobalSingleton } from "./Module825";
function $mk67285() {
return () => new WeakMap();
}
let _INTERNAL_flushMetricsBuffer;
const _INTERNAL_captureSerializedMetric = function _INTERNAL_captureSerializedMetric(a0, a1) {
const globalSingleton = getGlobalSingleton("clientToMetricBufferMap", $mk67285());
const r23 = getGlobalSingleton("clientToMetricBufferMap", $mk67285()).get(a0);
if (r23 === void 0) {
globalSingleton.set(a0, [a1]);
} else if (r23.length >= 1000) {
_INTERNAL_flushMetricsBuffer(a0, r23);
globalSingleton.set(a0, [a1]);
} else {
globalSingleton.set(a0, [...r23, a1]);
}
};
_INTERNAL_flushMetricsBuffer = function _INTERNAL_flushMetricsBuffer(a0, a1) {
let r11 = a1 == null ? getGlobalSingleton("clientToMetricBufferMap", $mk67285()).get(a0) : a1;
if (r11 == null) {
r11 = [];
}
if (r11.length !== 0) {
const options = a0.getOptions();
const metricEnvelope = createMetricEnvelope(r11, options._metadata, options.tunnel, a0.getDsn());
getGlobalSingleton("clientToMetricBufferMap", $mk67285()).set(a0, []);
a0.emit("flushMetrics");
a0.sendEnvelope(metricEnvelope);
}
};
Object.defineProperty(exports, Symbol.toStringTag, {
value: "Module"
});
export function _INTERNAL_captureMetric(a0, a1) {
let _experiments, beforeSendMetric;
let r13 = a1?.scope;
if (r13 == null) {
r13 = getCurrentScope();
}
let r27 = a1?.captureSerializedMetric;
if (r27 == null) {
r27 = _INTERNAL_captureSerializedMetric;
}
let r29 = r13 == null ? void 0 : r13.getClient();
if (r29 == null) {
r29 = getClient();
}
L90: {
if (r29) {
L24: {
const options = r29.getOptions();
_experiments = options._experiments;
const enableMetrics = options.enableMetrics;
beforeSendMetric = options.beforeSendMetric;
if (enableMetrics == null) {
const enableMetrics2 = _experiments?.enableMetrics;
if (enableMetrics2 == null) {
break L24;
}
if (enableMetrics2) {
break L24;
}
} else if (enableMetrics) {
break L24;
}
if (!DEBUG_BUILD) {
break L90;
}
debug.warn("metrics option not enabled, metric will not be captured.");
break L90;
}
const combinedScopeData = getCombinedScopeData(getIsolationScope(), r13);
const { user, attributes } = combinedScopeData;
const options2 = r29.getOptions();
const { release, environment } = options2;
const attributes2 = {
...a0.attributes
};
const id = user.id;
if (!(id ? "user.id" in attributes2 : !id)) {
attributes2["user.id"] = id;
}
const email = user.email;
if (!(email ? "user.email" in attributes2 : !email)) {
attributes2["user.email"] = email;
}
const username = user.username;
if (!(username ? "user.name" in attributes2 : !username)) {
attributes2["user.name"] = username;
}
if (!(release ? false : !release)) {
attributes2["sentry.release"] = release;
}
if (!(environment ? false : !environment)) {
attributes2["sentry.environment"] = environment;
}
let r89 = r29.getSdkMetadata()?.sdk;
if (r89 == null) {
r89 = {};
}
const { name, version } = r89;
if (!(name ? false : !name)) {
attributes2["sentry.sdk.name"] = name;
}
if (!(version ? false : !version)) {
attributes2["sentry.sdk.version"] = version;
}
const integrationByName = r29.getIntegrationByName("Replay");
let r98 = integrationByName == null ? void 0 : integrationByName.getReplayId(true);
if (!(r98 ? false : !r98)) {
attributes2["sentry.replay_id"] = r98;
}
if (r98) {
r98 = (integrationByName == null ? void 0 : integrationByName.getRecordingMode()) === "buffer";
}
if (r98) {
attributes2["sentry._internal.replay_is_buffering"] = true;
}
const r108 = {
...a0,
attributes: attributes2
};
r29.emit("processMetric", r108);
if (!beforeSendMetric) {
beforeSendMetric = _experiments?.beforeSendMetric;
}
const r117 = beforeSendMetric ? beforeSendMetric(r108) : r108;
if (r117) {
const [, r133] = _getTraceInfoFromScope(r29, r13);
const r137 = _getSpanForScope(r13);
let trace_id = r137 ? r137.spanContext().traceId : r133?.trace_id;
const span_id = r137 ? r137.spanContext().spanId : void 0;
const r149 = {
timestamp: timestampInSeconds(),
trace_id: null,
span_id: null,
name: null,
type: null,
unit: null,
value: null,
attributes: null
};
if (trace_id == null) {
trace_id = "";
}
r149.trace_id = trace_id;
r149.span_id = span_id;
r149.name = r117.name;
r149.type = r117.type;
r149.unit = r117.unit;
r149.value = r117.value;
r149.attributes = {
...serializeAttributes(attributes),
...serializeAttributes(r117.attributes, "skip-undefined")
};
if (DEBUG_BUILD) {
debug.log("[Metric]", r149);
}
r27(r29, r149);
r29.emit("afterCaptureMetric", r117);
} else if (DEBUG_BUILD) {
debug.log("`beforeSendMetric` returned `null`, will not send metric.");
}
} else if (DEBUG_BUILD) {
debug.warn("No client available to capture metric.");
}
}
}
export { _INTERNAL_captureSerializedMetric };
export { _INTERNAL_flushMetricsBuffer };
export function _INTERNAL_getMetricBuffer(a0) {
return getGlobalSingleton("clientToMetricBufferMap", $mk67285()).get(a0);
}