# OpenTelemetry for ASP.NET Core and .NET

Trace an ASP.NET Core app's requests, HttpClient calls and logs with OpenTelemetry, and send them to Flowhawk.

.NET has OpenTelemetry built into its hosting model: a few packages and one block in `Program.cs` trace every request and outgoing call, and send `ILogger` logs with their trace.

## What you get

- Every request as a trace, with its database calls and outgoing HTTP calls, in [Traces](https://flowhawk.dev/docs/signals#traces).
- Requests matched to your [business flows](https://flowhawk.dev/docs/flows) by service and route on our side, so you see "checkout is failing at place order" rather than a list of endpoints.
- Exceptions grouped into [Issues](https://flowhawk.dev/docs/signals#issues), slow and N+1 database queries on each database's page, and deploys found from `service.version`.
- Alerts, incidents and the on-call agent, which reads these traces when something breaks.

## Set it up

### 1. Install the packages

```
dotnet add package OpenTelemetry.Extensions.Hosting
dotnet add package OpenTelemetry.Instrumentation.AspNetCore
dotnet add package OpenTelemetry.Instrumentation.Http
dotnet add package OpenTelemetry.Exporter.OpenTelemetryProtocol
```

### 2. Add OpenTelemetry in Program.cs

```
builder.Services.AddOpenTelemetry()
    .WithTracing(t => t.AddAspNetCoreInstrumentation().AddHttpClientInstrumentation().AddOtlpExporter())
    .WithMetrics(m => m.AddAspNetCoreInstrumentation().AddOtlpExporter());
builder.Logging.AddOpenTelemetry(l => l.AddOtlpExporter());
```

For Entity Framework Core or SqlClient queries, add `OpenTelemetry.Instrumentation.EntityFrameworkCore` or `OpenTelemetry.Instrumentation.SqlClient` and their `Add...Instrumentation()` call.

### 3. Point it at Flowhawk

First create an ingest key: in the app, open **Settings > API keys** and pick **Services**. In the examples below, `KEY` stands for that key. Keep it out of your repository, like any other secret.

```
OTEL_SERVICE_NAME=orders
OTEL_EXPORTER_OTLP_ENDPOINT=https://ingest.flowhawk.dev
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
OTEL_EXPORTER_OTLP_HEADERS=Authorization=KEY
OTEL_RESOURCE_ATTRIBUTES=deployment.environment=production,service.version=1.4.2
```

Flowhawk accepts the key with or without `Bearer`. Without it there is no space to encode, which some .NET versions send literally. Set `service.version` to your release, so a deploy shows as a change next to the flows it made better or worse.

## Check it arrived

Open **Setup** in the app. It lists each service that sent data in the last 15 minutes. If yours isn't there, [Help and troubleshooting](https://flowhawk.dev/docs/help) says why telemetry can be refused (a wrong key, an empty balance) and how to see it.

## Common questions

### Is there a Flowhawk SDK for .NET?

It isn't on NuGet yet. Plain OpenTelemetry as above works today: Flowhawk matches your requests to flows by service and route. Switching to the SDK later adds exact flow tags across services and sampling per flow, and nothing else changes.

### Does it work in Azure?

Yes, on App Service, Container Apps, Functions and AKS alike. For the platform's own logs, see [Azure logs through Event Hubs](https://flowhawk.dev/integrations/azure-monitor-logs).

## Related

[**Azure logs through Event Hubs**Send the resource logs of App Service, Azure Functions, Container Apps and AKS to Flowhawk with a diagnostic setting and an Event Hub.](https://flowhawk.dev/integrations/azure-monitor-logs) [**OpenTelemetry for Spring Boot**Trace a Spring Boot app with the OpenTelemetry Java agent, with no code change, and send traces, metrics and logs to Flowhawk.](https://flowhawk.dev/integrations/opentelemetry-spring-boot) [**OpenTelemetry Collector**Send everything your OpenTelemetry Collector receives to Flowhawk, and collect host and container metrics on the way.](https://flowhawk.dev/integrations/opentelemetry-collector)

[Try it free for 14 days](https://app.flowhawk.dev/signup?trial=1) [Read the getting started guide](https://flowhawk.dev/docs/getting-started)

---

URL: https://flowhawk.dev/integrations/opentelemetry-dotnet
