Menu
Grafana Cloud

Configure Azure Event Hubs for logs

Complete the following steps to configure Azure Event Hubs.

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 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 using Apache Kafka endpoint.

  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.

StepExample 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
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>
Replace the following with your own values: resource-group-name, namespace-name, and eventhub-name.

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.

Complete the following steps in the Azure portal.

  1. Log in to your Azure account.

    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.

    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.

    {
      "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.

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

    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.

    PropertyRequired value
    namespace-nameReplace with the Azure Event Hub namespace name.
    eventhub-nameReplace 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.