|
| 1 | +/* eslint-disable max-lines */ |
1 | 2 | import { getCurrentHub, getIntegrationsToSetup, initAndBind, Integrations as CoreIntegrations } from '@sentry/core';
|
2 | 3 | import { getMainCarrier, setHubOnCarrier } from '@sentry/hub';
|
3 |
| -import { SessionStatus, StackParser } from '@sentry/types'; |
4 |
| -import { createStackParser, getGlobalObject, logger, stackParserFromStackParserOptions } from '@sentry/utils'; |
| 4 | +import { Event, ExtractedNodeRequestData, SessionStatus, StackParser } from '@sentry/types'; |
| 5 | +import { |
| 6 | + addRequestDataToEvent as _addRequestDataToEvent, |
| 7 | + AddRequestDataToEventOptions, |
| 8 | + createStackParser, |
| 9 | + CrossPlatformRequest, |
| 10 | + extractRequestData as _extractRequestData, |
| 11 | + getGlobalObject, |
| 12 | + logger, |
| 13 | + stackParserFromStackParserOptions, |
| 14 | +} from '@sentry/utils'; |
| 15 | +import * as cookie from 'cookie'; |
5 | 16 | import * as domain from 'domain';
|
| 17 | +import * as url from 'url'; |
6 | 18 |
|
7 | 19 | import { NodeClient } from './client';
|
8 | 20 | import { Console, ContextLines, Http, LinkedErrors, OnUncaughtException, OnUnhandledRejection } from './integrations';
|
@@ -255,3 +267,51 @@ function startSessionTracking(): void {
|
255 | 267 | if (session && !terminalStates.includes(session.status)) hub.endSession();
|
256 | 268 | });
|
257 | 269 | }
|
| 270 | + |
| 271 | +/** |
| 272 | + * Add data from the given request to the given event |
| 273 | + * |
| 274 | + * (Note that there is no sister function to this one in `@sentry/browser`, because the whole point of this wrapper is |
| 275 | + * to pass along injected dependencies, which isn't necessary in a browser context. Isomorphic packages like |
| 276 | + * `@sentry/nextjs` should export directly from `@sentry/utils` in their browser index file.) |
| 277 | + * |
| 278 | + * @param event The event to which the request data will be added |
| 279 | + * @param req Request object |
| 280 | + * @param options.include Flags to control what data is included |
| 281 | + * @hidden |
| 282 | + */ |
| 283 | +export function addRequestDataToEvent( |
| 284 | + event: Event, |
| 285 | + req: CrossPlatformRequest, |
| 286 | + options?: Omit<AddRequestDataToEventOptions, 'deps'>, |
| 287 | +): Event { |
| 288 | + return _addRequestDataToEvent(event, req, { |
| 289 | + ...options, |
| 290 | + // We have to inject these node-only dependencies because we can't import them in `@sentry/utils`, where the |
| 291 | + // original function lives |
| 292 | + deps: { cookie, url }, |
| 293 | + }); |
| 294 | +} |
| 295 | + |
| 296 | +/** |
| 297 | + * Normalize data from the request object, accounting for framework differences. |
| 298 | + * |
| 299 | + * (Note that there is no sister function to this one in `@sentry/browser`, because the whole point of this wrapper is |
| 300 | + * to inject dependencies, which isn't necessary in a browser context. Isomorphic packages like `@sentry/nextjs` should |
| 301 | + * export directly from `@sentry/utils` in their browser index file.) |
| 302 | + * |
| 303 | + * @param req The request object from which to extract data |
| 304 | + * @param options.keys An optional array of keys to include in the normalized data. Defaults to DEFAULT_REQUEST_KEYS if |
| 305 | + * not provided. |
| 306 | + * @returns An object containing normalized request data |
| 307 | + */ |
| 308 | +export function extractRequestData( |
| 309 | + req: CrossPlatformRequest, |
| 310 | + options?: { |
| 311 | + include?: string[]; |
| 312 | + }, |
| 313 | +): ExtractedNodeRequestData { |
| 314 | + // We have to inject these node-only dependencies because we can't import them in `@sentry/utils`, where the original |
| 315 | + // function lives |
| 316 | + return _extractRequestData(req, { ...options, deps: { cookie, url } }); |
| 317 | +} |
0 commit comments