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

Avoid calling bind on instances of RpcProperty #140

Closed JacobMarshallPP closed 1 month ago

JacobMarshallPP commented 1 month ago

Fixes #139.

This PR inspects the unwrapped value, and if it's constructor is of RpcProperty, it handles binding by returning a different function that calls the RPC property as if it was bound.

I checked, and this sort of introspection is not unlike what Cloudflare do in their own Miniflare project:

https://github.com/cloudflare/workers-sdk/blob/d0754780c6d9a12984f1e4ed9b4f0952ba6b0888/packages/miniflare/src/workers/core/proxy.worker.ts#L223