Configuration
NPM VersionNPM Version

Configuration

Once the plugin is installed, you have to add it to your project configuration. To do so here are the steps

1

Configure your sentry account to get your dsn and api token (optional)

2

Go to your medusa-config.js

3

Check that the variables are set with the appropriate values

const SentryDSN = process.env.SENTRY_DSN || ""
const SentryApiToken = process.env.SENTRY_API_TOKEN || ""

Then in your plugins collections, you can just add the plugin as follow

{
  resolve: `medusa-plugin-sentry`,
  options: {
    dsn: SentryDSN,
    // apiToken: SentryApiToken,
    integrations: (router, Sentry, Tracing) => {
      return [
        new Sentry.Integrations.Http({ tracing: true }),
        new Tracing.Integrations.Express({ router }),
      ];
    },
    tracesSampleRate: 1.0,
    // webHookOptions: {
    //   path: "/sentry/webhook",
    //   secret: "__YOUR_SECRET__",
    //   emitOnIssue: true,
    //   emitOnError: false,
    //   emitOnComment: true,
    //   emitOnEventOrMetricAlert: true,
    //   emitOnInstallOrDeleted: false,
    // }
  },
},

The options that are commented are optional. If you want to use the webHook options, then the apiToken is required

You can see all the options available here: NodeOptions (opens in a new tab)

And here are the plugin configuration typings to help you see what is available

// Web hook options
export type SentryWebHookOptions = {
    path: string;
    secret: string;
    emitOnIssue?: boolean | ((container: unknown, data: SentryWebHookData) => Promise<void>);
    emitOnError?: boolean | ((container: unknown, data: SentryWebHookData) => Promise<void>);
    emitOnComment?: boolean | ((container: unknown, data: SentryWebHookData) => Promise<void>);
    emitOnEventOrMetricAlert?: boolean | ((container: unknown, data: SentryWebHookData) => Promise<void>);
    emitOnInstallOrDeleted?: boolean | ((container: unknown, data: SentryWebHookData) => Promise<void>);
};
 
// Sentry options at the top level
export type SentryOptions = Omit<NodeOptions, 'integrations'> & {
    integrations: Integration[] | ((router: Router, sentry: typeof Sentry, tracing: typeof Tracing) => Integration[]);
    requestHandlerOptions?: RequestHandlerOptions;
    enableRequestHandler?: boolean;
    enableTracing?: boolean;
    webHookOptions?: SentryWebHookOptions,
};

With this configuration, you should start to see the requests arriving to your sentry dashboard and start to monitor your api.