UNPKG

@sentry/node

Version:

Sentry Node SDK using OpenTelemetry for performance instrumentation

65 lines (64 loc) • 2.75 kB
import { httpServerIntegration } from "./httpServerIntegration.js"; import { httpServerSpansIntegration } from "./httpServerSpansIntegration.js"; import { instrumentHttpOutgoingRequests } from "./SentryHttpInstrumentation.js"; import { URL_FULL } from "@sentry/conventions/attributes"; import { defineIntegration, getClient, hasSpanStreamingEnabled, hasSpansEnabled, stripDataUrlContent } from "@sentry/core"; import { getRequestUrlFromClientRequest } from "@sentry/core/server"; // src/integrations/http/index.ts const INTEGRATION_NAME = "Http"; /** * The http integration instruments Node's internal http and https modules. * It creates breadcrumbs and spans for outgoing HTTP requests which will be attached to the currently active span. */ const httpIntegration = defineIntegration((options = {}) => { const spans = options.spans ?? true; const enableServerSpans = spans && !options.disableIncomingRequestSpans; const server = httpServerIntegration(options); const serverSpans = httpServerSpansIntegration(options); const serverRequestOptions = { spans: enableServerSpans ? void 0 : false, sessions: options.sessions, sessionFlushingDelayMS: options.sessionFlushingDelayMS, maxRequestBodySize: options.maxRequestBodySize, ignoreRequestBody: options.ignoreRequestBody, ignoreIncomingRequests: options.ignoreIncomingRequests, ignoreStaticAssets: options.ignoreStaticAssets, onSpanCreated: options.onSpanCreated, onSpanEnd: options.onSpanEnd }; return { name: INTEGRATION_NAME, serverRequestOptions, setup(client) { const clientOptions = client.getOptions(); if (enableServerSpans && hasSpansEnabled(clientOptions)) serverSpans.setup(client); }, setupOnce() { server.setupOnce(); const outgoingRequestOptions = { breadcrumbs: options.breadcrumbs, spans, tracePropagation: options.tracePropagation ?? true, ignoreOutgoingRequests: options.ignoreOutgoingRequests, outgoingRequestHook: (span, request) => { const url = getRequestUrlFromClientRequest(request); if (url.startsWith("data:")) { const sanitizedUrl = stripDataUrlContent(url); const client = getClient(); if (!client || !hasSpanStreamingEnabled(client)) span.updateName(`${request.method || "GET"} ${sanitizedUrl}`); span.setAttributes({ [URL_FULL]: sanitizedUrl }); } options.outgoingRequestHook?.(span, request); }, outgoingResponseHook: options.outgoingResponseHook, outgoingRequestApplyCustomAttributes: options.outgoingRequestApplyCustomAttributes }; instrumentHttpOutgoingRequests(outgoingRequestOptions); }, processEvent(event) { return serverSpans.processEvent(event); } }; }); export { httpIntegration }; //# sourceMappingURL=index.js.map