11import { Integration } from '@sentry/types' ;
22import { fill } from '@sentry/utils/object' ;
3- import { ClientRequest , ClientRequestArgs , IncomingMessage , ServerResponse } from 'http' ;
4- import { inherits } from 'util' ;
3+ import * as http from 'http' ;
4+ import * as util from 'util' ;
55import { getCurrentHub } from '../hub' ;
66
7- let lastResponse : ServerResponse | undefined ;
7+ let lastResponse : http . ServerResponse | undefined ;
88
99/**
1010 * Request interface which can carry around unified url
1111 * independently of used framework
1212 */
13- interface SentryRequest extends IncomingMessage {
13+ interface SentryRequest extends http . IncomingMessage {
1414 __ravenBreadcrumbUrl ?: string ;
1515}
1616
@@ -20,7 +20,7 @@ interface SentryRequest extends IncomingMessage {
2020 * @param options url that should be returned or an object containing it's parts.
2121 * @returns constructed url
2222 */
23- function createBreadcrumbUrl ( options : string | ClientRequestArgs ) : string {
23+ function createBreadcrumbUrl ( options : string | http . ClientRequestArgs ) : string {
2424 // We could just always reconstruct this from this.agent, this._headers, this.path, etc
2525 // but certain other http-instrumenting libraries (like nock, which we use for tests) fail to
2626 // maintain the guarantee that after calling origClientRequest, those fields will be populated
@@ -54,7 +54,7 @@ function loadWrapper(nativeModule: any): any {
5454 const origClientRequest = originalModule . ClientRequest ;
5555 const clientRequest = function (
5656 this : SentryRequest ,
57- options : ClientRequestArgs | string ,
57+ options : http . ClientRequestArgs | string ,
5858 callback : ( ) => void ,
5959 ) : any {
6060 // Note: this won't capture a breadcrumb if a response never comes
@@ -68,7 +68,7 @@ function loadWrapper(nativeModule: any): any {
6868 this . __ravenBreadcrumbUrl = createBreadcrumbUrl ( options ) ;
6969 } ;
7070
71- inherits ( clientRequest , origClientRequest ) ;
71+ util . inherits ( clientRequest , origClientRequest ) ;
7272
7373 fill ( clientRequest . prototype , 'emit' , emitWrapper ) ;
7474
@@ -80,13 +80,13 @@ function loadWrapper(nativeModule: any): any {
8080 // it still points at orig ClientRequest after our monkeypatch; these reimpls
8181 // just get that reference updated to use our new ClientRequest
8282 fill ( originalModule , 'request' , function ( ) : any {
83- return function ( options : ClientRequestArgs , callback : ( ) => void ) : any {
84- return new originalModule . ClientRequest ( options , callback ) as ClientRequest ;
83+ return function ( options : http . ClientRequestArgs , callback : ( ) => void ) : any {
84+ return new originalModule . ClientRequest ( options , callback ) as http . ClientRequest ;
8585 } ;
8686 } ) ;
8787
8888 fill ( originalModule , 'get' , function ( ) : any {
89- return function ( options : ClientRequestArgs , callback : ( ) => void ) : any {
89+ return function ( options : http . ClientRequestArgs , callback : ( ) => void ) : any {
9090 const req = originalModule . request ( options , callback ) ;
9191 req . end ( ) ;
9292 return req ;
@@ -101,8 +101,8 @@ function loadWrapper(nativeModule: any): any {
101101/**
102102 * Wrapper function for request's `emit` calls
103103 */
104- function emitWrapper ( origEmit : EventListener ) : ( event : string , response : ServerResponse ) => EventListener {
105- return function ( this : SentryRequest , event : string , response : ServerResponse ) : any {
104+ function emitWrapper ( origEmit : EventListener ) : ( event : string , response : http . ServerResponse ) => EventListener {
105+ return function ( this : SentryRequest , event : string , response : http . ServerResponse ) : any {
106106 // I'm not sure why but Node.js (at least in v8.X)
107107 // is emitting all events twice :|
108108 if ( lastResponse === undefined || lastResponse !== response ) {
0 commit comments