Performance monitoring in Sentry

Hi Folks, How can I implement performance monitoring with Sentry. I went through the strapi-plugin-sentry plugin, but looks like it is used only for tracking errors.

I even tried by implementing this in ./config/plugins.js

sentry: {
    dsn: env('SENTRY_DSN'),
    sendMetadata: true,
    init: {
      integrations: [new Sentry.Integrations.Http({ tracing: true })],
      tracesSampleRate: 1.0,
    },
  },

But, I don’t see any requests being made to sentry.

I created custom middleware in Strapi and sent traces by following Koa | Sentry Documentation

Hi @Sujay_Prabhu would you mind sharing some code on how you have implemented your custom middleware please?

For Strapi v4:

For Strapi v3:

In config/middleware.js

module.exports = {
  settings: {
    sentry: {
      enabled: true,
    },
  },
};

middlewares/sentry/index.js

Sentry.init({...params})

module.exports = (strapi) => {
  return {
    initialize() {
      strapi.app.use(async (ctx, next) => {
        try {
          await next();
        } catch (error) {
          Sentry.captureException(error);
          throw error;
        }
      });
    },
  };
};
1 Like

hi @Sujay_Prabhu, strapi v4 it broke, and in the context request there are no headers for sentry-tracing.
Is there any solution?

My code like that code

Hi @Ahmed_Boghdady
Unfortunately I don’t have solution for this yet. Looks like @strapi/plugin-sentry plugin is the cause of the issue

any one found a solution for this

Find the same issue. While Strapi successfully sends events to Sentry SAAS it sends nothing to self hosted Sentry when I change DSN in config/plugins.js
It seems like it does send something and gets 200 response but there is nothing in Sentry
The code from Strapi logs that should go to Sentry

[2024-02-23 11:11:25.685] error: Some error
Error: Some error
    at /opt/app/src/api/faq-category/middlewares/middleware.js:31:21
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async policiesMiddleware (/opt/node_modules/@strapi/strapi/dist/services/server/policy.js:15:5)
    at async /opt/node_modules/@strapi/strapi/dist/services/server/compose-endpoint.js:27:12
    at async serve (/opt/node_modules/koa-static/index.js:59:5)
    at async returnBodyMiddleware (/opt/node_modules/@strapi/strapi/dist/services/server/compose-endpoint.js:42:18)
    at async policiesMiddleware (/opt/node_modules/@strapi/strapi/dist/services/server/policy.js:15:5)
    at async /opt/node_modules/@strapi/strapi/dist/services/server/compose-endpoint.js:27:12
    at async /opt/node_modules/@strapi/plugin-sentry/dist/server/index.js:31:7
    at async /opt/node_modules/@strapi/strapi/dist/middlewares/body.js:45:9

Can I somehow trace what is the reason of this? There are no any errors in Sentry logs about some errors or similar. Just nothing