diff --git a/composer.json b/composer.json index 4ff1f8e95..ad20013b3 100644 --- a/composer.json +++ b/composer.json @@ -48,7 +48,8 @@ }, "autoload": { "files": [ - "src/functions.php" + "src/functions.php", + "src/functions_experimental.php" ], "psr-4": { "Sentry\\": "src/" diff --git a/src/Metrics/Metrics.php b/src/Metrics/Metrics.php new file mode 100644 index 000000000..ab71cae10 --- /dev/null +++ b/src/Metrics/Metrics.php @@ -0,0 +1,134 @@ +getClient(); + + if ($client === null) { + return null; + } + + $event = Event::createMetric(); + $metric = [ + 'timestamp' => time(), + 'width' => 0, + 'name' => 'c:custom/' . $name . '@none', + 'type' => 'c', + 'value' => $value, + 'tags' => $tags, + ]; + $event->setMetric($metric); + + return $client->captureEvent($event); + } + + /** + * @param int|float $value + * @param string[] $tags + */ + public function distribution(string $name, $value, array $tags, ?string $unit = null): ?EventId + { + $client = SentrySdk::getCurrentHub()->getClient(); + + if ($client === null) { + return null; + } + + $event = Event::createMetric(); + $metric = [ + 'timestamp' => time(), + 'width' => 0, + 'name' => 'd:custom/' . $name . '@' . ($unit ?? 'none'), + 'type' => 'd', + 'value' => $value, + 'tags' => $tags, + ]; + $event->setMetric($metric); + + return $client->captureEvent($event); + } + + /** + * @param int|float $value + * @param string[] $tags + */ + public function set(string $name, $value, array $tags): ?EventId + { + $client = SentrySdk::getCurrentHub()->getClient(); + + if ($client === null) { + return null; + } + + $event = Event::createMetric(); + $metric = [ + 'timestamp' => time(), + 'width' => 0, + 'name' => 's:custom/' . $name . '@none', + 'type' => 's', + 'value' => $value, + 'tags' => $tags, + ]; + $event->setMetric($metric); + + return $client->captureEvent($event); + } + + /** + * @param int|float $value + * @param string[] $tags + */ + public function gauge(string $name, $value, array $tags): ?EventId + { + $client = SentrySdk::getCurrentHub()->getClient(); + + if ($client === null) { + return null; + } + + $event = Event::createMetric(); + $metric = [ + 'timestamp' => time(), + 'width' => 0, + 'name' => 'g:custom/' . $name . '@none', + 'type' => 'g', + 'value' => $value, + 'tags' => $tags, + ]; + $event->setMetric($metric); + + return $client->captureEvent($event); + } +} diff --git a/src/State/Hub.php b/src/State/Hub.php index f4432cedf..9ac3ff0e4 100644 --- a/src/State/Hub.php +++ b/src/State/Hub.php @@ -319,84 +319,6 @@ public function getTransaction(): ?Transaction return $this->getScope()->getTransaction(); } - /** - * @param int|float $value - * @param string[] $tags - */ - public function metricsIncr(string $name, $value, array $tags): ?EventId - { - $client = $this->getClient(); - - if ($client === null) { - return null; - } - - $event = Event::createMetric(); - $metric = [ - 'timestamp' => time(), - 'width' => 0, - 'name' => 'c:custom/' . $name . '@none', - 'type' => 'c', - 'value' => $value, - 'tags' => $tags, - ]; - $event->setMetric($metric); - - return $this->captureEvent($event); - } - - /** - * @param int|float $value - * @param string[] $tags - */ - public function metricsDistribution(string $name, $value, array $tags, ?string $unit = null): ?EventId - { - $client = $this->getClient(); - - if ($client === null) { - return null; - } - - $event = Event::createMetric(); - $metric = [ - 'timestamp' => time(), - 'width' => 0, - 'name' => 'd:custom/' . $name . '@' . ($unit ?? 'none'), - 'type' => 'd', - 'value' => $value, - 'tags' => $tags, - ]; - $event->setMetric($metric); - - return $this->captureEvent($event); - } - - /** - * @param int|float $value - * @param string[] $tags - */ - public function metricsSet(string $name, $value, array $tags): ?EventId - { - $client = $this->getClient(); - - if ($client === null) { - return null; - } - - $event = Event::createMetric(); - $metric = [ - 'timestamp' => time(), - 'width' => 0, - 'name' => 's:custom/' . $name . '@none', - 'type' => 's', - 'value' => $value, - 'tags' => $tags, - ]; - $event->setMetric($metric); - - return $this->captureEvent($event); - } - /** * {@inheritdoc} */ diff --git a/src/functions.php b/src/functions.php index 662ec6868..9dba70ab1 100644 --- a/src/functions.php +++ b/src/functions.php @@ -268,30 +268,3 @@ function continueTrace(string $sentryTrace, string $baggage): TransactionContext return TransactionContext::fromHeaders($sentryTrace, $baggage); } - -/** - * @param int|float $value - * @param string[] $tags - */ -function metricsIncr(string $key, $value, array $tags): ?EventId -{ - return SentrySdk::getCurrentHub()->metricsIncr($key, $value, $tags); -} - -/** - * @param int|float $value - * @param string[] $tags - */ -function metricsDistribution(string $key, $value, array $tags, ?string $unit = null): ?EventId -{ - return SentrySdk::getCurrentHub()->metricsDistribution($key, $value, $tags, $unit); -} - -/** - * @param int|float $value - * @param string[] $tags - */ -function metricsSet(string $key, $value, array $tags): ?EventId -{ - return SentrySdk::getCurrentHub()->metricsSet($key, $value, $tags); -} diff --git a/src/functions_experimental.php b/src/functions_experimental.php new file mode 100644 index 000000000..0a8feb075 --- /dev/null +++ b/src/functions_experimental.php @@ -0,0 +1,12 @@ +