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