Otel.Simplify 1.0.0

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

πŸ“¦ OpenTelemetry.Simplify β€” Π‘ΠΈΠ±Π»ΠΈΠΎΡ‚Π΅ΠΊΠ° для упрощСния ΠΈ стандартизации Ρ€Π°Π±ΠΎΡ‚Ρ‹ с OpenTelemetry Π² .NET

⚠️ Π’Π½ΠΈΠΌΠ°Π½ΠΈΠ΅: Π­Ρ‚ΠΎΡ‚ ΠΏΠ°ΠΊΠ΅Ρ‚ Π½Π΅ являСтся ΠΎΡ„ΠΈΡ†ΠΈΠ°Π»ΡŒΠ½Ρ‹ΠΌ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ΠΎΠΌ ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π° OpenTelemetry. Π­Ρ‚ΠΎ сторонняя ΠΎΠ±Ρ‘Ρ€Ρ‚ΠΊΠ°, созданная для упрощСния ΠΈΠ½Ρ‚Π΅Π³Ρ€Π°Ρ†ΠΈΠΈ OpenTelemetry Π² .NET-прилоТСниях.

OpenTelemetry.Simplify β€” это NuGet-Π±ΠΈΠ±Π»ΠΈΠΎΡ‚Π΅ΠΊΠ°, прСдназначСнная для стандартизации ΠΈ упрощСния ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΡ OpenTelemetry ΠΊ .NET прилоТСниям. Она прСдоставляСт ΠΏΠΎΠ»Π½ΡƒΡŽ ΠΈΠ½Ρ‚Π΅Π³Ρ€Π°Ρ†ΠΈΡŽ ΠΌΠ΅Ρ‚Ρ€ΠΈΠΊ ΠΈ трассировок с Prometheus, OTLP, Jaeger, ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΈΠ²Π°Π΅Ρ‚ Ρ€Π΅Π³ΠΈΡΡ‚Ρ€Π°Ρ†ΠΈΡŽ кастомных ΠΌΠ΅Ρ‚Ρ€ΠΈΠΊ, автоматичСскоС ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅ Meter, Π° Ρ‚Π°ΠΊΠΆΠ΅ Π³ΠΎΡ‚ΠΎΠ²Ρ‹Π΅ Grafana Π΄Π΅ΡˆΠ±ΠΎΡ€Π΄Ρ‹.


πŸ”§ ВозмоТности Π±ΠΈΠ±Π»ΠΈΠΎΡ‚Π΅ΠΊΠΈ

  • πŸ“Š Π˜Π½Ρ‚Π΅Π³Ρ€Π°Ρ†ΠΈΡ систСмных ΠΌΠ΅Ρ‚Ρ€ΠΈΠΊ: ASP.NET Core, Runtime, Uptime, Oracle (ΠΎΠΏΡ†ΠΈΠΎΠ½Π°Π»ΡŒΠ½ΠΎ)
  • βš™οΈ ΠŸΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° кастомных ΠΌΠ΅Ρ‚Ρ€ΠΈΠΊ Ρ‡Π΅Ρ€Π΅Π· интСрфСйс ICustomMetric
  • πŸ” ΠŸΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° трассировки: входящиС ΠΈ исходящиС HTTP-запросы
  • 🌐 ΠŸΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° экспортёров: Prometheus, OTLP, Jaeger, Console
  • 🧩 АвтоматичСская рСгистрация Meter Ρ‡Π΅Ρ€Π΅Π· IMeterAccessor
  • πŸš€ Extension-ΠΌΠ΅Ρ‚ΠΎΠ΄Ρ‹ для ΡƒΠ΄ΠΎΠ±Π½ΠΎΠΉ рСгистрации ΠΌΠ΅Ρ‚Ρ€ΠΈΠΊ ΠΈ трСйсов

πŸ“¦ Установка

dotnet add package OpenTelemetry.Simplify

<PackageReference Include="OpenTelemetry.Simplify" Version="1.0.0" />

πŸš€ Быстрый старт

builder.Services.AddOpenTelemetrySimplify(options =>
{
    options.ServiceName = "MyService";
    options.ServiceVersion = "1.0.0";

    options.AddMetrics(metrics =>
    {
        metrics.UseAspNetCoreInstrumentation();
        metrics.UseRuntimeInstrumentation();
        metrics.UseUptime();
        metrics.UseExporter(MetricExporterType.Prometheus);
    });

    options.AddTrace(tracing =>
    {
        tracing.UseAspNetCoreInstrumentation();
        tracing.UseHttpClientInstrumentation();
        tracing.UseExporter(TraceExporterType.Jaeger);
    });
});

