hydra-newmedia / hapi-sentry

A hapi plugin for request error logging to Sentry
MIT License
25 stars 19 forks source link

Zod error in parse request after hapi-sentry upgrade #148

Open gugu opened 8 months ago

gugu commented 8 months ago

Stack trace:

ZodError: [
  {
    "code": "invalid_arguments",
    "argumentsError": {
      "issues": [
        {
          "code": "invalid_type",
          "expected": "function",
          "received": "object",
          "path": [
            0
          ],
          "m...
  File "/app/node_modules/zod/lib/types.js", line 2721, in Object.parseRequest
    throw new ZodError_1.ZodError([makeArgsIssue(args, parsedArgs.error)]);
  File "/app/node_modules/hapi-sentry/index.js", line 73, in <anonymous>
    const sentryEvent = Sentry.Handlers.parseRequest(_sentryEvent, request.raw.req);
  File "/app/node_modules/@sentry/src/eventProcessors.ts", line 37, in <anonymous>
  File "/app/node_modules/@sentry/src/syncpromise.ts", line 61, in SyncPromise
  File "/app/node_modules/@sentry/src/eventProcessors.ts", line 32, in notifyEventProcessors
...
(5 additional frame(s) were not displayed)

Related piece of code:


    Sentry.withScope(scope => { // thus use a temp scope and re-assign it
      scope.addEventProcessor(_sentryEvent => {
        // format a sentry event from the request and triggered event
        const sentryEvent = Sentry.Handlers.parseRequest(_sentryEvent, request.raw.req); // <-- here
        // overwrite events request url if a baseUrl is provided
        if (opts.baseUri) {
          if (opts.baseUri.slice(-1) === '/') opts.baseUri = opts.baseUri.slice(0, -1);
          sentryEvent.request.url = opts.baseUri + request.path;
        }

Related versions in package.json:

{
  "name": "stator-query",
  "version": "1.0.1",
  "description": "",
  "main": "index.js",
  "dependencies": {
    "@hapi/catbox": "^12.1.1",
    "@hapi/catbox-memcached": "^4.0.0",
    "@hapi/hapi": "^21.3.3",
    "@hapi/inert": "^7.1.0",
    "@hapi/vision": "^7.0.3",
    "hapi-auth-jwt2": "^10.5.1",
    "hapi-pino": "^12.1.0",
    "hapi-rate-limit": "^7.1.0",
    "hapi-sentry": "4.0.1-2",
    "hapi-swagger": "^17.2.1",
    ...
  },
  "type": "module",
}

Transitive: zod@3.22.4

fiws commented 8 months ago

Thanks for reporting. Fyi you are using an unstable hapi-sentry version. you can downgrade to 4.0.0 to mitigate this problem.

I would like to fix this tho. Could you share your hapi-sentry config (without the DSN or any other confidential info)?

gugu commented 8 months ago

The error happened both in 4.0.0 when I passed Sentry or Sentry.getClient() object (I use ESM import to import Sentry). Everything is okay if I pass {dsn: "..."} as a sentry object