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

Metrics Support - alpha #2949

Merged
merged 60 commits into from
Jan 8, 2024
Merged

Metrics Support - alpha #2949

merged 60 commits into from
Jan 8, 2024

Conversation

jamescrosswell
Copy link
Collaborator

@jamescrosswell jamescrosswell commented Dec 6, 2023

Resolves #2880

image

Dogfooding

Once we have a nuget package, we can use the Symbol Collector to dogfood this.

@jamescrosswell jamescrosswell changed the title WIP: Delightful Developer Metrics pilot WIP: Delightful Developer Metrics alpha Dec 7, 2023
@jamescrosswell jamescrosswell changed the title WIP: Delightful Developer Metrics alpha Delightful Developer Metrics alpha Dec 7, 2023
src/Sentry/DelegatingMetricAggregator.cs Outdated Show resolved Hide resolved
src/Sentry/DisabledMetricAggregator.cs Outdated Show resolved Hide resolved
src/Sentry/IMetricAggregator.cs Outdated Show resolved Hide resolved
src/Sentry/MetricAggregator.cs Outdated Show resolved Hide resolved
src/Sentry/MetricAggregator.cs Outdated Show resolved Hide resolved
src/Sentry/MetricAggregator.cs Outdated Show resolved Hide resolved
src/Sentry/MetricAggregator.cs Outdated Show resolved Hide resolved
src/Sentry/Protocol/Envelopes/Envelope.cs Outdated Show resolved Hide resolved
src/Sentry/Protocol/Metrics/Metric.cs Outdated Show resolved Hide resolved
src/Sentry/Protocol/Metrics/Metric.cs Outdated Show resolved Hide resolved
src/Sentry/Protocol/Metrics/Metric.cs Outdated Show resolved Hide resolved
src/Sentry/MetricAggregator.cs Outdated Show resolved Hide resolved
Copy link
Member

@bruno-garcia bruno-garcia left a comment

Choose a reason for hiding this comment

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

Quick second pass

src/Sentry/MetricAggregator.cs Outdated Show resolved Hide resolved
src/Sentry/Protocol/Metrics/Metric.cs Outdated Show resolved Hide resolved
src/Sentry/Internal/Hub.cs Outdated Show resolved Hide resolved
src/Sentry/MetricAggregator.cs Outdated Show resolved Hide resolved
src/Sentry/MetricAggregator.cs Outdated Show resolved Hide resolved
@cleptric cleptric self-requested a review December 19, 2023 23:32
@bruno-garcia bruno-garcia changed the title Delightful Developer Metrics alpha Metrics Support - alpha Dec 20, 2023
@bruno-garcia
Copy link
Member

@jamescrosswell renamed the PR because we dropped the DDM internal name in favor of "Metrics"

Copy link
Member

@bruno-garcia bruno-garcia left a comment

Choose a reason for hiding this comment

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

Ranout of gas, didn't review MetricAggregator really and only did around 30/52 files.

CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

samples/Sentry.Samples.Console.Metrics/Program.cs Outdated Show resolved Hide resolved
src/Sentry/Protocol/Metrics/DistributionMetric.cs Outdated Show resolved Hide resolved
src/Sentry/Protocol/Metrics/DistributionMetric.cs Outdated Show resolved Hide resolved
src/Sentry/Protocol/Envelopes/Envelope.cs Outdated Show resolved Hide resolved
src/Sentry/MetricHelper.cs Outdated Show resolved Hide resolved
src/Sentry/MetricAggregator.cs Outdated Show resolved Hide resolved
Copy link
Member

@bruno-garcia bruno-garcia left a comment

Choose a reason for hiding this comment

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

Only got as far as 30/52 files and didn't go deep on MetricAggregator and other major pieces but sending some bits as it's what I managed to cover

@jamescrosswell
Copy link
Collaborator Author

Only got as far as 30/52 files and didn't go deep on MetricAggregator and other major pieces but sending some bits as it's what I managed to cover

Awesome - thank you! The meat of it is all in the MetricAggregator so that one might take a little while.

@jamescrosswell jamescrosswell self-assigned this Dec 20, 2023
Copy link
Member

@bruno-garcia bruno-garcia left a comment

Choose a reason for hiding this comment

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

Now at 48/52 (only what really matters is left lol)

Maybe on a follow up PR we should rename MeasurementUnit, it's quite verbose

