TrueMark.OtelSupport 1.0.2

dotnet add package TrueMark.OtelSupport --version 1.0.2                
NuGet\Install-Package TrueMark.OtelSupport -Version 1.0.2                
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="TrueMark.OtelSupport" Version="1.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TrueMark.OtelSupport --version 1.0.2                
#r "nuget: TrueMark.OtelSupport, 1.0.2"                
#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.
// Install TrueMark.OtelSupport as a Cake Addin
#addin nuget:?package=TrueMark.OtelSupport&version=1.0.2

// Install TrueMark.OtelSupport as a Cake Tool
#tool nuget:?package=TrueMark.OtelSupport&version=1.0.2                

TrueMark.OtelSupport

NuGet License

Overview

TrueMark.OtelSupport is a .NET library that provides OpenTelemetry support for instrumenting applications. It simplifies distributed tracing and metrics collection using OpenTelemetry standards.

Installation

You can install this package via NuGet:

dotnet add package TrueMark.OtelSupport --version 1.0.0

Or via the NuGet Package Manager:

Install-Package TrueMark.OtelSupport -Version 1.0.0

Compatibility

  • .NET Standard 2.0 (Compatible with .NET Core 2.1+, .NET 6+, .NET 8+)
  • OpenTelemetry API version 1.9.0

Usage

This library is mainly targeting web based dotnet applications. It provides a middleware that can be used to automatically instrument incoming requests and outgoing responses. It also has support for custom metrics. Below are the 2 major use cases that this library supports:

1. Adding default instrumentation

Given an instance services of IServiceCollection, you can enable OTEL with the below code in the Program.cs or Startup.cs file:

var resourceBuilder = ResourceBuilder
                      .CreateDefault()
                      .AddTelemetrySdk()
                      .AddEnvironmentVariableDetector()
                      .AddService(<service-name-here>) // Including environment e.g. payment-api-dev
                      .AddDetector(new AWSECSResourceDetector());
services.AddOpenTelemetry()
        .WithTracing(
            tracing => tracing
                       .AddAspNetCoreInstrumentation()
                       .AddXRayTraceId()
                       .SetResourceBuilder(resourceBuilder)
                       .AddAWSInstrumentation()
                       .AddHttpClientInstrumentation()
                       .AddAspNetCoreInstrumentation()
                       .AddOtlpExporter())
        .WithMetrics(
            metrics => metrics
                       .SetResourceBuilder(resourceBuilder)
                       .AddAspNetCoreInstrumentation()
                       .AddHttpClientInstrumentation()
                       .AddRuntimeInstrumentation()
                       .AddProcessInstrumentation()

                       // Only use "overrideHttpMetrics" value of true when using Minimal APIs
                       .AddMetricsServiceMeter(otelServiceName, true)

                       .AddOtlpExporter());

When using the Minimal APIs - default http.server* metrics don't emit by default, thus you can use the below code in the Program.cs/Startup.cs file to enable OTEL (where app is an instance of WebApplication):

// Only add this line when using Minimal APIs in .NET
app.UseHttpMetrics(new HttpMetricsRecorder());

2. Adding custom metrics

To add custom metrics to your application, you need to do the following:

  1. Extend the IMetricsRegistry and register your metrics with the IMetricsRegistry instance. Below is an example of how to add a custom metric:
public class CustomMetricsRegistry : IMetricsRegistry
    {
        public static readonly MetricTagHolder<long> AllTransactionsMetric = new MetricTagHolder<long>("transaction_event", "All Transaction related events", "per request");
        public static readonly MetricTagHolder<double> PaidTransactionMetric = new MetricTagHolder<double>("payment_transaction_event", "Payment Transaction related events", "per request");
        public void LoadMetrics(IApplicationBuilder app)
        {
            var metricsTagsLongType = new List<MetricTagHolder<long>>
            {
                AllTransactionsMetric
            };
            app.UseOpenTelemetry(metricsTagsLongType);

            var metricsTagsDoubleType = new List<MetricTagHolder<double>>
            {
                PaidTransactionMetric
            };
            app.UseOpenTelemetry(metricsTagsDoubleType);
        }
    }
  1. In the Program.cs or Startup.cs file, load the custom metrics with the IMetricsRegistry instance:
// Add Otel Metrics Registry for custom metrics here
new CustomMetricsRegistry().LoadMetrics(app);

License

This project is licensed under the BSD 3-Clause 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. 
.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
1.0.2 68 2/12/2025
1.0.1 41 2/12/2025
1.0.1-beta.8.50 32 2/12/2025
1.0.1-alpha.7.48 34 2/12/2025
1.0.1-alpha.6.47 33 2/12/2025
1.0.1-alpha.5.46 31 2/12/2025
1.0.1-alpha.3.43 31 2/12/2025
1.0.0 41 2/12/2025
1.0.0-beta.20 36 2/12/2025
1.0.0-beta.19 40 2/12/2025
1.0.0-beta.18 29 2/12/2025
1.0.0-beta 48 2/11/2025
0.2.1 36 2/12/2025
0.2.1-alpha.0.1 30 2/12/2025
0.2.0 33 2/12/2025
0.1.1-alpha.0.1 39 2/12/2025
0.1.0 37 2/12/2025