Repository navigation
ref(nitro): Move channel-based instrumentation into @sentry/server-utils #24861
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
+432
−146
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
04d650b
ref(nitro): Move channel-based instrumentation into @sentry/server-utils
mydea 0b22a63
feat(nitro): Auto-inject Nitro integrations on bundler-only SDKs via …
mydea fa2a7f2
docs(nitro): Explain the prerelease version-range idiom in the orches…
mydea 5ad6338
docs(nitro): Reword the version-range comment
mydea a28e5dd
test(nitro): Add cloudflare-nitro e2e app
mydea 7d702ed
Revert "test(nitro): Add cloudflare-nitro e2e app"
mydea 3facf8b
test(deno): Decouple event snapshots from the default integration list
mydea ec96837
chore: Bump @sentry/node size limits for the nitro integrations
mydea 65095d7
feat(nitro): Add nitroIntegration as an explicit default integration
mydea 9955611
feat(nitro): Re-export the nitro integrations from all node-based SDKs
mydea 26f8a1d
Apply batched suggestions from code review
mydea 71c7c0d
test(nitro): Add node integration tests for the nitro integrations
mydea d900bc4
test(nitro): Use conventions in the nitro node integration tests
mydea f7da752
test(node): Write logging transport envelopes with `process.stdout.wr…
mydea 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
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
9 changes: 9 additions & 0 deletions
9
dev-packages/node-integration-tests/suites/tracing/nitro/instrument.mjs
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,9 @@ | ||
| import * as Sentry from '@sentry/node'; | ||
| import { loggingTransport } from '@sentry-internal/node-integration-tests'; | ||
|
|
||
| Sentry.init({ | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| release: '1.0', | ||
| tracesSampleRate: 1.0, | ||
| transport: loggingTransport, | ||
| }); |
23 changes: 23 additions & 0 deletions
23
dev-packages/node-integration-tests/suites/tracing/nitro/scenario.mjs
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 @@ | ||
| import { sendPortToRunner } from '@sentry-internal/node-integration-tests'; | ||
| import { H3, serve } from 'h3'; | ||
| import { tracingPlugin as h3TracingPlugin } from 'h3/tracing'; | ||
| import { tracingPlugin as srvxTracingPlugin } from 'srvx/tracing'; | ||
| import { createStorage } from 'unstorage'; | ||
| import { withTracing } from 'unstorage/tracing'; | ||
|
|
||
| // Enables the same diagnostics channels a Nitro app publishes, without a Nitro build. | ||
| const storage = withTracing(createStorage()); | ||
|
|
||
| const app = new H3({ plugins: [h3TracingPlugin()] }); | ||
|
|
||
| app.get('/hello/:name', event => `Hello, ${event.context.params.name}!`); | ||
|
|
||
| app.get('/cache', async () => { | ||
| await storage.setItem('cache:key', 'value'); | ||
| return storage.getItem('cache:key'); | ||
| }); | ||
|
|
||
| const server = serve(app, { port: 0, silent: true, plugins: [srvxTracingPlugin()] }); | ||
|
|
||
| await server.ready(); | ||
| sendPortToRunner(new URL(server.url).port); |
115 changes: 115 additions & 0 deletions
115
dev-packages/node-integration-tests/suites/tracing/nitro/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,115 @@ | ||
| import { | ||
| CACHE_HIT, | ||
| CACHE_KEY, | ||
| DB_OPERATION_NAME, | ||
| DB_SYSTEM_NAME, | ||
| HTTP_RESPONSE_STATUS_CODE, | ||
| HTTP_ROUTE, | ||
| SENTRY_OP, | ||
| SENTRY_ORIGIN, | ||
| } from '@sentry/conventions/attributes'; | ||
| import { CACHE_GET, CACHE_PUT, HTTP_SERVER } from '@sentry/conventions/op'; | ||
| import { afterAll, describe, expect, vi } from 'vitest'; | ||
| import { supports } from '../../../utils'; | ||
| import { cleanupChildProcesses, createEsmTests } from '../../../utils/runner'; | ||
|
|
||
| // h3 v2 and srvx are ESM-only and require Node >= 20. | ||
| describe.runIf(supports({ min: 20 }))('nitro integrations', () => { | ||
| afterAll(() => { | ||
| cleanupChildProcesses(); | ||
| }); | ||
|
|
||
| createEsmTests(__dirname, 'scenario.mjs', 'instrument.mjs', (createRunner, test) => { | ||
| test('creates h3 and srvx spans and sets Server-Timing headers', async () => { | ||
| let traceId: string | undefined; | ||
|
|
||
| const runner = createRunner() | ||
| .expect({ | ||
| span: container => { | ||
| const segment = container.items.find(span => span.is_segment); | ||
| const srvxSpan = container.items.find( | ||
| span => span.attributes[SENTRY_ORIGIN]?.value === 'auto.http.nitro.srvx', | ||
| ); | ||
| const h3Span = container.items.find(span => span.attributes[SENTRY_ORIGIN]?.value === 'auto.http.nitro.h3'); | ||
|
|
||
| traceId = segment?.trace_id; | ||
|
|
||
| expect(segment?.name).toBe('GET /hello/:name'); | ||
| expect(segment?.attributes[HTTP_ROUTE]).toEqual({ type: 'string', value: '/hello/:name' }); | ||
|
|
||
| // Bun publishes no `http.server.request.start`, so there the srvx span is the segment itself. | ||
| expect(srvxSpan).toMatchObject({ | ||
| status: 'ok', | ||
| attributes: expect.objectContaining({ | ||
| [SENTRY_OP]: { type: 'string', value: HTTP_SERVER }, | ||
| [HTTP_RESPONSE_STATUS_CODE]: { type: 'integer', value: 200 }, | ||
| }), | ||
| }); | ||
|
|
||
| expect(h3Span).toMatchObject({ | ||
| name: 'GET /hello/:name', | ||
| parent_span_id: srvxSpan?.span_id, | ||
| status: 'ok', | ||
| attributes: expect.objectContaining({ | ||
| [SENTRY_OP]: { type: 'string', value: HTTP_SERVER }, | ||
| [HTTP_ROUTE]: { type: 'string', value: '/hello/:name' }, | ||
| }), | ||
| }); | ||
| }, | ||
| }) | ||
| .start(); | ||
|
|
||
| const port = await vi.waitFor(() => runner.getPort() ?? Promise.reject(new Error('port not ready')), { | ||
| timeout: 30_000, | ||
| }); | ||
| const response = await fetch(`http://localhost:${port}/hello/world`); | ||
| expect(await response.text()).toBe('Hello, world!'); | ||
|
|
||
| await runner.completed(); | ||
|
|
||
| const serverTiming = response.headers.get('server-timing'); | ||
| expect(serverTiming).toContain(`sentry-trace;desc="${traceId}-`); | ||
| expect(serverTiming).toContain('baggage;desc="'); | ||
| }); | ||
|
|
||
| test('creates cache spans for unstorage operations', async () => { | ||
| const runner = createRunner() | ||
| .expect({ | ||
| span: container => { | ||
| const segment = container.items.find(span => span.is_segment); | ||
| const cacheSpans = container.items.filter( | ||
| span => span.attributes[SENTRY_ORIGIN]?.value === 'auto.cache.nitro', | ||
| ); | ||
|
|
||
| expect(segment?.name).toBe('GET /cache'); | ||
| expect(cacheSpans).toEqual([ | ||
| expect.objectContaining({ | ||
| name: 'cache.put', | ||
| status: 'ok', | ||
| attributes: expect.objectContaining({ | ||
| [SENTRY_OP]: { type: 'string', value: CACHE_PUT }, | ||
| [CACHE_KEY]: { type: 'string', value: 'cache:key' }, | ||
| [DB_OPERATION_NAME]: { type: 'string', value: 'setItem' }, | ||
| [DB_SYSTEM_NAME]: { type: 'string', value: 'memory' }, | ||
| }), | ||
| }), | ||
| expect.objectContaining({ | ||
| name: 'cache.get', | ||
| status: 'ok', | ||
| attributes: expect.objectContaining({ | ||
| [SENTRY_OP]: { type: 'string', value: CACHE_GET }, | ||
| [CACHE_KEY]: { type: 'string', value: 'cache:key' }, | ||
| [CACHE_HIT]: { type: 'boolean', value: true }, | ||
| [DB_OPERATION_NAME]: { type: 'string', value: 'getItem' }, | ||
| }), | ||
| }), | ||
| ]); | ||
| }, | ||
| }) | ||
| .start(); | ||
|
|
||
| expect(await runner.makeRequest('get', '/cache')).toBe('value'); | ||
| await runner.completed(); | ||
| }); | ||
| }); | ||
| }); | ||
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
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
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
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
27 changes: 0 additions & 27 deletions
27
packages/nitro/src/runtime/hooks/setServerTimingHeaders.ts
This file was deleted.
Oops, something went wrong.
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 |
|---|---|---|
| @@ -1,11 +1,6 @@ | ||
| import { definePlugin } from 'nitro'; | ||
| import { captureErrorHook } from '../hooks/captureErrorHook'; | ||
| import { captureStorageEvents } from '../hooks/captureStorageEvents'; | ||
| import { captureTracingEvents } from '../hooks/captureTracingEvents'; | ||
|
|
||
| export default definePlugin(nitroApp => { | ||
| nitroApp.hooks.hook('error', captureErrorHook); | ||
|
|
||
| captureTracingEvents(); | ||
| captureStorageEvents(); | ||
| }); |
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.