1
1
import { Integration } from '@sentry/types' ;
2
2
import { 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' ;
5
5
import { getCurrentHub } from '../hub' ;
6
6
7
- let lastResponse : ServerResponse | undefined ;
7
+ let lastResponse : http . ServerResponse | undefined ;
8
8
9
9
/**
10
10
* Request interface which can carry around unified url
11
11
* independently of used framework
12
12
*/
13
- interface SentryRequest extends IncomingMessage {
13
+ interface SentryRequest extends http . IncomingMessage {
14
14
__ravenBreadcrumbUrl ?: string ;
15
15
}
16
16
@@ -20,7 +20,7 @@ interface SentryRequest extends IncomingMessage {
20
20
* @param options url that should be returned or an object containing it's parts.
21
21
* @returns constructed url
22
22
*/
23
- function createBreadcrumbUrl ( options : string | ClientRequestArgs ) : string {
23
+ function createBreadcrumbUrl ( options : string | http . ClientRequestArgs ) : string {
24
24
// We could just always reconstruct this from this.agent, this._headers, this.path, etc
25
25
// but certain other http-instrumenting libraries (like nock, which we use for tests) fail to
26
26
// maintain the guarantee that after calling origClientRequest, those fields will be populated
@@ -54,7 +54,7 @@ function loadWrapper(nativeModule: any): any {
54
54
const origClientRequest = originalModule . ClientRequest ;
55
55
const clientRequest = function (
56
56
this : SentryRequest ,
57
- options : ClientRequestArgs | string ,
57
+ options : http . ClientRequestArgs | string ,
58
58
callback : ( ) => void ,
59
59
) : any {
60
60
// Note: this won't capture a breadcrumb if a response never comes
@@ -68,7 +68,7 @@ function loadWrapper(nativeModule: any): any {
68
68
this . __ravenBreadcrumbUrl = createBreadcrumbUrl ( options ) ;
69
69
} ;
70
70
71
- inherits ( clientRequest , origClientRequest ) ;
71
+ util . inherits ( clientRequest , origClientRequest ) ;
72
72
73
73
fill ( clientRequest . prototype , 'emit' , emitWrapper ) ;
74
74
@@ -80,13 +80,13 @@ function loadWrapper(nativeModule: any): any {
80
80
// it still points at orig ClientRequest after our monkeypatch; these reimpls
81
81
// just get that reference updated to use our new ClientRequest
82
82
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 ;
85
85
} ;
86
86
} ) ;
87
87
88
88
fill ( originalModule , 'get' , function ( ) : any {
89
- return function ( options : ClientRequestArgs , callback : ( ) => void ) : any {
89
+ return function ( options : http . ClientRequestArgs , callback : ( ) => void ) : any {
90
90
const req = originalModule . request ( options , callback ) ;
91
91
req . end ( ) ;
92
92
return req ;
@@ -101,8 +101,8 @@ function loadWrapper(nativeModule: any): any {
101
101
/**
102
102
* Wrapper function for request's `emit` calls
103
103
*/
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 {
106
106
// I'm not sure why but Node.js (at least in v8.X)
107
107
// is emitting all events twice :|
108
108
if ( lastResponse === undefined || lastResponse !== response ) {
0 commit comments