Skip to content

Not Working with Cloudflare workers: dist.init is not a function #1665

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
3 tasks done
samuelcolvin opened this issue Oct 19, 2018 · 14 comments
Closed
3 tasks done

Not Working with Cloudflare workers: dist.init is not a function #1665

samuelcolvin opened this issue Oct 19, 2018 · 14 comments

Comments

@samuelcolvin
Copy link

samuelcolvin commented Oct 19, 2018

Package + Version

  • @sentry/minimal
  • @sentry/browser
  • 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.

@samuelcolvin
Copy link
Author

samuelcolvin commented Oct 19, 2018

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

@samuelcolvin
Copy link
Author

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.

@HazAT
Copy link
Member

HazAT commented Oct 22, 2018

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

@samuelcolvin
Copy link
Author

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.

@samuelcolvin
Copy link
Author

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.

@samuelcolvin
Copy link
Author

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

@HazAT
Copy link
Member

HazAT commented Oct 22, 2018

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

@samuelcolvin
Copy link
Author

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

@HazAT
Copy link
Member

HazAT commented Oct 22, 2018

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

@kamilogorek
Copy link
Contributor

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!

raphaelschwinger added a commit to raphaelschwinger/sentry-javascript that referenced this issue Aug 27, 2019
To handle errors occuring offline in JavaScript this integration saves
them in a queue and processes these queued up errors when back online.
As a storage API localForage (https://github.com/localForage/localForage)
is used. A new function listens to the 'online' event to start draining
the queue.

I am missing correct error handling and tests. Also Im not sure about
the correct way to include the interation to sdk.ts.
Building .min and .es6 files is also not working with 'yarn build'.
Minifing with uglyfy works.

Thanks especially to @kamilogorek and @	seromenho

Resolves: getsentry#1633
See also: getsentry#1665 getsentry#279
raphaelschwinger added a commit to raphaelschwinger/sentry-javascript that referenced this issue Aug 27, 2019
To handle errors occuring offline in JavaScript this integration saves
them in a queue and processes these queued up errors when back online.
As a storage API localForage (https://github.com/localForage/localForage)
is used. A new function listens to the 'online' event to start draining
the queue.

I am missing correct error handling and tests. Also I am not sure about
the correct way to include the interation to sdk.ts.
Building .min and .es6 files is also not working with 'yarn build'.
Minifing with uglify-js works.

Thanks especially to @kamilogorek and @	seromenho

Resolves: getsentry#1633
See also: getsentry#1665 getsentry#279
raphaelschwinger added a commit to raphaelschwinger/sentry-javascript that referenced this issue Aug 27, 2019
To handle errors occuring offline in JavaScript this integration saves
them in a queue and processes these queued up errors when back online.
As a storage API localForage (https://github.com/localForage/localForage)
is used. A new function listens to the 'online' event to start draining
the queue.

I am missing correct error handling and tests. Also I am not sure about
the correct way to include the interation to sdk.ts.
Building .min and .es6 files is also not working with 'yarn build'.
Minifing with uglify-js works.

Thanks especially to @kamilogorek and @	seromenho

Resolves: getsentry#1633
See also: getsentry#1665 getsentry#279
@tlianza
Copy link

tlianza commented Nov 10, 2019

@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.

@kamilogorek
Copy link
Contributor

kamilogorek commented Nov 11, 2019

@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! 😄

@berkant
Copy link

berkant commented Oct 6, 2020

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.

@tlianza
Copy link

tlianza commented Oct 6, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants