Skip to content

Commit 1bae76d

Browse files
committed
fix(runner): found in node20 production build testing
* allow service modules to expose non-default export called service * use require instead of import to load internal express module in telemetry
1 parent 04c21fe commit 1bae76d

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

src/express-app/app.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,11 @@ export async function startApp<
285285
return app;
286286
}
287287

288+
export type StartAppFn<
289+
SLocals extends ServiceLocals = ServiceLocals,
290+
RLocals extends RequestLocals = RequestLocals,
291+
> = typeof startApp<SLocals, RLocals>;
292+
288293
export async function shutdownApp(app: ServiceExpress) {
289294
const { logger } = app.locals;
290295
try {
@@ -397,3 +402,5 @@ export async function listen<SLocals extends ServiceLocals = ServiceLocals>(
397402
await listenPromise;
398403
return server;
399404
}
405+
406+
export type ListenFn<SLocals extends ServiceLocals = ServiceLocals> = typeof listen<SLocals>;

src/telemetry/index.ts

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import type {
88
ServiceLocals,
99
ServiceStartOptions,
1010
} from '../types';
11+
import type { ListenFn, StartAppFn } from '../express-app/index';
1112

1213
import { getAutoInstrumentations } from './instrumentations';
1314

14-
1515
// For troubleshooting, set the log level to DiagLogLevel.DEBUG
1616
diag.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 (!/^correlationid:/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

Comments
 (0)