Skip to content

[Express] Debugging where requests go #5695

Description

@pquerner

Is there an existing issue for this?

How do you use Sentry?

Self-hosted/on-premise

Which package are you using?

@sentry/node

SDK Version

7.12.1

Framework Version

express 4.18.1

Link to Sentry event

No response

Steps to Reproduce

I have a API created with express, and I want to integrate sentry into this so I can make performance checks for routes (how often are routes called, what is the request, what is the response) and I thought of using Sentry for that.

Right now my Sentry instance (Sentry 22.9.0.dev0 724ecd2) runs locally via Docker.

I am trying to integrate Sentry like this:

import express from 'express';
import * as bodyParser from 'body-parser';

import * as Sentry from "@sentry/node";
import "@sentry/tracing";
import {Integrations} from "@sentry/tracing";
import * as SentryUtils from '@sentry/utils';
import { RewriteFrames } from "@sentry/integrations";

const app = App.expressInstance; //express.Application
            Sentry.init({
                dsn: process.env.SENTRY_DSN,
                environment: process.env.ENV,
                debug: true,
                attachStacktrace: true,
                beforeSend(event) {
                    console.log(event);
                    return event;
                },
                integrations: [
                    new RewriteFrames({
                        root: process.cwd(),
                    }),
                    new Sentry.Integrations.Http({ tracing: true, breadcrumbs: true }),
                    new Integrations.Express({
                        app,
                    }),
                ],
                tracesSampleRate: 1.0,
            });

            App.expressInstance.use(Sentry.Handlers.requestHandler() as express.RequestHandler);
            App.expressInstance.use(Sentry.Handlers.tracingHandler());
            console.log("Sentry enabled");

I can see debugging logs like this in my console:

App listening on the port 5000
Sentry Logger [log]: [Tracing] starting http.server transaction - POST /cart
Sentry Logger [log]: [Tracing] Starting 'express.middleware.use' span on transaction 'POST /cart' (82ce398e82749a13).
Sentry Logger [log]: [Tracing] Finishing 'express.middleware.use' span on transaction 'POST /cart' (82ce398e82749a13).
Sentry Logger [log]: [Tracing] Starting 'http.client' span on transaction 'POST /cart' (82ce398e82749a13).
Sentry Logger [log]: [Tracing] Adding sentry-trace header 12fddcbf9f5141279de11c25c337ea4a-a8eb4b81bbd54870-1 to outgoing request to "https://snip": 
Sentry Logger [log]: [Tracing] Finishing 'http.client' span on transaction 'POST /cart' (82ce398e82749a13).
Sentry Logger [log]: [Tracing] Finishing http.server transaction: POST /cart.

However I have no events of it in my Sentry WebUI.

How can I check if requests (to Sentry) actually get sent?

Expected Result

See any results in Sentry WebUI > Performance

Actual Result

No results in Sentry WebUI > Performance

Activity

  1. pquerner commented on Sep 5, 2022

    @pquerner
    Author
    const transaction = Sentry.startTransaction({
      op: "test",
      name: "My First Test Transaction",
    });
    
    setTimeout(() => {
      try {
        foo();
      } catch (e) {
        Sentry.captureException(e);
      } finally {
        transaction.finish();
      }
    }, 99);
    

    Having a verify transaction like this (like recommended from the Docs) used to show this transaction in the Sentry WebUI.

    Screenshot 2022-09-05 at 17 45 35

    It did this morning. Running the code again, does not produce it anymore. (Might be something because I tinkered with the init call)

  2. pquerner commented on Sep 6, 2022

    @pquerner
    Author

    Fixed it. I had some other app listening on the same port (9000) and therefore no issues/reports got sent.

    Still, can this behaviour be reported back to the developer somehow?

  3. AbhiPrasad commented on Sep 6, 2022

    @AbhiPrasad
    Contributor

    Hey - glad to see you sorted out the issue. Is there something in particular you'd like to see reported back (any kind of specific info)?

  4. locked and limited conversation to collaborators on Sep 6, 2022
  5. converted this issue into a discussion #5698 on Sep 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions