ujamii / prometheus-sentry-exporter

Exports sentry project metrics for prometheus.
MIT License
38 stars 12 forks source link

Unhelpful error "Uncaught TypeError" #9

Open analytik opened 3 years ago

analytik commented 3 years ago

When I try to curl the scraper/metrics/, I get

<br />
<b>Fatal error</b>:  Uncaught TypeError: Return value of Ujamii\OpenMetrics\Sentry\SentryExporter::getJson() must be of the type array, null returned in /var/www/html/src/SentryExporter.php:108
Stack trace:
#0 /var/www/html/src/SentryExporter.php(98): Ujamii\OpenMetrics\Sentry\SentryExporter-&gt;getJson(Object(GuzzleHttp\Psr7\Response))
#1 /var/www/html/src/SentryExporter.php(55): Ujamii\OpenMetrics\Sentry\SentryExporter-&gt;getProjects()
#2 /var/www/html/metrics/index.php(7): Ujamii\OpenMetrics\Sentry\SentryExporter-&gt;run()
#3 {main}
  thrown in <b>/var/www/html/src/SentryExporter.php</b> on line <b>108</b><br />

To add to the confusion, there is nothing in the server log, and this returns http 200.

API token is configured, and the URL format seems correct. When I curl the Sentry API endpoint with the same token, I get a normal-seeming, valid JSON response.

Using the official docker image:

ujamii/prometheus-sentry-exporter latest 1a7d291064ac 9 months ago 523MB

mgrundkoetter commented 3 years ago

What exactly did you call? How does the response look like you requested manually? Which resource did you request (projects, issues)? Seems like the JSON Response is completely empty. Is the sentry instance reachable from inside your container? You can try to ping your server from inside the container. What is the result of that?

analytik commented 3 years ago

Well, that's why I filed the issue - there isn't any logging which URL was called, what was the response, what was the error code, etc. As stated above, I just call scraper-url:scraper-port/metrics/.

I "solved" this issue - our Sentry installation is available under two different URLs (www.example.com/stuff/sentry/ and sentry.example.com) - when I configured the exporter to use the latter (subdomain), it worked, and it's spitting out metrics happily.

However, the sub-path URL format still works for me with curl, so I'm not sure what was the error:

curl -v -H 'Authorization: Bearer qwertyasdf' https://www.example.com/foo/sentry/api/0/projects/
... HTTP/2 200 etc etc ...
[{"status": "active", "features": ["sample-events", "data-forwarding", "rate-limits", "releases", "minidump"], "color": "#3f67bf", ...

One possible, although unlikely explanation is that our CDN allows cURL request, but activates some kind of malware protection for PHP's user agent. Again, no way to tell if the exporter doesn't log/output any debug info.

mgrundkoetter commented 3 years ago

Ok, so the issue here is missing debug output in the container? If you are able to reproduce it, you can add exception handling and user output by opening a PR, I will try to merge it ASAP.