Skip to content

Commit 05b7508

Browse files
committed
Tidy up
1 parent d6dacd8 commit 05b7508

File tree

1 file changed

+9
-77
lines changed

1 file changed

+9
-77
lines changed

packages/remix/src/vendor/instrumentation.ts

Lines changed: 9 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-disable deprecation/deprecation */
22
/* eslint-disable max-lines */
3+
/* eslint-disable jsdoc/require-jsdoc */
34
import type { Span } from '@opentelemetry/api';
45
import opentelemetry, { SpanStatusCode } from '@opentelemetry/api';
56
import type { InstrumentationConfig } from '@opentelemetry/instrumentation';
@@ -16,13 +17,14 @@ import type * as remixRunServerRuntimeData from '@remix-run/server-runtime/dist/
1617
import type * as remixRunServerRuntimeRouteMatching from '@remix-run/server-runtime/dist/routeMatching';
1718
import type { RouteMatch } from '@remix-run/server-runtime/dist/routeMatching';
1819
import type { ServerRoute } from '@remix-run/server-runtime/dist/routes';
20+
import { SDK_VERSION } from '@sentry/core';
1921

2022
const RemixSemanticAttributes = {
2123
MATCH_PARAMS: 'match.params',
2224
MATCH_ROUTE_ID: 'match.route.id',
2325
};
2426

25-
const VERSION = '__OTEL_REMIX_INSTRUMENTATION_VERSION__';
27+
const VERSION = SDK_VERSION;
2628

2729
export interface RemixInstrumentationConfig extends InstrumentationConfig {
2830
/**
@@ -48,36 +50,24 @@ const DEFAULT_CONFIG: RemixInstrumentationConfig = {
4850
legacyErrorAttributes: false,
4951
};
5052

51-
/**
52-
*
53-
*/
5453
export class RemixInstrumentation extends InstrumentationBase {
5554
public constructor(config: RemixInstrumentationConfig = {}) {
5655
super('RemixInstrumentation', VERSION, Object.assign({}, DEFAULT_CONFIG, config));
5756
}
5857

59-
/**
60-
*
61-
*/
62-
public override getConfig(): RemixInstrumentationConfig {
58+
public getConfig(): RemixInstrumentationConfig {
6359
return this._config;
6460
}
6561

66-
/**
67-
*
68-
*/
69-
public override setConfig(config: RemixInstrumentationConfig = {}): void {
62+
public setConfig(config: RemixInstrumentationConfig = {}): void {
7063
this._config = Object.assign({}, DEFAULT_CONFIG, config);
7164
}
7265

73-
/**
74-
*
75-
*/
7666
// eslint-disable-next-line @typescript-eslint/naming-convention
77-
protected override init(): InstrumentationNodeModuleDefinition {
67+
protected init(): InstrumentationNodeModuleDefinition {
7868
const remixRunServerRuntimeRouteMatchingFile = new InstrumentationNodeModuleFile(
7969
'@remix-run/server-runtime/dist/routeMatching.js',
80-
['1.6.2 - 2.x'],
70+
['2.x'],
8171
(moduleExports: typeof remixRunServerRuntimeRouteMatching) => {
8272
// createRequestHandler
8373
if (isWrapped(moduleExports['matchServerRoutes'])) {
@@ -116,7 +106,7 @@ export class RemixInstrumentation extends InstrumentationBase {
116106
);
117107

118108
/*
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`.
120110
*/
121111
const remixRunServerRuntimeDataPre_2_9_File = new InstrumentationNodeModuleFile(
122112
'@remix-run/server-runtime/dist/data.js',
@@ -153,7 +143,7 @@ export class RemixInstrumentation extends InstrumentationBase {
153143

154144
const remixRunServerRuntimeModule = new InstrumentationNodeModuleDefinition(
155145
'@remix-run/server-runtime',
156-
['>=2.*'],
146+
['2.x'],
157147
(moduleExports: typeof remixRunServerRuntime) => {
158148
// createRequestHandler
159149
if (isWrapped(moduleExports['createRequestHandler'])) {
@@ -172,9 +162,6 @@ export class RemixInstrumentation extends InstrumentationBase {
172162
return remixRunServerRuntimeModule;
173163
}
174164

175-
/**
176-
*
177-
*/
178165
private _patchMatchServerRoutes(): (original: typeof remixRunServerRuntimeRouteMatching.matchServerRoutes) => any {
179166
return function matchServerRoutes(original) {
180167
return function patchMatchServerRoutes(
@@ -203,9 +190,6 @@ export class RemixInstrumentation extends InstrumentationBase {
203190
};
204191
}
205192

206-
/**
207-
*
208-
*/
209193
private _patchCreateRequestHandler(): (original: typeof remixRunServerRuntime.createRequestHandler) => any {
210194
// eslint-disable-next-line @typescript-eslint/no-this-alias
211195
const plugin = this;
@@ -247,9 +231,6 @@ export class RemixInstrumentation extends InstrumentationBase {
247231
};
248232
}
249233

250-
/**
251-
*
252-
*/
253234
private _patchCallRouteLoader(): (original: typeof remixRunServerRuntimeData.callRouteLoader) => any {
254235
// eslint-disable-next-line @typescript-eslint/no-this-alias
255236
const plugin = this;
@@ -285,52 +266,6 @@ export class RemixInstrumentation extends InstrumentationBase {
285266
};
286267
}
287268

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-
*/
334269
private _patchCallRouteAction(): (original: typeof remixRunServerRuntimeData.callRouteAction) => any {
335270
// eslint-disable-next-line @typescript-eslint/no-this-alias
336271
const plugin = this;
@@ -390,9 +325,6 @@ export class RemixInstrumentation extends InstrumentationBase {
390325
};
391326
}
392327

393-
/**
394-
*
395-
*/
396328
private _addErrorToSpan(span: Span, error: Error): void {
397329
addErrorEventToSpan(span, error);
398330

0 commit comments

Comments
 (0)