Skip to content

Commit ab49ab6

Browse files
committed
PR feedback
1 parent bba5667 commit ab49ab6

File tree

16 files changed

+82
-61
lines changed

16 files changed

+82
-61
lines changed

src/Event.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Sentry\Context\OsContext;
88
use Sentry\Context\RuntimeContext;
99
use Sentry\Logs\Log;
10-
use Sentry\Metrics\Types\AbstractType;
10+
use Sentry\Metrics\Types\Metric;
1111
use Sentry\Profiling\Profile;
1212
use Sentry\Tracing\Span;
1313

@@ -73,7 +73,7 @@ final class Event
7373
private $logs = [];
7474

7575
/**
76-
* @var AbstractType[]
76+
* @var Metric[]
7777
*/
7878
private $metrics = [];
7979

@@ -449,15 +449,15 @@ public function setLogs(array $logs): self
449449
}
450450

451451
/**
452-
* @return AbstractType[]
452+
* @return Metric[]
453453
*/
454454
public function getMetrics(): array
455455
{
456456
return $this->metrics;
457457
}
458458

459459
/**
460-
* @param AbstractType[] $metrics
460+
* @param Metric[] $metrics
461461
*/
462462
public function setMetrics(array $metrics): self
463463
{

src/EventType.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public function requiresEventId(): bool
7272
{
7373
switch ($this) {
7474
case self::metrics():
75+
case self::logs():
7576
return false;
7677
default:
7778
return true;

src/Metrics/Metrics.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Sentry\EventId;
88
use Sentry\Tracing\SpanContext;
99

10+
use Sentry\Unit;
1011
use function Sentry\trace;
1112

1213
class_alias(Unit::class, '\Sentry\Metrics\MetricsUnit');

src/Metrics/MetricsAggregator.php

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
use Sentry\Client;
88
use Sentry\Event;
99
use Sentry\EventId;
10-
use Sentry\Metrics\Types\AbstractType;
11-
use Sentry\Metrics\Types\CounterType;
12-
use Sentry\Metrics\Types\DistributionType;
13-
use Sentry\Metrics\Types\GaugeType;
10+
use Sentry\Metrics\Types\CounterMetric;
11+
use Sentry\Metrics\Types\DistributionMetric;
12+
use Sentry\Metrics\Types\GaugeMetric;
13+
use Sentry\Metrics\Types\Metric;
1414
use Sentry\SentrySdk;
1515
use Sentry\State\Scope;
1616
use Sentry\Util\RingBuffer;
@@ -26,7 +26,7 @@ final class MetricsAggregator
2626
public const METRICS_BUFFER_SIZE = 1000;
2727

2828
/**
29-
* @var RingBuffer<AbstractType>
29+
* @var RingBuffer<Metric>
3030
*/
3131
private $metrics;
3232

@@ -36,9 +36,9 @@ public function __construct()
3636
}
3737

3838
private const METRIC_TYPES = [
39-
CounterType::TYPE => CounterType::class,
40-
DistributionType::TYPE => DistributionType::class,
41-
GaugeType::TYPE => GaugeType::class,
39+
CounterMetric::TYPE => CounterMetric::class,
40+
DistributionMetric::TYPE => DistributionMetric::class,
41+
GaugeMetric::TYPE => GaugeMetric::class,
4242
];
4343

4444
/**
@@ -66,8 +66,26 @@ public function add(
6666
'sentry.sdk.name' => $client->getSdkIdentifier(),
6767
'sentry.sdk.version' => $client->getSdkVersion(),
6868
'sentry.environment' => $options->getEnvironment() ?? Event::DEFAULT_ENVIRONMENT,
69+
'server.address' => $options->getServerName(),
6970
];
7071

72+
if ($options->shouldSendDefaultPii()) {
73+
$hub->configureScope(function (Scope $scope) use (&$defaultAttributes) {
74+
$user = $scope->getUser();
75+
if ($user !== null) {
76+
if ($user->getId() !== null) {
77+
$defaultAttributes['user.id'] = $user->getId();
78+
}
79+
if ($user->getEmail() !== null) {
80+
$defaultAttributes['user.email'] = $user->getEmail();
81+
}
82+
if ($user->getUsername() !== null) {
83+
$defaultAttributes['user.name'] = $user->getUsername();
84+
}
85+
}
86+
});
87+
}
88+
7189
$release = $options->getRelease();
7290
if ($release !== null) {
7391
$defaultAttributes['sentry.release'] = $release;
@@ -92,7 +110,7 @@ public function add(
92110
}
93111

94112
$metricTypeClass = self::METRIC_TYPES[$type];
95-
/** @var AbstractType $metric */
113+
/** @var Metric $metric */
96114
/** @phpstan-ignore-next-line */
97115
$metric = new $metricTypeClass($name, $value, $traceId, $spanId, $attributes, microtime(true), $unit);
98116

src/Metrics/TraceMetrics.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
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;
8+
use Sentry\Metrics\Types\CounterMetric;
9+
use Sentry\Metrics\Types\DistributionMetric;
10+
use Sentry\Metrics\Types\GaugeMetric;
11+
use Sentry\Unit;
1112

1213
class TraceMetrics
1314
{
@@ -46,7 +47,7 @@ public function count(
4647
?Unit $unit = null
4748
): void {
4849
$this->aggregator->add(
49-
CounterType::TYPE,
50+
CounterMetric::TYPE,
5051
$name,
5152
$value,
5253
$attributes,
@@ -65,7 +66,7 @@ public function distribution(
6566
?Unit $unit = null
6667
): void {
6768
$this->aggregator->add(
68-
DistributionType::TYPE,
69+
DistributionMetric::TYPE,
6970
$name,
7071
$value,
7172
$attributes,
@@ -84,7 +85,7 @@ public function gauge(
8485
?Unit $unit = null
8586
): void {
8687
$this->aggregator->add(
87-
GaugeType::TYPE,
88+
GaugeMetric::TYPE,
8889
$name,
8990
$value,
9091
$attributes,
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
namespace Sentry\Metrics\Types;
66

7-
use Sentry\Metrics\Unit;
87
use Sentry\Tracing\SpanId;
98
use Sentry\Tracing\TraceId;
9+
use Sentry\Unit;
1010

1111
/**
1212
* @internal
1313
*/
14-
final class CounterType extends AbstractType
14+
final class CounterMetric extends Metric
1515
{
1616
/**
1717
* @var string
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
namespace Sentry\Metrics\Types;
66

7-
use Sentry\Metrics\Unit;
7+
use Sentry\Unit;
88
use Sentry\Tracing\SpanId;
99
use Sentry\Tracing\TraceId;
1010

1111
/**
1212
* @internal
1313
*/
14-
final class DistributionType extends AbstractType
14+
final class DistributionMetric extends Metric
1515
{
1616
/**
1717
* @var string
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
namespace Sentry\Metrics\Types;
66

7-
use Sentry\Metrics\Unit;
87
use Sentry\Tracing\SpanId;
98
use Sentry\Tracing\TraceId;
9+
use Sentry\Unit;
1010

1111
/**
1212
* @internal
1313
*/
14-
final class GaugeType extends AbstractType
14+
final class GaugeMetric extends Metric
1515
{
1616
/**
1717
* @var string
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
namespace Sentry\Metrics\Types;
66

77
use Sentry\Attributes\AttributeBag;
8-
use Sentry\Metrics\Unit;
98
use Sentry\Tracing\SpanId;
109
use Sentry\Tracing\TraceId;
10+
use Sentry\Unit;
1111

1212
/**
1313
* @internal
1414
*/
15-
abstract class AbstractType
15+
abstract class Metric
1616
{
1717
/**
1818
* @var string

src/Options.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Sentry\Integration\ErrorListenerIntegration;
1111
use Sentry\Integration\IntegrationInterface;
1212
use Sentry\Logs\Log;
13-
use Sentry\Metrics\Types\AbstractType;
13+
use Sentry\Metrics\Types\Metric;
1414
use Sentry\Transport\TransportInterface;
1515
use Symfony\Component\OptionsResolver\Options as SymfonyOptions;
1616
use Symfony\Component\OptionsResolver\OptionsResolver;
@@ -1317,7 +1317,7 @@ private function configureOptions(OptionsResolver $resolver): void
13171317
'before_send_metrics' => static function (Event $metrics): ?Event {
13181318
return null;
13191319
},
1320-
'before_send_metric' => static function (AbstractType $metric): AbstractType {
1320+
'before_send_metric' => static function (Metric $metric): Metric {
13211321
return $metric;
13221322
},
13231323
'trace_propagation_targets' => null,

0 commit comments

Comments
 (0)