-
-
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
33 commits
Select commit
Hold shift + click to select a range
958f29e
add orchestrion plan
mydea bb0dde5
add the plan
mydea 84382f9
Add general utils and exports to node SDK
mydea eae9f19
add mysql example
mydea 4a66d3b
fixes
mydea 41afb5e
fix lint
mydea dbb0728
fix exports
mydea 8b23a86
fix types build
mydea 7fd9293
fix import
mydea 6ed0b6e
better handle sync errors
mydea 0526eed
tests
mydea 5e8c6b8
mysql fixes
mydea 38e3c30
remove unused file
mydea 5c41159
be defensive
mydea 3f60a87
improvements
mydea 331bf67
add custom output
mydea 7ae8297
add some more size limit scenarios
mydea 22127cb
add test app
mydea 2d44bd3
bump transformer plugin
mydea 9be3fee
fixes
mydea 9637aa2
add other test app
mydea 2bee10a
add noExternal
mydea ea834cd
fix and cjs
mydea 2bea275
bump tracing hooks
mydea 41fb2e9
streamline detect
mydea f58a6ed
feat(orchestrion): move into server-utils
isaacs bddf297
fix(test): update node orchestrion tests to match usage
isaacs fbe347a
fix(orchestrion): enable import hook on deno 2.8+
isaacs 50f940b
fix(server-utils): add ./orchestrion shim for submodule export
isaacs 0d08ccc
fix(server-utils): add note about not warning in production
isaacs 20b6ae2
fix(server-utils): add double-load guard to orchestrion import hook
isaacs d7addf6
fix(orchestrion): remove unused submodule paths, fix sourcemaps
isaacs e27b2e9
feat(node): collapse orchestrion opt-in to a single option
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.
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/import ./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; |
72 changes: 72 additions & 0 deletions
72
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,72 @@ | ||
| const Sentry = require('@sentry/node'); | ||
|
|
||
| // The channels are injected by `node --import @sentry/node/import` (see the | ||
| // `start` script); opting in here via `experimentalDiagnosticsChannelInjection` | ||
| // makes the SDK subscribe to them instead of using the OTel instrumentation. | ||
| 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, | ||
| experimentalDiagnosticsChannelInjection: true, | ||
| }); | ||
|
|
||
| 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/.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/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-app", | ||
| "version": "1.0.0", | ||
| "private": true, | ||
| "type": "module", | ||
| "scripts": { | ||
| "start": "node --import ./src/instrument.mjs ./src/app.mjs", | ||
| "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/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.