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

Add support for Sentry Developer Metrics #1619

Merged
merged 38 commits into from
Dec 21, 2023
Merged

Add support for Sentry Developer Metrics #1619

merged 38 commits into from
Dec 21, 2023

Conversation

cleptric
Copy link
Member

@cleptric cleptric commented Oct 31, 2023

This adds support for Sentry Developer Metrics.

See getsentry/sentry#58584

image

use function Sentry\metrics;

// Add 4 to a counter named `hits`
metrics()->increment(key: 'hits', value: 4);

// Add 25 to a distribution named `response_time` with unit milliseconds
metrics()->distribution(key: 'response_time', value: 25, unit: MetricsUnit::millisecond());

// Add 2 to gauge named `parallel_requests`, tagged with `type: "a"`
metrics()->gauge(key: 'parallel_requests, value: 2, tags: ['type': 'a']);

// Add a user's email to a set named users.sessions, tagged with role admin
metrics()->set('users.sessions', '[email protected]', null, ['role' => User::admin()]);

// Flush the metrics to Sentry
metrics()->flush();

// We recommend registering the flushing in a shutdown function
register_shutdown_function(static fn () => metrics()->flush());

In case you're not already enrolled on our Metrics alpha program, please sign up here.

To-Dos

@cleptric cleptric marked this pull request as draft October 31, 2023 03:52
@cleptric cleptric self-assigned this Oct 31, 2023
@cleptric cleptric added this to the 4.0 milestone Oct 31, 2023
@cleptric cleptric force-pushed the metrics branch 2 times, most recently from 62bb5b7 to 46a9089 Compare October 31, 2023 11:49
@cleptric cleptric removed this from the 4.0 milestone Nov 6, 2023
Base automatically changed from 4.x to master November 6, 2023 10:15
@cleptric cleptric marked this pull request as ready for review November 8, 2023 04:28
@cleptric cleptric marked this pull request as draft November 10, 2023 12:31
@cleptric
Copy link
Member Author

Marking as Draft again, missed some stuff

  • The envelope should be serialized as statsd instead, it's more efficient https://getsentry.github.io/relay/relay_metrics/index.html#metric-envelopes
  • All metric types should support units
  • A custom string unit, like meter|inch etc. must also be supported
  • Distribution values should allow strings as well, which need to be hashed with crc32
  • We also should add some sort of aggregation, using 10 second buckets to not overwhelm the transport

src/Metrics/MetricsAggregator.php Outdated Show resolved Hide resolved
src/Tracing/Span.php Outdated Show resolved Hide resolved
@cleptric cleptric changed the title Add DDM support Add support for Sentry Developer Metrics Dec 21, 2023
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.

🪨

@HazAT HazAT marked this pull request as ready for review December 21, 2023 14:36
@cleptric cleptric merged commit c88988d into master Dec 21, 2023
31 checks passed
@cleptric cleptric deleted the metrics branch December 21, 2023 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants