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

295 lines
9.4 KiB
JavaScript

// Metro module 860 (f861).
import * as _classCallCheck from "./_classCallCheck";
import * as __createClass from "./_createClass";
import { generateTraceId, generateSpanId } from "./Module829";
import { timestampInSeconds } from "./dateTimestampInSeconds";
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, SEMANTIC_ATTRIBUTE_PROFILE_ID, SEMANTIC_ATTRIBUTE_EXCLUSIVE_TIME, SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME } from "./Module839";
import { TRACE_FLAG_SAMPLED, TRACE_FLAG_NONE, spanTimeInputToSeconds, getStatusMessage, getRootSpan, convertSpanLinksForEnvelope, spanToJSON, getSpanDescendants, spanToTransactionTraceContext } from "./spanToJSON";
import { logSpanEnd } from "./Module861";
import { timedEventsToMeasurements } from "./Module862";
import { DEBUG_BUILD } from "./Module823";
import { debug } from "./consoleSandbox";
import { getClient, getCurrentScope } from "./Module848";
import { createSpanEnvelope } from "./Module863";
import { getCapturedScopesOnSpan } from "./unwrapScopeFromWeakRef";
import { getDynamicSamplingContextFromSpan } from "./getDynamicSamplingContextFromSpan";
import { HermesBuiltin } from "../_hermes/prelude";
let c699_3;
let SentrySpan;
let env699 = {};
const isFullFinishedSpan = function isFullFinishedSpan(a0) {
return !!(a0.start_timestamp && a0.timestamp && a0.span_id && a0.trace_id);
};
Object.defineProperty(exports, Symbol.toStringTag, {
value: "Module"
});
SentrySpan = function SentrySpan() {
"use strict";
let r2 = arguments[0];
if (r2 === void 0) {
r2 = {};
}
_classCallCheck(this, SentrySpan);
this._traceId = r2.traceId || generateTraceId();
this._spanId = r2.spanId || generateSpanId();
this._startTime = r2.startTimestamp || timestampInSeconds();
this._links = r2.links;
this._attributes = {};
const setAttributes2 = this.setAttributes;
const r34 = {};
r34[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] = "manual";
r34[SEMANTIC_ATTRIBUTE_SENTRY_OP] = r2.op;
HermesBuiltin.copyDataProperties(r34, r2.attributes);
setAttributes2.call(this, r34);
this._name = r2.name;
if (r2.parentSpanId) {
this._parentSpanId = r2.parentSpanId;
}
if ("sampled" in r2) {
this._sampled = r2.sampled;
}
if (r2.endTimestamp) {
this._endTime = r2.endTimestamp;
}
this._events = [];
this._isStandaloneSpan = r2.isStandalone;
if (this._endTime) {
this._onSpanEnded();
}
};
c699_3 = __createClass(SentrySpan, [{
key: "addLink",
value: function addLink(a0) {
"use strict";
if (this._links) {
this._links.push(a0);
} else {
this._links = [a0];
}
return this;
}
}, {
key: "addLinks",
value: function addLinks(a0) {
"use strict";
if (this._links) {
const _links = this._links;
_links.push.apply(_links, [...a0]);
} else {
this._links = a0;
}
return this;
}
}, {
key: "recordException",
value: function recordException(a0, a1) {
"use strict";
}
}, {
key: "spanContext",
value: function spanContext() {
"use strict";
return {
spanId: this._spanId,
traceId: this._traceId,
traceFlags: this._sampled ? TRACE_FLAG_SAMPLED : TRACE_FLAG_NONE
};
}
}, {
key: "setAttribute",
value: function setAttribute(a0, a1) {
"use strict";
if (a1 === void 0) {
delete this._attributes[a0];
} else {
this._attributes[a0] = a1;
}
return this;
}
}, {
key: "setAttributes",
value: function setAttributes(a0) {
"use strict";
let c23856_0 = a0;
Object.keys(a0).forEach((item) => this.setAttribute(item, c23856_0[item]));
return this;
}
}, {
key: "updateStartTime",
value: function updateStartTime(a0) {
"use strict";
this._startTime = spanTimeInputToSeconds(a0);
}
}, {
key: "setStatus",
value: function setStatus(a0) {
"use strict";
this._status = a0;
return this;
}
}, {
key: "updateName",
value: function updateName(a0) {
"use strict";
this._name = a0;
this.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, "custom");
return this;
}
}, {
key: "end",
value: function end(a0) {
"use strict";
if (!this._endTime) {
this._endTime = spanTimeInputToSeconds(a0);
logSpanEnd(this);
this._onSpanEnded();
}
}
}, {
key: "getSpanJSON",
value: function getSpanJSON() {
"use strict";
return {
data: this._attributes,
description: this._name,
op: this._attributes[SEMANTIC_ATTRIBUTE_SENTRY_OP],
parent_span_id: this._parentSpanId,
span_id: this._spanId,
start_timestamp: this._startTime,
status: getStatusMessage(this._status),
timestamp: this._endTime,
trace_id: this._traceId,
origin: this._attributes[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN],
profile_id: this._attributes[SEMANTIC_ATTRIBUTE_PROFILE_ID],
exclusive_time: this._attributes[SEMANTIC_ATTRIBUTE_EXCLUSIVE_TIME],
measurements: timedEventsToMeasurements(this._events),
is_segment: this._isStandaloneSpan && getRootSpan(this) === this || void 0,
segment_id: this._isStandaloneSpan ? getRootSpan(this).spanContext().spanId : void 0,
links: convertSpanLinksForEnvelope(this._links)
};
}
}, {
key: "isRecording",
value: function isRecording() {
"use strict";
const _endTime = this._endTime;
return _endTime ? !_endTime : !!this._sampled;
}
}, {
key: "addEvent",
value: function addEvent(a0, a1, a2) {
"use strict";
if (DEBUG_BUILD) {
debug.log("[Tracing] Adding an event to span:", a0);
}
const r23 = (a1 ? typeof a1 === "number" : a1) || a1 instanceof Date || Array.isArray(a1) ? a1 : a2 ? a2 : timestampInSeconds();
const attributes = (a1 ? typeof a1 === "number" : a1) || a1 instanceof Date || Array.isArray(a1) ? {} : a1 ? a1 : {};
this._events.push({
name: a0,
time: spanTimeInputToSeconds(r23),
attributes
});
return this;
}
}, {
key: "isStandaloneSpan",
value: function isStandaloneSpan() {
"use strict";
return !!this._isStandaloneSpan;
}
}, {
key: "_onSpanEnded",
value: function _onSpanEnded() {
"use strict";
const client = getClient();
if (client) {
client.emit("spanEnd", this);
}
L19: {
if (!(!this._isStandaloneSpan && this !== getRootSpan(this))) {
if (this._isStandaloneSpan) {
if (this._sampled) {
const spanEnvelope = createSpanEnvelope([this], client);
const client2 = getClient();
if (client2) {
const r54 = spanEnvelope[1];
if (r54 && r54.length !== 0) {
client2.sendEnvelope(spanEnvelope);
break L19;
}
client2.recordDroppedEvent("before_send", "span");
}
} else {
if (DEBUG_BUILD) {
debug.log("[Tracing] Discarding standalone span because its trace was not chosen to be sampled.");
}
if (client) {
client.recordDroppedEvent("sample_rate", "span");
}
}
} else {
const r6 = this._convertSpanToTransaction();
if (r6) {
(getCapturedScopesOnSpan(this).scope || getCurrentScope()).captureEvent(r6);
}
}
}
}
}
}, {
key: "_convertSpanToTransaction",
value: function _convertSpanToTransaction() {
"use strict";
const r21 = spanToJSON(this);
if (r21.start_timestamp && r21.timestamp && r21.span_id && r21.trace_id) {
if (!this._name) {
if (DEBUG_BUILD) {
debug.warn("Transaction has no name, falling back to `<unlabeled transaction>`.");
}
this._name = "<unlabeled transaction>";
}
const capturedScopesOnSpan = getCapturedScopesOnSpan(this);
const { scope, isolationScope } = capturedScopesOnSpan;
const request = scope == null ? void 0 : scope.getScopeData().sdkProcessingMetadata?.normalizedRequest;
if (this._sampled === true) {
const r16 = getSpanDescendants(this).filter((item) => item !== this && !(item instanceof c699_3 && item.isStandaloneSpan())).map((item) => spanToJSON(item)).filter(isFullFinishedSpan);
const source = this._attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE];
delete this._attributes[SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME];
r16.forEach((item) => {
delete item.data[SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME];
});
const r75 = {
contexts: {
trace: spanToTransactionTraceContext(this)
},
spans: r16.length > 1000 ? r16.sort((a, b) => a.start_timestamp - b.start_timestamp).slice(0, 1000) : r16,
start_timestamp: this._startTime,
timestamp: this._endTime,
transaction: this._name,
type: "transaction",
sdkProcessingMetadata: {
capturedSpanScope: scope,
capturedSpanIsolationScope: isolationScope,
dynamicSamplingContext: getDynamicSamplingContextFromSpan(this)
},
request,
...source && {
transaction_info: {
source
}
}
};
const measurements = timedEventsToMeasurements(this._events);
if (measurements && Object.keys(measurements).length) {
if (DEBUG_BUILD) {
debug.log("[Measurements] Adding measurements to transaction event", JSON.stringify(measurements, void 0, 2));
}
r75.measurements = measurements;
}
return r75;
}
}
}
}]);
export { c699_3 as SentrySpan };