JF91.OpenTelemetry.Net7
1.0.0
使用此套件透過appsettings.json
將 OpenTelemetry 整合到 ASP.NET Web API 中
請依照以下步驟完成:
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;
}
);
範例 1:appsettings.json 中的 3 個 OTLP 匯出器和 2 個自訂選項將覆蓋 appsettings.json 中前 2 個自訂選項的前 2 個 OTLP 匯出。
範例 2:appsettings.json 中的 2 個 OTLP 匯出器和 3 個自訂選項將覆蓋 appsettings.json 中前 2 個自訂選項中的 2 個 OTLP 匯出器。
app.Run();
之前加入此內容 app.AddOpenTelemetryExtensions();
appsettings.json
並根據您的需求進行修改: "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.協定:udp / http |預設 => udp
[OtlpProtocols] > InfluxDB.Protocol:grpc / http |預設=> grpc