tslog icon indicating copy to clipboard operation
tslog copied to clipboard

Bug: Logs are blank in Sentry breadcrumbs

Open flybayer opened this issue 5 years ago • 5 comments

Describe the bug

Here's what tslog looks like in Sentry breadcrumbs with pretty logging:

image

This is captured to sentry in Node like this:

  } catch (error) {
    Sentry.captureException(error)
    throw error
  }

Not sure what the core issue is 🤷

Expected behavior Pretty logs would show up correctly

flybayer avatar Jan 09 '21 22:01 flybayer

Update: I'm now using JSON logs but they are still blank in Sentry

flybayer avatar Jan 27 '21 19:01 flybayer

Interesting. Would you share how you integrated Sentry?

This is how I did it (through transports)

    // Sentry
    if (this.logConfig.isSentryEnabled) {
      Sentry.init({
        dsn: this.logConfig.sentryDsn,
        maxBreadcrumbs: this.logConfig.sentryMaxBreadcrumbs,
        debug: this.logConfig.sentryDebug,
        serverName: hostname(),
        tracesSampleRate: this.logConfig.sentryTracesSampleRate,
        environment: process.env.NODE_ENV,
        release: `${process.env.npm_package_name}@${process.env.npm_package_version}`,
        integrations: [
          // enable HTTP calls tracing
          new Sentry.Integrations.Http({ tracing: true })
        ]
      });

      loggerFactory.logger.attachTransport(
        {
          silly: this.logToSentry,
          debug: this.logToSentry,
          trace: this.logToSentry,
          info: this.logToSentry,
          warn: this.logToSentry,
          error: this.logToSentry,
          fatal: this.logToSentry
        },
        this.logConfig.sentryMinLevel
      );
    }

and



  private logToSentry = async (logObject: tslog.ILogObject) => {
    // send only exceptions to Sentry
    logObject?.argumentsArray?.forEach((argument: tslog.IErrorObject) => {
      if (argument.isError === true) {
        Sentry.captureException(argument.nativeError);
      }
    });
  };

terehov avatar Feb 03 '21 12:02 terehov

@terehov I did not use any special integration, am just relying on Sentry's automatic pickup of console.log.

That is definitely interesting, but would be nice if it could just work without that.

flybayer avatar Feb 03 '21 16:02 flybayer

@flybayer Were you able to find a workaround for this? I like and could use @terehov's solution but it is a bit hacky.

amolpatel avatar Mar 16 '22 19:03 amolpatel

In V4 I am going to use consoleper default, rather than Stdout. I believe that should be more compatible with Sentry per default.

terehov avatar Aug 23 '22 19:08 terehov

As mentioned before, V4 uses console per default (can be overwritten though) and is even more flexible and allows overwriting every part of the log processing. Give it a go and let me know if that solves your problem:

  • npm i tslog@next

  • and run it with node --enable-source-maps or for TypeScript node --enable-source-maps --experimental-specifier-resolution=node --no-warnings --loader ts-node/esm

Thank you.

terehov avatar Sep 30 '22 12:09 terehov

V4 is released now, so I'm going to close this issue. Feel free to open a new one if V4 didn't solve it for you.

Here are the docs: tslog.js.org

terehov avatar Nov 15 '22 18:11 terehov