ISC.OpenTelemetryExtension 1.1.7

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

Hướng Dẫn Sử Dụng ISC.OpentelemetryExtension

1️⃣ Giới Thiệu

ISC.OpentelemetryExtension là một thư viện giúp tích hợp OpenTelemetry vào ứng dụng .NET một cách dễ dàng. Thư viện hỗ trợ:

  • Cấu hình TracerProviderBuilder một cách linh hoạt.
  • Cung cấp sẵn các instrumentation phổ biến.
  • Cho phép bổ sung instrumentation đặc thù.

2️⃣ Cài Đặt

Thêm package vào dự án:

 dotnet add package ISC.OpentelemetryExtension

3️⃣ Cách Gọi Code Từ Program.cs

Trong Program.cs, gọi phương thức AddTracing để cấu hình tracing:

using ISC.OpentelemetryExtension;
using OpenTelemetry.Trace;

var builder = WebApplication.CreateBuilder(args);

// Đăng ký OpenTelemetry Tracing
builder.Services.AddTracing(
    serviceName: "TenPhongBan-TenDuAn",
    exporterEndpoint: "http://otel-collector:4317",
    enviroment: "Development" //Nếu không truyền sẽ tự động lấy môi trường hiện tại của instance    
);

var app = builder.Build();
app.MapControllers();
app.Run();

Lưu ý: TracingService.Configure là phương thức mặc định của thư viện để tự động cấu hình tracing.


4️⃣ Tuỳ Chỉnh TracerProviderBuilder

Nếu cần cấu hình TracerProviderBuilder theo nhu cầu, bạn có thể cung cấp một delegate vào AddTracing:

builder.Services.AddTracing(
    serviceName: "MyCustomService",
    exporterEndpoint: "http://otel-collector:4317",
    configureTracing: builder =>
    {
        builder.SetSampler(new AlwaysOnSampler()); // Ghi lại toàn bộ dữ liệu
    }
);

Mẹo: Bạn có thể thay đổi SetSampler(new TraceIdRatioBasedSampler(0.5f)) để lấy 50% lượng dữ liệu thay vì toàn bộ.


5️⃣ Bổ Sung Instrumentation Đặc Thù

Nếu bạn muốn bổ sung các instrumentation đặc thù ngoài Program.cs, có thể dùng tham số extendInstrumentation:

builder.Services.AddTracing(
    serviceName: "MyAdvancedService",
    exporterEndpoint: "http://otel-collector:4317",
    configureTracing: TracingService.Configure,
    extendInstrumentation: builder =>
    {
        builder.AddMongoDBInstrumentation(); // Thêm MongoDB Instrumentation
    }
);

Nếu bạn muốn bật/tắt các Instrumentation chỉ cần cấu hình appsettings.json của bạn như sau:

{
  "Tracing": {
    "EnableMySql": true
  }
}

Ví dụ, nếu bạn cần logging thời gian mở connection và thực thi query SQL:

builder.Services.AddTracing(
    serviceName: "MySQLService",
    exporterEndpoint: "http://otel-collector:4317",
    configureTracing: builder =>
    {
        builder.AddSqlClientInstrumentation(opt =>
        {
            opt.SetDbStatementForText = true; // Ghi lại truy vấn SQL
            opt.RecordException = true; // Ghi lại lỗi
        });
    }
);

6️⃣ Kết Luận

  • Dùng AddTracing để dễ dàng tích hợp OpenTelemetry vào Program.cs.
  • Tuỳ chỉnh TracerProviderBuilder để thay đổi sampler, thêm instrumentation.
  • Bổ sung instrumentation đặc thù bằng tham số extendInstrumentation.

Nếu có câu hỏi, hãy liên hệ đội phát triển ISC.OpentelemetryExtension! 🚀

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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. 
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.1.7 142 23 days ago
1.1.6 130 24 days ago
1.1.5 112 24 days ago
1.1.4 115 24 days ago
1.1.3 132 24 days ago
1.1.2 129 24 days ago
1.1.1 114 a month ago
1.1.0 90 a month ago
1.0.2 90 a month ago
1.0.1 88 a month ago
1.0.0 104 a month ago