evanderkoogh / otel-cf-workers

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

Error when instrumenting a worker using Launch Darkly's edge SDK #45

Closed tygern closed 1 year ago

tygern commented 1 year ago

I'm using Launch Darkly's edge SDK in a Cloudflare worker. When I add instrumentation to the app I see an error triggered when fetching a Launch Darkly flag (which is stored in a KV store).

{"name":"TypeError","message":"Cannot read properties of undefined (reading 'Symbol(unwrap)')","stack":"TypeError: Cannot read properties of undefined (reading 'Symbol(unwrap)')\n    at isWrapped (worker.js:15817:16)\n    at wrap (worker.js:15820:7)\n    at instrumentKVFn (worker.js:16563:10)\n    at Object.get (worker.js:16570:14)\n    at proxyHandler.get (worker.js:15829:25)\n    at JSON.stringify (<anonymous>)\n    at createOptions (worker.js:13348:105)\n    at new LDClient (worker.js:13358:28)\n    at init (worker.js:13399:10)\n    at init2 (worker.js:13432:10)"}

Here's a minimal repository that reproduces the issue. Follow the readme and you should be able to reproduce the issue. Thanks!

evanderkoogh commented 1 year ago

Hey @tygern, thanks so much for the repo, that was super helpful in tracking down the issue. I think Launch Darkly might be adding something to Env, which the library was choking on. But I think I got it solved in the latest 1.0.0-rc.9.. Could you give that a go on your actual app?

tygern commented 1 year ago

Thanks for getting to this so quickly @evanderkoogh. I've updated the sample repo above with the 1.0.0-rc.9 release. There's no error now, but I don't see any traces.

It's possible I'm not configuring the new spanProcessors correctly. I added the BatchTraceSpanProcessor since it looked like that was the previous default. is that correct?

evanderkoogh commented 1 year ago

Hey @tygern, there was indeed an issue with rc.9 that prevented traces from showing up in some instances. That should have been fixed in rc.10 that I just released to npm.