![]() |
VOOZH | about |
dotnet add package ISC.OpenTelemetryExtension --version 1.1.7
NuGet\Install-Package ISC.OpenTelemetryExtension -Version 1.1.7
<PackageReference Include="ISC.OpenTelemetryExtension" Version="1.1.7" />
<PackageVersion Include="ISC.OpenTelemetryExtension" Version="1.1.7" />Directory.Packages.props
<PackageReference Include="ISC.OpenTelemetryExtension" />Project file
paket add ISC.OpenTelemetryExtension --version 1.1.7
#r "nuget: ISC.OpenTelemetryExtension, 1.1.7"
#:package ISC.OpenTelemetryExtension@1.1.7
#addin nuget:?package=ISC.OpenTelemetryExtension&version=1.1.7Install as a Cake Addin
#tool nuget:?package=ISC.OpenTelemetryExtension&version=1.1.7Install as a Cake Tool
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ợ:
TracerProviderBuilder một cách linh hoạt.Thêm package vào dự án:
dotnet add package ISC.OpentelemetryExtension
Program.csTrong 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.Configurelà phương thức mặc định của thư viện để tự động cấu hình tracing.
TracerProviderBuilderNế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ộ.
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
});
}
);
AddTracing để dễ dàng tích hợp OpenTelemetry vào Program.cs.TracerProviderBuilder để thay đổi sampler, thêm instrumentation.extendInstrumentation.Nếu có câu hỏi, hãy liên hệ đội phát triển ISC.OpentelemetryExtension! 🚀
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 net6.0 is compatible. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.