Skip to content

Commit 21a77e7

Browse files
authored
Remove metrics plumbing and deprecate/no-op public API (#1786)
1 parent 452fc34 commit 21a77e7

27 files changed

+101
-1396
lines changed

phpstan-baseline.neon

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,26 @@ parameters:
2525
count: 1
2626
path: src/Dsn.php
2727

28+
-
29+
message: "#^Method Sentry\\\\Event\\:\\:getMetrics\\(\\) return type has no value type specified in iterable type array\\.$#"
30+
count: 1
31+
path: src/Event.php
32+
33+
-
34+
message: "#^Method Sentry\\\\Event\\:\\:getMetricsSummary\\(\\) return type has no value type specified in iterable type array\\.$#"
35+
count: 1
36+
path: src/Event.php
37+
38+
-
39+
message: "#^Method Sentry\\\\Event\\:\\:setMetrics\\(\\) has parameter \\$metrics with no value type specified in iterable type array\\.$#"
40+
count: 1
41+
path: src/Event.php
42+
43+
-
44+
message: "#^Method Sentry\\\\Event\\:\\:setMetricsSummary\\(\\) has parameter \\$metricsSummary with no value type specified in iterable type array\\.$#"
45+
count: 1
46+
path: src/Event.php
47+
2848
-
2949
message: "#^Property Sentry\\\\Integration\\\\RequestIntegration\\:\\:\\$options \\(array\\{pii_sanitize_headers\\: array\\<string\\>\\}\\) does not accept array\\.$#"
3050
count: 1
@@ -40,11 +60,6 @@ parameters:
4060
count: 1
4161
path: src/Logger/DebugStdOutLogger.php
4262

43-
-
44-
message: "#^Method Sentry\\\\Metrics\\\\Types\\\\AbstractType\\:\\:add\\(\\) has parameter \\$value with no type specified\\.$#"
45-
count: 1
46-
path: src/Metrics/Types/AbstractType.php
47-
4863
-
4964
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\\.$#"
5065
count: 1
@@ -290,6 +305,21 @@ parameters:
290305
count: 1
291306
path: src/Tracing/GuzzleTracingMiddleware.php
292307

308+
-
309+
message: "#^Method Sentry\\\\Tracing\\\\Span\\:\\:getMetricsSummary\\(\\) return type has no value type specified in iterable type array\\.$#"
310+
count: 1
311+
path: src/Tracing/Span.php
312+
313+
-
314+
message: "#^Method Sentry\\\\Tracing\\\\Span\\:\\:setMetricsSummary\\(\\) has parameter \\$tags with no value type specified in iterable type array\\.$#"
315+
count: 1
316+
path: src/Tracing/Span.php
317+
318+
-
319+
message: "#^Method Sentry\\\\Tracing\\\\Span\\:\\:setMetricsSummary\\(\\) has parameter \\$value with no type specified\\.$#"
320+
count: 1
321+
path: src/Tracing/Span.php
322+
293323
-
294324
message: "#^Parameter \\#1 \\$email of method Sentry\\\\UserDataBag\\:\\:setEmail\\(\\) expects string\\|null, mixed given\\.$#"
295325
count: 1

src/Client.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,6 @@ private function applyBeforeSendCallback(Event $event, ?EventHint $hint): ?Event
409409
return ($this->options->getBeforeSendTransactionCallback())($event, $hint);
410410
case EventType::checkIn():
411411
return ($this->options->getBeforeSendCheckInCallback())($event, $hint);
412-
case EventType::metrics():
413-
return ($this->options->getBeforeSendMetricsCallback())($event, $hint);
414412
default:
415413
return $event;
416414
}
@@ -423,8 +421,6 @@ private function getBeforeSendCallbackName(Event $event): string
423421
return 'before_send_transaction';
424422
case EventType::checkIn():
425423
return 'before_send_check_in';
426-
case EventType::metrics():
427-
return 'before_send_metrics';
428424
default:
429425
return 'before_send';
430426
}

src/Event.php

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use Sentry\Context\OsContext;
88
use Sentry\Context\RuntimeContext;
9-
use Sentry\Metrics\Types\AbstractType;
109
use Sentry\Profiling\Profile;
1110
use Sentry\Tracing\Span;
1211

