Skip to content

"mod.require is not a function" in database tracing integrations #3293

Closed
@sergio-dreamcode

Description

@sergio-dreamcode

Package + Version

  • @sentry/browser
  • @sentry/node
  • raven-js
  • raven-node (raven for node)
  • other: @sentry/serverless

Version:

6.2.1

Description

In the past we reported #2971, that issue was preventing us from upgrading Sentry. With the release of 6.0.4 some weeks ago things started to work like a charm.

Once we were able to upgrade, we added Sentry performance tracing to our applications (frontend and backend) and it worked perfectly, however database tracing was missing. In order to improve this, we added the Postgres tracing integration to the backend. After investigating we found that the same issue from #2971 still is happening in the tracing system, not in the same way as #2971 (it does not crash the library) but prevents Postgres tracing to work. We are using version 6.2.1.

After adding the Postgres tracing integration as the documentation recommends, we noticed that the Postgres tracing was not working and found the next error in our logs:

ERROR Sentry Logger [Error]: Postgres Integration was unable to require `pg` package.

After checking the Postgres integration source (same will happens for all database integrations) I found that it calls to the dynamicRequire util which in turn calls mod.require.

In order to validate that we were having the same error I cloned a local copy of sentry-javascript and added an error log to display the Javascript exception and linked this local copy to our project. These were the logs:

ERROR Sentry Logger [Error]: Postgres Integration was unable to require `pg` package.
ERROR Sentry Logger [Error]: TypeError: mod.require is not a function

The code that I modified to get the TypeError: mod.require is not a function error was in the postgres.ts file:

...
  public setupOnce(_: (callback: EventProcessor) => void, getCurrentHub: () => Hub): void {
    let client: PgClient;

    try {
      const pgModule = dynamicRequire(module, 'pg') as { Client: PgClient };
      client = pgModule.Client;
    } catch (e) {
      logger.error('Postgres Integration was unable to require `pg` package.');
      logger.error(e); // <<<< the line I added to validate
      return;
    }
...

It is important to note that the mod.require error seems to only happen when using Webpack. More details about this issue can be found in #2971 and #2515

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions