Skip to content

Commit

Permalink
Ignore jsrpc bindings (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniFoldi authored Apr 7, 2024
1 parent 89e9719 commit 660e4a7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/new-lions-collect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@microlabs/otel-cf-workers": patch
---

Prevent incorrect detection of rpc bindings
10 changes: 9 additions & 1 deletion src/instrumentation/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import { instrumentQueueSender } from './queue.js'
import { instrumentServiceBinding } from './service.js'
import { instrumentAnalyticsEngineDataset } from './analytics-engine.js'

const isJSRPC = (item?: unknown): item is Service => {
// @ts-expect-error The point of RPC types is to block non-existent properties, but that's the goal here
return !!(item as Service)?.['__some_property_that_will_never_exist' + Math.random()]
}

const isKVNamespace = (item?: unknown): item is KVNamespace => {
return !!(item as KVNamespace)?.getWithMetadata
}
Expand Down Expand Up @@ -33,7 +38,10 @@ const instrumentEnv = (env: Record<string, unknown>): Record<string, unknown> =>
if (!isProxyable(item)) {
return item
}
if (isKVNamespace(item)) {
if (isJSRPC(item)) {
// TODO instrument JSRPC and maybe remove serviceBinding?
return item
} else if (isKVNamespace(item)) {
return instrumentKV(item, String(prop))
} else if (isQueue(item)) {
return instrumentQueueSender(item, String(prop))
Expand Down

0 comments on commit 660e4a7

Please sign in to comment.