JF91.OpenTelemetry.Net7
1.0.0
Gunakan paket ini untuk mengintegrasikan OpenTelemetry ke dalam ASP.NET Web API Anda menggunakan appsettings.json
Ikuti langkah-langkah berikut untuk menyelesaikannya:
dotnet add package JF91.OpenTelemetry
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddOpenTelemetryServices(builder.Configuration);
builder.Services.AddOpenTelemetryServices
(
builder.Configuration,
jaegerOptions =>
{
jaegerOptions.Enabled = true;
jaegerOptions.Endpoint = "http://www.test.com";
jaegerOptions.Protocol = JaegerProtocols.Http;
},
zipkinOptions =>
{
zipkinOptions.Enabled = true;
zipkinOptions.Endpoint = "http://www.test.com";
},
influxdbOptions =>
{
influxdbOptions.Enabled = true;
influxdbOptions.Url = "http://www.test.com";
influxdbOptions.Protocol = JaegerProtocols.Http;
},
new List>
{
otlp_one =>
{
otlp_one.Enabled = true;
otlp_one.Url = "http://www.test.com";
otlp_one.Protocol = OtlpProtocols.Http;
},
otlp_two =>
{
otlp_two.Enabled = true;
otlp_two.Url = "http://www.test2.com";
otlp_two.Protocol = OtlpProtocols.Grpc;
}
},
prometheusOptions =>
{
prometheusOptions.Enabled = true;
prometheusOptions.ScrapeEndpointPath = "/test";
prometheusOptions.ScrapeResponseCacheDurationMilliseconds = 1000;
}
);
Contoh 1: 3 Eksportir OTLP di appsettings.json dan 2 Opsi Kustom akan menggantikan 2 Ekspor OTLP pertama di appsettings.json dari 2 Opsi Kustom pertama.
Contoh 2: 2 Eksportir OTLP di appsettings.json dan 3 Opsi Kustom akan menggantikan 2 Eksportir OTLP di appsettings.json dari 2 Opsi Kustom pertama.
app.Run();
app.AddOpenTelemetryExtensions();
appsettings.json
Anda dan modifikasi sesuai kebutuhan Anda: "OpenTelemetrySettings": {
"EnableTraces": true,
"EnableMetrics": true,
"Exporters": {
"Console": {
"Enabled": true
},
"Jaeger": {
"Enabled": true,
"Endpoint": "http://localhost:14268/api/traces",
"Protocol": "udp"
},
"Zipkin": {
"Enabled": false,
"Endpoint": " https://localhost:9411/api/v2/spans"
},
"Prometheus": {
"Enabled": true,
"ScrapeEndpointPath": "/metrics-text",
"ScrapeResponseCacheDurationMilliseconds": 300
},
"InfluxDB": {
"Enabled": false,
"Url": "http://localhost:8086",
"Protocol": "http"
},
"Otlp": [
{
"Enabled": true,
"Url": "http://localhost:4317",
"Protocol": "grpc"
},
{
"Enabled": false,
"Url": "http://localhost:4317",
"Protocol": "http"
}
]
},
"Instrumentation": {
"Http": true,
"EfCore": false,
"Hangfire": false,
"SqlClient": false,
"Redis": false
}
}
Jaeger.Protokol: udp / http | Bawaan => udp
[OtlpProtocols] > InfluxDB.Protocol: grpc / http | Bawaan => grpc