77use Sentry \Client ;
88use Sentry \Event ;
99use 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 ;
1414use Sentry \SentrySdk ;
1515use Sentry \State \Scope ;
1616use 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
0 commit comments