Skip to content

Conversation

@Litarnus
Copy link
Contributor

@Litarnus Litarnus commented Nov 19, 2025

Introducing metrics for PHP!

Metrics have 3 supported types

  • Counter
  • Gauge
  • Distribution

Each of those metrics can be submitted by calling
\Sentry\metrics()->count('test-counter', 1, ['tag' => 'foo'])

It's also possible to attach units:
\Sentry\metrics()->gauge('test-gauge', 10, ['tag' => 'foo'], \Sentry\Metrics\Unit::second())

Up to 1000 metrics can be stored per request. Older metrics are dropped when the limit is reached.

Metrics need to be flushed manually by calling \Sentry\metrics()->flush().

@Litarnus Litarnus marked this pull request as ready for review November 19, 2025 10:54
string $key,
float $value,
?MetricsUnit $unit = null,
?Unit $unit = null,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
?Unit $unit = null,
?MetricsUnit $unit = null,

Copy link
Collaborator

@stayallive stayallive left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code wise the looks good (especially much love for the RingBuffer).

The only thing I'm worried about a bit is that we modify the existing code, namely MetricsUnit and some parameters which is a backwards incompatible break for people that did not yet cleanup their code after we deprecated the previous metrics iteration. Do we feel like that is an acceptable risk? If this is going in 5.x this is a non-issue but the target is master so hence my ask.

@Litarnus
Copy link
Contributor Author

Code wise the looks good (especially much love for the RingBuffer).

The only thing I'm worried about a bit is that we modify the existing code, namely MetricsUnit and some parameters which is a backwards incompatible break for people that did not yet cleanup their code after we deprecated the previous metrics iteration. Do we feel like that is an acceptable risk? If this is going in 5.x this is a non-issue but the target is master so hence my ask.

Initially we wanted to take the risk but after a longer thought we decided against it. I will revert the Metrics class back to how it originally was and will introduce a TraceMetrics class with the new methods.
I will also add a new alias for Unit -> MetricsUnit since we want to use the unit in different places too.

Thanks for your review, I make this a draft again and ping you once it's updated!

@Litarnus Litarnus marked this pull request as draft November 24, 2025 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants