-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
test(react-router): Finalize instrumentation api e2e coverage #21468
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
Changes from all commits
Commits
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
22 changes: 22 additions & 0 deletions
22
...st-applications/react-router-7-framework-instrumentation/app/routes/performance/redis.tsx
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,22 @@ | ||
| import Redis from 'ioredis'; | ||
| import type { Route } from './+types/redis'; | ||
|
|
||
| const redis = new Redis(); | ||
|
|
||
| export async function loader() { | ||
| const key = 'cache:greeting'; | ||
| await redis.set(key, 'hello from react-router'); | ||
| const value = await redis.get(key); | ||
|
|
||
| return { value }; | ||
| } | ||
|
|
||
| export default function RedisPage({ loaderData }: Route.ComponentProps) { | ||
| const { value } = loaderData; | ||
| return ( | ||
| <div> | ||
| <h1>Redis Page</h1> | ||
| <div id="redis-value">{value}</div> | ||
| </div> | ||
| ); | ||
| } |
12 changes: 12 additions & 0 deletions
12
...s/e2e-tests/test-applications/react-router-7-framework-instrumentation/docker-compose.yml
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,12 @@ | ||
| services: | ||
| redis: | ||
| image: redis:8 | ||
| restart: always | ||
| container_name: e2e-tests-react-router-7-instrumentation-redis | ||
| ports: | ||
| - '6379:6379' | ||
| healthcheck: | ||
| test: ['CMD', 'redis-cli', 'ping'] | ||
| interval: 1s | ||
| timeout: 3s | ||
| retries: 30 |
9 changes: 9 additions & 0 deletions
9
...ges/e2e-tests/test-applications/react-router-7-framework-instrumentation/global-setup.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 { execSync } from 'child_process'; | ||
| import { dirname } from 'path'; | ||
| import { fileURLToPath } from 'url'; | ||
|
|
||
| const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
|
|
||
| export default async function globalSetup() { | ||
| execSync('docker compose up -d --wait', { cwd: __dirname, stdio: 'inherit' }); | ||
| } |
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
13 changes: 9 additions & 4 deletions
13
...2e-tests/test-applications/react-router-7-framework-instrumentation/playwright.config.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 |
|---|---|---|
| @@ -1,8 +1,13 @@ | ||
| import { getPlaywrightConfig } from '@sentry-internal/test-utils'; | ||
| import { fileURLToPath } from 'url'; | ||
|
|
||
| const config = getPlaywrightConfig({ | ||
| startCommand: `PORT=3030 pnpm start`, | ||
| port: 3030, | ||
| }); | ||
| const config = getPlaywrightConfig( | ||
| { | ||
| startCommand: `PORT=3030 pnpm start`, | ||
| port: 3030, | ||
| }, | ||
| // Boot Redis before the tests run, outside the webServer startup-timeout window. | ||
| { globalSetup: fileURLToPath(new URL('./global-setup.mjs', import.meta.url)) }, | ||
| ); | ||
|
|
||
| export default config; |
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
35 changes: 35 additions & 0 deletions
35
...lications/react-router-7-framework-instrumentation/tests/performance/redis.server.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,35 @@ | ||
| import { expect, test } from '@playwright/test'; | ||
| import { waitForTransaction } from '@sentry-internal/test-utils'; | ||
| import { APP_NAME } from '../constants'; | ||
|
|
||
| test.describe('server - redis db spans (instrumentation API)', () => { | ||
| test('OTel db.redis spans nest under the native instrumentation-API http.server transaction', async ({ page }) => { | ||
| const txPromise = waitForTransaction(APP_NAME, async transactionEvent => { | ||
| return ( | ||
| transactionEvent.transaction === 'GET /performance/redis' && | ||
| (transactionEvent.spans?.some(span => span.op === 'db.redis') ?? false) | ||
| ); | ||
| }); | ||
|
|
||
| await page.goto('/performance/redis'); | ||
|
|
||
| const transaction = await txPromise; | ||
|
|
||
| // The server transaction must come from the native instrumentation API (not the legacy handler), | ||
| // proving auto-instrumented OTel spans still share context with the React Router server span. | ||
| expect(transaction.contexts?.trace?.op).toBe('http.server'); | ||
| expect(transaction.contexts?.trace?.origin).toBe('auto.http.react_router.instrumentation_api'); | ||
|
|
||
| const redisSpans = transaction.spans!.filter(span => span.op === 'db.redis'); | ||
|
|
||
| // loader runs SET then GET => at least two redis command spans | ||
| expect(redisSpans.length).toBeGreaterThanOrEqual(2); | ||
| expect(redisSpans.every(span => span.data?.['db.system'] === 'redis')).toBe(true); | ||
| expect(redisSpans.every(span => typeof span.parent_span_id === 'string')).toBe(true); | ||
| expect(redisSpans.some(span => span.data?.['net.peer.port'] === 6379)).toBe(true); | ||
|
|
||
| const statements = redisSpans.map(span => String(span.data?.['db.statement'] ?? '').toLowerCase()); | ||
| expect(statements.some(statement => statement.startsWith('set'))).toBe(true); | ||
| expect(statements.some(statement => statement.startsWith('get'))).toBe(true); | ||
| }); | ||
| }); | ||
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.
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.
Out of scope for this PR but heads-up that
db.statementanddb.systemare deprecated (alsonet.*): https://getsentry.github.io/sentry-conventions/attributes/db