1
1
/* eslint-disable deprecation/deprecation */
2
2
/* eslint-disable max-lines */
3
+ /* eslint-disable jsdoc/require-jsdoc */
3
4
import type { Span } from '@opentelemetry/api' ;
4
5
import opentelemetry , { SpanStatusCode } from '@opentelemetry/api' ;
5
6
import type { InstrumentationConfig } from '@opentelemetry/instrumentation' ;
@@ -16,13 +17,14 @@ import type * as remixRunServerRuntimeData from '@remix-run/server-runtime/dist/
16
17
import type * as remixRunServerRuntimeRouteMatching from '@remix-run/server-runtime/dist/routeMatching' ;
17
18
import type { RouteMatch } from '@remix-run/server-runtime/dist/routeMatching' ;
18
19
import type { ServerRoute } from '@remix-run/server-runtime/dist/routes' ;
20
+ import { SDK_VERSION } from '@sentry/core' ;
19
21
20
22
const RemixSemanticAttributes = {
21
23
MATCH_PARAMS : 'match.params' ,
22
24
MATCH_ROUTE_ID : 'match.route.id' ,
23
25
} ;
24
26
25
- const VERSION = '__OTEL_REMIX_INSTRUMENTATION_VERSION__' ;
27
+ const VERSION = SDK_VERSION ;
26
28
27
29
export interface RemixInstrumentationConfig extends InstrumentationConfig {
28
30
/**
@@ -48,36 +50,24 @@ const DEFAULT_CONFIG: RemixInstrumentationConfig = {
48
50
legacyErrorAttributes : false ,
49
51
} ;
50
52
51
- /**
52
- *
53
- */
54
53
export class RemixInstrumentation extends InstrumentationBase {
55
54
public constructor ( config : RemixInstrumentationConfig = { } ) {
56
55
super ( 'RemixInstrumentation' , VERSION , Object . assign ( { } , DEFAULT_CONFIG , config ) ) ;
57
56
}
58
57
59
- /**
60
- *
61
- */
62
- public override getConfig ( ) : RemixInstrumentationConfig {
58
+ public getConfig ( ) : RemixInstrumentationConfig {
63
59
return this . _config ;
64
60
}
65
61
66
- /**
67
- *
68
- */
69
- public override setConfig ( config : RemixInstrumentationConfig = { } ) : void {
62
+ public setConfig ( config : RemixInstrumentationConfig = { } ) : void {
70
63
this . _config = Object . assign ( { } , DEFAULT_CONFIG , config ) ;
71
64
}
72
65
73
- /**
74
- *
75
- */
76
66
// eslint-disable-next-line @typescript-eslint/naming-convention
77
- protected override init ( ) : InstrumentationNodeModuleDefinition {
67
+ protected init ( ) : InstrumentationNodeModuleDefinition {
78
68
const remixRunServerRuntimeRouteMatchingFile = new InstrumentationNodeModuleFile (
79
69
'@remix-run/server-runtime/dist/routeMatching.js' ,
80
- [ '1.6.2 - 2.x' ] ,
70
+ [ '2.x' ] ,
81
71
( moduleExports : typeof remixRunServerRuntimeRouteMatching ) => {
82
72
// createRequestHandler
83
73
if ( isWrapped ( moduleExports [ 'matchServerRoutes' ] ) ) {
@@ -116,7 +106,7 @@ export class RemixInstrumentation extends InstrumentationBase {
116
106
) ;
117
107
118
108
/*
119
- * In Remix 1.8 .0, the callXXLoader functions were renamed to callXXLoaderRR. They were renamed back in 2.9.0 .
109
+ * In Remix 2.9 .0, the `callXXLoaderRR` functions were renamed to `callXXLoader` .
120
110
*/
121
111
const remixRunServerRuntimeDataPre_2_9_File = new InstrumentationNodeModuleFile (
122
112
'@remix-run/server-runtime/dist/data.js' ,
@@ -153,7 +143,7 @@ export class RemixInstrumentation extends InstrumentationBase {
153
143
154
144
const remixRunServerRuntimeModule = new InstrumentationNodeModuleDefinition (
155
145
'@remix-run/server-runtime' ,
156
- [ '>=2.* ' ] ,
146
+ [ '2.x ' ] ,
157
147
( moduleExports : typeof remixRunServerRuntime ) => {
158
148
// createRequestHandler
159
149
if ( isWrapped ( moduleExports [ 'createRequestHandler' ] ) ) {
@@ -172,9 +162,6 @@ export class RemixInstrumentation extends InstrumentationBase {
172
162
return remixRunServerRuntimeModule ;
173
163
}
174
164
175
- /**
176
- *
177
- */
178
165
private _patchMatchServerRoutes ( ) : ( original : typeof remixRunServerRuntimeRouteMatching . matchServerRoutes ) => any {
179
166
return function matchServerRoutes ( original ) {
180
167
return function patchMatchServerRoutes (
@@ -203,9 +190,6 @@ export class RemixInstrumentation extends InstrumentationBase {
203
190
} ;
204
191
}
205
192
206
- /**
207
- *
208
- */
209
193
private _patchCreateRequestHandler ( ) : ( original : typeof remixRunServerRuntime . createRequestHandler ) => any {
210
194
// eslint-disable-next-line @typescript-eslint/no-this-alias
211
195
const plugin = this ;
@@ -247,9 +231,6 @@ export class RemixInstrumentation extends InstrumentationBase {
247
231
} ;
248
232
}
249
233
250
- /**
251
- *
252
- */
253
234
private _patchCallRouteLoader ( ) : ( original : typeof remixRunServerRuntimeData . callRouteLoader ) => any {
254
235
// eslint-disable-next-line @typescript-eslint/no-this-alias
255
236
const plugin = this ;
@@ -285,52 +266,6 @@ export class RemixInstrumentation extends InstrumentationBase {
285
266
} ;
286
267
}
287
268
288
- /**
289
- *
290
- */
291
- // eslint-disable-next-line @typescript-eslint/naming-convention
292
- private _patchCallRouteLoaderPre_1_7_2 ( ) : ( original : typeof remixRunServerRuntimeData . callRouteLoader ) => any {
293
- // eslint-disable-next-line @typescript-eslint/no-this-alias
294
- const plugin = this ;
295
- return function callRouteLoader ( original ) {
296
- return function patchCallRouteLoader ( this : any , ...args : Parameters < typeof original > ) : Promise < Response > {
297
- // Cast as `any` to avoid typescript errors since this is patching an older version
298
- const [ params ] = args as unknown as any ;
299
-
300
- const span = plugin . tracer . startSpan (
301
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
302
- `LOADER ${ params . match . route . id } ` ,
303
- { attributes : { [ SemanticAttributes . CODE_FUNCTION ] : 'loader' } } ,
304
- opentelemetry . context . active ( ) ,
305
- ) ;
306
-
307
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
308
- addRequestAttributesToSpan ( span , params . request ) ;
309
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
310
- addMatchAttributesToSpan ( span , { routeId : params . match . route . id , params : params . match . params } ) ;
311
-
312
- return opentelemetry . context . with ( opentelemetry . trace . setSpan ( opentelemetry . context . active ( ) , span ) , ( ) => {
313
- const originalResponsePromise : Promise < Response > = original . apply ( this , args ) ;
314
- return originalResponsePromise
315
- . then ( response => {
316
- addResponseAttributesToSpan ( span , response ) ;
317
- return response ;
318
- } )
319
- . catch ( error => {
320
- plugin . _addErrorToSpan ( span , error ) ;
321
- throw error ;
322
- } )
323
- . finally ( ( ) => {
324
- span . end ( ) ;
325
- } ) ;
326
- } ) ;
327
- } ;
328
- } ;
329
- }
330
-
331
- /**
332
- *
333
- */
334
269
private _patchCallRouteAction ( ) : ( original : typeof remixRunServerRuntimeData . callRouteAction ) => any {
335
270
// eslint-disable-next-line @typescript-eslint/no-this-alias
336
271
const plugin = this ;
@@ -390,9 +325,6 @@ export class RemixInstrumentation extends InstrumentationBase {
390
325
} ;
391
326
}
392
327
393
- /**
394
- *
395
- */
396
328
private _addErrorToSpan ( span : Span , error : Error ) : void {
397
329
addErrorEventToSpan ( span , error ) ;
398
330
0 commit comments