@@ -8,10 +8,10 @@ import type {
88 ServiceLocals ,
99 ServiceStartOptions ,
1010} from '../types' ;
11+ import type { ListenFn , StartAppFn } from '../express-app/index' ;
1112
1213import { getAutoInstrumentations } from './instrumentations' ;
1314
14-
1515// For troubleshooting, set the log level to DiagLogLevel.DEBUG
1616diag . setLogger ( new DiagConsoleLogger ( ) , DiagLogLevel . INFO ) ;
1717
@@ -32,33 +32,24 @@ export async function startWithTelemetry<
3232 serviceName : options . name ,
3333 autoDetectResources : true ,
3434 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 ( ) ] ,
4936 } ) ;
5037 await sdk . start ( ) ;
5138
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+ } ;
5444 // 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 ;
5647 const startOptions : ServiceStartOptions < SLocals > = {
5748 ...options ,
5849 service,
5950 locals : { ...options . locals } as Partial < SLocals > ,
6051 } ;
61- const app = await startApp < SLocals , RLocals > ( startOptions ) ;
52+ const app = await startApp ( startOptions ) ;
6253 app . locals . logger . info ( 'OpenTelemetry enabled' ) ;
6354
6455 const server = await listen ( app , async ( ) => {
0 commit comments