src/Sentry/MetricHelper.cs Outdated Show resolved Hide resolved
src/Sentry/MetricHelper.cs Outdated Show resolved Hide resolved
src/Sentry/MetricHelper.cs Show resolved Hide resolved
src/Sentry/MetricHelper.cs Outdated Show resolved Hide resolved
src/Sentry/Protocol/Envelopes/Envelope.cs Outdated Show resolved Hide resolved
src/Sentry/Protocol/Metrics/DistributionMetric.cs Outdated Show resolved Hide resolved
src/Sentry/Protocol/Metrics/DistributionMetric.cs Outdated Show resolved Hide resolved
src/Sentry/Protocol/Metrics/Metric.cs Outdated Show resolved Hide resolved
src/Sentry/Timing.cs Outdated Show resolved Hide resolved
test/Sentry.Tests/MetricAggregatorTests.cs Outdated Show resolved Hide resolved

internal SentryStackFrame? GetCodeLocation(int stackLevel)
{
var stackTrace = new StackTrace(true);
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't see an easy way to do so. There's no way to supply a stackLevel to the CallerMemberName, that I can see. That's the main reason for the _seenLocations cache though... so at least this expensive operation only occurs once per unique metric per day.

_codeLocationLock.Wait();
try
{
var result = _pendingLocations;
Copy link
Member

Choose a reason for hiding this comment

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

You can do this atomically with Interlocked afaik, CompareExchange iirc

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hm, the _codeLocationLock is used elsewhere in the MetricAggregator to lock on different operations against _pendingLocations though. For example, there's this:

if (!_pendingLocations.ContainsKey(startOfDay))
{
_pendingLocations[startOfDay] = new Dictionary<MetricResourceIdentifier, SentryStackFrame>();
}
_pendingLocations[startOfDay][metaKey] = location;

Copy link
Member

@bruno-garcia bruno-garcia left a comment

Choose a reason for hiding this comment

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

There's a race condition in RecordCodeLocation

src/Sentry/Protocol/Metrics/CodeLocations.cs Outdated Show resolved Hide resolved
src/Sentry/Protocol/Metrics/CodeLocations.cs Outdated Show resolved Hide resolved
src/Sentry/MetricHelper.cs Outdated Show resolved Hide resolved
src/Sentry/DelegatingMetricAggregator.cs Outdated Show resolved Hide resolved
src/Sentry/MetricAggregator.cs Outdated Show resolved Hide resolved
src/Sentry/MetricAggregator.cs Outdated Show resolved Hide resolved
src/Sentry/MetricAggregator.cs Outdated Show resolved Hide resolved
src/Sentry/MetricAggregator.cs Show resolved Hide resolved
src/Sentry/MetricAggregator.cs Outdated Show resolved Hide resolved
src/Sentry/MetricAggregator.cs Outdated Show resolved Hide resolved
Copy link
Contributor

@bitsandfoxes bitsandfoxes left a comment

Choose a reason for hiding this comment

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

This looks amazing!

src/Sentry/Timing.cs Outdated Show resolved Hide resolved
src/Sentry/Timing.cs Outdated Show resolved Hide resolved
src/Sentry/IMetricAggregator.cs Show resolved Hide resolved
src/Sentry/IMetricAggregator.cs Show resolved Hide resolved
src/Sentry/MetricAggregator.cs Show resolved Hide resolved
src/Sentry/Internal/Hub.cs Show resolved Hide resolved
src/Sentry/Protocol/Metrics/CodeLocations.cs Outdated Show resolved Hide resolved
src/Sentry/IMetricAggregator.cs Outdated Show resolved Hide resolved
src/Sentry/Protocol/Envelopes/Envelope.cs Show resolved Hide resolved
src/Sentry/SentryClient.cs Outdated Show resolved Hide resolved
Copy link
Member

@bruno-garcia bruno-garcia left a comment

Choose a reason for hiding this comment

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

There are a few comments that I might have dropped outside a review that are pending. Could you please take a look on the files view: https://github.com/getsentry/sentry-dotnet/pull/2949/files

I don't see any blockers so I'm happy to merge this and ship a beta so we can test. It's just too hard to review this change now and we can do improvements/fixes in follow up PRs now.

src/Sentry/Timing.cs Show resolved Hide resolved
internal void CaptureCodeLocations(CodeLocations codeLocations)
{
_options.LogDebug($"Capturing code locations for period: {codeLocations.Timestamp}");
CaptureEnvelope(Envelope.FromCodeLocations(codeLocations));
Copy link
Member

Choose a reason for hiding this comment

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

Are code locations not coupled with metrics? In which case they should be on the same envelope ideally

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@bruno-garcia bruno-garcia merged commit 0fde2e3 into main Jan 8, 2024
19 checks passed
@bruno-garcia bruno-garcia deleted the metrics branch January 8, 2024 17:24
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.

Add Metrics API
6 participants