var app = builder.Build();
app.UseOpenTelemetryPrometheusScrapingEndpoint();

πŸ“Š ВстроСнныС ΠΌΠ΅Ρ‚Ρ€ΠΈΠΊΠΈ

ASP.NET Core

  • ΠšΠΎΠ»ΠΈΡ‡Π΅ΡΡ‚Π²ΠΎ запросов
  • ВрСмя выполнСния (latency)
  • АктивныС запросы
  • ΠšΠΎΠ΄Ρ‹ ΠΎΡ‚Π²Π΅Ρ‚ΠΎΠ²

Runtime

  • ΠŸΠ°ΠΌΡΡ‚ΡŒ
  • GC
  • Π˜ΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΡ
  • ΠŸΠΎΡ‚ΠΎΠΊΠΈ ΠΈ Π°Π»Π»ΠΎΠΊΠ°Ρ†ΠΈΠΈ

Uptime

  • ВрСмя Π½Π΅ΠΏΡ€Π΅Ρ€Ρ‹Π²Π½ΠΎΠΉ Ρ€Π°Π±ΠΎΡ‚Ρ‹ прилоТСния (Π² сСкундах)

Oracle (ΠΎΠΏΡ†ΠΈΠΎΠ½Π°Π»ΡŒΠ½ΠΎ)

  • ΠœΠ΅Ρ‚Ρ€ΠΈΠΊΠΈ ΠΏΡƒΠ»Π° соСдинСний ΠΈ Π²Ρ€Π΅ΠΌΠ΅Π½ΠΈ выполнСния ΠΊΠΎΠΌΠ°Π½Π΄ (Ρ‚Ρ€Π΅Π±ΡƒΠ΅Ρ‚ Oracle.ManagedDataAccess.Core 23.3.2+)

🧠 ΠšΠ°ΡΡ‚ΠΎΠΌΠ½Ρ‹Π΅ ΠΌΠ΅Ρ‚Ρ€ΠΈΠΊΠΈ Ρ‡Π΅Ρ€Π΅Π· ICustomMetric

ΠŸΡ€ΠΈΠΌΠ΅Ρ€ Π±Π΅Π· зависимостСй

public class SampleCustomMetric : ICustomMetric
{
    private readonly DateTimeOffset _startTime = DateTimeOffset.UtcNow;

    public void Register(Meter meter)
    {
        meter.CreateObservableGauge<double>(
            name: "test_uptime_seconds_test",
            observeValues: () =>
            {
                double uptime = (DateTimeOffset.UtcNow - _startTime).TotalSeconds;
                return new[] { new Measurement<double>(uptime) };
            },
            unit: "seconds",
            description: "Description");
    }
}

ΠŸΡ€ΠΈΠΌΠ΅Ρ€ с Π·Π°Π²ΠΈΡΠΈΠΌΠΎΡΡ‚ΡŒΡŽ

public class RandomCustomMetric : ICustomMetric
{
    private readonly IRandomService _service;
    public RandomCustomMetric(IRandomService service) => _service = service;

    public void Register(Meter meter)
    {
        meter.CreateObservableGauge("random_number",
            () => new Measurement<int>(_service.GetRandomNumber()));
    }
}

РСгистрация:

builder.Services.AddOpenTelemetrySimplify(options =>
{
    options.AddMetrics(metrics =>
    {
        metrics.AddCustomMetric<SampleCustomMetric>();
    });
});

app.RegisterCustomMetrics(
    new RandomCustomMetric(app.Services.GetRequiredService<IRandomService>())
);

πŸ”§ IMeterAccessor β€” ΠΏΡ€Π°Π²ΠΈΠ»ΡŒΠ½Ρ‹ΠΉ способ ΠΏΠΎΠ»ΡƒΡ‡ΠΈΡ‚ΡŒ Meter

public interface IMeterAccessor
{
    Meter Meter { get; }
}
var meter = app.Services.GetRequiredService<IMeterAccessor>().Meter;

βš™οΈ ИспользованиС Meter Π½Π°ΠΏΡ€ΡΠΌΡƒΡŽ Π² middleware ΠΈΠ»ΠΈ HostedService

