Observator 0.1.0-preview3

This is a prerelease version of Observator.
dotnet add package Observator --version 0.1.0-preview3
                    
NuGet\Install-Package Observator -Version 0.1.0-preview3
                    
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="Observator" Version="0.1.0-preview3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Observator" Version="0.1.0-preview3" />
                    
Directory.Packages.props
<PackageReference Include="Observator" />
                    
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 Observator --version 0.1.0-preview3
                    
#r "nuget: Observator, 0.1.0-preview3"
                    
#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.
#addin nuget:?package=Observator&version=0.1.0-preview3&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Observator&version=0.1.0-preview3&prerelease
                    
Install as a Cake Tool

Observator: Zero-Effort .NET Observability

NuGet version Build Status License

Observator is an AOT-compatible source generator that automatically instruments .NET assemblies with OpenTelemetry tracing, logging, and metrics capabilities. It uses compile-time code generation and interceptors to provide zero-configuration, high-performance observability instrumentation that works seamlessly with modern .NET applications, including those using Native AOT compilation.

Features

  • AOT-First Design: Full compatibility with Native AOT compilation by eliminating runtime reflection.
  • Zero Dependencies: Only references System.Diagnostics.DiagnosticSource, which is built into .NET.
  • Zero Configuration: Works out-of-the-box with sensible defaults.
  • Attribute-Driven Instrumentation: Enable selective instrumentation by decorating methods, classes, or interfaces with a simple [ObservatorTrace] attribute.
  • Cross-Assembly Compatibility: Supports instrumentation across project boundaries within a solution.
  • High Performance: Generates optimized code that adds minimal overhead to instrumented methods.
  • Standards Compliant: Generates code compatible with OpenTelemetry standards and .NET diagnostic conventions.

Getting Started

Installation

Add the Observator NuGet package to your project:

dotnet add package Observator

Usage

  1. Add the [ObservatorTrace] attribute to any method, class, or interface you want to instrument. For classes and interfaces, all public instance methods will be traced.

    • Note: You cannot use [ObservatorTrace] on both a class and its methods at the same time. If both are present, a compile-time error will be emitted.
    using Observator;
    
    namespace MyAwesomeApp;
    
    // Class-level usage (all methods instrumented)
    [ObservatorTrace]
    public class MyService
    {
        public virtual string Greet(string name)
        {
            return $"Hello, {name}!";
        }
    }
    
    // Method-level usage (only this method instrumented)
    public class MyOtherService
    {
        [ObservatorTrace]
        public string OnlyThisIsTraced() => "Traced!";
    }
    
    // Error: Do not combine class-level and method-level attributes
    [ObservatorTrace]
    public class InvalidService
    {
        [ObservatorTrace] // This will cause a compile-time error
        public void Conflict() { }
    }
    
  2. Configure your OpenTelemetry pipeline to listen to the ActivitySource created by Observator.

    using OpenTelemetry;
    using OpenTelemetry.Trace;
    using Observator.Generated.MyAwesomeApp; // Import the generated namespace
    
    public class Program
    {
        public static void Main(string[] args)
        {
            using var tracerProvider = Sdk.CreateTracerProviderBuilder()
                .AddSource(ObservatorInfrastructure.ActivitySourceName)
                .AddConsoleExporter() // Or your preferred exporter
                .Build();
    
            var myService = new MyAwesomeApp.MyService();
            myService.Greet("World");
        }
    }
    

Building from Source

To build the project from source, you will need the .NET 9 SDK.

  1. Clone the repository:
    git clone https://github.com/psimsa/observator.git
    
  2. Navigate to the project directory:
    cd observator
    
  3. Build the solution:
    dotnet build
    

License

This project is licensed under the MIT License. See the LICENSE file for details.

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.
  • .NETStandard 2.0

    • No dependencies.

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.1.0-preview3 107 7/1/2025
0.1.0-preview2 102 6/30/2025