Skip to content

Document how to use SDK for Node.js Server without ExpressΒ #7783

Open
@mjomble

Description

@mjomble

Core or SDK?

Platform/SDK

Which part? Which one?

Node.js

Description

The Distributed Tracing for Node.js page says:

If you're using version 7.58.0 or above of our Node SDK and have the HTTP integration set up, distributed tracing will work out of the box.
...
If you're using express or an express-compatible framework, you'll also need to use Sentry middleware

The documentation doesn't clarify what I should do if I'm not using express or an express-compatible framework.

A naive conclusion from the wording would be that extra steps are only needed when using express and everything just works out of the box if you're not using it.

But technically, that wouldn't make much sense and, as expected, is not the case.

Suggested Solution

Ideally there would be clear instructions for how to add code that's equivalent to the express middleware into a vanilla Node.js server, e.g.

http.createServer((req, res) => {
    Sentry.something(req, res, async () => {
        // your regular request handling code here
    })
})

Since there's no req.body in vanilla and the stream can be read only once, we might need something like Sentry.captureRequestBody(body) that needs to be called separately.

Alternatively, if supporting vanilla Node.js is too difficult, the documentation could at least be clear that this is not officially supported. And that one could read the source of the express handlers and try to build something like that into their own server. At least that's what I ended up doing πŸ˜„

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions