Repository navigation
feat(node): Add oRPC v2 integration #26588
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { ORPCError, os } from '@orpc/server'; | ||
| import { RPCHandler } from '@orpc/server/fetch'; | ||
|
|
||
| const router = { | ||
| planet: { | ||
| find: os.handler(() => ({ name: 'Earth' })), | ||
| crash: os.handler(() => { | ||
| throw new Error('Sentry Test Error'); | ||
| }), | ||
| missing: os.handler(() => { | ||
| throw new ORPCError('NOT_FOUND'); | ||
| }), | ||
| }, | ||
| }; | ||
|
|
||
| // At module scope, as in most apps. The vite plugin hooks only per-request oRPC internals. | ||
| const handler = new RPCHandler(router); | ||
|
|
||
| export default { | ||
| async fetch(request, _env, _ctx) { | ||
| const { matched, response } = await handler.handle(request, { prefix: '/rpc' }); | ||
| return matched ? response : new Response('Not found', { status: 404 }); | ||
| }, | ||
| } satisfies ExportedHandler; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import * as Sentry from '@sentry/cloudflare'; | ||
|
|
||
| interface Env { | ||
| SENTRY_DSN: string; | ||
| } | ||
|
|
||
| export default Sentry.defineCloudflareOptions((env: Env) => ({ | ||
| dsn: env.SENTRY_DSN, | ||
| tracesSampleRate: 1, | ||
| })); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import { SENTRY_OP, SENTRY_ORIGIN } from '@sentry/conventions/attributes'; | ||
| import { RPC } from '@sentry/conventions/op'; | ||
| import { expect, it } from 'vitest'; | ||
| import { createRunner } from '../../../../runner'; | ||
|
|
||
| const ORIGIN = { type: 'string', value: 'auto.rpc.orpc' }; | ||
|
|
||
| const JSON_REQUEST = { | ||
| headers: { 'content-type': 'application/json' }, | ||
| data: JSON.stringify({ json: { name: 'Earth' } }), | ||
| }; | ||
|
|
||
| it('records one span for a procedure call and names the transaction after the procedure', async ({ signal }) => { | ||
| const runner = createRunner(__dirname).ignore('event').start(signal); | ||
|
|
||
| const spansPromise = runner.collectStreamedSpans(spansOfTrace => | ||
| spansOfTrace.some(span => span.name === 'planet/find' && !span.is_segment), | ||
| ); | ||
|
|
||
| await runner.makeRequest('post', '/rpc/planet/find', JSON_REQUEST); | ||
|
|
||
| const spans = await spansPromise; | ||
| expect(spans.find(span => span.is_segment)?.name).toBe('planet/find'); | ||
| expect(spans.filter(span => span.attributes?.[SENTRY_ORIGIN]?.value === ORIGIN.value)).toEqual([ | ||
| expect.objectContaining({ | ||
| name: 'planet/find', | ||
| is_segment: false, | ||
| attributes: expect.objectContaining({ | ||
| [SENTRY_OP]: { type: 'string', value: RPC }, | ||
| [SENTRY_ORIGIN]: ORIGIN, | ||
| 'rpc.method': { type: 'string', value: 'planet/find' }, | ||
| }), | ||
| }), | ||
| ]); | ||
| }); | ||
|
|
||
| it('captures errors thrown by procedures, but not 4xx ORPCErrors', async ({ signal }) => { | ||
| const runner = createRunner(__dirname) | ||
| .ignore('span') | ||
| .expect(envelope => { | ||
| const event = envelope[1][0]?.[1] as { | ||
| transaction?: string; | ||
| exception?: { values?: Array<{ value?: string; mechanism?: unknown }> }; | ||
| contexts?: Record<string, unknown>; | ||
| }; | ||
| expect(event.transaction).toBe('planet/crash'); | ||
| expect(event.exception?.values?.[0]).toMatchObject({ | ||
| type: 'Error', | ||
| value: 'Sentry Test Error', | ||
| mechanism: { type: 'auto.rpc.orpc', handled: false }, | ||
| }); | ||
| expect(event.contexts?.orpc).toMatchObject({ procedure_path: 'planet/crash' }); | ||
| }) | ||
| .start(signal); | ||
|
|
||
| // Sent first, so an event for it would fail the expectation above. | ||
| await runner.makeRequest('post', '/rpc/planet/missing', { ...JSON_REQUEST, expectError: true }); | ||
| await runner.makeRequest('post', '/rpc/planet/crash', { ...JSON_REQUEST, expectError: true }); | ||
| await runner.completed(); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import { cloudflare } from '@cloudflare/vite-plugin'; | ||
| import { sentryCloudflareVitePlugin } from '@sentry/cloudflare/vite'; | ||
| import { defineConfig } from 'vite'; | ||
|
|
||
| export default defineConfig({ | ||
| plugins: [cloudflare(), sentryCloudflareVitePlugin()], | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "name": "orpc-worker", | ||
| "compatibility_date": "2026-04-26", | ||
| "main": "index.ts", | ||
| "compatibility_flags": ["nodejs_compat"], | ||
| } |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
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.
why does this have to be exlucded? should that not work on bun
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.
It does work on Bun, just not unbundled.
NO_AUTO_INSTRUMENTATIONonly excludes the plainbun runproject:bun runcan't inject the orchestrion channels (see the comment above the list and #23882), soexecuteProcedureInternalnever publishes and there are no spans or errors. The suite still runs in the bundlednode-suites-bun-buildproject with@sentry/bun/plugin, and it passed there (4/4 locally and in CI). That matches how hono and koa are handled in the same list.