# 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.

Azure Monitor can't post logs to an outside address by itself. A diagnostic setting streams them to an Event Hub, and a small Azure Function with an Event Hub trigger posts each batch to Flowhawk, which reads Azure's record format directly.

## What you get

- Azure resource logs in [Logs](https://flowhawk.dev/docs/signals#logs), next to your traces and metrics, searchable with the same query language (`severity>=WARN service=checkout "timeout"`), grouped into patterns or followed live.
- A log line that names a request path joins the [business flow](https://flowhawk.dev/docs/flows) of that route, so a failing checkout shows these logs on the checkout flow's page.
- A line that carries a trace id opens its trace.
- Alert on any search with **Alert on this**, and let the agent read these logs when it investigates an incident.

## Set it up

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.

### 1. Create an Event Hub

```
az eventhubs namespace create -g my-group -n my-logs-ns -l westeurope
az eventhubs eventhub create -g my-group --namespace-name my-logs-ns -n logs
```

### 2. Stream a resource's logs to it

Add a diagnostic setting to each resource whose logs you want (an App Service app, a Function App, a Container Apps environment, an AKS cluster). In the portal it is **Diagnostic settings > Add diagnostic setting > Stream to an event hub**. With the CLI:

```
az monitor diagnostic-settings create --name flowhawk \
  --resource RESOURCE_ID \
  --event-hub logs \
  --event-hub-rule /subscriptions/SUB/resourceGroups/my-group/providers/Microsoft.EventHub/namespaces/my-logs-ns/authorizationRules/RootManageSharedAccessKey \
  --logs '[{"categoryGroup":"allLogs","enabled":true}]'
```

### 3. Forward the batches with a function

Create a Function App on Node.js 18 or later (the v4 programming model) with this function. Give it two app settings: `EventHubConnection`, the namespace's connection string, and `FLOWHAWK_KEY`, your ingest key.

```
// src/functions/flowhawk.js
const { app } = require("@azure/functions");
app.eventHub("flowhawk", {
  connection: "EventHubConnection", eventHubName: "logs", cardinality: "many",
  handler: async (messages) => {
    const res = await fetch("https://api.flowhawk.dev/v1/logs/azure", {
      method: "POST", body: JSON.stringify(messages),
      headers: { "content-type": "application/json", authorization: `Bearer ${process.env.FLOWHAWK_KEY}` },
    });
    if (!res.ok) throw new Error(`Flowhawk answered ${res.status}`); // retried by the trigger
  },
});
```

The same code, with your workspace's address filled in, is in the app under **Settings > Integrations > Log drains**.

## What arrives

| Azure record | In Flowhawk |
| --- | --- |
| App Service, Function App, Container App or container name | The service. Add `?service=` to the address to name it yourself |
| A message that is itself JSON | Its fields: `level`, `message`, `trace_id` and the rest |
| `properties` | Attributes, with `cloud.resource_id` and `azure.category` |
| A request path in the record | The business flow and step of that route |

## Common questions

### Does this include application traces?

No, these are logs. For traces, add OpenTelemetry to the app ([.NET](https://flowhawk.dev/integrations/opentelemetry-dotnet), [other languages](https://flowhawk.dev/docs/languages)) and send it straight to Flowhawk. Logs that carry a trace id then open their trace.

### What does it cost on the Azure side?

An Event Hubs namespace and a Function App on the consumption plan. Flowhawk charges for the logs you keep, like any other data ([Billing](https://flowhawk.dev/docs/billing)).

## Related

[**AWS CloudWatch logs**Stream CloudWatch log groups from Lambda, ECS, EKS, API Gateway or RDS to Flowhawk through Amazon Data Firehose.](https://flowhawk.dev/integrations/aws-cloudwatch-logs) [**Google Cloud Logging**Route logs from Cloud Run, Cloud Functions, GKE and App Engine to Flowhawk with a log sink and a Pub/Sub push subscription.](https://flowhawk.dev/integrations/google-cloud-logging) [**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.](https://flowhawk.dev/integrations/opentelemetry-dotnet)

[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/azure-monitor-logs
