googleapis / nodejs-logging-bunyan

Node.js client integration between Stackdriver Logging and Bunyan.
https://cloud.google.com/logging/
Apache License 2.0
63 stars 34 forks source link

Large request payload crashing API #736

Open seeARMS opened 7 months ago

seeARMS commented 7 months ago

I am having the exact same issue described here: https://github.com/googleapis/nodejs-logging-bunyan/issues/14

Throughout the codebase, occasionally (and accidentally) I am logging very large entries, and encountering an exception which crashes the server:

Error: 3 INVALID_ARGUMENT: Request payload size exceeds the limit: 10485760 bytes.
  File "/workspace/node_modules/@grpc/grpc-js/build/src/call.js", line 31, col 19, in callErrorFromStatus
    const error = new Error(message);
  File "/workspace/node_modules/@grpc/grpc-js/build/src/client.js", line 192, col 76, in Object.onReceiveStatus
    callProperties.callback((0, call_1.callErrorFromStatus)(status, /*callerStack*/ ''));
  File "/workspace/node_modules/@grpc/grpc-js/build/src/client-interceptors.js", line 360, col 141, in Object.onReceiveStatus
    '{snip} istener === null || listener === void 0 ? void 0 : listener.onReceiveStatus) === null || _b === void 0 ? void 0 : _b.call(listener, status);
  File "/workspace/node_modules/@grpc/grpc-js/build/src/client-interceptors.js", line 323, col 181, in Object.onReceiveStatus
    '{snip} ener === void 0 ? void 0 : interceptingListener.onReceiveStatus) === null || _b === void 0 ? void 0 : _b.call(interceptingListener, status);
  File "/workspace/node_modules/@grpc/grpc-js/build/src/resolving-call.js", line 94, col 78, in <anonymous>
    (_a = this.listener) === null || _a === void 0 ? void 0 : _a.onReceiveStatus(filteredStatus);
  File "node:internal/process/task_queues", line 77, col 11, in process.processTicksAndRejections

I am using the logging-bunyan Express middleware as follows:

  const { logger: gcpLogger, mw } = await lb.express.middleware({
    logName: "api-" + process.env.FLY_APP_NAME,
    level: "debug",
    defaultCallback: (err: any) => {
      try {
        if (err) {
          console.error("Error occured with logger.", err)
          Sentry.captureMessage(err, { level: "error" })
        }
      } catch (_err) {
        console.error("Error occured with logger in try/catch blog.", _err)
        Sentry.captureException(_err)
      }
      return true
    },

    // GCP should truncate the message down to 200kb.
    // See https://github.com/googleapis/nodejs-logging/pull/607.
    maxEntrySize: 200000,
  })

It doesn't look like I'm able to pass in the arguments to this middleware as per the solution described here: https://github.com/googleapis/gax-nodejs/issues/157#issuecomment-345335610

maxEntrySize also doesn't seem to properly truncate.

Ideally, I don't care as much about truncating; I just want to properly handle the exception and not crash the server whenever I inadvertently attempt to log a massive entry.

Environment details

cindy-peng commented 4 months ago

Hi @seeARMS, are you still running into this issue? If the GRPC options didn't work for you, could you also share the parameters you set?

seeARMS commented 4 months ago

Hi @seeARMS, are you still running into this issue? If the GRPC options didn't work for you, could you also share the parameters you set?

Where do I set those gRPC options? I mentioned in the OP that I'm using the logging bunyan Express middleware and the gRPC options don't get passed down

pedroyan commented 3 months ago

I'm also facing this issue with our services, where we see outages on our production servers due to accidental large log entries (which is very annoying :( ). @seeARMS, did you find a way to pass those options on to the Express middleware?

pedroyan commented 3 months ago

Also @cindy-peng - would you like a repro of the issue in a repository somewhere for better inspection?

cindy-peng commented 1 month ago

Hi @pedroyan, are you also using the Express middleware? If so, do you mind also sharing your latest repro? Thank you!