-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(server-utils): Expose channel-based, streamlined fastifyIntegration
#21706
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
mydea
wants to merge
8
commits into
develop
Choose a base branch
from
ref/streamline-fastify-otel-vendored
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
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f91f40a
leftover
mydea 667f0e4
wip
mydea f15c458
WIP
mydea 5997af9
fastify v5
mydea a6845af
no need to add sentry conventions to node package
mydea 2a4b912
fixes
mydea bb07b62
fix deps
mydea 7edd803
skip test on node 18
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
9 changes: 9 additions & 0 deletions
9
dev-packages/node-integration-tests/suites/tracing/fastify/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, | ||
| }); |
44 changes: 44 additions & 0 deletions
44
dev-packages/node-integration-tests/suites/tracing/fastify/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,44 @@ | ||
| import * as Sentry from '@sentry/node'; | ||
| import { sendPortToRunner } from '@sentry-internal/node-integration-tests'; | ||
| import Fastify from 'fastify'; | ||
|
|
||
| const app = Fastify(); | ||
|
|
||
| let port; | ||
|
|
||
| app.get( | ||
| '/test-transaction', | ||
| { | ||
| preHandler: function routePreHandler(_request, _reply, done) { | ||
| done(); | ||
| }, | ||
| }, | ||
| async () => { | ||
| Sentry.startSpan({ name: 'test-span' }, () => { | ||
| Sentry.startSpan({ name: 'child-span' }, () => {}); | ||
| }); | ||
|
|
||
| return {}; | ||
| }, | ||
| ); | ||
|
|
||
| app.get('/test-exception/:id', async request => { | ||
| throw new Error(`This is an exception with id ${request.params.id}`); | ||
| }); | ||
|
|
||
| app.get('/test-inbound-headers/:id', async request => { | ||
| return { headers: request.headers, id: request.params.id }; | ||
| }); | ||
|
|
||
| app.get('/test-outgoing-fetch/:id', async request => { | ||
| const response = await fetch(`http://localhost:${port}/test-inbound-headers/${request.params.id}`); | ||
| return response.json(); | ||
| }); | ||
|
|
||
| const run = async () => { | ||
| await app.listen({ port: 0, host: 'localhost' }); | ||
| port = app.server.address().port; | ||
| sendPortToRunner(port); | ||
| }; | ||
|
|
||
| run(); | ||
98 changes: 98 additions & 0 deletions
98
dev-packages/node-integration-tests/suites/tracing/fastify/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,98 @@ | ||
| import { afterAll, describe, expect } from 'vitest'; | ||
| import { conditionalTest } from '../../../utils'; | ||
| import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner'; | ||
|
|
||
| describe('fastify auto-instrumentation', () => { | ||
| afterAll(() => { | ||
| cleanupChildProcesses(); | ||
| }); | ||
|
|
||
| createEsmAndCjsTests(__dirname, 'scenario.mjs', 'instrument.mjs', (createRunner, test) => { | ||
| test('creates transaction with fastify hook, request-handler and manual spans', async () => { | ||
| const runner = createRunner() | ||
| .expect({ | ||
| transaction: { | ||
| transaction: 'GET /test-transaction', | ||
| spans: expect.arrayContaining([ | ||
| expect.objectContaining({ | ||
| op: 'hook.fastify', | ||
| origin: 'auto.http.otel.fastify', | ||
| data: expect.objectContaining({ | ||
| 'fastify.type': 'hook', | ||
| 'sentry.op': 'hook.fastify', | ||
| 'sentry.origin': 'auto.http.otel.fastify', | ||
| }), | ||
| }), | ||
| expect.objectContaining({ | ||
| op: 'request_handler.fastify', | ||
| origin: 'auto.http.otel.fastify', | ||
| data: expect.objectContaining({ | ||
| 'sentry.op': 'request_handler.fastify', | ||
| 'sentry.origin': 'auto.http.otel.fastify', | ||
| }), | ||
| }), | ||
| expect.objectContaining({ | ||
| description: 'test-span', | ||
| origin: 'manual', | ||
| }), | ||
| expect.objectContaining({ | ||
| description: 'child-span', | ||
| origin: 'manual', | ||
| }), | ||
| ]), | ||
| }, | ||
| }) | ||
| .start(); | ||
| runner.makeRequest('get', '/test-transaction'); | ||
| await runner.completed(); | ||
| }); | ||
|
|
||
| // Fastify v5 only publishes the `tracing:fastify.request.handler:error` diagnostics channel when | ||
| // `tracingChannel(...).hasSubscribers` is truthy. That aggregate getter does not exist on Node 18 | ||
| // (it was added in Node 20), so fastify takes the fast path and never publishes the channel there — | ||
| // making automatic error capture (without `setupFastifyErrorHandler`) impossible on Node 18. | ||
| conditionalTest({ min: 20 })('error capture via diagnostics channel', () => { | ||
| test('captures errors thrown in route handlers', async () => { | ||
| const runner = createRunner() | ||
| .ignore('transaction') | ||
| .expect({ | ||
| event: { | ||
| exception: { | ||
| values: [ | ||
| { | ||
| type: 'Error', | ||
| value: 'This is an exception with id 123', | ||
| mechanism: { | ||
| type: 'auto.function.fastify', | ||
| handled: false, | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| transaction: 'GET /test-exception/:id', | ||
| // The error must be parented to the fastify request span (not the root `http.server` span), | ||
| // so the trace context carries a `parent_span_id`. | ||
| contexts: { | ||
| trace: { | ||
| trace_id: expect.stringMatching(/[a-f0-9]{32}/), | ||
| span_id: expect.stringMatching(/[a-f0-9]{16}/), | ||
| parent_span_id: expect.stringMatching(/[a-f0-9]{16}/), | ||
| }, | ||
| }, | ||
| }, | ||
| }) | ||
| .start(); | ||
| runner.makeRequest('get', '/test-exception/123', { expectError: true }); | ||
| await runner.completed(); | ||
| }); | ||
| }); | ||
|
|
||
| test('propagates trace data to outgoing requests within a request handler', async () => { | ||
| const runner = createRunner().start(); | ||
| const response = await runner.makeRequest<{ headers: Record<string, string> }>('get', '/test-outgoing-fetch/123'); | ||
|
|
||
| expect(response?.headers?.['sentry-trace']).toMatch(/^[a-f0-9]{32}-[a-f0-9]{16}-1$/); | ||
| expect(response?.headers?.['baggage']).toEqual(expect.any(String)); | ||
| }); | ||
| }); | ||
| }); |
7 changes: 0 additions & 7 deletions
7
packages/node/src/integrations/tracing/fastify/fastify-otel/.oxlintrc.json
This file was deleted.
Oops, something went wrong.
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.