-
-
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
Merged
Merged
feat(cloudflare): Add instrumentPrototypeMethods
option to instrument RPC methods for DurableObjects
#17424
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
729a668
fix(cloudflare): Avoid breaking rpc calls when wrapping DurableObjects
andreiborza 943c816
Add integration tests for DurableObjects
andreiborza 412dfc7
Instrument methods at prototype level not instance level
andreiborza b038abf
Fix type issues
andreiborza 61bf262
Add option to instrument rpc methods
andreiborza 3e1fa93
Fix integration tests
andreiborza 8e383a6
Add changelog entry
andreiborza d8bf84a
Formatting fix
andreiborza 7e8f9a5
Fix e2e-tests
andreiborza dcffbfa
Reword changelog to indicate performance concerns
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.
Uh oh!
There was an error while loading. Please reload this page.