getsentry / sentry-javascript

Official Sentry SDKs for JavaScript
https://sentry.io
MIT License
7.99k stars 1.57k forks source link

[@sentry/node] AWS lambda + TypeScript + Webpack need help #1947

Closed zorji closed 5 years ago

zorji commented 5 years ago

I am writing an AWS Lambda + Typescript and trying to integrate Sentry to capture the errors but I couldn't make the source show correctly in Sentry.

The source maps files are available at run time. Is it possible to make Sentry read these source maps instead of uploading to Sentry?

For my case, the error stack trace looks like something like this

Error: SentryPlugin (NO); Sentry Integrations (Yes); source-map-support (No); devtools: (inline-source-map) tsc:inlineSourceMap(Yes) Tue Mar 19 2019 13:59:40 GMT+1100 (Australian Eastern Daylight Time)
    at Nested.<anonymous> (/app/serverless/term-discovery/.webpack/service/webpack:/src/Nested.ts:9:11)
    at /app/serverless/term-discovery/.webpack/service/webpack:/handler.ts:56:16
    at /app/serverless/term-discovery/.webpack/service/webpack:/handler.ts:61:11
    at Promise (/.nvm/versions/node/v10.5.0/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:409:30)
    at AwsInvokeLocal.invokeLocalNodeJs (/.nvm/versions/node/v10.5.0/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:363:12)
    at AwsInvokeLocal.invokeLocal (/.nvm/versions/node/v10.5.0/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:137:19)
    at AwsInvokeLocal.tryCatcher (/.nvm/versions/node/v10.5.0/lib/node_modules/serverless/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/.nvm/versions/node/v10.5.0/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (/.nvm/versions/node/v10.5.0/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromiseCtx (/.nvm/versions/node/v10.5.0/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:606:10)
    at _drainQueueStep (/.nvm/versions/node/v10.5.0/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:142:12)
    at _drainQueue (/.nvm/versions/node/v10.5.0/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:131:9)
    at Async._drainQueues (/.nvm/versions/node/v10.5.0/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:147:5)
    at Immediate.Async.drainQueues (/.nvm/versions/node/v10.5.0/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:17:14)
    at runCallback (timers.js:696:18)
    at tryOnImmediate (timers.js:667:5)
    at processImmediate (timers.js:649:5)
    at process.topLevelDomainCallback (domain.js:121:23)

The path is something like webpack:/src/Nested.ts:9:11

Is it possible to make Sentry or override Sentry to read from my local source map?

Thanks

kamilogorek commented 5 years ago

Not as of now, there's open issue for this – https://github.com/getsentry/sentry-javascript/issues/1622

You can create a custom integration that'd do that though.

class ResolveSourceMaps {
  constructor() {
    this.name = "ResolveSourceMaps";
  }

  setupOnce() {
    Sentry.addGlobalEventProcessor(async (event) => {
      if (getCurrentHub().getIntegration(ResolveSourceMaps)) {
        await this.processSourceMaps(event)
      }
      return event;
    });
  }

  async processSourceMaps(event) {
    // do your work here
  }
}

Sentry.init({
  dsn: "https://363a337c11a64611be4845ad6e24f3ac@sentry.io/297378",
  integrations: [new ResolveSourceMaps()]
})

Keep in mind that it can be very costly and you should cache all your I/O reads.

zorji commented 5 years ago

Thanks @kamilogorek