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

Make it work with Miniflare 2.14.0 #36

Closed vzaramel closed 10 months ago

vzaramel commented 11 months ago

Because of how miniflare handles the default export from modules the Proxy returned by wrap.ts is passing through the bind call. And that makes the proxy be bypassed by miniflare.

https://github.com/cloudflare/miniflare/blob/7e4d906e19cc69cd3446512bfeb7f8aee3a2bda7/packages/core/src/index.ts#L813-L814

Fixed this in a fork adding a case for 'bind' here

proxyHandler.get = (target, prop, receiver) => {
if (prop === unwrapSymbol) {
      return item
  } else if(prop === 'bind') {
      return () => receiver
  } else {
      if (handler.get) {
          return handler.get(target, prop, receiver)
      } else if (autoPassthrough) {
          return passthroughGet(target, prop)
      }
  }
}

As I am not sure if that is the proper solution to the problem I will not submit a PR yet.

evanderkoogh commented 10 months ago

Apologies for the long delay. This had escaped my attention. I have made the change in the rc.10 release. Could you test it?