-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
WIP: POC to use orchestrion-js for instrumentation #20900
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
Open
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
1c97b68
add orchestrion plan
mydea 2c73b3f
add the plan
mydea 5a326f5
Add general utils and exports to node SDK
mydea 0245e9c
add mysql example
mydea 273d88f
fixes
mydea 94994c9
fix lint
mydea f93b1c7
fix exports
mydea 6c6b27f
fix types build
mydea 386fbb7
fix import
mydea 731a2fd
better handle sync errors
mydea fc32803
tests
mydea 0f90775
mysql fixes
mydea 28b5d80
remove unused file
mydea 581ea31
be defensive
mydea aab44be
improvements
mydea cf95d48
add custom output
mydea d2f0ef4
add some more size limit scenarios
mydea 390fafd
add test app
mydea 1b6c939
bump transformer plugin
mydea 9497725
fixes
mydea 17c095e
add other test app
mydea dfbfb8c
add noExternal
mydea 7f80b79
fix and cjs
mydea 0738034
bump tracing hooks
mydea 09f432a
streamline detect
mydea 7fe9763
feat(orchestrion): move into server-utils
isaacs aa80fbb
fix(test): update node orchestrion tests to match usage
isaacs 3607d00
fix(orchestrion): enable import hook on deno 2.8+
isaacs b5aec2f
fix(server-utils): add ./orchestrion shim for submodule export
isaacs 541e7fc
fix(server-utils): add note about not warning in production
isaacs eb983dc
fix(server-utils): add double-load guard to orchestrion import hook
isaacs 7b69e3b
fix(orchestrion): remove unused submodule paths, fix sourcemaps
isaacs 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
Large diffs are not rendered by default.
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
1 change: 1 addition & 0 deletions
1
dev-packages/e2e-tests/test-applications/node-express-orchestrion-cjs/.gitignore
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 @@ | ||
| dist |
26 changes: 26 additions & 0 deletions
26
dev-packages/e2e-tests/test-applications/node-express-orchestrion-cjs/package.json
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,26 @@ | ||
| { | ||
| "name": "node-express-orchestrion-cjs-app", | ||
| "version": "1.0.0", | ||
| "private": true, | ||
| "type": "commonjs", | ||
| "scripts": { | ||
| "start": "node --import @sentry/node/orchestrion ./src/app.js", | ||
| "test": "playwright test", | ||
| "clean": "npx rimraf node_modules pnpm-lock.yaml dist", | ||
| "test:build": "pnpm install", | ||
| "test:assert": "pnpm test" | ||
| }, | ||
| "dependencies": { | ||
| "@sentry/node": "file:../../packed/sentry-node-packed.tgz", | ||
| "express": "^5.1.0", | ||
| "mysql": "2.18.1" | ||
| }, | ||
| "devDependencies": { | ||
| "@playwright/test": "~1.56.0", | ||
| "@sentry-internal/test-utils": "link:../../../test-utils", | ||
| "@sentry/core": "file:../../packed/sentry-core-packed.tgz" | ||
| }, | ||
| "volta": { | ||
| "extends": "../../package.json" | ||
| } | ||
| } |
7 changes: 7 additions & 0 deletions
7
dev-packages/e2e-tests/test-applications/node-express-orchestrion-cjs/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 |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import { getPlaywrightConfig } from '@sentry-internal/test-utils'; | ||
|
|
||
| const config = getPlaywrightConfig({ | ||
| startCommand: `pnpm start`, | ||
| }); | ||
|
|
||
| export default config; |
71 changes: 71 additions & 0 deletions
71
dev-packages/e2e-tests/test-applications/node-express-orchestrion-cjs/src/app.js
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,71 @@ | ||
| const Sentry = require('@sentry/node'); | ||
|
|
||
| const client = Sentry.init({ | ||
| environment: 'qa', // dynamic sampling bias to keep transactions | ||
| dsn: process.env.E2E_TEST_DSN, | ||
| debug: !!process.env.DEBUG, | ||
| tunnel: `http://localhost:3031/`, // proxy server | ||
| tracesSampleRate: 1, | ||
| _experimentalUseOrchestrion: true, | ||
| }); | ||
|
|
||
| Sentry._experimentalSetupOrchestrion(client); | ||
|
|
||
| const express = require('express'); | ||
| const mysql = require('mysql'); | ||
|
|
||
| const connection = mysql.createConnection({ | ||
| user: 'root', | ||
| password: 'docker', | ||
| }); | ||
|
|
||
| const app = express(); | ||
| const port = 3030; | ||
|
|
||
| app.get('/test-success', function (req, res) { | ||
| res.send({ version: 'v1' }); | ||
| }); | ||
|
|
||
| app.get('/test-param/:param', function (req, res) { | ||
| res.send({ paramWas: req.params.param }); | ||
| }); | ||
|
|
||
| app.get('/test-mysql', function (req, res) { | ||
| connection.query('SELECT 1 + 1 AS solution', function () { | ||
| connection.query('SELECT NOW()', ['1', '2'], () => { | ||
| res.send({ status: 'ok' }); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| app.get('/test-transaction', function (_req, res) { | ||
| Sentry.startSpan({ name: 'test-span' }, () => undefined); | ||
|
|
||
| res.send({ status: 'ok' }); | ||
| }); | ||
|
|
||
| app.get('/test-error', async function (req, res) { | ||
| const exceptionId = Sentry.captureException(new Error('This is an error')); | ||
|
|
||
| await Sentry.flush(2000); | ||
|
|
||
| res.send({ exceptionId }); | ||
| }); | ||
|
|
||
| app.get('/test-exception/:id', function (req, _res) { | ||
| throw new Error(`This is an exception with id ${req.params.id}`); | ||
| }); | ||
|
|
||
| Sentry.setupExpressErrorHandler(app); | ||
|
|
||
| // @ts-ignore | ||
| app.use(function onError(err, req, res, next) { | ||
| // The error id is attached to `res.sentry` to be returned | ||
| // and optionally displayed to the user for support. | ||
| res.statusCode = 500; | ||
| res.end(res.sentry + '\n'); | ||
| }); | ||
|
|
||
| app.listen(port, () => { | ||
| console.log(`Example app listening on port ${port}`); | ||
| }); | ||
6 changes: 6 additions & 0 deletions
6
dev-packages/e2e-tests/test-applications/node-express-orchestrion-cjs/start-event-proxy.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,6 @@ | ||
| import { startEventProxyServer } from '@sentry-internal/test-utils'; | ||
|
|
||
| startEventProxyServer({ | ||
| port: 3031, | ||
| proxyServerName: 'node-express-orchestrion-cjs', | ||
| }); |
29 changes: 29 additions & 0 deletions
29
dev-packages/e2e-tests/test-applications/node-express-orchestrion-cjs/tests/errors.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,29 @@ | ||
| import { expect, test } from '@playwright/test'; | ||
| import { waitForError } from '@sentry-internal/test-utils'; | ||
|
|
||
| test('Sends correct error event', async ({ baseURL }) => { | ||
| const errorEventPromise = waitForError('node-express-orchestrion-cjs', event => { | ||
| return !event.type && event.exception?.values?.[0]?.value === 'This is an exception with id 123'; | ||
| }); | ||
|
|
||
| await fetch(`${baseURL}/test-exception/123`); | ||
|
|
||
| const errorEvent = await errorEventPromise; | ||
|
|
||
| expect(errorEvent.exception?.values).toHaveLength(1); | ||
| expect(errorEvent.exception?.values?.[0]?.value).toBe('This is an exception with id 123'); | ||
|
|
||
| expect(errorEvent.request).toEqual({ | ||
| method: 'GET', | ||
| cookies: {}, | ||
| headers: expect.any(Object), | ||
| url: 'http://localhost:3030/test-exception/123', | ||
| }); | ||
|
|
||
| expect(errorEvent.transaction).toEqual('GET /test-exception/:id'); | ||
|
|
||
| expect(errorEvent.contexts?.trace).toEqual({ | ||
| trace_id: expect.stringMatching(/[a-f0-9]{32}/), | ||
| span_id: expect.stringMatching(/[a-f0-9]{16}/), | ||
| }); | ||
| }); |
154 changes: 154 additions & 0 deletions
154
...kages/e2e-tests/test-applications/node-express-orchestrion-cjs/tests/transactions.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,154 @@ | ||
| import { expect, test } from '@playwright/test'; | ||
| import { waitForTransaction } from '@sentry-internal/test-utils'; | ||
|
|
||
| test('Sends an API route transaction', async ({ baseURL }) => { | ||
| const pageloadTransactionEventPromise = waitForTransaction('node-express-orchestrion-cjs', transactionEvent => { | ||
| return ( | ||
| transactionEvent?.contexts?.trace?.op === 'http.server' && | ||
| transactionEvent?.transaction === 'GET /test-transaction' | ||
| ); | ||
| }); | ||
|
|
||
| await fetch(`${baseURL}/test-transaction`); | ||
|
|
||
| const transactionEvent = await pageloadTransactionEventPromise; | ||
|
|
||
| expect(transactionEvent.contexts?.trace).toEqual({ | ||
| data: { | ||
| 'sentry.source': 'route', | ||
| 'sentry.origin': 'auto.http.otel.http', | ||
| 'sentry.op': 'http.server', | ||
| 'sentry.sample_rate': 1, | ||
| url: 'http://localhost:3030/test-transaction', | ||
| 'otel.kind': 'SERVER', | ||
| 'http.response.status_code': 200, | ||
| 'http.url': 'http://localhost:3030/test-transaction', | ||
| 'http.host': 'localhost:3030', | ||
| 'net.host.name': 'localhost', | ||
| 'http.method': 'GET', | ||
| 'http.scheme': 'http', | ||
| 'http.target': '/test-transaction', | ||
| 'http.user_agent': 'node', | ||
| 'http.flavor': '1.1', | ||
| 'net.transport': 'ip_tcp', | ||
| 'net.host.ip': expect.any(String), | ||
| 'net.host.port': expect.any(Number), | ||
| 'net.peer.ip': expect.any(String), | ||
| 'net.peer.port': expect.any(Number), | ||
| 'http.status_code': 200, | ||
| 'http.status_text': 'OK', | ||
| 'http.route': '/test-transaction', | ||
| 'http.request.header.accept': '*/*', | ||
| 'http.request.header.accept_encoding': 'gzip, deflate', | ||
| 'http.request.header.accept_language': '*', | ||
| 'http.request.header.connection': 'keep-alive', | ||
| 'http.request.header.host': expect.any(String), | ||
| 'http.request.header.sec_fetch_mode': 'cors', | ||
| 'http.request.header.user_agent': 'node', | ||
| }, | ||
| op: 'http.server', | ||
| span_id: expect.stringMatching(/[a-f0-9]{16}/), | ||
| status: 'ok', | ||
| trace_id: expect.stringMatching(/[a-f0-9]{32}/), | ||
| origin: 'auto.http.otel.http', | ||
| }); | ||
|
|
||
| expect(transactionEvent.contexts?.response).toEqual({ | ||
| status_code: 200, | ||
| }); | ||
|
|
||
| expect(transactionEvent).toEqual( | ||
| expect.objectContaining({ | ||
| transaction: 'GET /test-transaction', | ||
| type: 'transaction', | ||
| transaction_info: { | ||
| source: 'route', | ||
| }, | ||
| }), | ||
| ); | ||
|
|
||
| const spans = transactionEvent.spans || []; | ||
|
|
||
| // Manually started span | ||
| expect(spans).toContainEqual({ | ||
| data: { 'sentry.origin': 'manual' }, | ||
| description: 'test-span', | ||
| origin: 'manual', | ||
| parent_span_id: expect.stringMatching(/[a-f0-9]{16}/), | ||
| span_id: expect.stringMatching(/[a-f0-9]{16}/), | ||
| start_timestamp: expect.any(Number), | ||
| status: 'ok', | ||
| timestamp: expect.any(Number), | ||
| trace_id: expect.stringMatching(/[a-f0-9]{32}/), | ||
| }); | ||
|
|
||
| // auto instrumented span | ||
| expect(spans).toContainEqual({ | ||
| data: { | ||
| 'sentry.origin': 'auto.http.express', | ||
| 'sentry.op': 'request_handler.express', | ||
| 'http.route': '/test-transaction', | ||
| 'express.name': '/test-transaction', | ||
| 'express.type': 'request_handler', | ||
| }, | ||
| description: '/test-transaction', | ||
| op: 'request_handler.express', | ||
| origin: 'auto.http.express', | ||
| parent_span_id: expect.stringMatching(/[a-f0-9]{16}/), | ||
| span_id: expect.stringMatching(/[a-f0-9]{16}/), | ||
| start_timestamp: expect.any(Number), | ||
| status: 'ok', | ||
| timestamp: expect.any(Number), | ||
| trace_id: expect.stringMatching(/[a-f0-9]{32}/), | ||
| }); | ||
| }); | ||
|
|
||
| test('Sends an API route transaction for an errored route', async ({ baseURL }) => { | ||
| const transactionEventPromise = waitForTransaction('node-express-orchestrion-cjs', transactionEvent => { | ||
| return ( | ||
| transactionEvent.contexts?.trace?.op === 'http.server' && | ||
| transactionEvent.transaction === 'GET /test-exception/:id' && | ||
| transactionEvent.request?.url === 'http://localhost:3030/test-exception/777' | ||
| ); | ||
| }); | ||
|
|
||
| await fetch(`${baseURL}/test-exception/777`); | ||
|
|
||
| const transactionEvent = await transactionEventPromise; | ||
|
|
||
| expect(transactionEvent.contexts?.trace?.op).toEqual('http.server'); | ||
| expect(transactionEvent.transaction).toEqual('GET /test-exception/:id'); | ||
| expect(transactionEvent.contexts?.trace?.status).toEqual('internal_error'); | ||
| expect(transactionEvent.contexts?.trace?.data?.['http.status_code']).toEqual(500); | ||
| }); | ||
|
|
||
| test('Instruments MySQL via Orchestrion', async ({ baseURL }) => { | ||
| const transactionEventPromise = waitForTransaction('node-express-orchestrion-cjs', transactionEvent => { | ||
| return transactionEvent.contexts?.trace?.op === 'http.server' && transactionEvent.transaction === 'GET /test-mysql'; | ||
| }); | ||
|
|
||
| await fetch(`${baseURL}/test-mysql`); | ||
|
|
||
| const transactionEvent = await transactionEventPromise; | ||
|
|
||
| expect(transactionEvent.contexts?.trace?.op).toEqual('http.server'); | ||
| expect(transactionEvent.transaction).toEqual('GET /test-mysql'); | ||
| expect(transactionEvent.contexts?.trace?.status).toEqual('ok'); | ||
| expect(transactionEvent.contexts?.trace?.data?.['http.status_code']).toEqual(200); | ||
|
|
||
| const spans = transactionEvent.spans || []; | ||
| expect(spans).toContainEqual( | ||
| expect.objectContaining({ | ||
| op: 'db', | ||
| origin: 'auto.db.orchestrion.mysql', | ||
| description: 'SELECT 1 + 1 AS solution', | ||
| }), | ||
| ); | ||
| expect(spans).toContainEqual( | ||
| expect.objectContaining({ | ||
| op: 'db', | ||
| origin: 'auto.db.orchestrion.mysql', | ||
| description: 'SELECT NOW()', | ||
| }), | ||
| ); | ||
| }); |
1 change: 1 addition & 0 deletions
1
dev-packages/e2e-tests/test-applications/node-express-orchestrion-vite/.gitignore
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 @@ | ||
| dist |
34 changes: 34 additions & 0 deletions
34
dev-packages/e2e-tests/test-applications/node-express-orchestrion-vite/package.json
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,34 @@ | ||
| { | ||
| "name": "node-express-orchestrion-vite-app", | ||
| "version": "1.0.0", | ||
| "private": true, | ||
| "type": "module", | ||
| "scripts": { | ||
| "build": "vite build", | ||
| "start": "node --import ./dist/instrument.js ./dist/app.js", | ||
| "test": "playwright test", | ||
| "clean": "npx rimraf node_modules pnpm-lock.yaml dist", | ||
| "test:build": "pnpm install && pnpm build", | ||
| "test:assert": "pnpm test" | ||
| }, | ||
| "dependencies": { | ||
| "@sentry/node": "file:../../packed/sentry-node-packed.tgz", | ||
| "@types/express": "^4.17.21", | ||
| "@types/node": "^18.19.1", | ||
| "express": "^5.1.0", | ||
| "mysql": "2.18.1", | ||
| "typescript": "~5.0.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@playwright/test": "~1.56.0", | ||
| "@sentry-internal/test-utils": "link:../../../test-utils", | ||
| "@sentry/core": "file:../../packed/sentry-core-packed.tgz", | ||
| "vite": "^5.4.11" | ||
| }, | ||
| "resolutions": { | ||
| "@types/qs": "6.9.17" | ||
| }, | ||
| "volta": { | ||
| "extends": "../../package.json" | ||
| } | ||
| } |
7 changes: 7 additions & 0 deletions
7
dev-packages/e2e-tests/test-applications/node-express-orchestrion-vite/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 |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import { getPlaywrightConfig } from '@sentry-internal/test-utils'; | ||
|
|
||
| const config = getPlaywrightConfig({ | ||
| startCommand: `pnpm start`, | ||
| }); | ||
|
|
||
| export default config; |
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.