Autometrics.Instrumentation 0.2.0-beta

This is a prerelease version of Autometrics.Instrumentation.
dotnet add package Autometrics.Instrumentation --version 0.2.0-beta
                    
NuGet\Install-Package Autometrics.Instrumentation -Version 0.2.0-beta
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Autometrics.Instrumentation" Version="0.2.0-beta" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Autometrics.Instrumentation" Version="0.2.0-beta" />
                    
Directory.Packages.props
<PackageReference Include="Autometrics.Instrumentation" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Autometrics.Instrumentation --version 0.2.0-beta
                    
#r "nuget: Autometrics.Instrumentation, 0.2.0-beta"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Autometrics.Instrumentation@0.2.0-beta
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Autometrics.Instrumentation&version=0.2.0-beta&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Autometrics.Instrumentation&version=0.2.0-beta&prerelease
                    
Install as a Cake Tool

Autometrics for .NET

Autometrics-CS is a C# instrumentation of the Autometrics observability micro-framework. It makes it quick and easy to instrument your code to collect standardized metrics, including function call counts, durations, and build information. This project includes a sample application which shows examples for generating metrics to the console, Prometheus, or hosting and endpoint for scraping.

Table of Contents

Aspect-Oriented Programming and AspectInjector

Autometrics-CS utilizes Aspect-Oriented Programming (AOP) techniques to provide non-invasive and modular instrumentation. AOP allows you to inject additional behavior (in our case, metrics collection) into your methods without altering the original code. This project uses the AspectInjector library to achieve AOP in C#.

How it Works

Metrics Instrumentation

Metrics instrumentation is performed using Microsoft's System.Diagnostics.Metrics library. This provides a lightweight and well-tested method of instrumentation that's used as a .NET standard.

Read more on Microsoft's Metrics Overview page.

Metrics Collection and OpenTelemetry

When using System.Diagnostics.Metrics, the metrics instrumentation occurs but the data isn't listened to or sent anywhere. We've provided examples below of using OpenTelemetry's .NET exporters to export this data in an Otel-friendly format. Additional options such as using the dotnet-counters command-line tool or the MeterListener API can be seen on the Metrics Collection page.

Getting Started

Usage

To use Autometrics, follow these simple steps:

  1. Import the Autometrics package and its dependencies in your code.
  2. Add the [Autometrics] attribute and any SLOs to the methods you want to instrument.
  3. Configure the Collection method and Exporter in your application.

Instrumenting Methods

The instrumentation attribute can be added to any method and its usage doesn't change for Libraries, Console Applications, or Web Applications. The only difference is how the metrics are exported. The attribute class is AutometricsAttribute, however Visual Studio will show it as only Autometrics.

[Autometrics]
private bool CheckRedisCache()
{
    // Your unchanged code here
}

Instrumenting Classes

The instrumentation attribute can be added to classes and will apply to all methods within a class. The SkipInjection attribute from the AspectInjector package can be added to methods to prevent them from being instrumented.

[Autometrics]
public class BusinessLayer
{ 
    public DataAccessLayer? DataAccessLayer { get; set; }

    public void ProcessRequest()
    {
        // Your instrumented code here
    }

    [SkipInjection]
    public void CalculateShippingCost()
    {
        // Your non instrumented code here
    }
}

Adding SLO Information

Autometrics makes it easy to add Prometheus Service-Level Objectives (SLOs) to your methods. SLOs are a great way to track the performance of your code and ensure that it meets your expectations. SLOs can be added as three different types:

Success Rate: The percentage of calls that succeed.

[Autometrics("UserAuth", ObjectivePercentile.P99)]
public void UserAuthentication()
{
    // Your code here
}

Latency Threshold: The amount of time it takes for a call to complete.

[Autometrics("OrderCreation", ObjectivePercentile.P99, ObjectiveLatency.Ms500, ObjectiveType.LatencyThreshold)]
public void OrderGeneration()
{
    // Your code here
}

Both Latency and Success Rate: The amount of time it takes for a call to complete and the percentage of calls that succeed. This is the default if a ObjectiveLatency is specifyed but no ObjectiveType is specified.

[Autometrics("OrderCreation", ObjectivePercentile.P99, ObjectiveLatency.Ms500, ObjectiveType.SuccessAndLatency)]
public void OrderGeneration()
{
    // Your code here
}
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.0-beta 210 9/19/2023
0.1.0-alpha1 166 5/16/2023

This is the initial Beta release of Autometrics for .NET