11// TODO (v8 or v9): Whenever this becomes a default integration for `@sentry/browser`, move this to `@sentry/core`. For
22// now, we leave it in `@sentry/integrations` so that it doesn't contribute bytes to our CDN bundles.
33
4- import { EventProcessor , Hub , Integration , Transaction } from '@sentry/types' ;
4+ import { Event , EventProcessor , Hub , Integration , PolymorphicRequest , Transaction } from '@sentry/types' ;
55import { extractPathForTransaction } from '@sentry/utils' ;
66
77import { addRequestDataToEvent , AddRequestDataToEventOptions , TransactionNamingScheme } from '../requestdata' ;
@@ -28,18 +28,9 @@ type RequestDataIntegrationOptions = {
2828
2929 /** Whether to identify transactions by parameterized path, parameterized path with method, or handler name */
3030 transactionNamingScheme : TransactionNamingScheme ;
31-
32- /**
33- * Function for adding request data to event. Defaults to `addRequestDataToEvent` from `@sentry/node` for now, but
34- * left injectable so this integration can be moved to `@sentry/core` and used in browser-based SDKs in the future.
35- *
36- * @hidden
37- */
38- addRequestData : typeof addRequestDataToEvent ;
3931} ;
4032
4133const DEFAULT_OPTIONS = {
42- addRequestData : addRequestDataToEvent ,
4334 include : {
4435 cookies : true ,
4536 data : true ,
@@ -69,12 +60,20 @@ export class RequestData implements Integration {
6960 */
7061 public name : string = RequestData . id ;
7162
63+ /**
64+ * Function for adding request data to event. Defaults to `addRequestDataToEvent` from `@sentry/node` for now, but
65+ * left as a property so this integration can be moved to `@sentry/core` as a base class in case we decide to use
66+ * something similar in browser-based SDKs in the future.
67+ */
68+ protected _addRequestData : ( event : Event , req : PolymorphicRequest , options ?: { [ key : string ] : unknown } ) => Event ;
69+
7270 private _options : RequestDataIntegrationOptions ;
7371
7472 /**
7573 * @inheritDoc
7674 */
7775 public constructor ( options : Partial < RequestDataIntegrationOptions > = { } ) {
76+ this . _addRequestData = addRequestDataToEvent ;
7877 this . _options = {
7978 ...DEFAULT_OPTIONS ,
8079 ...options ,
@@ -104,7 +103,7 @@ export class RequestData implements Integration {
104103 // the moment it lives here, though, until https://github.com/getsentry/sentry-javascript/issues/5718 is addressed.
105104 // (TL;DR: Those functions touch many parts of the repo in many different ways, and need to be clened up. Once
106105 // that's happened, it will be easier to add this logic in without worrying about unexpected side effects.)
107- const { addRequestData , transactionNamingScheme } = this . _options ;
106+ const { transactionNamingScheme } = this . _options ;
108107
109108 addGlobalEventProcessor ( event => {
110109 const hub = getCurrentHub ( ) ;
@@ -119,7 +118,7 @@ export class RequestData implements Integration {
119118
120119 const addRequestDataOptions = convertReqDataIntegrationOptsToAddReqDataOpts ( this . _options ) ;
121120
122- const processedEvent = addRequestData ( event , req , addRequestDataOptions ) ;
121+ const processedEvent = this . _addRequestData ( event , req , addRequestDataOptions ) ;
123122
124123 // Transaction events already have the right `transaction` value
125124 if ( event . type === 'transaction' || transactionNamingScheme === 'handler' ) {
0 commit comments