184 lines
5.9 KiB
JavaScript
184 lines
5.9 KiB
JavaScript
// Metro module 6473 (f6474).
|
|
import * as _toArray from "./_toArray";
|
|
import "./errorCallback";
|
|
import "./Module6367";
|
|
import "./consoleSandbox_6368";
|
|
import "./Module6382";
|
|
import "./SyncPromise_6392";
|
|
import "./Module6396";
|
|
import { hasTracingEnabled } from "./Module6400";
|
|
import { parseUrl } from "./Module6450";
|
|
import { getActiveSpan } from "./spanTimeInputToSeconds";
|
|
import { startInactiveSpan } from "./createChildOrRootSpan_6402";
|
|
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_OP } from "./Module6383";
|
|
import { SentryNonRecordingSpan } from "./SentryNonRecordingSpan_6401";
|
|
import { getTraceData } from "./Module6439";
|
|
import { setHttpStatus, SPAN_STATUS_ERROR } from "./Module6385";
|
|
import { SENTRY_BAGGAGE_KEY_PREFIX } from "./Module6381";
|
|
import { isInstanceOf } from "./isInstanceOf_6375";
|
|
function $mk78693($env) {
|
|
return (a0) => !a0.split("=")[0].startsWith(SENTRY_BAGGAGE_KEY_PREFIX);
|
|
}
|
|
let env4174 = {};
|
|
const _addTracingHeadersToFetchRequest = function _addTracingHeadersToFetchRequest(a0, a1, a2) {
|
|
let r49;
|
|
const r4 = env4174;
|
|
const traceData = getTraceData({
|
|
span: a2
|
|
});
|
|
const r22 = traceData["sentry-trace"];
|
|
const baggage = traceData.baggage;
|
|
if (r22) {
|
|
let headers = a1.headers;
|
|
if (!headers) {
|
|
const Request2 = globalThis.Request;
|
|
headers = (typeof Request2 !== "undefined" ? isInstanceOf(a0, Request) : typeof Request2 !== "undefined") ? a0.headers : void 0;
|
|
}
|
|
if (headers) {
|
|
const Headers2 = globalThis.Headers;
|
|
if (typeof Headers2 !== "undefined" ? isInstanceOf(headers, Headers) : typeof Headers2 !== "undefined") {
|
|
const headers2 = new Headers(headers);
|
|
headers2.set("sentry-trace", r22);
|
|
if (baggage) {
|
|
const r98 = headers2.get("baggage");
|
|
if (r98) {
|
|
const r108 = r98.split(",").filter($mk78693(r4)).join(",");
|
|
headers2.set("baggage", r108 ? `${r108},${baggage}` : baggage);
|
|
} else {
|
|
headers2.set("baggage", baggage);
|
|
}
|
|
}
|
|
return headers2;
|
|
}
|
|
if (Array.isArray(headers)) {
|
|
const r81 = [...headers.filter((header) => !(Array.isArray(header) && header[0] === "sentry-trace")).map((item) => {
|
|
if (Array.isArray(item) && item[0] === "baggage" && typeof item[1] === "string") {
|
|
const r16 = env4174;
|
|
const r18 = _toArray(item);
|
|
const r5 = r18[0];
|
|
const r7 = r18[1];
|
|
const r9 = r18.slice(2);
|
|
return [r5, r7.split(",").filter($mk78693(r16)).join(","), ...r9];
|
|
}
|
|
return item;
|
|
}), ["sentry-trace", r22]];
|
|
if (baggage) {
|
|
r81.push(["baggage", baggage]);
|
|
}
|
|
return r81;
|
|
}
|
|
const r43 = "baggage" in headers ? headers.baggage : void 0;
|
|
const isArray = Array.isArray(r43);
|
|
if (isArray) {
|
|
r49 = r43.map((item) => {
|
|
let r0 = item;
|
|
if (typeof item === "string") {
|
|
const r1 = env4174;
|
|
r0 = item.split(",").filter($mk78693(r1)).join(",");
|
|
}
|
|
return r0;
|
|
}).filter((item) => item === "");
|
|
} else {
|
|
const r48 = [];
|
|
r49 = r48;
|
|
if (r43) {
|
|
r48.push(r43.split(",").filter($mk78693(r4)).join(","));
|
|
r49 = r48;
|
|
}
|
|
}
|
|
if (baggage) {
|
|
r49.push(baggage);
|
|
}
|
|
return {
|
|
...headers,
|
|
"sentry-trace": r22,
|
|
baggage: r49.length > 0 ? r49.join(",") : void 0
|
|
};
|
|
}
|
|
return {
|
|
...traceData
|
|
};
|
|
}
|
|
};
|
|
export function addTracingHeadersToFetchRequest(a0, a1, a2, a3, a4) {
|
|
return _addTracingHeadersToFetchRequest(a0, a3, a4);
|
|
}
|
|
export function instrumentFetchRequest(a0, a1, a2, a3, r14 = "auto.http.browser") {
|
|
let r46;
|
|
L36: {
|
|
if (a0.fetchData) {
|
|
const r26 = hasTracingEnabled() && a1(a0.fetchData.url);
|
|
if (a0.endTimestamp && r26) {
|
|
const __span = a0.fetchData.__span;
|
|
if (__span) {
|
|
const r86 = a3[__span];
|
|
if (!r86) {
|
|
break L36;
|
|
}
|
|
if (a0.response) {
|
|
setHttpStatus(r86, a0.response.status);
|
|
const r101 = a0.response && a0.response.headers && a0.response.headers.get("content-length");
|
|
if (r101) {
|
|
const r109 = parseInt(r101);
|
|
if (r109 > 0) {
|
|
r86.setAttribute("http.response_content_length", r109);
|
|
}
|
|
}
|
|
} else if (a0.error) {
|
|
r86.setStatus({
|
|
code: SPAN_STATUS_ERROR,
|
|
message: "internal_error"
|
|
});
|
|
}
|
|
r86.end();
|
|
delete a3[__span];
|
|
break L36;
|
|
}
|
|
return void 0;
|
|
}
|
|
const fetchData = a0.fetchData;
|
|
const { method, url } = fetchData;
|
|
const r15 = (function getFullURL(a0) {
|
|
let href;
|
|
try {
|
|
href = new URL(a0).href;
|
|
} catch ($e) {
|
|
return void 0;
|
|
}
|
|
return href;
|
|
})(url);
|
|
const r13 = r15 ? parseUrl(r15).host : void 0;
|
|
const r40 = !!getActiveSpan();
|
|
if (r26 && r40) {
|
|
const attributes = {
|
|
url,
|
|
type: "fetch",
|
|
"http.method": method,
|
|
"http.url": r15,
|
|
"server.address": r13
|
|
};
|
|
attributes[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] = r14;
|
|
attributes[SEMANTIC_ATTRIBUTE_SENTRY_OP] = "http.client";
|
|
r46 = startInactiveSpan({
|
|
name: `${method} ${url}`,
|
|
attributes
|
|
});
|
|
} else {
|
|
r46 = new SentryNonRecordingSpan();
|
|
}
|
|
a0.fetchData.__span = r46.spanContext().spanId;
|
|
a3[r46.spanContext().spanId] = r46;
|
|
if (a2(a0.fetchData.url)) {
|
|
const r73 = a0.args[0];
|
|
const r75 = a0.args[1] || {};
|
|
const headers = _addTracingHeadersToFetchRequest(r73, r75, hasTracingEnabled() ? r40 ? r46 : void 0 : void 0);
|
|
if (headers) {
|
|
a0.args[1] = r75;
|
|
r75.headers = headers;
|
|
}
|
|
}
|
|
return r46;
|
|
}
|
|
}
|
|
}
|