---
title: "Collect Azure Logs with Grafana Alloy | Grafana Cloud documentation"
description: "How to configure Azure logs with Grafana Alloy"
---

> For a curated documentation index, see [llms.txt](/llms.txt). For the complete documentation index, see [llms-full.txt](/llms-full.txt).

# Collect Azure Logs with Grafana Alloy

[Azure Monitor](https://learn.microsoft.com/en-us/azure/azure-monitor/overview) streams log data from configured sources to an [Event Hubs](https://learn.microsoft.com/en-us/azure/event-hubs/event-hubs-about) namespace that has been created with a Kafka endpoint. Grafana Alloy pulls the data from the Event Hubs namespace and sends it to Grafana Cloud.

The following diagram illustrates how Grafana Alloy pulls data from the Event Hubs namespace and sends it to Grafana Cloud:

[How Azure Logs works](/media/docs/grafana-cloud/cloud-provider/-Azure-Event-Hubs.png)

Complete the following steps to configure Grafana Alloy to send logs from an Azure Event Hub to Grafana Cloud.

## Select your platform

Select the platform from the drop-down menu.

## Install Grafana Alloy

Click **Run Grafana Alloy** to open steps to set up [Grafana Alloy](/docs/grafana-cloud/send-data/alloy/) and create a configuration file.

1. If you have not already installed Alloy where you intend to run Azure Event Hubs, click **Run Grafana Alloy**.
2. At the **Alloy configuration** screen, either create a token or use an existing token.
   
   1. To create a token, enter a token name, then click **Create token**. The token displays on the screen and is added to the command for running Alloy. Copy the command and paste it into the terminal.
   2. To use an existing token, paste it into the token field, then click **Proceed to install integration**.
3. Copy the command and paste it into the terminal.
4. Click **Proceed to install integration**.

## Set up Azure Event Hubs

Grafana Alloy consumes events from [Azure Event Hub](https://learn.microsoft.com/en-us/azure/event-hubs/event-hubs-about) using [Apache Kafka endpoint](https://learn.microsoft.com/en-us/azure/event-hubs/azure-event-hubs-kafka-overview#overview).

1. Click **Setup instructions**.
2. At the **Set up Azure Event Hubs** screen, use these steps in the Azure portal to start Event Hubs and route logs from the Function App.

### Create a namespace

Complete the following steps in the Azure portal, and use the example command for each step.

Expand table

| Step                                                                                                        | Example command                                                                                                                                                                                                                                                                                                                                           |
|-------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 1\. Log in to your Azure account with the command.                                                          | `az login`                                                                                                                                                                                                                                                                                                                                                |
| 2\. List your available subscriptions.                                                                      | `az account list --output table`                                                                                                                                                                                                                                                                                                                          |
| 3\. Select the subscription that you want to use by replacing `subscription-id` with the appropriate value. | `az account set --subscription <subscription-id>`                                                                                                                                                                                                                                                                                                         |
| 4\. Create an Azure Event Hubs namespace.                                                                   | `az eventhubs namespace create --resource-group <resource-group-name> --name <namespace-name> --location <location> --sku <sku> --enable-kafka true`<br /><br />Replace the following with your own values: `resource-group-name`, `namespace-name`, `location`, and `sku`. **If you want to enable Kafka, set `sku` to either `Standard` or `Premium`.** |
| 5\. Create an Event Hub within the namespace you created.                                                   | `az eventhubs eventhub create --resource-group <resource-group-name> --namespace-name <namespace-name> --name <eventhub-name>`<br /><br />Replace the following with your own values: `resource-group-name`, `namespace-name`, and `eventhub-name`.                                                                                                       |

> Note
> 
> You **must** set your Event Hubs namespace pricing tier to **Standard** or **Premium** if you want to **enable Kafka**. The Basic tier doesn’t support Apache Kafka workloads.
> 
> Refer to [Create an Event Hubs namespace](https://learn.microsoft.com/en-us/azure/event-hubs/event-hubs-create#create-an-event-hubs-namespace) and the [AWS CLI command reference](https://learn.microsoft.com/en-us/cli/azure/eventhubs/namespace?view=azure-cli-latest#az-eventhubs-namespace-create) in the Azure documentation for more information.

### Configure access for Grafana Alloy to consume from Event Hub

To read logs from Azure Event Hub, Grafana Alloy will need the proper authorization to read from the Event Hub created.

Alloy uses the azure sdk for go, which has multiple options for configuring authentication to Azure including, but not limited to:

- A service principal with environment variable
- A workload identity
- A managed identity

Whichever option you choose, you must assign the identity to the Azure Event Hubs Data Receiver role for the Azure Resource Group where your Event Hub exists.

Use the example below to help you create a service principal with the Azure Event Hubs Data Receiver role using the Azure CLI. This is just one example. Refer to the various options for configuring authentication in [Azure documentation](https://learn.microsoft.com/en-us/azure/developer/go/azure-sdk-authentication?tabs=bash#2-authenticate-with-azure).

Complete the following steps in the Azure portal.

1. Log in to your Azure account.
   
   ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```none
   az login
   ```
2. Create a service principal, and give it the proper role. If the service principal already exists with this name, it will be updated with the role and scopes provided.
   
   ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```none
   az ad sp create-for-rbac --name grafana-alloy --role "Azure Event Hubs Data Receiver" --scopes "/subscriptions/{subscription-id}"
   ```
3. If the service principal was created, be sure to capture the output of the command. It includes the credential information for using the service principal.
   
   ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```none
   {
     "appId": "54321a67-8fd9-123d-45d6-7891234567fd",
   
   
     "displayName": "grafana-alloy",
   
   
     "password": "asdf1234~4321fdsa",
   
   
     "tenant": "12345a67-8fd9-123d-45d6-7891234567fd"
   }
   ```
4. Set environment variables to configure Grafana Alloy to use your new service principal. The placeholder references in the environment variables are based on the output of the az ad sp create-for-rbac command.
   
   ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```none
   export AZURE_TENANT_ID="<tenant>"
   
   export AZURE_CLIENT_ID="<appId>"
   
   export AZURE_CLIENT_SECRET="<password>"
   ```

## Configure Alloy

Set up Grafana Alloy to get events from Azure Event Hub.

1. [Navigate](/docs/grafana-cloud/send-data/alloy/configure/linux/) to the configuration file for your Alloy instance.
2. Copy and append the following to your Alloy configuration file so that Grafana Alloy can scrape your Azure Event Hub instances.
   
   ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```none
   discovery.relabel "logs_integrations_integrations_azure_event_hubs" {
     targets = []
   
     rule {
       source_labels = ["__meta_kafka_topic"]
       target_label  = "topic"
     }
   }
   
   loki.source.azure_event_hubs "logs_integrations_integrations_azure_event_hubs" {
     fully_qualified_namespace = "<namespace-name>.servicebus.windows.net:9093"
     event_hubs                = ["<eventhub-name>"]
   
     authentication {
       mechanism         = "oauth"
     }
     use_incoming_timestamp = true
     relabel_rules          = discovery.relabel.logs_integrations_integrations_azure_event_hubs.rules
     labels                 = {
       job = "integrations/azure_event_hubs",
     }
     forward_to = [loki.write.grafana_cloud_loki.receiver]
   }
   ```
3. Find the value for the following properties in Azure, and replace them with values you created when you set up the Azure Event Hub.
   
   Expand table
   
   | Property         | Required value                                   |
   |------------------|--------------------------------------------------|
   | `namespace-name` | Replace with the Azure Event Hub namespace name. |
   | `eventhub-name`  | Replace with the Azure Event Hub name..          |

## Restart Grafana Alloy

Run the command appropriate for your platform to restart Grafana Alloy so your changes can take effect.

## Test connection

Click **Test connection** to test that Grafana Alloy is collecting data and sending it to Grafana Cloud.

## View your logs

Click the **Logs** tab to view your logs.
