-
-
Notifications
You must be signed in to change notification settings - Fork 452
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Sentry Developer Metrics (#1619)
Co-authored-by: Alex Bouma <alex@bouma.me>
- Loading branch information
1 parent
2f6b413
commit c88988d
Showing
24 changed files
with
1,519 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sentry\Metrics; | ||
|
||
use Sentry\EventId; | ||
use Sentry\Metrics\Types\CounterType; | ||
use Sentry\Metrics\Types\DistributionType; | ||
use Sentry\Metrics\Types\GaugeType; | ||
use Sentry\Metrics\Types\SetType; | ||
|
||
final class Metrics | ||
{ | ||
/** | ||
* @var self|null | ||
*/ | ||
private static $instance; | ||
|
||
/** | ||
* @var MetricsAggregator | ||
*/ | ||
private $aggregator; | ||
|
||
private function __construct() | ||
{ | ||
$this->aggregator = new MetricsAggregator(); | ||
} | ||
|
||
public static function getInstance(): self | ||
{ | ||
if (self::$instance === null) { | ||
self::$instance = new self(); | ||
} | ||
|
||
return self::$instance; | ||
} | ||
|
||
/** | ||
* @param int|float $value | ||
* @param string[] $tags | ||
*/ | ||
public function increment( | ||
string $key, | ||
$value, | ||
?MetricsUnit $unit = null, | ||
array $tags = [], | ||
?int $timestamp = null, | ||
int $stackLevel = 0 | ||
): void { | ||
$this->aggregator->add( | ||
CounterType::TYPE, | ||
$key, | ||
$value, | ||
$unit, | ||
$tags, | ||
$timestamp, | ||
$stackLevel | ||
); | ||
} | ||
|
||
/** | ||
* @param int|float $value | ||
* @param string[] $tags | ||
*/ | ||
public function distribution( | ||
string $key, | ||
$value, | ||
?MetricsUnit $unit = null, | ||
array $tags = [], | ||
?int $timestamp = null, | ||
int $stackLevel = 0 | ||
): void { | ||
$this->aggregator->add( | ||
DistributionType::TYPE, | ||
$key, | ||
$value, | ||
$unit, | ||
$tags, | ||
$timestamp, | ||
$stackLevel | ||
); | ||
} | ||
|
||
/** | ||
* @param int|float $value | ||
* @param string[] $tags | ||
*/ | ||
public function gauge( | ||
string $key, | ||
$value, | ||
?MetricsUnit $unit = null, | ||
array $tags = [], | ||
?int $timestamp = null, | ||
int $stackLevel = 0 | ||
): void { | ||
$this->aggregator->add( | ||
GaugeType::TYPE, | ||
$key, | ||
$value, | ||
$unit, | ||
$tags, | ||
$timestamp, | ||
$stackLevel | ||
); | ||
} | ||
|
||
/** | ||
* @param int|string $value | ||
* @param string[] $tags | ||
*/ | ||
public function set( | ||
string $key, | ||
$value, | ||
?MetricsUnit $unit = null, | ||
array $tags = [], | ||
?int $timestamp = null, | ||
int $stackLevel = 0 | ||
): void { | ||
$this->aggregator->add( | ||
SetType::TYPE, | ||
$key, | ||
$value, | ||
$unit, | ||
$tags, | ||
$timestamp, | ||
$stackLevel | ||
); | ||
} | ||
|
||
public function flush(): ?EventId | ||
{ | ||
return $this->aggregator->flush(); | ||
} | ||
} |
Oops, something went wrong.