evanderkoogh / otel-cf-workers

An OpenTelemetry compatible library for instrumenting and exporting traces for Cloudflare Workers
BSD 3-Clause "New" or "Revised" License
210 stars 40 forks source link

TypeError: Cannot read properties of undefined (reading 'fetch') #31

Closed jokull closed 11 months ago

jokull commented 11 months ago

If I import instrument wrangler 3.3.0 (and 3.2.0) get fetch as undefined.

evanderkoogh commented 11 months ago

Apologies for the delay, been a crazy couple of days, but could you give me a bit more information on what you are trying to do and what actually happens?

jokull commented 11 months ago

I think I figured it out. If you import instrument without calling it, fetch is undefined until instrument is called.

Now I'm doing:

if (ENV === "production") {
  const instrument = (await import("@microlabs/otel-cf-workers")).instrument;
  handler = instrument(handler, config);
}
jokull commented 11 months ago

With both RC6 and 7 my queue does not get processed. I'm using scheduled tasks to add to the queue and then consumer on the same worker code. I'm on holiday so I don't have a lot of spare time to create minimal reproductions, sorry about that, but thought I'd report this anyhow. I've removed otel for now - looking forward to having another look when I get back from my road trip.

evanderkoogh commented 11 months ago

Hmm.. the fetch being undefined when we import instrument, but not use it is certainly a bug. Will have a look at that.

And I’ll have a look at the queue thing as well. Thanks for reporting and enjoy the rest of the road trip!

evanderkoogh commented 11 months ago

You are correct that there was an issue if you imported instrument, but didn't actually use it. Found the culprit and should have fixed it.

evanderkoogh commented 11 months ago

@jokull, I have tried the queue example myself and that worked just fine. Once you are back, could you try the latest version to check and make a new issue if it is still not working?

jokull commented 11 months ago

Will do! Thanks for looking into this