@@ -62,16 +61,6 @@ final class Event
6261
*/
6362
private $checkIn;
6463

65-
/**
66-
* @var array<string, AbstractType> The metrics data
67-
*/
68-
private $metrics = [];
69-
70-
/**
71-
* @var array<string, array<string, MetricsSummary>>
72-
*/
73-
private $metricsSummary = [];
74-
7564
/**
7665
* @var string|null The name of the server (e.g. the host name)
7766
*/
@@ -227,6 +216,9 @@ public static function createCheckIn(?EventId $eventId = null): self
227216
return new self($eventId, EventType::checkIn());
228217
}
229218

219+
/**
220+
* @deprecated Metrics are no longer supported. Metrics API is a no-op and will be removed in 5.x.
221+
*/
230222
public static function createMetrics(?EventId $eventId = null): self
231223
{
232224
return new self($eventId, EventType::metrics());
@@ -377,38 +369,34 @@ public function setCheckIn(?CheckIn $checkIn): self
377369
}
378370

379371
/**
380-
* @return array<string, AbstractType>
372+
* @deprecated Metrics are no longer supported. Metrics API is a no-op and will be removed in 5.x.
381373
*/
382374
public function getMetrics(): array
383375
{
384-
return $this->metrics;
376+
return [];
385377
}
386378

387379
/**
388-
* @param array<string, AbstractType> $metrics
380+
* @deprecated Metrics are no longer supported. Metrics API is a no-op and will be removed in 5.x.
389381
*/
390382
public function setMetrics(array $metrics): self
391383
{
392-
$this->metrics = $metrics;
393-
394384
return $this;
395385
}
396386

397387
/**
398-
* @return array<string, array<string, MetricsSummary>>
388+
* @deprecated Metrics are no longer supported. Metrics API is a no-op and will be removed in 5.x.
399389
*/
400390
public function getMetricsSummary(): array
401391
{
402-
return $this->metricsSummary;
392+
return [];
403393
}
404394

405395
/**
406-
* @param array<string, array<string, MetricsSummary>> $metricsSummary
396+
* @deprecated Metrics are no longer supported. Metrics API is a no-op and will be removed in 5.x.
407397
*/
408398
public function setMetricsSummary(array $metricsSummary): self
409399
{
410-
$this->metricsSummary = $metricsSummary;
411-
412400
return $this;
413401
}
414402

src/EventType.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ public static function checkIn(): self
4242
return self::getInstance('check_in');
4343
}
4444

45+
/**
46+
* @deprecated Metrics are no longer supported. Metrics API is a no-op and will be removed in 5.x.
47+
*/
4548
public static function metrics(): self
4649
{
4750
return self::getInstance('metrics');

src/Integration/FrameContextifierIntegration.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,6 @@ public function setupOnce(): void
6666
}
6767
}
6868

69-
foreach ($event->getMetrics() as $metric) {
70-
if ($metric->hasCodeLocation()) {
71-
$frame = $metric->getCodeLocation();
72-
$integration->addContextToStacktraceFrame($maxContextLines, $frame);
73-
}
74-
}
75-
7669
return $event;
7770
});
7871
}

src/Metrics/Metrics.php

Lines changed: 16 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
namespace Sentry\Metrics;
66

77
use Sentry\EventId;
8-
use Sentry\Metrics\Types\CounterType;
9-
use Sentry\Metrics\Types\DistributionType;
10-
use Sentry\Metrics\Types\GaugeType;
11-
use Sentry\Metrics\Types\SetType;
128
use Sentry\Tracing\SpanContext;
139

1410
use function Sentry\trace;
@@ -20,16 +16,6 @@ class Metrics
2016
*/
2117
private static $instance;
2218

