Skip to content

Commit

Permalink
Merge pull request #21 from ujamii/sergeylanzman/master
Browse files Browse the repository at this point in the history
Sergeylanzman/master
  • Loading branch information
mgrundkoetter authored Mar 15, 2023
2 parents 0d37917 + e1a6914 commit dec1fe3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
3 changes: 2 additions & 1 deletion metrics/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require_once '../vendor/autoload.php';

$scheme = getenv('HTTP_PROTO') ?: 'https';
$exporter = new \Ujamii\OpenMetrics\Sentry\SentryExporter(getenv('AUTH_TOKEN'), $scheme .'://'. getenv('SENTRY_HOST') .'/api/0/');
$useThrottling = strtolower(getenv("USE_THROTTLING")) === "true" || getenv("USE_THROTTLING") === "1";
$exporter = new \Ujamii\OpenMetrics\Sentry\SentryExporter(getenv('AUTH_TOKEN'), $scheme .'://'. getenv('SENTRY_HOST') .'/api/0/', $useThrottling);
$exporter->run();

6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ $exporter->run();
The image is based on `php:8.1-apache` and thus exposes data on port 80 by default. Assuming you fire this up with `-p 80:80` on
localhost, you can see the metrics on http://localhost/metrics.

Configuration is done with 3 env variables: `SENTRY_HOST`, `AUTH_TOKEN` and `HTTP_PROTO`.
The first 2 are mandatory, `HTTP_PROTO` is optional and set to `https` by default. If you're working with the Sentry
Cloud, your `SENTRY_HOST` variable must be "sentry.io"
Configuration is done with 3 env variables: `SENTRY_HOST`, `AUTH_TOKEN`, `USE_THROTTLING` and `HTTP_PROTO`.
The first 2 are mandatory, `HTTP_PROTO` is optional and set to `https` by default. If you're working with the Sentry Cloud, your `SENTRY_HOST` variable must be "sentry.io"
When you set `USE_THROTTLING` to `true/TRUE` or `1`, the exporter will throttle the API requests to prevent a rate limit. This is useful if you have a lot of projects and/or a lot of issues.

```shell
docker run -d --name sentry-prometheus -e SENTRY_HOST=sentry.foobar.com -e AUTH_TOKEN=foobarlongtoken -p "80:80" ghcr.io/ujamii/prometheus-sentry-exporter
Expand Down
12 changes: 10 additions & 2 deletions src/SentryExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ class SentryExporter

protected array $options = [];

public function __construct(string $token, string $sentryBase = 'https://sentry.io/api/0/')
protected bool $useThrottling = false;

public function __construct(string $token, string $sentryBase = 'https://sentry.io/api/0/', bool $useThrottling = false)
{
$this->httpClient = new Client([
'base_uri' => $sentryBase,
Expand All @@ -29,7 +31,7 @@ public function __construct(string $token, string $sentryBase = 'https://sentry.
'Accept' => 'application/json',
]
];

$this->useThrottling = $useThrottling;
}

/**
Expand All @@ -40,8 +42,14 @@ public function run(): void
$gauges = GaugeCollection::withMetricName(MetricName::fromString('sentry_open_issue_events'))->withHelp('Number of events for one unresolved issue.');

$projectData = $this->getProjects();
if($this->useThrottling){
sleep(1);
}
foreach ($projectData as $project) {
$projectIssues = $this->getIssues($project);
if($this->useThrottling){
sleep(1);
}
foreach ($projectIssues as $issue) {
$gauges->add(
Gauge::fromValue($issue->count)->withLabels(
Expand Down

0 comments on commit dec1fe3

Please sign in to comment.