fix(telemetry): avoid async import if telemetry disabled, fix for esbuild (#5086)

This commit is contained in:
Shawn Erquhart
2025-10-04 09:37:45 -07:00
committed by GitHub
parent f34a9733f0
commit 6aa0c1c10f
2 changed files with 14 additions and 8 deletions

View File

@@ -100,13 +100,17 @@ export const init = async (options: BetterAuthOptions) => {
return generateId(size);
};
const { publish } = await createTelemetry(options, {
const { publish } = options.telemetry?.enabled
? await createTelemetry(options, {
adapter: adapter.id,
database:
typeof options.database === "function"
? "adapter"
: getKyselyDatabaseType(options.database) || "unknown",
});
})
: {
publish: async () => {},
};
let ctx: AuthContext = {
appName: options.appName || "Better Auth",

View File

@@ -5,7 +5,9 @@ let lazyImportCreateTelemetry: Promise<
export const createTelemetry: typeof import("./create-telemetry").createTelemetry =
async (...args) => {
if (!lazyImportCreateTelemetry) {
lazyImportCreateTelemetry = import("./create-telemetry").then(
// keep esbuild from following dynamic import during bundling
const importPath = "./create-telemetry";
lazyImportCreateTelemetry = import(importPath).then(
(mod) => mod.createTelemetry,
);
}