Files
klz-cables.com/.pnpm-store/v10/files/97/6fbfe09e131c2d7f141eaf947b9fabb4659a215b6c5e0718097f0bc7fc991edea1550d941c465eccee17847ce15ce4a843cd7340b4a9a8028edfdef0a1c324
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

147 lines
4.1 KiB
Plaintext

import { getBreadcrumbLogLevelFromHttpStatusCode, addBreadcrumb, getClient, shouldPropagateTraceForUrl, getTraceData, debug, isError, parseUrl, getSanitizedUrlString } from '@sentry/core';
import { DEBUG_BUILD } from '../debug-build.js';
import { mergeBaggageHeaders } from './baggage.js';
const LOG_PREFIX = '@sentry/instrumentation-http';
/** Add a breadcrumb for outgoing requests. */
function addRequestBreadcrumb(request, response) {
const data = getBreadcrumbData(request);
const statusCode = response?.statusCode;
const level = getBreadcrumbLogLevelFromHttpStatusCode(statusCode);
addBreadcrumb(
{
category: 'http',
data: {
status_code: statusCode,
...data,
},
type: 'http',
level,
},
{
event: 'response',
request,
response,
},
);
}
/**
* Add trace propagation headers to an outgoing request.
* This must be called _before_ the request is sent!
*/
// eslint-disable-next-line complexity
function addTracePropagationHeadersToOutgoingRequest(
request,
propagationDecisionMap,
) {
const url = getRequestUrl(request);
const { tracePropagationTargets, propagateTraceparent } = getClient()?.getOptions() || {};
const headersToAdd = shouldPropagateTraceForUrl(url, tracePropagationTargets, propagationDecisionMap)
? getTraceData({ propagateTraceparent })
: undefined;
if (!headersToAdd) {
return;
}
const { 'sentry-trace': sentryTrace, baggage, traceparent } = headersToAdd;
if (sentryTrace && !request.getHeader('sentry-trace')) {
try {
request.setHeader('sentry-trace', sentryTrace);
DEBUG_BUILD && debug.log(LOG_PREFIX, 'Added sentry-trace header to outgoing request');
} catch (error) {
DEBUG_BUILD &&
debug.error(
LOG_PREFIX,
'Failed to add sentry-trace header to outgoing request:',
isError(error) ? error.message : 'Unknown error',
);
}
}
if (traceparent && !request.getHeader('traceparent')) {
try {
request.setHeader('traceparent', traceparent);
DEBUG_BUILD && debug.log(LOG_PREFIX, 'Added traceparent header to outgoing request');
} catch (error) {
DEBUG_BUILD &&
debug.error(
LOG_PREFIX,
'Failed to add traceparent header to outgoing request:',
isError(error) ? error.message : 'Unknown error',
);
}
}
if (baggage) {
const newBaggage = mergeBaggageHeaders(request.getHeader('baggage'), baggage);
if (newBaggage) {
try {
request.setHeader('baggage', newBaggage);
DEBUG_BUILD && debug.log(LOG_PREFIX, 'Added baggage header to outgoing request');
} catch (error) {
DEBUG_BUILD &&
debug.error(
LOG_PREFIX,
'Failed to add baggage header to outgoing request:',
isError(error) ? error.message : 'Unknown error',
);
}
}
}
}
function getBreadcrumbData(request) {
try {
// `request.host` does not contain the port, but the host header does
const host = request.getHeader('host') || request.host;
const url = new URL(request.path, `${request.protocol}//${host}`);
const parsedUrl = parseUrl(url.toString());
const data = {
url: getSanitizedUrlString(parsedUrl),
'http.method': request.method || 'GET',
};
if (parsedUrl.search) {
data['http.query'] = parsedUrl.search;
}
if (parsedUrl.hash) {
data['http.fragment'] = parsedUrl.hash;
}
return data;
} catch {
return {};
}
}
/** Convert an outgoing request to request options. */
function getRequestOptions(request) {
return {
method: request.method,
protocol: request.protocol,
host: request.host,
hostname: request.host,
path: request.path,
headers: request.getHeaders(),
};
}
function getRequestUrl(request) {
const hostname = request.getHeader('host') || request.host;
const protocol = request.protocol;
const path = request.path;
return `${protocol}//${hostname}${path}`;
}
export { addRequestBreadcrumb, addTracePropagationHeadersToOutgoingRequest, getRequestOptions };
//# sourceMappingURL=outgoingHttpRequest.js.map