-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(node): Add context info for missing instrumentation #12639
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
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6fa2ccb
feat(node): add context info for missing intrumentation
chargome 49b5cbd
feat: rename package attribute and add isCjs to context
chargome a26d2e9
test: Add e2e test for missing instrumentation
chargome eae9855
feat: update context for missing instrumentation
chargome 83cda6b
ref: Move context create fn to utils
chargome 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
1 change: 1 addition & 0 deletions
1
dev-packages/e2e-tests/test-applications/node-express-incorrect-instrumentation/.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 |
2 changes: 2 additions & 0 deletions
2
dev-packages/e2e-tests/test-applications/node-express-incorrect-instrumentation/.npmrc
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,2 @@ | ||
@sentry:registry=http://127.0.0.1:4873 | ||
@sentry-internal:registry=http://127.0.0.1:4873 |
32 changes: 32 additions & 0 deletions
32
dev-packages/e2e-tests/test-applications/node-express-incorrect-instrumentation/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,32 @@ | ||
{ | ||
"name": "node-express-incorrect-instrumentation", | ||
"version": "1.0.0", | ||
"private": true, | ||
"scripts": { | ||
"build": "tsc", | ||
"start": "node dist/app.js", | ||
"test": "playwright test", | ||
"clean": "npx rimraf node_modules pnpm-lock.yaml", | ||
"test:build": "pnpm install && pnpm build", | ||
"test:assert": "pnpm test" | ||
}, | ||
"dependencies": { | ||
"@sentry/core": "latest || *", | ||
"@sentry/node": "latest || *", | ||
"@sentry/types": "latest || *", | ||
"@trpc/server": "10.45.2", | ||
"@trpc/client": "10.45.2", | ||
"@types/express": "4.17.17", | ||
"@types/node": "18.15.1", | ||
"express": "4.19.2", | ||
"typescript": "4.9.5", | ||
"zod": "~3.22.4" | ||
}, | ||
"devDependencies": { | ||
"@playwright/test": "^1.44.1", | ||
"@sentry-internal/test-utils": "link:../../../test-utils" | ||
}, | ||
"volta": { | ||
"extends": "../../package.json" | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
.../e2e-tests/test-applications/node-express-incorrect-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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { getPlaywrightConfig } from '@sentry-internal/test-utils'; | ||
|
||
const config = getPlaywrightConfig({ | ||
startCommand: `pnpm start`, | ||
}); | ||
|
||
export default config; |
39 changes: 39 additions & 0 deletions
39
dev-packages/e2e-tests/test-applications/node-express-incorrect-instrumentation/src/app.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,39 @@ | ||
declare global { | ||
namespace globalThis { | ||
var transactionIds: string[]; | ||
} | ||
} | ||
|
||
import express from 'express'; | ||
|
||
const app = express(); | ||
const port = 3030; | ||
|
||
// import and init sentry last for missing instrumentation | ||
import * as Sentry from '@sentry/node'; | ||
Sentry.init({ | ||
environment: 'qa', // dynamic sampling bias to keep transactions | ||
dsn: process.env.E2E_TEST_DSN, | ||
includeLocalVariables: true, | ||
debug: !!process.env.DEBUG, | ||
tunnel: `http://localhost:3031/`, // proxy server | ||
tracesSampleRate: 1, | ||
}); | ||
|
||
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
.../e2e-tests/test-applications/node-express-incorrect-instrumentation/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', | ||
}); |
20 changes: 20 additions & 0 deletions
20
...ts/test-applications/node-express-incorrect-instrumentation/tests/instrumentation.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,20 @@ | ||
import { expect, test } from '@playwright/test'; | ||
import { waitForError } from '@sentry-internal/test-utils'; | ||
|
||
test('Sends correct context when instrumentation was set up incorrectly', async ({ baseURL }) => { | ||
const errorEventPromise = waitForError('node-express', 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.contexts?.missing_instrumentation).toEqual({ | ||
package: 'express', | ||
'javascript.is_cjs': true, | ||
}); | ||
}); |
10 changes: 10 additions & 0 deletions
10
...packages/e2e-tests/test-applications/node-express-incorrect-instrumentation/tsconfig.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,10 @@ | ||
{ | ||
"compilerOptions": { | ||
"types": ["node"], | ||
"esModuleInterop": true, | ||
"lib": ["es2018"], | ||
"strict": true, | ||
"outDir": "dist" | ||
}, | ||
"include": ["src/**/*.ts"] | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/node/src/utils/createMissingInstrumentationContext.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,7 @@ | ||
import type { MissingInstrumentationContext } from '@sentry/types'; | ||
import { isCjs } from './commonjs'; | ||
|
||
export const createMissingInstrumentationContext = (pkg: string): MissingInstrumentationContext => ({ | ||
package: pkg, | ||
'javascript.is_cjs': isCjs(), | ||
}); |
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
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.