benvinegar / counterscale

Scalable web analytics you run yourself on Cloudflare
https://counterscale.dev
MIT License
1.52k stars 66 forks source link

Getting "Application Error" #23

Closed chiubaca closed 10 months ago

chiubaca commented 10 months ago

Hey love the idea of this and wanted to give it a spin. I followed all the steps and deployed all smooth sailing.

I've installed the script tag to a very simple site (its just a HTML page) at https://im.chiubaca.com/ and I can see request are being made to my worker at counterscale.chiubaca.workers.dev.

However my dashboard is returning the following error:

image

see for your self at https://counterscale.chiubaca.workers.dev/dashboard.

benvinegar commented 10 months ago

First off – wow, thank you for trying this out! You're the first person to share a production deployment and I'm really grateful for that, even if it's erroring (sorry!).

This is definitely failing somewhere in the worker code trying to serve the dashboard – the minified stack trace makes this really hard to determine where.

I could try firing up my own separate deployment and try to recreate the same issue (maybe I left out a step somewhere), or if you're willing, we could communicate over email or even over Google Meet and debug what's going on.

chiubaca commented 10 months ago

No worries at all, happy to help out! Email or google meet works for me. Feel free to message me at alexchiu11@gmail.com

benvinegar commented 10 months ago

I shot you an email.

I did spend 30 minutes spinning up a brand new Cloudflare user account and following the steps in hopes I might trigger the issue. I did find #24, but once it tracked / collected a pageview the Dashboard loaded fine and I couldn't recreate.

benvinegar commented 10 months ago

I managed to recreate the same error message in a test script. Not sure if this is the same situation, but it occurred when invoking the Dashboard loader, and the code tries to query the Analytics Engine API for data and fails with something like:

{
  result: null,
  success: false,
  errors: [
    {
      code: 7003,
      message: 'Could not route to /client/v4/accounts/fake/analytics_engine/sql, perhaps your object identifier is invalid?'
    }
  ],
  messages: []
}

In my case it's because fake is not a valid account ID / generates a bad URL. But I imagine this could fail a bunch of ways, e.g. if the API token has wrong permissions.

chiubaca commented 10 months ago

I got it working!

It was a mis-config on my end 😅

I double-checked my envs were correct by going into my counterscale worker > clicking on the Settings tab > Variables . Then I nuked the existing variables for CF_ACCOUNT_ID and CF_BEARER_TOKEN and input them in again, then voila the dashboard is alive!

benvinegar commented 10 months ago

Phew – closing as resolved. I think I will add more docs/troubleshooting around this though. And thanks again for opening this ticket; it got me to identify some failure modes, add some new tests, etc.