evanderkoogh / otel-cf-workers

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

Bug: Calling a Service Binding RPC method throws a DOMException #139

Closed JacobMarshallPP closed 1 month ago

JacobMarshallPP commented 1 month ago

When using this package and calling a Service Binding's RPC property - the following error is thrown.

DOMException {
  code: 25,
  name: 'DataCloneError',
  message: 'Could not serialize object of type "Fetcher". This type does not support serialization.'
}

It admittedly took me a while to figure out where this was coming from, but I finally narrowed it down to the following line of code:

https://github.com/evanderkoogh/otel-cf-workers/blob/6f1c79056776024fd3e816b9e3991527e7217510/src/wrap.ts#L51

More specifically, it looks like calling .bind actually returns an RpcPromise, not a function. And then the actual error occurs when calling the "bound" function (which at this point is actually a promise-like object). I didn't spend too much time looking into that, but that was my initial assessment.

I have a fix for this locally, so I'm creating this issue to have an issue ID to reference in my pull request :)