@sentry/browser
Version:
Official Sentry SDK for browsers
46 lines (45 loc) • 2.44 kB
JavaScript
const require_helpers = require("../helpers.js");
let _sentry_core = require("@sentry/core");
let _sentry_conventions_attributes = require("@sentry/conventions/attributes");
// src/integrations/httpcontext.ts
/**
* Collects information about HTTP request headers and
* attaches them to the event.
*/
const httpContextIntegration = (0, _sentry_core.defineIntegration)(() => {
return {
name: "HttpContext",
preprocessEvent(event, _hint, client) {
if (!require_helpers.WINDOW.navigator && !require_helpers.WINDOW.location && !require_helpers.WINDOW.document) return;
const { url, headers: collectedHeaders } = require_helpers.getHttpRequestData(client);
const behavior = client.getDataCollectionOptions().httpHeaders.request;
const userHeaders = Object.entries(event.request?.headers ?? {}).filter(([key]) => !(key in collectedHeaders));
const headers = {
...(0, _sentry_core._INTERNAL_filterKeyValueData)(collectedHeaders, behavior),
...Object.fromEntries(userHeaders)
};
event.request = {
url: (0, _sentry_core.filterCollectedUrl)(url, client),
...event.request,
...Object.keys(headers).length > 0 ? { headers } : { headers: void 0 }
};
},
processSpan(span, client) {
if (!require_helpers.WINDOW.navigator && !require_helpers.WINDOW.location && !require_helpers.WINDOW.document) return;
const reqData = require_helpers.getHttpRequestData(client);
const headers = (0, _sentry_core._INTERNAL_filterKeyValueData)(reqData.headers, client.getDataCollectionOptions().httpHeaders.request);
const referer = headers["Referer"];
const { hostname, protocol } = require_helpers.WINDOW.location || {};
(0, _sentry_core.safeSetSpanJSONAttributes)(span, {
[_sentry_conventions_attributes.USER_AGENT_ORIGINAL]: headers["User-Agent"],
[_sentry_conventions_attributes.SENTRY_IS_LOCALHOST]: protocol === "file:" || hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]" || !!hostname?.endsWith(".localhost"),
...span.is_segment && {
[_sentry_conventions_attributes.URL_FULL]: span.attributes?.[_sentry_conventions_attributes.SENTRY_OP] !== "http.client" ? (0, _sentry_core.filterCollectedUrl)(reqData.url) : void 0,
[`${_sentry_conventions_attributes.HTTP_REQUEST_HEADER_KEY_BASE}.referer`]: referer ? [referer] : void 0
}
});
}
};
});
exports.httpContextIntegration = httpContextIntegration;
//# sourceMappingURL=httpcontext.js.map