@sentry/nextjs
Version:
Official Sentry SDK for Next.js
30 lines (27 loc) • 1.09 kB
JavaScript
import { HTTP_REQUEST_METHOD, HTTP_METHOD, URL_FULL, URL_PATH, HTTP_TARGET, URL_QUERY } from '@sentry/conventions/attributes';
function getNormalizedRequestFromAttributes(attributes) {
const method = attributes[HTTP_REQUEST_METHOD] || attributes[HTTP_METHOD];
const url = attributes[URL_FULL] || attributes[URL_PATH] || attributes[HTTP_TARGET];
if (typeof method !== "string" && typeof url !== "string") {
return void 0;
}
const normalizedRequest = {};
if (typeof method === "string") {
normalizedRequest.method = method;
}
if (typeof url === "string") {
normalizedRequest.url = url;
const queryFromAttribute = attributes[URL_QUERY];
if (typeof queryFromAttribute === "string") {
normalizedRequest.query_string = queryFromAttribute;
} else {
const queryIndex = url.indexOf("?");
if (queryIndex !== -1) {
normalizedRequest.query_string = url.slice(queryIndex + 1);
}
}
}
return normalizedRequest;
}
export { getNormalizedRequestFromAttributes };
//# sourceMappingURL=getNormalizedRequestFromAttributes.js.map