-
-
Notifications
You must be signed in to change notification settings - Fork 212
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
Metrics Support - alpha #2949
Changes from 58 commits
Commits
Show all changes
60 commits
Select commit
Hold shift + click to select a range
5794a6c
Added basic metric types
jamescrosswell 3752fd5
Moved Metric classes
jamescrosswell 0d6587b
Added Increment aggregator
jamescrosswell 088e4fd
Implemented Gauge metric
jamescrosswell 9fac649
Implemented Distribution and Set aggregations
jamescrosswell c65355d
Added Metrics to ISentryClient API
jamescrosswell b77c04d
Update Hub.cs
jamescrosswell c0233db
Verify tests
jamescrosswell 3b74b80
Basic flush loop (no tests yet)
jamescrosswell c83e9c9
Implemented statsd serialization
jamescrosswell 9150098
Update CHANGELOG.md
jamescrosswell 19dc74a
Split tests for Aggregagtor and BucketHelper
jamescrosswell cac0d79
Update MetricBucketHelperTests.cs
jamescrosswell 721e6b3
Integrated review feedback
jamescrosswell a7ba47e
Create MetricTests.verify.cs
jamescrosswell 90be220
Updated verify tests
jamescrosswell 73be790
Merge branch 'main' into metrics
jamescrosswell 94790d7
Added Timing
jamescrosswell e05f8ee
Merge branch 'metrics' of github.com:getsentry/sentry-dotnet into met…
jamescrosswell 54af5c2
Added a (commented out) test to check if the aggregator is threadsafe
jamescrosswell 9344f38
Fixed concurrency issue (could still make this more performant)
jamescrosswell 5827608
Reduced the scope of the lock for updating metrics
jamescrosswell f3275ac
Fixed unit tests
jamescrosswell 0f86158
Update MetricAggregator.cs
jamescrosswell 7a75155
Initial implementation of Code Locations
jamescrosswell a116f56
Merge branch 'main' into metrics
jamescrosswell 7f47f1a
Update Program.cs
jamescrosswell cd83a4e
Updated solution filters
jamescrosswell 826a413
Update CHANGELOG.md
jamescrosswell 994b8ba
Changed Flush to FlushAsync
jamescrosswell 8e7f0ce
Metrics now get flushed properly when disposing of the Hub
jamescrosswell aa3682f
Fixed serialization for code locations
jamescrosswell d9918d8
Update Timing.cs
jamescrosswell 6de5909
Clear stale seen periods at the end of each day
jamescrosswell d180a9d
Update CodeLocations.cs
jamescrosswell 2a6f344
Fixed stacklevel when calling one of the two Timing constructors
jamescrosswell 052c7a9
Removed IAsyncDisposable from MetricAggregator
jamescrosswell 82469ba
Merge branch 'main' into metrics
jamescrosswell 2eedd9c
Cherry picked https://github.com/getsentry/Ben.Demystifier/pull/4
jamescrosswell 18a08bd
Merge branch 'metrics' of github.com:getsentry/sentry-dotnet into met…
jamescrosswell c72c7e1
Update Ben.Demystifier
jamescrosswell 2a323c5
Get line numbers with stack traces without enhanced stack traces
jamescrosswell 57e2b12
Update Ben.Demystifier
jamescrosswell d2c6cb5
Reversed changes to AspNetCore.Basic sample (unrelated to this PR)
jamescrosswell a9c5d6b
Update Program.cs
jamescrosswell 30ef3b4
Improved the lock when incrementing/adding to existing metrics
jamescrosswell 34a5c3e
Tweaking docs
jamescrosswell 7faa57c
Update CHANGELOG.md
jamescrosswell d956b5d
Integrating review feedback
jamescrosswell 3efab8a
Source generated RegEx in metric helper
jamescrosswell 62a7001
Merge branch 'metrics' of github.com:getsentry/sentry-dotnet into met…
jamescrosswell c68c25c
Update Envelope.cs
jamescrosswell 1c3b275
Merge branch 'main' into metrics
jamescrosswell 4cb9ef7
Review feedback
jamescrosswell 36fe029
Merge branch 'main' into metrics
jamescrosswell 8cc439c
Integrating review feedback
jamescrosswell 705d131
More performant string delimited tags used in the bucket key
jamescrosswell 353a928
Integrating review feedback
jamescrosswell 589c3b2
Integrated review feedback
jamescrosswell bce6e50
Removed unused private field
jamescrosswell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,110 @@ | ||||||||||||||
using System.Numerics; | ||||||||||||||
|
||||||||||||||
namespace Sentry.Samples.Console.Metrics; | ||||||||||||||
|
||||||||||||||
internal static class Program | ||||||||||||||
{ | ||||||||||||||
private static readonly Random Roll = new(); | ||||||||||||||
|
||||||||||||||
private static void Main() | ||||||||||||||
{ | ||||||||||||||
// Enable the SDK | ||||||||||||||
using (SentrySdk.Init(options => | ||||||||||||||
{ | ||||||||||||||
options.Dsn = | ||||||||||||||
// NOTE: ADD YOUR OWN DSN BELOW so you can see the events in your own Sentry account | ||||||||||||||
"https://[email protected]/5428537"; | ||||||||||||||
|
||||||||||||||
options.Debug = true; | ||||||||||||||
options.StackTraceMode = StackTraceMode.Enhanced; | ||||||||||||||
// Initialize some (non null) ExperimentalMetricsOptions to enable Sentry Metrics, | ||||||||||||||
options.ExperimentalMetrics = new ExperimentalMetricsOptions | ||||||||||||||
{ | ||||||||||||||
EnableCodeLocations = | ||||||||||||||
true // Set this to false if you don't want to track code locations for some reason | ||||||||||||||
}; | ||||||||||||||
})) | ||||||||||||||
{ | ||||||||||||||
System.Console.WriteLine("Measure, Yeah, Measure!"); | ||||||||||||||
while (true) | ||||||||||||||
{ | ||||||||||||||
// Perform your task here | ||||||||||||||
switch (Roll.Next(1,3)) | ||||||||||||||
{ | ||||||||||||||
case 1: | ||||||||||||||
PlaySetBingo(10); | ||||||||||||||
break; | ||||||||||||||
case 2: | ||||||||||||||
CreateRevenueGauge(100); | ||||||||||||||
break; | ||||||||||||||
case 3: | ||||||||||||||
MeasureShrimp(30); | ||||||||||||||
break; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
// Optional: Delay to prevent tight looping | ||||||||||||||
var sleepTime = Roll.Next(1, 10); | ||||||||||||||
System.Console.WriteLine($"Sleeping for {sleepTime} second(s)."); | ||||||||||||||
System.Console.WriteLine("Press any key to stop..."); | ||||||||||||||
Thread.Sleep(TimeSpan.FromSeconds(sleepTime)); | ||||||||||||||
// Check if a key has been pressed | ||||||||||||||
if (System.Console.KeyAvailable) | ||||||||||||||
{ | ||||||||||||||
break; | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
System.Console.WriteLine("Measure up"); | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
private static void PlaySetBingo(int attempts) | ||||||||||||||
{ | ||||||||||||||
var solution = new[] { 3, 5, 7, 11, 13, 17 }; | ||||||||||||||
|
||||||||||||||
// The Timing class creates a distribution that is designed to measure the amount of time it takes to run code | ||||||||||||||
// blocks. By default it will use a unit of Seconds - we're configuring it to use milliseconds here though. | ||||||||||||||
using (new Timing("bingo", MeasurementUnit.Duration.Millisecond)) | ||||||||||||||
{ | ||||||||||||||
for (var i = 0; i < attempts; i++) | ||||||||||||||
{ | ||||||||||||||
var guess = Roll.Next(1, 100); | ||||||||||||||
// This demonstrates the use of a set metric. | ||||||||||||||
SentrySdk.Metrics.Gauge("guesses", guess); | ||||||||||||||
|
||||||||||||||
if (solution.Contains(guess)) | ||||||||||||||
{ | ||||||||||||||
// And this is a counter | ||||||||||||||
SentrySdk.Metrics.Increment("correct_answers"); | ||||||||||||||
} | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would this help us make sure correct+incorrect add up to guesses?
Suggested change
|
||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
private static void CreateRevenueGauge(int sampleCount) | ||||||||||||||
{ | ||||||||||||||
using (new Timing(nameof(CreateRevenueGauge), MeasurementUnit.Duration.Millisecond)) | ||||||||||||||
{ | ||||||||||||||
for (var i = 0; i < sampleCount; i++) | ||||||||||||||
{ | ||||||||||||||
var movement = Roll.NextDouble() * 30 - Roll.NextDouble() * 10; | ||||||||||||||
// This demonstrates measuring something in your app using a gauge... we're also using a custom | ||||||||||||||
// measurement unit here (which is optional - by default the unit will be "None") | ||||||||||||||
SentrySdk.Metrics.Gauge("revenue", movement, MeasurementUnit.Custom("$")); | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
private static void MeasureShrimp(int sampleCount) | ||||||||||||||
{ | ||||||||||||||
using (new Timing(nameof(MeasureShrimp), MeasurementUnit.Duration.Millisecond)) | ||||||||||||||
{ | ||||||||||||||
for (var i = 0; i < sampleCount; i++) | ||||||||||||||
{ | ||||||||||||||
var sizeOfShrimp = 15 + Roll.NextDouble() * 30; | ||||||||||||||
// This is an example of emitting a distribution metric | ||||||||||||||
SentrySdk.Metrics.Distribution("shrimp.size", sizeOfShrimp, MeasurementUnit.Custom("cm")); | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
} |
12 changes: 12 additions & 0 deletions
12
samples/Sentry.Samples.Console.Metrics/Sentry.Samples.Console.Metrics.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Sentry\Sentry.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
namespace Sentry; | ||
|
||
internal class DisabledMetricAggregator : IMetricAggregator | ||
{ | ||
public void Increment(string key, double value = 1.0, MeasurementUnit? unit = null, | ||
IDictionary<string, string>? tags = null, | ||
DateTimeOffset? timestamp = null, int stackLevel = 1) | ||
{ | ||
// No Op | ||
} | ||
|
||
public void Gauge(string key, double value = 1.0, MeasurementUnit? unit = null, | ||
IDictionary<string, string>? tags = null, | ||
DateTimeOffset? timestamp = null, int stackLevel = 1) | ||
{ | ||
// No Op | ||
} | ||
|
||
public void Distribution(string key, double value = 1.0, MeasurementUnit? unit = null, | ||
IDictionary<string, string>? tags = null, | ||
DateTimeOffset? timestamp = null, int stackLevel = 1) | ||
{ | ||
// No Op | ||
} | ||
|
||
public void Set(string key, int value, MeasurementUnit? unit = null, | ||
IDictionary<string, string>? tags = null, | ||
DateTimeOffset? timestamp = null, int stackLevel = 1) | ||
{ | ||
// No Op | ||
} | ||
|
||
public void Timing(string key, double value, MeasurementUnit.Duration unit = MeasurementUnit.Duration.Second, | ||
IDictionary<string, string>? tags = null, | ||
DateTimeOffset? timestamp = null, int stackLevel = 1) | ||
{ | ||
// No Op | ||
} | ||
|
||
public Task FlushAsync(bool force = true, CancellationToken cancellationToken = default) | ||
{ | ||
// No Op | ||
return Task.CompletedTask; | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
// No Op | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For reference: getsentry/Ben.Demystifier#4