I have a .net windows forms application and this application call API (e.g. http://localhost:8080/api). I need to collect metrics using OpenTelemetry using prometheus exporter so that scraping can be done by prometheus. I am able to do it for .net core APIs but for win forms app , do not have idea. Looking for an example code or guidance for the same.
I have tried as mentioned here https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/docs/metrics/getting-started-aspnetcore/README.md but I believe I am not able to do it properly and also do not find it fully explained.
1
Prometheus exporting typically needs to expose an endpoint for Prometheus to scrape metrics from. It is easy in ASP.NET Core apps which already has a webserver, so adding an additional endpoint is trivial. For Non ASP.NET Core app, https://github.com/open-telemetry/opentelemetry-dotnet/tree/main/src/OpenTelemetry.Exporter.Prometheus.HttpListener can be used, but be warned that this component is only for dev/test purposes and has no intention to be made PROD ready! This can be leveraged in your app. (Again for test/learn purposes)
If you need to move beyond test/learn mode, then the following are options:
-
Use OTLP Exporter and “push” Metrics to Prometheus. This requires enabling a special feature flag in Prometheus. This doc shows this approach: https://github.com/open-telemetry/opentelemetry-dotnet/tree/main/docs/metrics/getting-started-prometheus-grafana
-
Use OTLP Exporter and “push” Metrics to an OpenTelemetry Collector, and then let this collector expose metrics in an http endpoint for Prometheus to scrape from. This is feasible, if you have the ability to run an OTel Collector. https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/exporter/prometheusexporter can be used to setup Collector with this setup.
0