|
1 | 1 | import type * as http from 'node:http';
|
2 | 2 | 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'; |
4 | 8 | import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express';
|
5 | 9 | import type { IntegrationFn } from '@sentry/core';
|
6 | 10 | import {
|
@@ -89,26 +93,31 @@ function spanNameHook(info: ExpressRequestInfo<unknown>, defaultName: string): s
|
89 | 93 | return defaultName;
|
90 | 94 | }
|
91 | 95 |
|
| 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 | + |
92 | 113 | export const instrumentExpress = generateInstrumentOnce(
|
93 | 114 | 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)), |
101 | 116 | );
|
102 | 117 |
|
103 | 118 | export const instrumentExpressV5 = generateInstrumentOnce(
|
104 | 119 | 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)), |
112 | 121 | );
|
113 | 122 |
|
114 | 123 | const _expressIntegration = ((options: ExpressOptions = {}) => {
|
|
0 commit comments