Skip to content

james-world/demo-net8-metrics

Repository files navigation

Open Telemetry Demo with .NET 8

This demo shows how to use Open Telemetry with .NET 8 to instrument a simple web application. It sends traces to Jaeger and metrics to Prometheus and Grafana.

Grafana has been pre-fitted with slightly modified versions of James Newton-King's ASP.NET Core 8 Grafana dashboards to show off some of the new metrics.

Demo Diagram

Prequisites

  • .NET 8 SDK
  • Docker Desktop, or Docker + Docker Compose
  • Tested on Mac OS Sonoma with M1 and M2 chips, and on Windows 11

Run the telemetry backends

From the root of the repository, run:

docker compose up

This will start Prometheus, Grafana and Jaegar, and the Otel Contrib Collector. The collector will receive telemetry from the demo application over gRPC using OTLP protocol and forward it to the backends.

Running the Demo Application

From the root of the repository, run:

dotnet run --project src/SimpleAPI

This will start a simple web api on https://localhost:8080.

Generating Telemetry

If you are using Visual Studio Code with an extension like REST Client, or Rider's scratch pad, then you can use the test.http file to generate some individual requests to the API.

Alternatively, you can run the load tests using k6 with the following command, from the root of the repository. This will send a decent amount of traffic to the API and generate some interesting telemetry, including some calls that will fail with 404 and 500 errors.

docker run --name k6 -v ${PWD}/load-test.js:/load-test.js --rm grafana/k6 run --insecure-skip-tls-verify --vus 10 -d 1m /load-test.js

Browse Telemetry

  • Grafana at http://localhost:3000 - here you can explore the ASP.NET dashboards and try creating your own for the custom metric "simpleapi.roll_die_roll_count".
  • Jaegar at http://localhost:16686 - here you can explore traces.

How everything is configured

Configuration is mapped into the various contains using Docker volumes in the docker-compose.yaml file. The purpose of exposed ports and files is described in the comments in that file.

The file otel-collector-config.yaml configures the Otel Contrib Collector to receive telemetry from the demo application over gRPC using OTLP protocol and forward it to the backends.

The folder grafana-config contains various configuration files and JSON files that configure the Grafana dashboards. You can read about provisioning Grafana here.

The file prometheus.yaml configures Prometheus to scrape metrics from the Otel Contrib Collector.

Find Out More!

About

Metrics via OpenTelemetry in ASP.NET 8 Core

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published