Sentry-javascript: Not Working with Cloudflare workers: dist.init is not a function

Created on 19 Oct 2018  路  14Comments  路  Source: getsentry/sentry-javascript

Package + Version

  • [x] @sentry/minimal
  • [x] @sentry/browser
  • [x] raven-js

Version:

4.1.1

Description

I'm trying to use Sentry's javascript SDK with cloudflare workers, however I'm getting an error using either @sentry/minimal, @sentry/browser or raven-js.

The code is at available at https://github.com/tutorcruncher/cloudflare-worker and a preview is avilable at https://cloudflareworkers.com/#8dc47c7e9bd4a5463e6495630f82b7e9:https://workers.tutorcruncher.com although I'm not sure how long that will last for.

If the preview has stopped working you should be able to run a new preview with simply yarn && python preview.py.

Uncaught TypeError: dist.init is not a function
    at Module.<anonymous> (worker.js:1863:13)
    at __webpack_require__ (worker.js:20:30)
    at worker.js:84:18
    at worker.js:87:10

I also tried @sentry/browser but an error The 'referrerPolicy' field on 'RequestInitializerDict' is not implemented. which makes sense. raven-js gave yet another error.

Most helpful comment

Just to confirm, personally I don't need this anymore as I spent Friday afternoon ignoring my real work and building my own sentry logger which plays nicely with web worker's event.waitUntil() and even uploads source maps to sentry so I get full traces.

All 14 comments

I'm aware of https://blog.cloudflare.com/dogfooding-edge-workers/ but I was hoping to use the standard sentry sdk.

I've updated the code to log errors to sentry directly and that's working fine.

If you want to replicate the error you'll need to use this commit which actually uses raven-js and edit from there, I don't have a commit with @sentry/minimal or @sentry/browser I'm afraid.

How does your import / require statement look like of @sentry/browser?

I think you mean @sentry/minimal? (@sentry/browser failed with an understandable error about referrerPolicy)

Here's my code:

import * as Sentry from '@sentry/minimal'
import {Request, router} from './src/utils'
import test from './src/test'

Sentry.init({dsn: process.env.RAVEN_DSN})

const routes = {
  default: test
}

async function handle_request(raw_request) {
  const request = new Request(raw_request)
  await request.prepare()
  Sentry.captureMessage(`request ${request.url}`, {extra: {request: request.debug_info()}})
  try {
    const handler = router(routes)
    return handler(event.request)
  } catch (e) {
    Sentry.captureException(e)
  }
}

addEventListener('fetch', event => {
  event.respondWith(handle_request(event.request))
})

And here's a branch with that code on it.

And here's a worker preview with that code running.

Just to confirm, personally I don't need this anymore as I spent Friday afternoon ignoring my real work and building my own sentry logger which plays nicely with web worker's event.waitUntil() and even uploads source maps to sentry so I get full traces.

(and let's me include extra in captureMessage #1666 :wink:)

You can write your own transport class and still use Sentry.

would that solve the dist.init is not a function problem?

No, but I referrerPolicy error, I think.
tbh I am not sure where this is coming from though.

The initially reported issue is resolved I guess, so let me close it. Feel free to ping me if this still needs to be reopened. Cheers!

@samuelcolvin - this project might be of interest to you: https://github.com/tlianza/pigeon - I wrote it while trying to solve what sounds like the same problem.

@tlianza nicely done! Love that someone used our custom client/backend architecture :)
btw. name Raven comes from https://liquipedia.net/starcraft2/Raven_(Legacy_of_the_Void) (same as Sentry itself https://liquipedia.net/starcraft2/Sentry_(Legacy_of_the_Void)) but I love Pidgeon! 馃槃

I can fix the referrerPolicy issue by commenting out that line in fetch call. There are still various issues with the SDK on Workers though.

FYI I'd recommend this library these days: https://github.com/robertcepa/toucan-js

Was this page helpful?
0 / 5 - 0 ratings