generated from arcus-azure/arcus.github.template
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add request measurement for requests (#270)
* feat: add request measurement for requests * Update docs/preview/02-Features/writing-different-telemetry-types.md Co-authored-by: Frederik Gheysels <[email protected]> Co-authored-by: Frederik Gheysels <[email protected]>
- Loading branch information
1 parent
03f6ff8
commit 3ae1b79
Showing
4 changed files
with
118 additions
and
53 deletions.
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
45 changes: 45 additions & 0 deletions
45
src/Arcus.Observability.Telemetry.Core/RequestMeasurement.cs
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,45 @@ | ||
using System; | ||
using System.Diagnostics; | ||
|
||
namespace Arcus.Observability.Telemetry.Core | ||
{ | ||
/// <summary> | ||
/// Represents an instance to measure easily requests in an application. | ||
/// </summary> | ||
public class RequestMeasurement : IDisposable | ||
{ | ||
private readonly Stopwatch _stopwatch; | ||
|
||
private RequestMeasurement() | ||
{ | ||
_stopwatch = Stopwatch.StartNew(); | ||
StartTime = DateTimeOffset.UtcNow; | ||
} | ||
|
||
/// <summary> | ||
/// Starts measuring a request until the measurement is disposed. | ||
/// </summary> | ||
public static RequestMeasurement Start() | ||
{ | ||
return new RequestMeasurement(); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the time when the request measurement was started. | ||
/// </summary> | ||
public DateTimeOffset StartTime { get; } | ||
|
||
/// <summary> | ||
/// Gets the total elapsed time measured for the request. | ||
/// </summary> | ||
public TimeSpan Elapsed => _stopwatch.Elapsed; | ||
|
||
/// <summary> | ||
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. | ||
/// </summary> | ||
public void Dispose() | ||
{ | ||
_stopwatch.Stop(); | ||
} | ||
} | ||
} |
Oops, something went wrong.