Skip to content

Commit

Permalink
Use path.resolve to resolve a path to next-server.js
Browse files Browse the repository at this point in the history
  • Loading branch information
chtushar committed May 11, 2024
1 parent f459f85 commit c8ba50d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
7 changes: 7 additions & 0 deletions labels.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"status": 200,
"body": {
"message": "GET method called",
"store": "undefined"
}
}
6 changes: 5 additions & 1 deletion src/OpenAPM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as os from 'os';
import http from 'http';
import ResponseTime from 'response-time';
import promClient from 'prom-client';
import path from 'path';

import type {
Counter,
Expand Down Expand Up @@ -435,7 +436,9 @@ export class OpenAPM extends LevitateEvents {
instrumentNestFactory(NestFactory, this._REDMiddleware);
}
if (moduleName === 'nextjs') {
const nextServer = require('next/dist/src/server/next-server');
const nextServer = require(path.resolve(
'node_modules/next/dist/server/next-server.js'
));
instrumentNextjs(
nextServer.default,
{
Expand All @@ -448,6 +451,7 @@ export class OpenAPM extends LevitateEvents {

return true;
} catch (error) {
console.error('OpenAPM:', error);
if (Object.keys(moduleNames).includes(moduleName)) {
throw new Error(
`OpenAPM couldn't import the ${moduleNames[moduleName]} package, please install it.`
Expand Down
1 change: 0 additions & 1 deletion tests/nextjs/nextjs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ describe('Next.js', () => {
});

test('Dynamic Labels are captured', async () => {
// writeFileSync('metrics.txt', JSON.stringify(parsedData, null, 2));
const res = await makeRequest(expressApp, '/labels');
writeFileSync('labels.txt', JSON.stringify(res.body, null, 2));
expect(true).toBe(true);
Expand Down
2 changes: 1 addition & 1 deletion tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import glob from 'tiny-glob';
export default defineConfig(async () => ({
entry: await glob('src/**/*.ts'),
sourcemap: false,
bundle: true,
bundle: false,
format: ['cjs', 'esm'],
legacyOutput: true,
cjsInterop: true,
Expand Down

0 comments on commit c8ba50d

Please sign in to comment.