From abe620d8d9c541720fcc8a97631a54ba70bb963b Mon Sep 17 00:00:00 2001 From: Alex Bouma Date: Tue, 29 Oct 2024 19:55:29 +0100 Subject: [PATCH 1/3] Remove metrics plumbing and deprecate/no-op public API --- src/Client.php | 4 - src/Event.php | 30 +-- src/EventType.php | 3 + .../FrameContextifierIntegration.php | 7 - src/Metrics/Metrics.php | 87 ++------- src/Metrics/MetricsAggregator.php | 157 ---------------- src/Metrics/MetricsUnit.php | 3 + src/Metrics/Types/AbstractType.php | 129 ------------- src/Metrics/Types/CounterType.php | 51 ----- src/Metrics/Types/DistributionType.php | 51 ----- src/Metrics/Types/GaugeType.php | 92 --------- src/Metrics/Types/SetType.php | 57 ------ src/Options.php | 18 +- src/Serializer/EnvelopItems/MetricsItem.php | 160 ---------------- .../EnvelopItems/TransactionItem.php | 26 --- src/Serializer/PayloadSerializer.php | 4 - src/Tracing/Span.php | 49 +---- src/Tracing/Transaction.php | 4 - src/Transport/RateLimiter.php | 4 - src/functions.php | 3 + tests/ClientTest.php | 31 ---- tests/Metrics/MetricsTest.php | 175 ++---------------- .../EnvelopeItems/MetricsItemTest.php | 30 --- tests/Serializer/PayloadSerializerTest.php | 82 -------- tests/Tracing/SpanTest.php | 127 ------------- tests/Transport/RateLimiterTest.php | 33 ---- 26 files changed, 65 insertions(+), 1352 deletions(-) delete mode 100644 src/Metrics/MetricsAggregator.php delete mode 100644 src/Metrics/Types/AbstractType.php delete mode 100644 src/Metrics/Types/CounterType.php delete mode 100644 src/Metrics/Types/DistributionType.php delete mode 100644 src/Metrics/Types/GaugeType.php delete mode 100644 src/Metrics/Types/SetType.php delete mode 100644 src/Serializer/EnvelopItems/MetricsItem.php delete mode 100644 tests/Serializer/EnvelopeItems/MetricsItemTest.php diff --git a/src/Client.php b/src/Client.php index b97a19c0b..02757beeb 100644 --- a/src/Client.php +++ b/src/Client.php @@ -409,8 +409,6 @@ private function applyBeforeSendCallback(Event $event, ?EventHint $hint): ?Event return ($this->options->getBeforeSendTransactionCallback())($event, $hint); case EventType::checkIn(): return ($this->options->getBeforeSendCheckInCallback())($event, $hint); - case EventType::metrics(): - return ($this->options->getBeforeSendMetricsCallback())($event, $hint); default: return $event; } @@ -423,8 +421,6 @@ private function getBeforeSendCallbackName(Event $event): string return 'before_send_transaction'; case EventType::checkIn(): return 'before_send_check_in'; - case EventType::metrics(): - return 'before_send_metrics'; default: return 'before_send'; } diff --git a/src/Event.php b/src/Event.php index 8b096d3cd..0148069ac 100644 --- a/src/Event.php +++ b/src/Event.php @@ -6,7 +6,6 @@ use Sentry\Context\OsContext; use Sentry\Context\RuntimeContext; -use Sentry\Metrics\Types\AbstractType; use Sentry\Profiling\Profile; use Sentry\Tracing\Span; @@ -62,16 +61,6 @@ final class Event */ private $checkIn; - /** - * @var array The metrics data - */ - private $metrics = []; - - /** - * @var array> - */ - private $metricsSummary = []; - /** * @var string|null The name of the server (e.g. the host name) */ @@ -227,6 +216,9 @@ public static function createCheckIn(?EventId $eventId = null): self return new self($eventId, EventType::checkIn()); } + /** + * @deprecated Metrics are no longer supported. Metrics API is a no-op and will be removed in 5.x. + */ public static function createMetrics(?EventId $eventId = null): self { return new self($eventId, EventType::metrics()); @@ -377,38 +369,34 @@ public function setCheckIn(?CheckIn $checkIn): self } /** - * @return array + * @deprecated Metrics are no longer supported. Metrics API is a no-op and will be removed in 5.x. */ public function getMetrics(): array { - return $this->metrics; + return []; } /** - * @param array $metrics + * @deprecated Metrics are no longer supported. Metrics API is a no-op and will be removed in 5.x. */ public function setMetrics(array $metrics): self { - $this->metrics = $metrics; - return $this; } /** - * @return array> + * @deprecated Metrics are no longer supported. Metrics API is a no-op and will be removed in 5.x. */ public function getMetricsSummary(): array { - return $this->metricsSummary; + return []; } /** - * @param array> $metricsSummary + * @deprecated Metrics are no longer supported. Metrics API is a no-op and will be removed in 5.x. */ public function setMetricsSummary(array $metricsSummary): self { - $this->metricsSummary = $metricsSummary; - return $this; } diff --git a/src/EventType.php b/src/EventType.php index 7e34cefc1..b8ffdef94 100644 --- a/src/EventType.php +++ b/src/EventType.php @@ -42,6 +42,9 @@ public static function checkIn(): self return self::getInstance('check_in'); } + /** + * @deprecated Metrics are no longer supported. Metrics API is a no-op and will be removed in 5.x. + */ public static function metrics(): self { return self::getInstance('metrics'); diff --git a/src/Integration/FrameContextifierIntegration.php b/src/Integration/FrameContextifierIntegration.php index 8935d055d..8a541d13d 100644 --- a/src/Integration/FrameContextifierIntegration.php +++ b/src/Integration/FrameContextifierIntegration.php @@ -66,13 +66,6 @@ public function setupOnce(): void } } - foreach ($event->getMetrics() as $metric) { - if ($metric->hasCodeLocation()) { - $frame = $metric->getCodeLocation(); - $integration->addContextToStacktraceFrame($maxContextLines, $frame); - } - } - return $event; }); } diff --git a/src/Metrics/Metrics.php b/src/Metrics/Metrics.php index 868944fa9..6f0fa6764 100644 --- a/src/Metrics/Metrics.php +++ b/src/Metrics/Metrics.php @@ -5,10 +5,6 @@ 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; use Sentry\Tracing\SpanContext; use function Sentry\trace; @@ -20,16 +16,6 @@ class Metrics */ private static $instance; - /** - * @var MetricsAggregator - */ - private $aggregator; - - private function __construct() - { - $this->aggregator = new MetricsAggregator(); - } - public static function getInstance(): self { if (self::$instance === null) { @@ -41,6 +27,8 @@ public static function getInstance(): self /** * @param array $tags + * + * @deprecated Metrics are no longer supported. Metrics API is a no-op and will be removed in 5.x. */ public function increment( string $key, @@ -50,19 +38,12 @@ public function increment( ?int $timestamp = null, int $stackLevel = 0 ): void { - $this->aggregator->add( - CounterType::TYPE, - $key, - $value, - $unit, - $tags, - $timestamp, - $stackLevel - ); } /** * @param array $tags + * + * @deprecated Metrics are no longer supported. Metrics API is a no-op and will be removed in 5.x. */ public function distribution( string $key, @@ -72,19 +53,12 @@ public function distribution( ?int $timestamp = null, int $stackLevel = 0 ): void { - $this->aggregator->add( - DistributionType::TYPE, - $key, - $value, - $unit, - $tags, - $timestamp, - $stackLevel - ); } /** * @param array $tags + * + * @deprecated Metrics are no longer supported. Metrics API is a no-op and will be removed in 5.x. */ public function gauge( string $key, @@ -94,20 +68,13 @@ public function gauge( ?int $timestamp = null, int $stackLevel = 0 ): void { - $this->aggregator->add( - GaugeType::TYPE, - $key, - $value, - $unit, - $tags, - $timestamp, - $stackLevel - ); } /** * @param int|string $value * @param array $tags + * + * @deprecated Metrics are no longer supported. Metrics API is a no-op and will be removed in 5.x. */ public function set( string $key, @@ -117,15 +84,6 @@ public function set( ?int $timestamp = null, int $stackLevel = 0 ): void { - $this->aggregator->add( - SetType::TYPE, - $key, - $value, - $unit, - $tags, - $timestamp, - $stackLevel - ); } /** @@ -135,6 +93,8 @@ public function set( * @param array $tags * * @return T + * + * @deprecated Metrics are no longer supported. Metrics API is a no-op and will be removed in 5.x. */ public function timing( string $key, @@ -143,26 +103,8 @@ public function timing( int $stackLevel = 0 ) { return trace( - function () use ($callback, $key, $tags, $stackLevel) { - $startTimestamp = microtime(true); - - $result = $callback(); - - /** - * Emitting the metric here, will attach it to the - * "metric.timing" span. - */ - $this->aggregator->add( - DistributionType::TYPE, - $key, - microtime(true) - $startTimestamp, - MetricsUnit::second(), - $tags, - (int) $startTimestamp, - $stackLevel + 4 // the `trace` helper adds 4 additional stack frames - ); - - return $result; + function () use ($callback) { + return $callback(); }, SpanContext::make() ->setOp('metric.timing') @@ -171,8 +113,11 @@ function () use ($callback, $key, $tags, $stackLevel) { ); } + /** + * @deprecated Metrics are no longer supported. Metrics API is a no-op and will be removed in 5.x. + */ public function flush(): ?EventId { - return $this->aggregator->flush(); + return null; } } diff --git a/src/Metrics/MetricsAggregator.php b/src/Metrics/MetricsAggregator.php deleted file mode 100644 index 5014c97fe..000000000 --- a/src/Metrics/MetricsAggregator.php +++ /dev/null @@ -1,157 +0,0 @@ - - */ - private $buckets = []; - - private const METRIC_TYPES = [ - CounterType::TYPE => CounterType::class, - DistributionType::TYPE => DistributionType::class, - GaugeType::TYPE => GaugeType::class, - SetType::TYPE => SetType::class, - ]; - - /** - * @param array $tags - * @param int|float|string $value - */ - public function add( - string $type, - string $key, - $value, - ?MetricsUnit $unit, - array $tags, - ?int $timestamp, - int $stackLevel - ): void { - if ($timestamp === null) { - $timestamp = time(); - } - if ($unit === null) { - $unit = MetricsUnit::none(); - } - - $tags = $this->serializeTags($tags); - - $bucketTimestamp = floor($timestamp / self::ROLLUP_IN_SECONDS); - $bucketKey = md5( - $type . - $key . - $unit . - serialize($tags) . - $bucketTimestamp - ); - - if (\array_key_exists($bucketKey, $this->buckets)) { - $metric = $this->buckets[$bucketKey]; - $metric->add($value); - } else { - $metricTypeClass = self::METRIC_TYPES[$type]; - /** @var AbstractType $metric */ - /** @phpstan-ignore-next-line SetType accepts int|float|string, others only int|float */ - $metric = new $metricTypeClass($key, $value, $unit, $tags, $timestamp); - $this->buckets[$bucketKey] = $metric; - } - - $hub = SentrySdk::getCurrentHub(); - $client = $hub->getClient(); - - if ($client !== null) { - $options = $client->getOptions(); - - if ( - $options->shouldAttachMetricCodeLocations() - && !$metric->hasCodeLocation() - ) { - $metric->addCodeLocation($stackLevel); - } - } - - $span = $hub->getSpan(); - if ($span !== null) { - $span->setMetricsSummary($type, $key, $value, $unit, $tags); - } - } - - public function flush(): ?EventId - { - if ($this->buckets === []) { - return null; - } - - $hub = SentrySdk::getCurrentHub(); - $event = Event::createMetrics()->setMetrics($this->buckets); - - $this->buckets = []; - - return $hub->captureEvent($event); - } - - /** - * @param array $tags - * - * @return array - */ - private function serializeTags(array $tags): array - { - $hub = SentrySdk::getCurrentHub(); - $client = $hub->getClient(); - - if ($client !== null) { - $options = $client->getOptions(); - - $defaultTags = [ - 'environment' => $options->getEnvironment() ?? Event::DEFAULT_ENVIRONMENT, - ]; - - $release = $options->getRelease(); - if ($release !== null) { - $defaultTags['release'] = $release; - } - - $hub->configureScope(function (Scope $scope) use (&$defaultTags) { - $transaction = $scope->getTransaction(); - if ( - $transaction !== null - // Only include the transaction name if it has good quality - && $transaction->getMetadata()->getSource() !== TransactionSource::url() - ) { - $defaultTags['transaction'] = $transaction->getName(); - } - }); - - $tags = array_merge($defaultTags, $tags); - } - - // It's very important to sort the tags in order to obtain the same bucket key. - ksort($tags); - - return $tags; - } -} diff --git a/src/Metrics/MetricsUnit.php b/src/Metrics/MetricsUnit.php index 3e39d56fe..e94951fe3 100644 --- a/src/Metrics/MetricsUnit.php +++ b/src/Metrics/MetricsUnit.php @@ -4,6 +4,9 @@ namespace Sentry\Metrics; +/** + * @deprecated Metrics are no longer supported. Metrics API is a no-op and will be removed in 5.x. + */ final class MetricsUnit implements \Stringable { /** diff --git a/src/Metrics/Types/AbstractType.php b/src/Metrics/Types/AbstractType.php deleted file mode 100644 index ecafca06d..000000000 --- a/src/Metrics/Types/AbstractType.php +++ /dev/null @@ -1,129 +0,0 @@ - - */ - private $tags; - - /** - * @var int - */ - private $timestamp; - - /** - * @var Frame - */ - private $codeLocation; - - /** - * @param array $tags - */ - public function __construct(string $key, MetricsUnit $unit, array $tags, int $timestamp) - { - $this->key = $key; - $this->unit = $unit; - $this->tags = $tags; - $this->timestamp = $timestamp; - } - - abstract public function add($value): void; - - /** - * @return array - */ - abstract public function serialize(): array; - - abstract public function getType(): string; - - public function getKey(): string - { - return $this->key; - } - - public function getUnit(): MetricsUnit - { - return $this->unit; - } - - /** - * @return array - */ - public function getTags(): array - { - return $this->tags; - } - - public function getTimestamp(): int - { - return $this->timestamp; - } - - /** - * @phpstan-assert-if-true !null $this->getCodeLocation() - */ - public function hasCodeLocation(): bool - { - return $this->codeLocation !== null; - } - - public function getCodeLocation(): ?Frame - { - return $this->codeLocation; - } - - public function addCodeLocation(int $stackLevel): void - { - $client = SentrySdk::getCurrentHub()->getClient(); - if ($client === null) { - return; - } - - $options = $client->getOptions(); - - $backtrace = debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 3 + $stackLevel); - $frame = end($backtrace); - - // If we don't have a valid frame there is no code location to resolve - if ($frame === false || empty($frame['file']) || empty($frame['line'])) { - return; - } - - $frameBuilder = new FrameBuilder($options, new RepresentationSerializer($options)); - $this->codeLocation = $frameBuilder->buildFromBacktraceFrame($frame['file'], $frame['line'], $frame); - } - - public function getMri(): string - { - return \sprintf( - '%s:%s@%s', - $this->getType(), - $this->getKey(), - (string) $this->getUnit() - ); - } -} diff --git a/src/Metrics/Types/CounterType.php b/src/Metrics/Types/CounterType.php deleted file mode 100644 index 6f54b3f9c..000000000 --- a/src/Metrics/Types/CounterType.php +++ /dev/null @@ -1,51 +0,0 @@ -value = (float) $value; - } - - /** - * @param int|float $value - */ - public function add($value): void - { - $this->value += (float) $value; - } - - public function serialize(): array - { - return [$this->value]; - } - - public function getType(): string - { - return self::TYPE; - } -} diff --git a/src/Metrics/Types/DistributionType.php b/src/Metrics/Types/DistributionType.php deleted file mode 100644 index fa43e4f48..000000000 --- a/src/Metrics/Types/DistributionType.php +++ /dev/null @@ -1,51 +0,0 @@ - - */ - private $values; - - /** - * @param int|float $value - */ - public function __construct(string $key, $value, MetricsUnit $unit, array $tags, int $timestamp) - { - parent::__construct($key, $unit, $tags, $timestamp); - - $this->add($value); - } - - /** - * @param int|float $value - */ - public function add($value): void - { - $this->values[] = (float) $value; - } - - public function serialize(): array - { - return $this->values; - } - - public function getType(): string - { - return self::TYPE; - } -} diff --git a/src/Metrics/Types/GaugeType.php b/src/Metrics/Types/GaugeType.php deleted file mode 100644 index 1803365a9..000000000 --- a/src/Metrics/Types/GaugeType.php +++ /dev/null @@ -1,92 +0,0 @@ -last = $value; - $this->min = $value; - $this->max = $value; - $this->sum = $value; - $this->count = 1; - } - - /** - * @param int|float $value - */ - public function add($value): void - { - $value = (float) $value; - - $this->last = $value; - $this->min = min($this->min, $value); - $this->max = max($this->min, $value); - $this->sum += $value; - ++$this->count; - } - - /** - * @return array - */ - public function serialize(): array - { - return [ - $this->last, - $this->min, - $this->max, - $this->sum, - $this->count, - ]; - } - - public function getType(): string - { - return self::TYPE; - } -} diff --git a/src/Metrics/Types/SetType.php b/src/Metrics/Types/SetType.php deleted file mode 100644 index d761bc264..000000000 --- a/src/Metrics/Types/SetType.php +++ /dev/null @@ -1,57 +0,0 @@ - - */ - private $values; - - /** - * @param int|string $value - */ - public function __construct(string $key, $value, MetricsUnit $unit, array $tags, int $timestamp) - { - parent::__construct($key, $unit, $tags, $timestamp); - - $this->add($value); - } - - /** - * @param int|string $value - */ - public function add($value): void - { - $this->values[] = $value; - } - - public function serialize(): array - { - foreach ($this->values as $key => $value) { - if (\is_string($value)) { - $this->values[$key] = crc32($value); - } - } - - return $this->values; - } - - public function getType(): string - { - return self::TYPE; - } -} diff --git a/src/Options.php b/src/Options.php index 34ebd5a7c..dd2930547 100644 --- a/src/Options.php +++ b/src/Options.php @@ -224,6 +224,8 @@ public function setAttachStacktrace(bool $enable): self /** * Gets whether a metric has their code location attached. + * + * @deprecated Metrics are no longer supported. Metrics API is a no-op and will be removed in 5.x. */ public function shouldAttachMetricCodeLocations(): bool { @@ -232,6 +234,8 @@ public function shouldAttachMetricCodeLocations(): bool /** * Sets whether a metric will have their code location attached. + * + * @deprecated Metrics are no longer supported. Metrics API is a no-op and will be removed in 5.x. */ public function setAttachMetricCodeLocations(bool $enable): self { @@ -581,6 +585,8 @@ public function setBeforeSendCheckInCallback(callable $callback): self * If `null` is returned it won't be sent. * * @psalm-return callable(Event, ?EventHint): ?Event + * + * @deprecated Metrics are no longer supported. Metrics API is a no-op and will be removed in 5.x. */ public function getBeforeSendMetricsCallback(): callable { @@ -594,6 +600,8 @@ public function getBeforeSendMetricsCallback(): callable * @param callable $callback The callable * * @psalm-param callable(Event, ?EventHint): ?Event $callback + * + * @deprecated Metrics are no longer supported. Metrics API is a no-op and will be removed in 5.x. */ public function setBeforeSendMetricsCallback(callable $callback): self { @@ -1112,6 +1120,9 @@ private function configureOptions(OptionsResolver $resolver): void 'traces_sampler' => null, 'profiles_sample_rate' => null, 'attach_stacktrace' => false, + /** + * @deprecated Metrics are no longer supported. Metrics API is a no-op and will be removed in 5.x. + */ 'attach_metric_code_locations' => false, 'context_lines' => 5, 'environment' => $_SERVER['SENTRY_ENVIRONMENT'] ?? null, @@ -1132,8 +1143,11 @@ private function configureOptions(OptionsResolver $resolver): void 'before_send_check_in' => static function (Event $checkIn): Event { return $checkIn; }, - 'before_send_metrics' => static function (Event $metrics): Event { - return $metrics; + /** + * @deprecated Metrics are no longer supported. Metrics API is a no-op and will be removed in 5.x. + */ + 'before_send_metrics' => static function (Event $metrics): ?Event { + return null; }, 'trace_propagation_targets' => null, 'tags' => [], diff --git a/src/Serializer/EnvelopItems/MetricsItem.php b/src/Serializer/EnvelopItems/MetricsItem.php deleted file mode 100644 index 8b78ccec2..000000000 --- a/src/Serializer/EnvelopItems/MetricsItem.php +++ /dev/null @@ -1,160 +0,0 @@ -getMetrics(); - if (empty($metrics)) { - return ''; - } - - $statsdPayload = []; - $metricMetaPayload = []; - - foreach ($metrics as $metric) { - $statsdPayload[] = self::seralizeMetric($metric); - - if ($metric->hasCodeLocation()) { - $metricMetaPayload[$metric->getMri()][] = array_merge( - ['type' => 'location'], - self::serializeStacktraceFrame($metric->getCodeLocation()) - ); - } - } - - $statsdPayload = implode("\n", $statsdPayload); - - $statsdHeader = [ - 'type' => 'statsd', - 'length' => mb_strlen($statsdPayload), - ]; - - if (!empty($metricMetaPayload)) { - $metricMetaPayload = JSON::encode([ - 'timestamp' => time(), - 'mapping' => $metricMetaPayload, - ]); - - $metricMetaHeader = [ - 'type' => 'metric_meta', - 'length' => mb_strlen($metricMetaPayload), - ]; - - return \sprintf( - "%s\n%s\n%s\n%s", - JSON::encode($statsdHeader), - $statsdPayload, - JSON::encode($metricMetaHeader), - $metricMetaPayload - ); - } - - return \sprintf( - "%s\n%s", - JSON::encode($statsdHeader), - $statsdPayload - ); - } - - public static function seralizeMetric(AbstractType $metric): string - { - /** - * In case of us adding support for emitting metrics from other namespaces, - * we have to alter the RateLimiter::class to properly handle these - * namespaces. - */ - - // key - my.metric - $line = preg_replace(self::KEY_PATTERN, '_', $metric->getKey()); - - if ($metric->getUnit() !== MetricsUnit::none()) { - // unit - @second - $line .= '@' . preg_replace(self::UNIT_PATTERN, '', (string) $metric->getUnit()); - } - - foreach ($metric->serialize() as $value) { - // value - 2:3:4... - $line .= ':' . $value; - } - - // type - |c|, |d|, ... - $line .= '|' . $metric->getType() . '|'; - - $tags = []; - foreach ($metric->getTags() as $key => $value) { - $tags[] = preg_replace(self::TAG_KEY_PATTERN, '', $key) . - ':' . self::escapeTagValues($value); - } - - if (!empty($tags)) { - // tags - #key:value,key:value... - $line .= '#' . implode(',', $tags) . '|'; - } - - // timestamp - T123456789 - $line .= 'T' . $metric->getTimestamp(); - - return $line; - } - - public static function escapeTagValues(string $tagValue): string - { - $result = ''; - - for ($i = 0; $i < mb_strlen($tagValue); ++$i) { - $character = mb_substr($tagValue, $i, 1); - $result .= str_replace( - [ - "\n", - "\r", - "\t", - '\\', - '|', - ',', - ], - [ - '\n', - '\r', - '\t', - '\\\\', - '\u{7c}', - '\u{2c}', - ], - $character - ); - } - - return $result; - } -} diff --git a/src/Serializer/EnvelopItems/TransactionItem.php b/src/Serializer/EnvelopItems/TransactionItem.php index 9d102f3b4..de6fd624a 100644 --- a/src/Serializer/EnvelopItems/TransactionItem.php +++ b/src/Serializer/EnvelopItems/TransactionItem.php @@ -125,10 +125,6 @@ public static function toEnvelopeItem(Event $event): string $payload['spans'] = array_values(array_map([self::class, 'serializeSpan'], $event->getSpans())); - if (!empty($event->getMetricsSummary())) { - $payload['_metrics_summary'] = self::serializeMetricsSummary($event->getMetricsSummary()); - } - $transactionMetadata = $event->getSdkMetadata('transaction_metadata'); if ($transactionMetadata instanceof TransactionMetadata) { $payload['transaction_info']['source'] = (string) $transactionMetadata->getSource(); @@ -191,28 +187,6 @@ protected static function serializeSpan(Span $span): array $result['tags'] = $span->getTags(); } - if (!empty($span->getMetricsSummary())) { - $result['_metrics_summary'] = self::serializeMetricsSummary($span->getMetricsSummary()); - } - return $result; } - - /** - * @param array> $metricsSummary - * - * @return array - */ - protected static function serializeMetricsSummary(array $metricsSummary): array - { - $formattedSummary = []; - - foreach ($metricsSummary as $mri => $metrics) { - foreach ($metrics as $metric) { - $formattedSummary[$mri][] = $metric; - } - } - - return $formattedSummary; - } } diff --git a/src/Serializer/PayloadSerializer.php b/src/Serializer/PayloadSerializer.php index 7dbfd2aa9..c109e0336 100644 --- a/src/Serializer/PayloadSerializer.php +++ b/src/Serializer/PayloadSerializer.php @@ -9,7 +9,6 @@ use Sentry\Options; use Sentry\Serializer\EnvelopItems\CheckInItem; use Sentry\Serializer\EnvelopItems\EventItem; -use Sentry\Serializer\EnvelopItems\MetricsItem; use Sentry\Serializer\EnvelopItems\ProfileItem; use Sentry\Serializer\EnvelopItems\TransactionItem; use Sentry\Tracing\DynamicSamplingContext; @@ -78,9 +77,6 @@ public function serialize(Event $event): string case EventType::checkIn(): $items = CheckInItem::toEnvelopeItem($event); break; - case EventType::metrics(): - $items = MetricsItem::toEnvelopeItem($event); - break; } return \sprintf("%s\n%s", JSON::encode($envelopeHeader), $items); diff --git a/src/Tracing/Span.php b/src/Tracing/Span.php index 8810edb13..fdbba775c 100644 --- a/src/Tracing/Span.php +++ b/src/Tracing/Span.php @@ -6,7 +6,6 @@ use Sentry\EventId; use Sentry\Metrics\MetricsUnit; -use Sentry\Metrics\Types\SetType; use Sentry\SentrySdk; use Sentry\State\Scope; @@ -88,11 +87,6 @@ class Span */ protected $transaction; - /** - * @var array> - */ - protected $metricsSummary = []; - /** * @var string|null The trace origin of the span. If no origin is set, the span is considered to be "manual". * @@ -508,16 +502,15 @@ public function detachSpanRecorder() } /** - * @return array> + * @deprecated Metrics are no longer supported. Metrics API is a no-op and will be removed in 5.x. */ public function getMetricsSummary(): array { - return $this->metricsSummary; + return []; } /** - * @param string|int|float $value - * @param string[] $tags + * @deprecated Metrics are no longer supported. Metrics API is a no-op and will be removed in 5.x. */ public function setMetricsSummary( string $type, @@ -526,42 +519,6 @@ public function setMetricsSummary( MetricsUnit $unit, array $tags ): void { - $mri = \sprintf('%s:%s@%s', $type, $key, (string) $unit); - $bucketKey = $mri . serialize($tags); - - if ( - isset($this->metricsSummary[$mri]) - && \array_key_exists($bucketKey, $this->metricsSummary[$mri]) - ) { - if ($type === SetType::TYPE) { - $value = 1.0; - } else { - $value = (float) $value; - } - - $summary = $this->metricsSummary[$mri][$bucketKey]; - $this->metricsSummary[$mri][$bucketKey] = [ - 'min' => min($summary['min'], $value), - 'max' => max($summary['max'], $value), - 'sum' => $summary['sum'] + $value, - 'count' => $summary['count'] + 1, - 'tags' => $tags, - ]; - } else { - if ($type === SetType::TYPE) { - $value = 0.0; - } else { - $value = (float) $value; - } - - $this->metricsSummary[$mri][$bucketKey] = [ - 'min' => $value, - 'max' => $value, - 'sum' => $value, - 'count' => 1, - 'tags' => $tags, - ]; - } } /** diff --git a/src/Tracing/Transaction.php b/src/Tracing/Transaction.php index 735768c57..5e4d727d2 100644 --- a/src/Tracing/Transaction.php +++ b/src/Tracing/Transaction.php @@ -190,10 +190,6 @@ public function finish(?float $endTimestamp = null): ?EventId } } - if (!empty($this->getMetricsSummary())) { - $event->setMetricsSummary($this->getMetricsSummary()); - } - return $this->hub->captureEvent($event); } } diff --git a/src/Transport/RateLimiter.php b/src/Transport/RateLimiter.php index 6a4f89bf8..be3801b01 100644 --- a/src/Transport/RateLimiter.php +++ b/src/Transport/RateLimiter.php @@ -132,10 +132,6 @@ public function getDisabledUntil(EventType $eventType): int $category = self::DATA_CATEGORY_ERROR; } - if ($eventType === EventType::metrics()) { - $category = self::DATA_CATEGORY_METRIC_BUCKET; - } - return max($this->rateLimits['all'] ?? 0, $this->rateLimits[$category] ?? 0); } diff --git a/src/functions.php b/src/functions.php index 1865d397c..46a3d99e0 100644 --- a/src/functions.php +++ b/src/functions.php @@ -377,6 +377,9 @@ function continueTrace(string $sentryTrace, string $baggage): TransactionContext return TransactionContext::fromHeaders($sentryTrace, $baggage); } +/** + * @deprecated Metrics are no longer supported. Metrics API is a no-op and will be removed in 5.x. + */ function metrics(): Metrics { return Metrics::getInstance(); diff --git a/tests/ClientTest.php b/tests/ClientTest.php index ddc3dc6c9..2aa111e64 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -629,11 +629,6 @@ public static function processEventChecksBeforeSendMetricsOptionDataProvider(): Event::createCheckIn(), false, ]; - - yield [ - Event::createMetrics(), - true, - ]; } public function testProcessEventDiscardsEventWhenSampleRateOptionIsZero(): void @@ -822,32 +817,6 @@ public function testProcessEventDiscardsEventWhenBeforeSendCheckInCallbackReturn $client->captureEvent(Event::createCheckIn()); } - public function testProcessEventDiscardsEventWhenBeforeSendMetricsCallbackReturnsNull(): void - { - /** @var LoggerInterface&MockObject $logger */ - $logger = $this->createMock(LoggerInterface::class); - $logger->expects($this->once()) - ->method('info') - ->with( - new StringMatchesFormatDescription('The metrics [%s] will be discarded because the "before_send_metrics" callback returned "null".'), - $this->callback(static function (array $context): bool { - return isset($context['event']) && $context['event'] instanceof Event; - }) - ); - - $options = [ - 'before_send_metrics' => static function () { - return null; - }, - ]; - - $client = ClientBuilder::create($options) - ->setLogger($logger) - ->getClient(); - - $client->captureEvent(Event::createMetrics()); - } - public function testProcessEventDiscardsEventWhenEventProcessorReturnsNull(): void { /** @var LoggerInterface&MockObject $logger */ diff --git a/tests/Metrics/MetricsTest.php b/tests/Metrics/MetricsTest.php index 5e19d9750..1e8a0d64a 100644 --- a/tests/Metrics/MetricsTest.php +++ b/tests/Metrics/MetricsTest.php @@ -39,31 +39,8 @@ public function testIncrement(): void $self = $this; - $client->expects($this->once()) - ->method('captureEvent') - ->with($this->callback(static function (Event $event) use ($self): bool { - $metric = $event->getMetrics()['2794a118fd879e10a3a97836df803872']; - - $self->assertSame(CounterType::TYPE, $metric->getType()); - $self->assertSame('foo', $metric->getKey()); - $self->assertSame([3.0], $metric->serialize()); - $self->assertSame(MetricsUnit::second(), $metric->getUnit()); - $self->assertSame( - [ - 'environment' => 'development', - 'foo' => 'bar', - 'release' => '1.0.0', - ], - $metric->getTags() - ); - $self->assertSame(1699412953, $metric->getTimestamp()); - - $codeLocation = $metric->getCodeLocation(); - - $self->assertSame('Sentry\Metrics\Metrics::increment', $codeLocation->getFunctionName()); - - return true; - })); + $client->expects($this->never()) + ->method('captureEvent'); $hub = new Hub($client); SentrySdk::setCurrentHub($hub); @@ -101,31 +78,8 @@ public function testDistribution(): void $self = $this; - $client->expects($this->once()) - ->method('captureEvent') - ->with($this->callback(static function (Event $event) use ($self): bool { - $metric = $event->getMetrics()['edb74f95b4572e82dc4600cfeea76181']; - - $self->assertSame(DistributionType::TYPE, $metric->getType()); - $self->assertSame('foo', $metric->getKey()); - $self->assertSame([1.0, 2.0], $metric->serialize()); - $self->assertSame(MetricsUnit::second(), $metric->getUnit()); - $self->assertSame( - [ - 'environment' => 'development', - 'foo' => 'bar', - 'release' => '1.0.0', - ], - $metric->getTags() - ); - $self->assertSame(1699412953, $metric->getTimestamp()); - - $codeLocation = $metric->getCodeLocation(); - - $self->assertSame('Sentry\Metrics\Metrics::distribution', $codeLocation->getFunctionName()); - - return true; - })); + $client->expects($this->never()) + ->method('captureEvent'); $hub = new Hub($client); SentrySdk::setCurrentHub($hub); @@ -163,31 +117,8 @@ public function testTiming(): void $self = $this; - $client->expects($this->once()) - ->method('captureEvent') - ->with($this->callback(static function (Event $event) use ($self): bool { - $metric = $event->getMetrics()['edb74f95b4572e82dc4600cfeea76181']; - - $self->assertSame(DistributionType::TYPE, $metric->getType()); - $self->assertSame('foo', $metric->getKey()); - $self->assertSame([1.0, 2.0], $metric->serialize()); - $self->assertSame(MetricsUnit::second(), $metric->getUnit()); - $self->assertSame( - [ - 'environment' => 'development', - 'foo' => 'bar', - 'release' => '1.0.0', - ], - $metric->getTags() - ); - $self->assertSame(1699412953, $metric->getTimestamp()); - - $codeLocation = $metric->getCodeLocation(); - - $self->assertSame('Sentry\Metrics\Metrics::timing', $codeLocation->getFunctionName()); - - return true; - })); + $client->expects($this->never()) + ->method('captureEvent'); $hub = new Hub($client); SentrySdk::setCurrentHub($hub); @@ -237,37 +168,8 @@ public function testGauge(): void $self = $this; - $client->expects($this->once()) - ->method('captureEvent') - ->with($this->callback(static function (Event $event) use ($self): bool { - $metric = $event->getMetrics()['f39c23c73897d4f006fd617f76664571']; - - $self->assertSame(GaugeType::TYPE, $metric->getType()); - $self->assertSame('foo', $metric->getKey()); - $self->assertSame([ - 2.0, // last - 1.0, // min - 2.0, // max - 3.0, // sum, - 2, // count, - ], $metric->serialize()); - $self->assertSame(MetricsUnit::second(), $metric->getUnit()); - $self->assertSame( - [ - 'environment' => 'development', - 'foo' => 'bar', - 'release' => '1.0.0', - ], - $metric->getTags() - ); - $self->assertSame(1699412953, $metric->getTimestamp()); - - $codeLocation = $metric->getCodeLocation(); - - $self->assertSame('Sentry\Metrics\Metrics::gauge', $codeLocation->getFunctionName()); - - return true; - })); + $client->expects($this->never()) + ->method('captureEvent'); $hub = new Hub($client); SentrySdk::setCurrentHub($hub); @@ -305,31 +207,8 @@ public function testSet(): void $self = $this; - $client->expects($this->once()) - ->method('captureEvent') - ->with($this->callback(static function (Event $event) use ($self): bool { - $metric = $event->getMetrics()['868b190d923bbd619570328d7ba3e4cd']; - - $self->assertSame(SetType::TYPE, $metric->getType()); - $self->assertSame('foo', $metric->getKey()); - $self->assertSame([1, 1, 2356372769], $metric->serialize()); - $self->assertSame(MetricsUnit::second(), $metric->getUnit()); - $self->assertSame( - [ - 'environment' => 'development', - 'foo' => 'bar', - 'release' => '1.0.0', - ], - $metric->getTags() - ); - $self->assertSame(1699412953, $metric->getTimestamp()); - - $codeLocation = $metric->getCodeLocation(); - - $self->assertSame('Sentry\Metrics\Metrics::set', $codeLocation->getFunctionName()); - - return true; - })); + $client->expects($this->never()) + ->method('captureEvent'); $hub = new Hub($client); SentrySdk::setCurrentHub($hub); @@ -378,42 +257,12 @@ public function testMetricsSummary(): void ->method('captureEvent') ->with($this->callback(static function (Event $event) use ($self): bool { $self->assertSame( - [ - 'c:foo@second' => [ - 'c:foo@seconda:4:{s:11:"environment";s:11:"development";s:3:"foo";s:3:"bar";s:7:"release";s:5:"1.0.0";s:11:"transaction";s:12:"GET /metrics";}' => [ - 'min' => 1.0, - 'max' => 1.0, - 'sum' => 1.0, - 'count' => 1, - 'tags' => [ - 'environment' => 'development', - 'foo' => 'bar', - 'release' => '1.0.0', - 'transaction' => 'GET /metrics', - ], - ], - ], - ], + [], $event->getMetricsSummary() ); $self->assertSame( - [ - 'c:foo@second' => [ - 'c:foo@seconda:4:{s:11:"environment";s:11:"development";s:3:"foo";s:3:"bar";s:7:"release";s:5:"1.0.0";s:11:"transaction";s:12:"GET /metrics";}' => [ - 'min' => 1.0, - 'max' => 1.0, - 'sum' => 2.0, - 'count' => 2, - 'tags' => [ - 'environment' => 'development', - 'foo' => 'bar', - 'release' => '1.0.0', - 'transaction' => 'GET /metrics', - ], - ], - ], - ], + [], $event->getSpans()[0]->getMetricsSummary() ); diff --git a/tests/Serializer/EnvelopeItems/MetricsItemTest.php b/tests/Serializer/EnvelopeItems/MetricsItemTest.php deleted file mode 100644 index 399fcf40b..000000000 --- a/tests/Serializer/EnvelopeItems/MetricsItemTest.php +++ /dev/null @@ -1,30 +0,0 @@ -assertSame('plain', MetricsItem::escapeTagValues('plain')); - $this->assertSame('plain text', MetricsItem::escapeTagValues('plain text')); - $this->assertSame('plain%text', MetricsItem::escapeTagValues('plain%text')); - - // Escape sequences - $this->assertSame('plain \\\\\\\\ text', MetricsItem::escapeTagValues('plain \\\\ text')); - $this->assertSame('plain\\u{2c}text', MetricsItem::escapeTagValues('plain,text')); - $this->assertSame('plain\\u{7c}text', MetricsItem::escapeTagValues('plain|text')); - $this->assertSame('plain 😅', MetricsItem::escapeTagValues('plain 😅')); - - // Escapable control characters - $this->assertSame('plain\\\\ntext', MetricsItem::escapeTagValues("plain\ntext")); - $this->assertSame('plain\\\\rtext', MetricsItem::escapeTagValues("plain\rtext")); - $this->assertSame('plain\\\\ttext', MetricsItem::escapeTagValues("plain\ttext")); - } -} diff --git a/tests/Serializer/PayloadSerializerTest.php b/tests/Serializer/PayloadSerializerTest.php index 1d528ca8d..05045e6c0 100644 --- a/tests/Serializer/PayloadSerializerTest.php +++ b/tests/Serializer/PayloadSerializerTest.php @@ -410,88 +410,6 @@ public static function serializeAsEnvelopeDataProvider(): iterable {"event_id":"fc9442f5aef34234bb22b9a615e30ccd","sent_at":"2020-08-18T22:47:15Z","dsn":"http:\/\/public@example.com\/sentry\/1","sdk":{"name":"sentry.php","version":"$sdkVersion"}} {"type":"check_in","content_type":"application\/json"} {"check_in_id":"$checkinId","monitor_slug":"my-monitor","status":"ok","duration":10,"release":"1.0.0","environment":"dev","monitor_config":{"schedule":{"type":"crontab","value":"0 0 * * *","unit":""},"checkin_margin":10,"max_runtime":12,"timezone":"Europe\/Amsterdam","failure_issue_threshold":5,"recovery_threshold":10},"contexts":{"trace":{"trace_id":"21160e9b836d479f81611368b2aa3d2c","span_id":"5dd538dc297544cc"}}} -TEXT - , - ]; - - $counter = new CounterType('counter', 1.0, MetricsUnit::second(), ['foo' => 'bar', 'route' => 'GET /foo'], 1597790835); - $distribution = new DistributionType('distribution', 1.0, MetricsUnit::second(), ['foo' => 'bar'], 1597790835); - $gauge = new GaugeType('gauge', 1.0, MetricsUnit::second(), ['foo' => 'bar', 'bar' => 'baz'], 1597790835); - $set = new SetType('set', 1.0, MetricsUnit::second(), ['key' => 'value'], 1597790835); - $noTags = new CounterType('no_tags', 1.0, MetricsUnit::second(), [], 1597790835); - - $event = Event::createMetrics(new EventId('fc9442f5aef34234bb22b9a615e30ccd')); - $event->setMetrics([ - $counter, - $distribution, - $gauge, - $set, - $noTags, - ]); - - yield [ - $event, - <<setSpanId(new SpanId('5dd538dc297544cc')); - $span->setTraceId(new TraceId('21160e9b836d479f81611368b2aa3d2c')); - $span->setMetricsSummary( - CounterType::TYPE, - 'counter', - 10, - MetricsUnit::custom('star'), - [ - 'repository' => 'client', - ] - ); - $span->setMetricsSummary( - CounterType::TYPE, - 'counter', - 50, - MetricsUnit::custom('star'), - [ - 'repository' => 'client', - ] - ); - - $event = Event::createTransaction(new EventId('fc9442f5aef34234bb22b9a615e30ccd')); - $event->setSpans([$span]); - $event->setTransaction('GET /'); - $event->setContext('trace', [ - 'trace_id' => '21160e9b836d479f81611368b2aa3d2c', - 'span_id' => '5dd538dc297544cc', - ]); - $event->setMetricsSummary([ - 'c:counter@star' => [ - 'c:counter@stara:0:{s:10:"repository";s:6:"client";}' => [ - 'min' => 1, - 'max' => 1, - 'sum' => 1, - 'count' => 1, - 'tags' => [ - 'repository' => 'client', - ], - ], - ], - ]); - - yield [ - $event, - <<setMetricsSummary( - CounterType::TYPE, - 'counter', - 10, - MetricsUnit::custom('star'), - [ - 'repository' => 'client', - ] - ); - $span->setMetricsSummary( - CounterType::TYPE, - 'counter', - 50, - MetricsUnit::custom('star'), - [ - 'repository' => 'client', - ] - ); - $span->setMetricsSummary( - CounterType::TYPE, - 'counter', - 10, - MetricsUnit::custom('star'), - [ - 'repository' => 'server', - ] - ); - - $span->setMetricsSummary( - DistributionType::TYPE, - 'distribution', - 10.2, - MetricsUnit::millisecond(), - [] - ); - $span->setMetricsSummary( - DistributionType::TYPE, - 'distribution', - 5.7, - MetricsUnit::millisecond(), - [] - ); - - $span->setMetricsSummary( - GaugeType::TYPE, - 'gauge', - 10, - MetricsUnit::none(), - [] - ); - $span->setMetricsSummary( - GaugeType::TYPE, - 'gauge', - 20, - MetricsUnit::none(), - [] - ); - - $span->setMetricsSummary( - SetType::TYPE, - 'set', - 'jane@doe@example.com', - MetricsUnit::custom('user'), - [] - ); - $span->setMetricsSummary( - SetType::TYPE, - 'set', - 'jon@doe@example.com', - MetricsUnit::custom('user'), - [] - ); - - $this->assertSame([ - 'c:counter@star' => [ - 'c:counter@stara:1:{s:10:"repository";s:6:"client";}' => [ - 'min' => 10.0, - 'max' => 50.0, - 'sum' => 60.0, - 'count' => 2, - 'tags' => [ - 'repository' => 'client', - ], - ], - 'c:counter@stara:1:{s:10:"repository";s:6:"server";}' => [ - 'min' => 10.0, - 'max' => 10.0, - 'sum' => 10.0, - 'count' => 1, - 'tags' => [ - 'repository' => 'server', - ], - ], - ], - 'd:distribution@millisecond' => [ - 'd:distribution@milliseconda:0:{}' => [ - 'min' => 5.7, - 'max' => 10.2, - 'sum' => 15.899999999999999, - 'count' => 2, - 'tags' => [], - ], - ], - 'g:gauge@none' => [ - 'g:gauge@nonea:0:{}' => [ - 'min' => 10.0, - 'max' => 20.0, - 'sum' => 30.0, - 'count' => 2, - 'tags' => [], - ], - ], - 's:set@user' => [ - 's:set@usera:0:{}' => [ - 'min' => 0.0, - 'max' => 1.0, - 'sum' => 1.0, - 'count' => 2, - 'tags' => [], - ], - ], - ], $span->getMetricsSummary()); - } - public function testDataGetter(): void { $span = new Span(); diff --git a/tests/Transport/RateLimiterTest.php b/tests/Transport/RateLimiterTest.php index be6c4e24c..19f9a9f89 100644 --- a/tests/Transport/RateLimiterTest.php +++ b/tests/Transport/RateLimiterTest.php @@ -57,7 +57,6 @@ public static function handleResponseDataProvider(): \Generator [ EventType::event(), EventType::transaction(), - EventType::metrics(), ], ]; @@ -67,38 +66,6 @@ public static function handleResponseDataProvider(): \Generator EventType::cases(), ]; - yield 'Back-off using X-Sentry-Rate-Limits header with metric_bucket category' => [ - new Response(429, ['X-Sentry-Rate-Limits' => ['60:metric_bucket:organization:quota_exceeded:custom']], ''), - true, - [ - EventType::metrics(), - ], - ]; - - yield 'Back-off using X-Sentry-Rate-Limits header with metric_bucket category, namespace custom and foo' => [ - new Response(429, ['X-Sentry-Rate-Limits' => ['60:metric_bucket:organization:quota_exceeded:custom;foo']], ''), - true, - [ - EventType::metrics(), - ], - ]; - - yield 'Back-off using X-Sentry-Rate-Limits header with metric_bucket category without reason code' => [ - new Response(429, ['X-Sentry-Rate-Limits' => ['60:metric_bucket:organization::custom']], ''), - true, - [ - EventType::metrics(), - ], - ]; - - yield 'Back-off using X-Sentry-Rate-Limits header with metric_bucket category without metric namespaces' => [ - new Response(429, ['X-Sentry-Rate-Limits' => ['60:metric_bucket:organization:quota_exceeded']], ''), - true, - [ - EventType::metrics(), - ], - ]; - yield 'Do not back-off using X-Sentry-Rate-Limits header with metric_bucket category, namespace foo' => [ new Response(429, ['X-Sentry-Rate-Limits' => ['60:metric_bucket:organization:quota_exceeded:foo']], ''), false, From 5afe5f4a2da29e93aa04b72bd5ead9d1f09ee241 Mon Sep 17 00:00:00 2001 From: Alex Bouma Date: Tue, 29 Oct 2024 20:01:17 +0100 Subject: [PATCH 2/3] CS --- phpstan-baseline.neon | 40 +++++++++++++++++++--- tests/Metrics/MetricsTest.php | 4 --- tests/Serializer/PayloadSerializerTest.php | 5 --- tests/Tracing/SpanTest.php | 5 --- 4 files changed, 35 insertions(+), 19 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index e3c69ed59..ae65ebb11 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -25,6 +25,26 @@ parameters: count: 1 path: src/Dsn.php + - + message: "#^Method Sentry\\\\Event\\:\\:getMetrics\\(\\) return type has no value type specified in iterable type array\\.$#" + count: 1 + path: src/Event.php + + - + message: "#^Method Sentry\\\\Event\\:\\:getMetricsSummary\\(\\) return type has no value type specified in iterable type array\\.$#" + count: 1 + path: src/Event.php + + - + message: "#^Method Sentry\\\\Event\\:\\:setMetrics\\(\\) has parameter \\$metrics with no value type specified in iterable type array\\.$#" + count: 1 + path: src/Event.php + + - + message: "#^Method Sentry\\\\Event\\:\\:setMetricsSummary\\(\\) has parameter \\$metricsSummary with no value type specified in iterable type array\\.$#" + count: 1 + path: src/Event.php + - message: "#^Property Sentry\\\\Integration\\\\RequestIntegration\\:\\:\\$options \\(array\\{pii_sanitize_headers\\: array\\\\}\\) does not accept array\\.$#" count: 1 @@ -40,11 +60,6 @@ parameters: count: 1 path: src/Logger/DebugStdOutLogger.php - - - message: "#^Method Sentry\\\\Metrics\\\\Types\\\\AbstractType\\:\\:add\\(\\) has parameter \\$value with no type specified\\.$#" - count: 1 - path: src/Metrics/Types/AbstractType.php - - message: "#^Parameter \\#1 \\$level of method Monolog\\\\Handler\\\\AbstractHandler\\:\\:__construct\\(\\) expects 100\\|200\\|250\\|300\\|400\\|500\\|550\\|600\\|'ALERT'\\|'alert'\\|'CRITICAL'\\|'critical'\\|'DEBUG'\\|'debug'\\|'EMERGENCY'\\|'emergency'\\|'ERROR'\\|'error'\\|'INFO'\\|'info'\\|'NOTICE'\\|'notice'\\|'WARNING'\\|'warning'\\|Monolog\\\\Level, int\\|Monolog\\\\Level\\|string given\\.$#" count: 1 @@ -290,6 +305,21 @@ parameters: count: 1 path: src/Tracing/GuzzleTracingMiddleware.php + - + message: "#^Method Sentry\\\\Tracing\\\\Span\\:\\:getMetricsSummary\\(\\) return type has no value type specified in iterable type array\\.$#" + count: 1 + path: src/Tracing/Span.php + + - + message: "#^Method Sentry\\\\Tracing\\\\Span\\:\\:setMetricsSummary\\(\\) has parameter \\$tags with no value type specified in iterable type array\\.$#" + count: 1 + path: src/Tracing/Span.php + + - + message: "#^Method Sentry\\\\Tracing\\\\Span\\:\\:setMetricsSummary\\(\\) has parameter \\$value with no type specified\\.$#" + count: 1 + path: src/Tracing/Span.php + - message: "#^Parameter \\#1 \\$email of method Sentry\\\\UserDataBag\\:\\:setEmail\\(\\) expects string\\|null, mixed given\\.$#" count: 1 diff --git a/tests/Metrics/MetricsTest.php b/tests/Metrics/MetricsTest.php index 1e8a0d64a..654156c5c 100644 --- a/tests/Metrics/MetricsTest.php +++ b/tests/Metrics/MetricsTest.php @@ -8,10 +8,6 @@ use Sentry\ClientInterface; use Sentry\Event; use Sentry\Metrics\MetricsUnit; -use Sentry\Metrics\Types\CounterType; -use Sentry\Metrics\Types\DistributionType; -use Sentry\Metrics\Types\GaugeType; -use Sentry\Metrics\Types\SetType; use Sentry\Options; use Sentry\SentrySdk; use Sentry\State\Hub; diff --git a/tests/Serializer/PayloadSerializerTest.php b/tests/Serializer/PayloadSerializerTest.php index 05045e6c0..c9283825d 100644 --- a/tests/Serializer/PayloadSerializerTest.php +++ b/tests/Serializer/PayloadSerializerTest.php @@ -16,11 +16,6 @@ use Sentry\ExceptionDataBag; use Sentry\ExceptionMechanism; use Sentry\Frame; -use Sentry\Metrics\MetricsUnit; -use Sentry\Metrics\Types\CounterType; -use Sentry\Metrics\Types\DistributionType; -use Sentry\Metrics\Types\GaugeType; -use Sentry\Metrics\Types\SetType; use Sentry\MonitorConfig; use Sentry\MonitorSchedule; use Sentry\Options; diff --git a/tests/Tracing/SpanTest.php b/tests/Tracing/SpanTest.php index 4e5035bd8..140c3fe81 100644 --- a/tests/Tracing/SpanTest.php +++ b/tests/Tracing/SpanTest.php @@ -5,11 +5,6 @@ namespace Sentry\Tests\Tracing; use PHPUnit\Framework\TestCase; -use Sentry\Metrics\MetricsUnit; -use Sentry\Metrics\Types\CounterType; -use Sentry\Metrics\Types\DistributionType; -use Sentry\Metrics\Types\GaugeType; -use Sentry\Metrics\Types\SetType; use Sentry\Tracing\Span; use Sentry\Tracing\SpanContext; use Sentry\Tracing\SpanId; From 173cdb16f1d9dbe1c38b51d6b824b78abeccd4e5 Mon Sep 17 00:00:00 2001 From: Alex Bouma Date: Tue, 5 Nov 2024 18:01:13 +0100 Subject: [PATCH 3/3] Remove metric bucket rate limiting category --- src/Transport/RateLimiter.php | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/src/Transport/RateLimiter.php b/src/Transport/RateLimiter.php index be3801b01..9a3d6d0f5 100644 --- a/src/Transport/RateLimiter.php +++ b/src/Transport/RateLimiter.php @@ -16,11 +16,6 @@ final class RateLimiter */ private const DATA_CATEGORY_ERROR = 'error'; - /** - * @var string - */ - private const DATA_CATEGORY_METRIC_BUCKET = 'metric_bucket'; - /** * The name of the header to look at to know the rate limits for the events * categories supported by the server. @@ -72,26 +67,7 @@ public function handleResponse(Response $response): bool $retryAfter = $now + (ctype_digit($parameters[0]) ? (int) $parameters[0] : self::DEFAULT_RETRY_AFTER_SECONDS); foreach (explode(';', $parameters[1]) as $category) { - switch ($category) { - case self::DATA_CATEGORY_METRIC_BUCKET: - $namespaces = []; - if (isset($parameters[4])) { - $namespaces = explode(';', $parameters[4]); - } - - /** - * As we do not support setting any metric namespaces in the SDK, - * checking for the custom namespace suffices. - * In case the namespace was ommited in the response header, - * we'll also back off. - */ - if ($namespaces === [] || \in_array('custom', $namespaces)) { - $this->rateLimits[self::DATA_CATEGORY_METRIC_BUCKET] = $retryAfter; - } - break; - default: - $this->rateLimits[$category ?: 'all'] = $retryAfter; - } + $this->rateLimits[$category ?: 'all'] = $retryAfter; $this->logger->warning( \sprintf('Rate limited exceeded for category "%s", backing off until "%s".', $category, gmdate(\DATE_ATOM, $retryAfter))