Skip to content

Sentry 8 Performance set user Context in node express server #14024

@Calion54

Description

@Calion54

Is there an existing issue for this?

How do you use Sentry?

Self-hosted/on-premise

Which SDK are you using?

@sentry/node

SDK Version

8.34.0

Framework Version

Node20 Express4

Link to Sentry event

No response

Reproduction Example/SDK Setup

Sentry.init({
        dsn: sentryConfig.dsn,
        environment: this.configService.env,
        maxBreadcrumbs: 50,
        integrations: [
          nodeProfilingIntegration()
        ],
        tracesSampleRate: 1.0,
        profilesSampleRate: 1.0
      })
      const tags = sentryConfig.tags || {}
      Sentry.setTags(tags)
this.express.use((req, res, next) => {
  Sentry.withIsolationScope(null, (scope) => {
    scope.setUser({ id: 'toto' })
    next()
  })
})

Steps to Reproduce

I want to set a user context for each request in my Express API.

Each request is sent to Sentry's performance monitoring, but I can't find any examples on how to add user context or extra data inside a transaction.

Could you provide an example?

Expected Result

Set user inside each sentry event

Image

Actual Result

Image

Need to increase it

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugPackage: nodeIssues related to the Sentry Node SDK

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions