Skip to content

Commit d7bd90e

Browse files
committed
adjust how options are set
1 parent 2b178b5 commit d7bd90e

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

packages/node/src/integrations/tracing/express.ts

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import type * as http from 'node:http';
22
import type { Span } from '@opentelemetry/api';
3-
import type { ExpressLayerType, ExpressRequestInfo } from '@opentelemetry/instrumentation-express';
3+
import type {
4+
ExpressInstrumentationConfig,
5+
ExpressLayerType,
6+
ExpressRequestInfo,
7+
} from '@opentelemetry/instrumentation-express';
48
import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express';
59
import type { IntegrationFn } from '@sentry/core';
610
import {
@@ -89,26 +93,31 @@ function spanNameHook(info: ExpressRequestInfo<unknown>, defaultName: string): s
8993
return defaultName;
9094
}
9195

96+
function buildInstrumentationConfig(options: ExpressOptions): ExpressInstrumentationConfig {
97+
const config: ExpressInstrumentationConfig = {
98+
requestHook: (span: Span) => requestHook(span),
99+
spanNameHook: (info: ExpressRequestInfo<unknown>, defaultName: string) => spanNameHook(info, defaultName),
100+
};
101+
102+
if (options.ignoreLayers) {
103+
config.ignoreLayers = options.ignoreLayers;
104+
}
105+
106+
if (options.ignoreLayersType) {
107+
config.ignoreLayersType = options.ignoreLayersType as ExpressLayerType[];
108+
}
109+
110+
return config;
111+
}
112+
92113
export const instrumentExpress = generateInstrumentOnce(
93114
INTEGRATION_NAME,
94-
(options: ExpressOptions = {}) =>
95-
new ExpressInstrumentation({
96-
requestHook: span => requestHook(span),
97-
spanNameHook: (info, defaultName) => spanNameHook(info, defaultName),
98-
ignoreLayers: options.ignoreLayers,
99-
ignoreLayersType: options.ignoreLayersType as ExpressLayerType[],
100-
}),
115+
(options: ExpressOptions = {}) => new ExpressInstrumentation(buildInstrumentationConfig(options)),
101116
);
102117

103118
export const instrumentExpressV5 = generateInstrumentOnce(
104119
INTEGRATION_NAME_V5,
105-
(options: ExpressOptions = {}) =>
106-
new ExpressInstrumentationV5({
107-
requestHook: span => requestHook(span),
108-
spanNameHook: (info, defaultName) => spanNameHook(info, defaultName),
109-
ignoreLayers: options.ignoreLayers,
110-
ignoreLayersType: options.ignoreLayersType as ExpressLayerType[],
111-
}),
120+
(options: ExpressOptions = {}) => new ExpressInstrumentationV5(buildInstrumentationConfig(options)),
112121
);
113122

114123
const _expressIntegration = ((options: ExpressOptions = {}) => {

0 commit comments

Comments
 (0)