// Metro module 6409 (f6410). import * as _classCallCheck from "./_classCallCheck"; import * as __createClass from "./_createClass"; import { generateTraceId, generateSpanId } from "./Module6378"; import { timestampInSeconds } from "./Module6382"; 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 "./Module6383"; import { TRACE_FLAG_SAMPLED, TRACE_FLAG_NONE, spanTimeInputToSeconds, getStatusMessage, getRootSpan, spanToJSON, getSpanDescendants, spanToTransactionTraceContext } from "./spanTimeInputToSeconds"; import { logSpanEnd } from "./Module6406"; import { dropUndefinedKeys } from "./addNonEnumerableProperty_6374"; import { getMetricSummaryJsonForSpan } from "./Module6384"; import { timedEventsToMeasurements } from "./Module6410"; import { DEBUG_BUILD } from "./Module6396"; import { logger } from "./consoleSandbox_6368"; import { getClient, getCurrentScope } from "./Module6395"; import { createSpanEnvelope } from "./Module6411"; import { getCapturedScopesOnSpan } from "./Module6397"; import { getDynamicSamplingContextFromSpan } from "./getDynamicSamplingContextFromSpan_6404"; import { HermesBuiltin } from "../_hermes/prelude"; let c4106_3; let SentrySpan; let env4106 = {}; const isFullFinishedSpan = function isFullFinishedSpan(a0) { return !!(a0.start_timestamp && a0.timestamp && a0.span_id && a0.trace_id); }; 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._attributes = {}; const setAttributes2 = this.setAttributes; const r33 = {}; r33[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] = "manual"; r33[SEMANTIC_ATTRIBUTE_SENTRY_OP] = r2.op; HermesBuiltin.copyDataProperties(r33, r2.attributes); setAttributes2.call(this, r33); 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(); } }; c4106_3 = __createClass(SentrySpan, [{ key: "addLink", value: function addLink(a0) { "use strict"; return this; } }, { key: "addLinks", value: function addLinks(a0) { "use strict"; 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 c25853_0 = a0; Object.keys(a0).forEach((item) => this.setAttribute(item, c25853_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 dropUndefinedKeys({ 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], _metrics_summary: getMetricSummaryJsonForSpan(this), 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 }); } }, { 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) { logger.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) { logger.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 r20 = spanToJSON(this); if (r20.start_timestamp && r20.timestamp && r20.span_id && r20.trace_id) { if (!this._name) { if (DEBUG_BUILD) { logger.warn("Transaction has no name, falling back to ``."); } this._name = ""; } const capturedScopesOnSpan = getCapturedScopesOnSpan(this); const { scope, isolationScope } = capturedScopesOnSpan; const r42 = (scope || getCurrentScope()).getClient() || getClient(); if (this._sampled !== true) { if (DEBUG_BUILD) { logger.log("[Tracing] Discarding transaction because its trace was not chosen to be sampled."); } if (r42) { r42.recordDroppedEvent("sample_rate", "transaction"); } return void 0; } const r15 = getSpanDescendants(this).filter((item) => item !== this && !(item instanceof c4106_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]; r15.forEach((item) => { if (item.data) { delete item.data[SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME]; } }); const r77 = { contexts: { trace: spanToTransactionTraceContext(this) }, spans: r15.length > 1000 ? r15.sort((a, b) => a.start_timestamp - b.start_timestamp).slice(0, 1000) : r15, start_timestamp: this._startTime, timestamp: this._endTime, transaction: this._name, type: "transaction", sdkProcessingMetadata: { capturedSpanScope: scope, capturedSpanIsolationScope: isolationScope, ...dropUndefinedKeys({ dynamicSamplingContext: getDynamicSamplingContextFromSpan(this) }) }, _metrics_summary: getMetricSummaryJsonForSpan(this), ...source && { transaction_info: { source } } }; const measurements = timedEventsToMeasurements(this._events); if (measurements && Object.keys(measurements).length) { if (DEBUG_BUILD) { logger.log("[Measurements] Adding measurements to transaction event", JSON.stringify(measurements, void 0, 2)); } r77.measurements = measurements; } return r77; } } }]); export { c4106_3 as SentrySpan };