1
- import { getCurrentHub , Span } from '@sentry/core' ;
2
- import { Integration } from '@sentry/types' ;
1
+ import { Hub } from '@sentry/apm' ;
2
+ import { getCurrentHub } from '@sentry/core' ;
3
+ import { makeMain } from '@sentry/hub' ;
4
+ import { Integration , Span } from '@sentry/types' ;
3
5
import { fill , parseSemver } from '@sentry/utils' ;
4
6
import * as http from 'http' ;
5
7
import * as https from 'https' ;
@@ -31,6 +33,8 @@ export class Http implements Integration {
31
33
* @inheritDoc
32
34
*/
33
35
public constructor ( options : { breadcrumbs ?: boolean ; tracing ?: boolean } = { } ) {
36
+ // TODO
37
+ makeMain ( new Hub ( ) ) ;
34
38
this . _breadcrumbs = typeof options . breadcrumbs === 'undefined' ? true : options . breadcrumbs ;
35
39
this . _tracing = typeof options . tracing === 'undefined' ? false : options . tracing ;
36
40
}
@@ -80,10 +84,14 @@ function createHandlerWrapper(
80
84
81
85
let span : Span ;
82
86
if ( tracingEnabled ) {
83
- span = getCurrentHub ( ) . startSpan ( {
84
- description : `${ typeof options === 'string' || ! options . method ? 'GET' : options . method } |${ requestUrl } ` ,
85
- op : 'request' ,
86
- } ) ;
87
+ // TODO
88
+ const hub = ( getCurrentHub ( ) as unknown ) as Hub ;
89
+ if ( hub . startSpan ) {
90
+ span = hub . startSpan ( {
91
+ description : `${ typeof options === 'string' || ! options . method ? 'GET' : options . method } |${ requestUrl } ` ,
92
+ op : 'request' ,
93
+ } ) ;
94
+ }
87
95
}
88
96
89
97
return originalHandler
@@ -93,7 +101,7 @@ function createHandlerWrapper(
93
101
addRequestBreadcrumb ( 'response' , requestUrl , this , res ) ;
94
102
}
95
103
// TODO: Mark >= 500 as failed as well?
96
- if ( tracingEnabled ) {
104
+ if ( tracingEnabled && span ) {
97
105
span . setSuccess ( ) ;
98
106
span . finish ( ) ;
99
107
}
@@ -102,7 +110,7 @@ function createHandlerWrapper(
102
110
if ( breadcrumbsEnabled ) {
103
111
addRequestBreadcrumb ( 'error' , requestUrl , this ) ;
104
112
}
105
- if ( tracingEnabled ) {
113
+ if ( tracingEnabled && span ) {
106
114
span . setFailure ( ) ;
107
115
span . finish ( ) ;
108
116
}
0 commit comments