1
1
import { getCurrentHub , Span } from '@sentry/core' ;
2
2
import { Integration } from '@sentry/types' ;
3
- import { fill } from '@sentry/utils' ;
3
+ import { fill , parseSemver } from '@sentry/utils' ;
4
4
import * as http from 'http' ;
5
5
import * as https from 'https' ;
6
6
7
+ const NODE_VERSION = parseSemver ( process . versions . node ) ;
8
+
7
9
/** http module integration */
8
10
export class Http implements Integration {
9
11
/**
@@ -48,9 +50,14 @@ export class Http implements Integration {
48
50
fill ( httpModule , 'get' , handlerWrapper ) ;
49
51
fill ( httpModule , 'request' , handlerWrapper ) ;
50
52
51
- const httpsModule = require ( 'https' ) ;
52
- fill ( httpsModule , 'get' , handlerWrapper ) ;
53
- fill ( httpsModule , 'request' , handlerWrapper ) ;
53
+ // NOTE: Prior to Node 9, `https` used internals of `http` module, thus we don't patch it.
54
+ // If we do, we'd get double breadcrumbs and double spans for `https` calls.
55
+ // It has been changed in Node 9, so for all versions equal and above, we patch `https` separately.
56
+ if ( NODE_VERSION . major && NODE_VERSION . major > 8 ) {
57
+ const httpsModule = require ( 'https' ) ;
58
+ fill ( httpsModule , 'get' , handlerWrapper ) ;
59
+ fill ( httpsModule , 'request' , handlerWrapper ) ;
60
+ }
54
61
}
55
62
}
56
63
@@ -74,7 +81,7 @@ function createHandlerWrapper(
74
81
let span : Span ;
75
82
if ( tracingEnabled ) {
76
83
span = getCurrentHub ( ) . startSpan ( {
77
- description : `${ typeof options === 'string' ? 'GET' : options . method } |${ requestUrl } ` ,
84
+ description : `${ typeof options === 'string' || ! options . method ? 'GET' : options . method } |${ requestUrl } ` ,
78
85
op : 'request' ,
79
86
} ) ;
80
87
}
0 commit comments