@@ -8,10 +8,10 @@ import type {
8
8
ServiceLocals ,
9
9
ServiceStartOptions ,
10
10
} from '../types' ;
11
+ import type { ListenFn , StartAppFn } from '../express-app/index' ;
11
12
12
13
import { getAutoInstrumentations } from './instrumentations' ;
13
14
14
-
15
15
// For troubleshooting, set the log level to DiagLogLevel.DEBUG
16
16
diag . setLogger ( new DiagConsoleLogger ( ) , DiagLogLevel . INFO ) ;
17
17
@@ -32,33 +32,24 @@ export async function startWithTelemetry<
32
32
serviceName : options . name ,
33
33
autoDetectResources : true ,
34
34
traceExporter : getExporter ( ) ,
35
- instrumentations : [ getAutoInstrumentations ( {
36
- 'opentelemetry-instrumentation-node-18-fetch' : {
37
- onRequest ( { request, span, additionalHeaders } ) {
38
- // This particular line is "GasBuddy" specific, in that we have a number
39
- // of services not yet on OpenTelemetry that look for this header instead.
40
- // Putting traceId gives us a "shot in heck" of useful searches.
41
- if ( ! / ^ c o r r e l a t i o n i d : / m. test ( request . headers ) ) {
42
- const ctx = span . spanContext ( ) ;
43
- additionalHeaders . correlationid = ctx . traceId ;
44
- additionalHeaders . span = ctx . spanId ;
45
- }
46
- } ,
47
- } ,
48
- } ) ] ,
35
+ instrumentations : [ getAutoInstrumentations ( ) ] ,
49
36
} ) ;
50
37
await sdk . start ( ) ;
51
38
52
- // eslint-disable-next-line import/no-unresolved
53
- const { startApp, listen } = await import ( '../express-app/app.js' ) ;
39
+ // eslint-disable-next-line import/no-unresolved, @typescript-eslint/no-var-requires
40
+ const { startApp, listen } = require ( '../express-app/app.js' ) as {
41
+ startApp : StartAppFn < SLocals , RLocals > ;
42
+ listen : ListenFn < SLocals > ;
43
+ } ;
54
44
// eslint-disable-next-line import/no-dynamic-require, global-require, @typescript-eslint/no-var-requires
55
- const { default : service } = require ( options . service ) ;
45
+ const serviceModule = require ( options . service ) ;
46
+ const service = serviceModule . default || serviceModule . service ;
56
47
const startOptions : ServiceStartOptions < SLocals > = {
57
48
...options ,
58
49
service,
59
50
locals : { ...options . locals } as Partial < SLocals > ,
60
51
} ;
61
- const app = await startApp < SLocals , RLocals > ( startOptions ) ;
52
+ const app = await startApp ( startOptions ) ;
62
53
app . locals . logger . info ( 'OpenTelemetry enabled' ) ;
63
54
64
55
const server = await listen ( app , async ( ) => {
0 commit comments