@@ -4,19 +4,11 @@ import { SpanKind } from '@opentelemetry/api';
4
4
import { registerInstrumentations } from '@opentelemetry/instrumentation' ;
5
5
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http' ;
6
6
7
- import {
8
- addBreadcrumb ,
9
- defineIntegration ,
10
- getIsolationScope ,
11
- hasTracingEnabled ,
12
- isSentryRequestUrl ,
13
- } from '@sentry/core' ;
7
+ import { addBreadcrumb , defineIntegration , getIsolationScope , isSentryRequestUrl } from '@sentry/core' ;
14
8
import { _INTERNAL , getClient , getSpanKind , setSpanMetadata } from '@sentry/opentelemetry' ;
15
- import type { EventProcessor , Hub , Integration , IntegrationFn } from '@sentry/types' ;
16
- import { stringMatchesSomePattern } from '@sentry/utils' ;
9
+ import type { IntegrationFn } from '@sentry/types' ;
17
10
18
11
import { setIsolationScope } from '../sdk/scope' ;
19
- import type { NodeExperimentalClient } from '../types' ;
20
12
import { addOriginToSpan } from '../utils/addOriginToSpan' ;
21
13
import { getRequestUrl } from '../utils/getRequestUrl' ;
22
14
@@ -111,148 +103,6 @@ const _httpIntegration = ((options: HttpOptions = {}) => {
111
103
112
104
export const httpIntegration = defineIntegration ( _httpIntegration ) ;
113
105
114
- interface OldHttpOptions {
115
- /**
116
- * Whether breadcrumbs should be recorded for requests
117
- * Defaults to true
118
- */
119
- breadcrumbs ?: boolean ;
120
-
121
- /**
122
- * Whether tracing spans should be created for requests
123
- * Defaults to false
124
- */
125
- spans ?: boolean ;
126
-
127
- /**
128
- * Do not capture spans or breadcrumbs for outgoing HTTP requests to URLs matching the given patterns.
129
- */
130
- ignoreOutgoingRequests ?: ( string | RegExp ) [ ] ;
131
- }
132
-
133
- /**
134
- * Http instrumentation based on @opentelemetry/instrumentation-http.
135
- * This instrumentation does two things:
136
- * * Create breadcrumbs for outgoing requests
137
- * * Create spans for outgoing requests
138
- *
139
- * Note that this integration is also needed for the Express integration to work!
140
- *
141
- * @deprecated Use `httpIntegration()` instead.
142
- */
143
- export class Http implements Integration {
144
- /**
145
- * @inheritDoc
146
- */
147
- public static id : string = 'Http' ;
148
-
149
- /**
150
- * @inheritDoc
151
- */
152
- public name : string ;
153
-
154
- /**
155
- * If spans for HTTP requests should be captured.
156
- */
157
- public shouldCreateSpansForRequests : boolean ;
158
-
159
- private _unload ?: ( ) => void ;
160
- private readonly _breadcrumbs : boolean ;
161
- // If this is undefined, use default behavior based on client settings
162
- private readonly _spans : boolean | undefined ;
163
- private _ignoreOutgoingRequests : ( string | RegExp ) [ ] ;
164
-
165
- /**
166
- * @inheritDoc
167
- */
168
- public constructor ( options : OldHttpOptions = { } ) {
169
- // eslint-disable-next-line deprecation/deprecation
170
- this . name = Http . id ;
171
- this . _breadcrumbs = typeof options . breadcrumbs === 'undefined' ? true : options . breadcrumbs ;
172
- this . _spans = typeof options . spans === 'undefined' ? undefined : options . spans ;
173
-
174
- this . _ignoreOutgoingRequests = options . ignoreOutgoingRequests || [ ] ;
175
-
176
- // Properly set in setupOnce based on client settings
177
- this . shouldCreateSpansForRequests = false ;
178
- }
179
-
180
- /**
181
- * @inheritDoc
182
- */
183
- public setupOnce ( _addGlobalEventProcessor : ( callback : EventProcessor ) => void , _getCurrentHub : ( ) => Hub ) : void {
184
- // No need to instrument if we don't want to track anything
185
- if ( ! this . _breadcrumbs && this . _spans === false ) {
186
- return ;
187
- }
188
-
189
- const client = getClient < NodeExperimentalClient > ( ) ;
190
- const clientOptions = client ?. getOptions ( ) ;
191
-
192
- // This is used in the sampler function
193
- this . shouldCreateSpansForRequests =
194
- typeof this . _spans === 'boolean' ? this . _spans : hasTracingEnabled ( clientOptions ) ;
195
-
196
- // Register instrumentations we care about
197
- this . _unload = registerInstrumentations ( {
198
- instrumentations : [
199
- new HttpInstrumentation ( {
200
- ignoreOutgoingRequestHook : request => {
201
- const url = getRequestUrl ( request ) ;
202
-
203
- if ( ! url ) {
204
- return false ;
205
- }
206
-
207
- if ( isSentryRequestUrl ( url , getClient ( ) ) ) {
208
- return true ;
209
- }
210
-
211
- if ( this . _ignoreOutgoingRequests . length && stringMatchesSomePattern ( url , this . _ignoreOutgoingRequests ) ) {
212
- return true ;
213
- }
214
-
215
- return false ;
216
- } ,
217
-
218
- ignoreIncomingRequestHook : request => {
219
- const method = request . method ?. toUpperCase ( ) ;
220
- // We do not capture OPTIONS/HEAD requests as transactions
221
- if ( method === 'OPTIONS' || method === 'HEAD' ) {
222
- return true ;
223
- }
224
-
225
- return false ;
226
- } ,
227
-
228
- requireParentforOutgoingSpans : true ,
229
- requireParentforIncomingSpans : false ,
230
- requestHook : ( span , req ) => {
231
- _updateSpan ( span , req ) ;
232
-
233
- // Update the isolation scope, isolate this request
234
- if ( getSpanKind ( span ) === SpanKind . SERVER ) {
235
- setIsolationScope ( getIsolationScope ( ) . clone ( ) ) ;
236
- }
237
- } ,
238
- responseHook : ( span , res ) => {
239
- if ( this . _breadcrumbs ) {
240
- _addRequestBreadcrumb ( span , res ) ;
241
- }
242
- } ,
243
- } ) ,
244
- ] ,
245
- } ) ;
246
- }
247
-
248
- /**
249
- * Unregister this integration.
250
- */
251
- public unregister ( ) : void {
252
- this . _unload ?.( ) ;
253
- }
254
- }
255
-
256
106
/** Update the span with data we need. */
257
107
function _updateSpan ( span : Span , request : ClientRequest | IncomingMessage ) : void {
258
108
addOriginToSpan ( span , 'auto.http.otel.http' ) ;
0 commit comments