Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove metrics plumbing and deprecate/no-op public API #1786

Merged
merged 4 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 35 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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\\<string\\>\\}\\) does not accept array\\.$#"
count: 1
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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';
}
Expand Down
30 changes: 9 additions & 21 deletions src/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -62,16 +61,6 @@ final class Event
*/
private $checkIn;

/**
* @var array<string, AbstractType> The metrics data
*/
private $metrics = [];

/**
* @var array<string, array<string, MetricsSummary>>
*/
private $metricsSummary = [];

/**
* @var string|null The name of the server (e.g. the host name)
*/
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -377,38 +369,34 @@ public function setCheckIn(?CheckIn $checkIn): self
}

/**
* @return array<string, AbstractType>
* @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<string, AbstractType> $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<string, array<string, MetricsSummary>>
* @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<string, array<string, MetricsSummary>> $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;
}

Expand Down
3 changes: 3 additions & 0 deletions src/EventType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
7 changes: 0 additions & 7 deletions src/Integration/FrameContextifierIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}
Expand Down
87 changes: 16 additions & 71 deletions src/Metrics/Metrics.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -41,6 +27,8 @@ public static function getInstance(): self

/**
* @param array<string, string> $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,
Expand All @@ -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<string, string> $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,
Expand All @@ -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<string, string> $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,
Expand All @@ -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<string, string> $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,
Expand All @@ -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
);
}

/**
Expand All @@ -135,6 +93,8 @@ public function set(
* @param array<string, string> $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,
Expand All @@ -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')
Expand All @@ -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;
}
}
Loading
Loading