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
99 lines
2.6 KiB
Plaintext
99 lines
2.6 KiB
Plaintext
import { subscribe } from 'node:diagnostics_channel';
|
|
import { LRUMap, getCurrentScope } from '@sentry/core';
|
|
import { addTracePropagationHeadersToFetchRequest, addFetchRequestBreadcrumb, getAbsoluteUrl } from '../../utils/outgoingFetchRequest.js';
|
|
|
|
const INTEGRATION_NAME = 'NodeFetch';
|
|
|
|
const _nativeNodeFetchIntegration = ((options = {}) => {
|
|
const _options = {
|
|
breadcrumbs: options.breadcrumbs ?? true,
|
|
ignoreOutgoingRequests: options.ignoreOutgoingRequests,
|
|
};
|
|
|
|
const propagationDecisionMap = new LRUMap(100);
|
|
const ignoreOutgoingRequestsMap = new WeakMap();
|
|
|
|
return {
|
|
name: INTEGRATION_NAME,
|
|
setupOnce() {
|
|
const onRequestCreated = ((_data) => {
|
|
const data = _data ;
|
|
onUndiciRequestCreated(data.request, _options, propagationDecisionMap, ignoreOutgoingRequestsMap);
|
|
}) ;
|
|
|
|
const onResponseHeaders = ((_data) => {
|
|
const data = _data ;
|
|
onUndiciResponseHeaders(data.request, data.response, _options, ignoreOutgoingRequestsMap);
|
|
}) ;
|
|
|
|
subscribe('undici:request:create', onRequestCreated);
|
|
subscribe('undici:request:headers', onResponseHeaders);
|
|
},
|
|
};
|
|
}) ;
|
|
|
|
/**
|
|
* This integration handles outgoing fetch (undici) requests in light mode (without OpenTelemetry).
|
|
* It propagates trace headers and creates breadcrumbs for responses.
|
|
*/
|
|
const nativeNodeFetchIntegration = _nativeNodeFetchIntegration
|
|
|
|
;
|
|
|
|
function onUndiciRequestCreated(
|
|
request,
|
|
options,
|
|
propagationDecisionMap,
|
|
ignoreOutgoingRequestsMap,
|
|
) {
|
|
const shouldIgnore = shouldIgnoreRequest(request, options);
|
|
ignoreOutgoingRequestsMap.set(request, shouldIgnore);
|
|
|
|
if (shouldIgnore) {
|
|
return;
|
|
}
|
|
|
|
addTracePropagationHeadersToFetchRequest(request, propagationDecisionMap);
|
|
}
|
|
|
|
function onUndiciResponseHeaders(
|
|
request,
|
|
response,
|
|
options,
|
|
ignoreOutgoingRequestsMap,
|
|
) {
|
|
if (!options.breadcrumbs) {
|
|
return;
|
|
}
|
|
|
|
const shouldIgnore = ignoreOutgoingRequestsMap.get(request);
|
|
if (shouldIgnore) {
|
|
return;
|
|
}
|
|
|
|
addFetchRequestBreadcrumb(request, response);
|
|
}
|
|
|
|
/** Check if the given outgoing request should be ignored. */
|
|
function shouldIgnoreRequest(
|
|
request,
|
|
options,
|
|
) {
|
|
// Check if tracing is suppressed (e.g. for Sentry's own transport requests)
|
|
if (getCurrentScope().getScopeData().sdkProcessingMetadata.__SENTRY_SUPPRESS_TRACING__) {
|
|
return true;
|
|
}
|
|
|
|
const { ignoreOutgoingRequests } = options;
|
|
|
|
if (!ignoreOutgoingRequests) {
|
|
return false;
|
|
}
|
|
|
|
const url = getAbsoluteUrl(request.origin, request.path);
|
|
return ignoreOutgoingRequests(url);
|
|
}
|
|
|
|
export { nativeNodeFetchIntegration };
|
|
//# sourceMappingURL=nativeNodeFetchIntegration.js.map
|