23-
/**
24-
* @var MetricsAggregator
25-
*/
26-
private $aggregator;
27-
28-
private function __construct()
29-
{
30-
$this->aggregator = new MetricsAggregator();
31-
}
32-
3319
public static function getInstance(): self
3420
{
3521
if (self::$instance === null) {
@@ -41,6 +27,8 @@ public static function getInstance(): self
4127

4228
/**
4329
* @param array<string, string> $tags
30+
*
31+
* @deprecated Metrics are no longer supported. Metrics API is a no-op and will be removed in 5.x.
4432
*/
4533
public function increment(
4634
string $key,
@@ -50,19 +38,12 @@ public function increment(
5038
?int $timestamp = null,
5139
int $stackLevel = 0
5240
): void {
53-
$this->aggregator->add(
54-
CounterType::TYPE,
55-
$key,
56-
$value,
57-
$unit,
58-
$tags,
59-
$timestamp,
60-
$stackLevel
61-
);
6241
}
6342

6443
/**
6544
* @param array<string, string> $tags
45+
*
46+
* @deprecated Metrics are no longer supported. Metrics API is a no-op and will be removed in 5.x.
6647
*/
6748
public function distribution(
6849
string $key,
@@ -72,19 +53,12 @@ public function distribution(
7253
?int $timestamp = null,
7354
int $stackLevel = 0
7455
): void {
75-
$this->aggregator->add(
76-
DistributionType::TYPE,
77-
$key,
78-
$value,
79-
$unit,
80-
$tags,
81-
$timestamp,
82-
$stackLevel
83-
);
8456
}
8557

8658
/**
8759
* @param array<string, string> $tags
60+
*
61+
* @deprecated Metrics are no longer supported. Metrics API is a no-op and will be removed in 5.x.
8862
*/
8963
public function gauge(
9064
string $key,
@@ -94,20 +68,13 @@ public function gauge(
9468
?int $timestamp = null,
9569
int $stackLevel = 0
9670
): void {
97-
$this->aggregator->add(
98-
GaugeType::TYPE,
99-
$key,
100-
$value,
101-
$unit,
102-
$tags,
103-
$timestamp,
104-
$stackLevel
105-
);
10671
}
10772

10873
/**
10974
* @param int|string $value
11075
* @param array<string, string> $tags
76+
*
77+
* @deprecated Metrics are no longer supported. Metrics API is a no-op and will be removed in 5.x.
11178
*/
11279
public function set(
11380
string $key,
@@ -117,15 +84,6 @@ public function set(
11784
?int $timestamp = null,
11885
int $stackLevel = 0
11986
): void {
120-
$this->aggregator->add(
121-
SetType::TYPE,
122-
$key,
123-
$value,
124-
$unit,
125-
$tags,
126-
$timestamp,
127-
$stackLevel
128-
);
12987
}
13088

13189
/**
@@ -135,6 +93,8 @@ public function set(
13593
* @param array<string, string> $tags
13694
*
13795
* @return T
96+
*
97+
* @deprecated Metrics are no longer supported. Metrics API is a no-op and will be removed in 5.x.
13898
*/
13999
public function timing(
140100
string $key,
@@ -143,26 +103,8 @@ public function timing(
143103
int $stackLevel = 0
144104
) {
145105
return trace(
146-
function () use ($callback, $key, $tags, $stackLevel) {
147-
$startTimestamp = microtime(true);
148-
149-
$result = $callback();
150-
151-
/**
152-
* Emitting the metric here, will attach it to the
153-
* "metric.timing" span.
154-
*/
155-
$this->aggregator->add(
156-
DistributionType::TYPE,
157-
$key,
158-
microtime(true) - $startTimestamp,
159-
MetricsUnit::second(),
160-
$tags,
161-
(int) $startTimestamp,
162-
$stackLevel + 4 // the `trace` helper adds 4 additional stack frames
163-
);
164-
165-
return $result;
106+
function () use ($callback) {
107+
return $callback();
166108
},
167109
SpanContext::make()
168110
->setOp('metric.timing')
@@ -171,8 +113,11 @@ function () use ($callback, $key, $tags, $stackLevel) {
171113
);
172114
}
173115

116+
/**
117+
* @deprecated Metrics are no longer supported. Metrics API is a no-op and will be removed in 5.x.
118+
*/
174119
public function flush(): ?EventId
175120
{
176-
return $this->aggregator->flush();
121+
return null;
177122
}
178123
}

0 commit comments

Comments
 (0)