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 experimental metrics implementation #618

Merged
merged 34 commits into from
Dec 12, 2023
Merged

Add experimental metrics implementation #618

merged 34 commits into from
Dec 12, 2023

Conversation

Swatinem
Copy link
Member

@Swatinem Swatinem commented Oct 17, 2023

This adds:

  • A new statsd EnvelopeItem
  • A new MetricAggregator which is implemented similarly to the Python prototype implementation
  • The Client instantiates a metric flusher and starts it in the background
  • A Metric type that allows building and sending metrics, which is the primary user-facing API
  • A cadence-compatible SentryMetricSink that makes it easier to integrate Sentry into existing environments
  • Internal types that are mostly adapted from relay-metrics

This PR does not yet include support for code locations and span linking; both will follow at a later stage.

@codecov
Copy link

codecov bot commented Oct 17, 2023

Codecov Report

Merging #618 (69080ab) into master (dfdb7b6) will increase coverage by 0.31%.
The diff coverage is 75.72%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #618      +/-   ##
==========================================
+ Coverage   72.75%   73.07%   +0.31%     
==========================================
  Files          59       62       +3     
  Lines        6706     7494     +788     
==========================================
+ Hits         4879     5476     +597     
- Misses       1827     2018     +191     

@Swatinem Swatinem self-assigned this Oct 18, 2023
@Swatinem Swatinem marked this pull request as ready for review October 18, 2023 13:47
sentry-core/src/metrics.rs Outdated Show resolved Hide resolved
sentry-core/src/metrics.rs Outdated Show resolved Hide resolved
count: u64,
}
enum BucketValue {
Counter(f64),
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are counters f64?

Copy link
Member Author

Choose a reason for hiding this comment

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

That is what relay-metrics uses: https://getsentry.github.io/relay/relay_metrics/type.CounterType.html
So I just stuck with that. Admittedly it does not make as much sense.

Copy link
Member

Choose a reason for hiding this comment

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

This allows the user to count / accumulate things that are not whole numbers.

sentry-core/src/metrics.rs Outdated Show resolved Hide resolved
sentry-core/src/metrics.rs Outdated Show resolved Hide resolved
sentry-core/src/metrics.rs Outdated Show resolved Hide resolved
sentry-core/src/client.rs Outdated Show resolved Hide resolved
sentry-core/src/metrics.rs Outdated Show resolved Hide resolved
sentry-core/src/metrics.rs Outdated Show resolved Hide resolved
sentry-core/src/metrics.rs Outdated Show resolved Hide resolved
let mut value = mk_value(ty, values.next()?)?;

for value_s in values {
value.merge(mk_value(ty, value_s)?).ok()?;
Copy link
Member

Choose a reason for hiding this comment

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

I notice that this parser is written differently than the one in Relay -- have you performed benchmarks on this? I'm asking because we might want to update the implementation in Relay in that case, too.

sentry-core/src/metrics.rs Outdated Show resolved Hide resolved
sentry-core/src/metrics.rs Outdated Show resolved Hide resolved
sentry-core/src/client.rs Outdated Show resolved Hide resolved
@jan-auer jan-auer assigned jan-auer and unassigned Swatinem Dec 11, 2023
* master:
  tracing: send spans' attributes along with the event ones (#629)
  release: 0.32.0
  Update crate dependencies (#628)
  feat: bump http to 1.0.0 (#627)
  release: 0.31.8
  MonitorSchedule constructor that validates crontab syntax (#625)
  fix(docs): Fix some doc errors that slipped in (#623)
  docs(tower): Mention how to enable http feature from sentry crate (#622)
  build(deps): bump rustix from 0.37.23 to 0.37.25 (#619)
@jan-auer
Copy link
Member

jan-auer commented Dec 11, 2023

I've updated the implementation to address above comments. The current state is still missing a few things, however:

  • There's no shift while flushing. Edit: I believe we might not need such a shift. The flush cycle begins immediately when the client is started, so it is shifted naturally.
  • The cadence sink test is flakey
  • There are no tests of the metrics module
  • Default tags (release and environment) are still missing
  • The public API needs a review, we should probably add top-level utility functions
  • flush does not work properly, as it doesn't wait

Copy link
Contributor

@loewenheim loewenheim left a comment

Choose a reason for hiding this comment

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

Some nits, but otherwise looks good

sentry-core/src/cadence.rs Show resolved Hide resolved
sentry-core/src/client.rs Outdated Show resolved Hide resolved
sentry-core/src/metrics.rs Outdated Show resolved Hide resolved
sentry-core/src/metrics.rs Outdated Show resolved Hide resolved
sentry-core/src/metrics.rs Outdated Show resolved Hide resolved
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(match s {
"nanosecond" | "ns" => Self::Duration(DurationUnit::NanoSecond),
"microsecond" => Self::Duration(DurationUnit::MicroSecond),
Copy link
Contributor

Choose a reason for hiding this comment

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

Could do μs here, but I don't know if that's common.

Copy link
Member

Choose a reason for hiding this comment

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

Good point, μ is an ASCII character so we could add this as an alias. We'd have to add this to the spec and Relay too, though.

@jan-auer jan-auer merged commit a2b60da into master Dec 12, 2023
13 checks passed
@jan-auer jan-auer deleted the swatinem/metrics branch December 12, 2023 15:32
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.

3 participants