Skip to content

Commit

Permalink
CJS default export
Browse files Browse the repository at this point in the history
  • Loading branch information
CircleCI committed Nov 4, 2024
1 parent 7168630 commit d871d94
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/distro-sync-init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,28 @@ let done = false;
let lumigoSdk: LumigoSdkInitialization | undefined;

init.then((initializedLumigoSdk) => {
done = true;
lumigoSdk = initializedLumigoSdk;
});
}).catch((err) => {
console.error(`Lumigo JS distro synchronous bootstrap failed: ${err}`);
}).finally(() => {
done = true;
})

deasync.loopWhile(() => !done);

export default lumigoSdk;
/*
This is an intentional use of `module.exports` instead of `export default`.
using `export default lumigoSdk` would cause the `lumigo` object to have a `default` attribute,
which is not the desired behavior. See the following examples:
// With `export default lumigoSdk`:
const lumigo = require('@lumigo/opentelemetry/sync');
console.log(lumigo) // { default: tracerProvider }
// With `module.exports = lumigoSdk`:
const lumigo = require('@lumigo/opentelemetry/sync');
console.log(lumigo) // { tracerProvider }
*/
module.exports = lumigoSdk;
6 changes: 6 additions & 0 deletions test/instrumentations/features/app/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const fastify = require('fastify')({ logger: true });
const bunyan = require('bunyan');
const bunyanLogger = bunyan.createLogger({ name: __filename })
const assert = require('assert');

let tracerProvider;
let loggerProvider;
Expand All @@ -14,6 +15,11 @@ fastify.get('/', async (request, reply) => {
});

fastify.get('/no-init', async (request, reply) => {
const lumigo = require('@lumigo/opentelemetry/sync');
assert(typeof lumigo == "object", 'the default export from the sync entrypoint is not an object!');
assert(typeof lumigo.tracerProvider == "object", `lumigo.tracerProvider is not an object! (${typeof lumigo.tracerProvider})`);
assert(typeof lumigo.loggerProvider == "object", `lumigo.default.loggerProvider is not an object! (${typeof lumigo.loggerProvider})`);

bunyanLogger.info('this log should be exported to Lumigo without init');
reply.send('no-init: all good')
});
Expand Down

0 comments on commit d871d94

Please sign in to comment.