Issues using this with Wrangler
Closed this issue · 12 comments
If I follow the instructions here https://baselime.io/docs/sending-data/platforms/cloudflare/pages/ and run it with wrangler, I get:
../node_modules/@baselime/edge-logger/dist/index.mjs:4:29: ERROR: Could not resolve
"@opentelemetry/api"
Hi @treeder,
I was under the assumption that this
let tracingApiPromise: Promise<typeof import("@opentelemetry/api") | null>;
try {
/**
* Only load the tracing API if it's available
* It can't be provided by this library as the version needs to match the opentelemetry version
* provided by the user
*/
tracingApiPromise = import("@opentelemetry/api");
} catch (_) {
tracingApiPromise = Promise.resolve(null);
}
would shave off some of the bundle for people not using opentelemetry with cloudflare but it looks like it is just problematic. Is this just a warning or does it crash your application?
Thanks, npm installing @opentelemetry/api
will fix the issue but I will get a proper fix out tomorrow
I think the direction you were intending is the way to go, omit it if it's not there, but something must be hard referencing that library.
I think I might know what's going on, probably need await on the import, ie: await import("@opentelemetry/api");
https://www.npmjs.com/package/@baselime/edge-logger?activeTab=code
Ya, that works, I edited it myself and now it starts up.
var tracingApiPromise;
try {
tracingApiPromise = await import("@opentelemetry/api");
} catch (_) {
tracingApiPromise = Promise.resolve(null);
}
Hey @treeder, i took a look at your suggestion and it does fix it but I'm worried that top level await might break things for some people.
I then got distracted and forgot about it so thanks for reminding me.
I will figure out if top level await is safe and ship your fix or just include a pinned version of the opentelemetry api this weekend
In the meantime you can just add the package to your dependencies so this doesn't block you
Thanks
Hey @treeder I have opted for the slightly suboptimal approach of always importing @opentelemetry/api after doing some research on workers support for top level await.
This was published in 0.3.0
Looks like it needs an npm push.