https://github.com/joaofranco91/jf91.opentelemetry.net7
OpenTelemetry for ASP.NET Web API Plug-And-Play. Select exporters like Console, Jaeger, Zipkin, Prometheus, InfluxDB and OTLP and Instrumentators like Http, EfCore, Hangfire, SqlClient and Redis
https://github.com/joaofranco91/jf91.opentelemetry.net7
7 api asp asp-net asp-net-core core metrics net net-core net7 open opentelemetry otlp telemetry tracing web
Last synced: 21 days ago
JSON representation
OpenTelemetry for ASP.NET Web API Plug-And-Play. Select exporters like Console, Jaeger, Zipkin, Prometheus, InfluxDB and OTLP and Instrumentators like Http, EfCore, Hangfire, SqlClient and Redis
- Host: GitHub
- URL: https://github.com/joaofranco91/jf91.opentelemetry.net7
- Owner: JoaoFranco91
- Created: 2023-07-11T01:16:19.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2023-07-24T14:31:04.000Z (almost 3 years ago)
- Last Synced: 2025-08-01T01:28:58.006Z (10 months ago)
- Topics: 7, api, asp, asp-net, asp-net-core, core, metrics, net, net-core, net7, open, opentelemetry, otlp, telemetry, tracing, web
- Language: C#
- Homepage:
- Size: 99.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Use this package to integrate OpenTelemetry into your ASP.NET Web API using ```appsettings.json```
Follow these steps to get it done:
#### 1: Install Nuget Package
```
dotnet add package JF91.OpenTelemetry
```
#### 2: Add this after ```var builder = WebApplication.CreateBuilder(args);```
```
builder.Services.AddOpenTelemetryServices(builder.Configuration);
```
#### 2.2: Customize settings (Optional):
###### Custom options are optional which means that you can mix options from appsettings.json with the ones defined below
```
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;
}
);
```
#### IMPORTANT: For a custom options list to OTLP Exporters, you need to have the same ammount of entries in appsettings.json with the same order.
Example 1: 3 OTLP Exporters in appsettings.json and 2 Custom Options will override the first 2 OTLP Exportes in appsettings.json from the first 2 Custom Options.
Example 2: 2 OTLP Exporters in appsettings.json and 3 Custom Options will override the 2 OTLP Exporters in appsettings.json from the first 2 Custom Options.
#### 3: Add this before ```app.Run();```
```
app.AddOpenTelemetryExtensions();
```
#### 4: Add this to your ```appsettings.json``` and modify it to your needs:
```
"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
}
}
```
### Properties Values:
- Jaeger.Protocol: udp / http | Default => udp
- [OtlpProtocols] > InfluxDB.Protocol: grpc / http | Default => grpc
#### Reference: https://opentelemetry.io/docs/instrumentation/net/exporters/