Skip to content

[Feature Request] Expose Request Scope in Express Integration #4607

Description

@derN3rd

Hey there,

I've been looking around the issues here for quite some time, but I only find some dirty work-arounds or solution where you would need to rewrite half of your application to have access to the scope inside of middlewares or route handlers.

I want to enrich all Sentry events based on the request they are thrown/reported in and not globally set some values that get changed by other async requests on the same server.

e.g.

  • Adding a client version (custom header value) as a tag to the scope
  • Using scope.setExtras in a request that is causing weird issues and we want to debug (without wrapping everything inside of Sentry.withScope and try/catch

Afaik there is nothing yet like req.sentryScope, but it seems "relatively easy" to just add req.sentryScope = scope before this line.

If so, it should help people that are having issues with async scopes inside their express apps.

Do you see any downsides or problems with the described solution?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions