Closed
Description
- Review the documentation: https://docs.sentry.io/
- Search for existing issues: https://github.com/getsentry/sentry-javascript/issues
- Use the latest release: https://github.com/getsentry/sentry-javascript/releases
Package + Version
-
@sentry/browser
-
@sentry/node
-
raven-js
-
raven-node
(raven for node) - other:
Version:
4.6.4
Description
I'm having a lot of issues setting request-specific context when using Sentry with Express. As a reference, I took a look at the official Express integration docs, as well as the following issue and PR:
- Docs: https://docs.sentry.io/platforms/node/express/
- Issue: Unable to include tags #1632
- Docs PR: https://github.com/getsentry/sentry-docs/pull/447/files (As an aside, I don't see these latest doc changes published anywhere though they were merged in)
const express = require('express')
const Sentry = require('@sentry/node')
const constants = require('./config/constants')
const api = express()
Sentry.init({
dsn: constants.SENTRY_DSN_KEY,
environment: constants.ENV_CURRENT
})
api.use(Sentry.Handlers.requestHandler())
api.use((req, res, next) => {
console.log('Point A', Sentry.getHubFromCarrier(req))
Sentry.getHubFromCarrier(req).configureScope(scope => {
console.log('Point B')
scope.setTag('test', 'Tag')
scope.setExtra('test', req.path)
})
throw new Error('Request-specific context does not work')
})
api.use(Sentry.Handlers.errorHandler())
api.listen(constants.API_PORT)
Console Output:
Point A
Hub {
version: 3,
stack: [ { client: undefined, scope: [Object] } ] }
Error: Request-specific context does not work
at api.use (api/index.js:21:10)
at Layer.handle [as handle_request] (api/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (api/node_modules/express/lib/router/index.js:317:13)
at api/node_modules/express/lib/router/index.js:284:7
at Function.process_params (api/node_modules/express/lib/router/index.js:335:12)
at next (api/node_modules/express/lib/router/index.js:275:10)
at Domain.<anonymous> (api/node_modules/@sentry/node/dist/handlers.js:161:13)
at Domain.run (domain.js:242:14)
at sentryRequestMiddleware (api/node_modules/@sentry/node/dist/handlers.js:155:15)
at Layer.handle [as handle_request] (api/node_modules/express/lib/router/layer.js:95:5)
Notice from the console output above:
- that
Point B
is never output in the console client
in thestack
of theHub
instance isundefined
- not sure if this is related
Using node 8.14.0
and express 4.16.4
.
Metadata
Metadata
Assignees
Labels
No labels