Skip to content

Commit 042bfec

Browse files
committed
fix: capture bound function result in instrumentDO
The bind() method returns a new bound function but the code was discarding the return value. This caused 'Illegal invocation' errors when calling Durable Object methods via RPC. Fixes method binding for Cloudflare Workers RPC calls and PartyServer .name property access.
1 parent 730fc0e commit 042bfec

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/instrumentation/do.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import { context as api_context, trace, SpanOptions, SpanKind, Exception, SpanStatusCode } from '@opentelemetry/api'
1+
import { context as api_context, Exception, SpanKind, SpanOptions, SpanStatusCode, trace } from '@opentelemetry/api'
22
import { SemanticAttributes } from '@opentelemetry/semantic-conventions'
3+
import { Initialiser, setConfig } from '../config.js'
4+
import { DOConstructorTrigger } from '../types.js'
35
import { passthroughGet, unwrap, wrap } from '../wrap.js'
6+
import { instrumentStorage } from './do-storage.js'
7+
import { instrumentEnv } from './env.js'
48
import {
5-
getParentContextFromHeaders,
69
gatherIncomingCfAttributes,
710
gatherRequestAttributes,
811
gatherResponseAttributes,
12+
getParentContextFromHeaders,
913
instrumentClientFetch,
1014
} from './fetch.js'
11-
import { instrumentEnv } from './env.js'
12-
import { Initialiser, setConfig } from '../config.js'
13-
import { instrumentStorage } from './do-storage.js'
14-
import { DOConstructorTrigger } from '../types.js'
1515

1616
import { DurableObject as DurableObjectClass } from 'cloudflare:workers'
1717

@@ -217,8 +217,8 @@ function instrumentDurableObject(
217217
} else {
218218
const result = Reflect.get(target, prop)
219219
if (typeof result === 'function') {
220-
result.bind(doObj)
221-
return instrumentAnyFn(result, initialiser, env, state.id)
220+
const boundResult = result.bind(doObj)
221+
return instrumentAnyFn(boundResult, initialiser, env, state.id)
222222
}
223223
return result
224224
}

0 commit comments

Comments
 (0)