-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(cloudflare): Add instrumentPrototypeMethods
option to instrument RPC methods for DurableObjects
#17424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
andreiborza
wants to merge
8
commits into
develop
Choose a base branch
from
ab/durable-objects-rpc
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat(cloudflare): Add instrumentPrototypeMethods
option to instrument RPC methods for DurableObjects
#17424
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ac55737
fix(cloudflare): Avoid breaking rpc calls when wrapping DurableObjects
andreiborza a974262
Add integration tests for DurableObjects
andreiborza aa04f4b
Instrument methods at prototype level not instance level
andreiborza 996b2a9
Fix type issues
andreiborza 2ea28b1
Add option to instrument rpc methods
andreiborza 878052c
Fix integration tests
andreiborza adcd67d
Add changelog entry
andreiborza 0b821ad
Formatting fix
andreiborza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
dev-packages/cloudflare-integration-tests/suites/tracing/durableobject/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import * as Sentry from '@sentry/cloudflare'; | ||
import { DurableObject } from 'cloudflare:workers'; | ||
|
||
interface Env { | ||
SENTRY_DSN: string; | ||
TEST_DURABLE_OBJECT: DurableObjectNamespace; | ||
} | ||
|
||
class TestDurableObjectBase extends DurableObject<Env> { | ||
public constructor(ctx: DurableObjectState, env: Env) { | ||
super(ctx, env); | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/explicit-member-accessibility | ||
async sayHello(name: string): Promise<string> { | ||
return `Hello, ${name}`; | ||
} | ||
} | ||
|
||
export const TestDurableObject = Sentry.instrumentDurableObjectWithSentry( | ||
(env: Env) => ({ | ||
dsn: env.SENTRY_DSN, | ||
tracesSampleRate: 1.0, | ||
instrumentPrototypeMethods: true, | ||
}), | ||
TestDurableObjectBase, | ||
); | ||
|
||
export default { | ||
async fetch(request: Request, env: Env): Promise<Response> { | ||
const id: DurableObjectId = env.TEST_DURABLE_OBJECT.idFromName('test'); | ||
const stub = env.TEST_DURABLE_OBJECT.get(id) as unknown as TestDurableObjectBase; | ||
|
||
if (request.url.includes('hello')) { | ||
const greeting = await stub.sayHello('world'); | ||
return new Response(greeting); | ||
} | ||
|
||
return new Response('Usual response'); | ||
}, | ||
}; |
27 changes: 27 additions & 0 deletions
27
dev-packages/cloudflare-integration-tests/suites/tracing/durableobject/test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { expect, it } from 'vitest'; | ||
import { createRunner } from '../../../runner'; | ||
|
||
it('traces a durable object method', async () => { | ||
const runner = createRunner(__dirname) | ||
.expect(envelope => { | ||
const transactionEvent = envelope[1]?.[0]?.[1]; | ||
expect(transactionEvent).toEqual( | ||
expect.objectContaining({ | ||
contexts: expect.objectContaining({ | ||
trace: expect.objectContaining({ | ||
op: 'rpc', | ||
data: expect.objectContaining({ | ||
'sentry.op': 'rpc', | ||
'sentry.origin': 'auto.faas.cloudflare_durableobjects', | ||
}), | ||
origin: 'auto.faas.cloudflare_durableobjects', | ||
}), | ||
}), | ||
transaction: 'sayHello', | ||
}), | ||
); | ||
}) | ||
.start(); | ||
await runner.makeRequest('get', '/hello'); | ||
await runner.completed(); | ||
}); |
23 changes: 23 additions & 0 deletions
23
dev-packages/cloudflare-integration-tests/suites/tracing/durableobject/wrangler.jsonc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "worker-name", | ||
"main": "index.ts", | ||
"compatibility_date": "2025-06-17", | ||
"migrations": [ | ||
{ | ||
"new_sqlite_classes": ["TestDurableObject"], | ||
"tag": "v1" | ||
} | ||
], | ||
"durable_objects": { | ||
"bindings": [ | ||
{ | ||
"class_name": "TestDurableObject", | ||
"name": "TEST_DURABLE_OBJECT" | ||
} | ||
] | ||
}, | ||
"compatibility_flags": ["nodejs_als"], | ||
"vars": { | ||
"SENTRY_DSN": "https://[email protected]/4509553159831552" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Proxy Overhead in Prototype Instrumentation
The
wrappedMethod
in the prototype instrumentation callswrapMethodWithSentry()
on every invocation. This creates a new Proxy wrapper and performs instrumentation setup on each call, causing significant performance degradation for frequently used methods.