public class MetricsMiddleware
{
    private readonly RequestDelegate _next;
    private readonly Counter<long> _counter;

    public MetricsMiddleware(RequestDelegate next, IMeterAccessor meterAccessor)
    {
        _next = next;
        _counter = meterAccessor.Meter.CreateCounter<long>("custom_middleware_requests_total", "req", "Запросы Ρ‡Π΅Ρ€Π΅Π· middleware");
    }

    public async Task InvokeAsync(HttpContext context)
    {
        _counter.Add(1);
        await _next(context);
    }
}
app.UseMiddleware<MetricsMiddleware>();

πŸ“Š Grafana Dashboards

(Π² процСссС ΠΏΠΎΠ΄Π³ΠΎΡ‚ΠΎΠ²ΠΊΠΈ)


πŸ“ Π‘Ρ‚Ρ€ΡƒΠΊΡ‚ΡƒΡ€Π° Π±ΠΈΠ±Π»ΠΈΠΎΡ‚Π΅ΠΊΠΈ

ΠŸΡƒΡ‚ΡŒ НазначСниС
TelemetryConfigurator.cs ΠšΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΡ ΠΌΠ΅Ρ‚Ρ€ΠΈΠΊ ΠΈ трСйсов
TelemetryOptions.cs ΠšΠΎΡ€Π½Π΅Π²Π°Ρ конфигурация
MetricsOptions.cs ΠžΠΏΡ†ΠΈΠΈ ΠΌΠ΅Ρ‚Ρ€ΠΈΠΊ ΠΈ экспортёров
TracingOptions.cs ΠžΠΏΡ†ΠΈΠΈ трассировки
ICustomMetric.cs Π˜Π½Ρ‚Π΅Ρ€Ρ„Π΅ΠΉΡ для кастомной ΠΌΠ΅Ρ‚Ρ€ΠΈΠΊΠΈ
IMeterAccessor.cs Π˜Π½Ρ‚Π΅Ρ€Ρ„Π΅ΠΉΡ доступа ΠΊ Meter
MeterAccessor.cs РСализация IMeterAccessor
TelemetryAppExtensions.cs Extension-ΠΌΠ΅Ρ‚ΠΎΠ΄Ρ‹ для рСгистрации послС Build
UptimeMetric.cs ΠœΠ΅Ρ‚Ρ€ΠΈΠΊΠ° Π°ΠΏΡ‚Π°ΠΉΠΌΠ°

βœ… Π Π΅ΠΊΠΎΠΌΠ΅Π½Π΄Π°Ρ†ΠΈΠΈ ΠΏΠΎ использованию

ℹ️ Π’Π°ΠΆΠ½ΠΎ: Ссли Π²Ρ‹ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚Π΅ ΠΌΠ΅Ρ‚Ρ€ΠΈΠΊΠΈ, зависящиС ΠΎΡ‚ сСрвисов Ρ‡Π΅Ρ€Π΅Π· Dependency Injection (DI), ΠΎΠ±ΡΠ·Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎ рСгистрируйтС ΠΈΡ… Ρ‡Π΅Ρ€Π΅Π· app.RegisterCustomMetrics(...) послС app.Build().

  • НС ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉ new Meter(...) β€” Ρ‚ΠΎΠ»ΡŒΠΊΠΎ IMeterAccessor
  • ВсСгда ΡƒΠΊΠ°Π·Ρ‹Π²Π°ΠΉ ServiceName ΠΈ ServiceVersion
  • ΠœΠ΅Ρ‚Ρ€ΠΈΠΊΠΈ с зависимостями рСгистрируй послС app.Build()
  • Π”Π°Ρ‘ΠΌ meaningful-названия ΠΌΠ΅Ρ‚Ρ€ΠΈΠΊΠ°ΠΌ (Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€: my_service.http_duration_seconds)

πŸ—‚ Π‘Ρ‚Ρ€ΡƒΠΊΡ‚ΡƒΡ€Π° ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π°

OpenTelemetry.Simplify/
β”œβ”€β”€ src/
β”‚   └── OpenTelemetry.Simplify/
β”œβ”€β”€ examples/
β”‚   └── OpenTelemetry.Simplify.Example/ (Web API)
└── OpenTelemetry.Simplify.sln

πŸ“ ЛицСнзия

MIT Β© 2025 β€” OpenTelemetry.Simplify Contributors

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
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.0 116 4/30/2025