Azure Functions Host Configuration

The Azure Functions host is responsible for managing the execution of your functions. You can configure its behavior and settings to suit your needs. This section covers the primary configuration options available for the Functions host.

Key Configuration Concepts

The host configuration is primarily defined in the host.json file. This file is located at the root of your function app project.

host.json Structure

The host.json file uses a JSON format and supports various top-level properties to control host behavior. Here's a basic example:

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[3.*, 4.0.0)"
  },
  "extensions": {
    "http": {
      "routePrefix": "api"
    }
  }
}

Common Configuration Settings

Logging Configuration

Fine-tune your logging settings to capture the right amount of information for debugging and monitoring. The logging object within host.json controls this.

Application Insights Integration

The applicationInsights object within logging allows you to configure how your function app integrates with Azure Application Insights.

{
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request",
        "includedTypes": "Exception,Trace,Dependency",
        "percentage": 100
      },
      "enableLiveMetricsFilters": false
    },
    "logLevel": {
      "default": "Information",
      "Host.Startup": "Trace"
    }
  }
}
Tip: Setting logLevel to Trace provides the most detailed logs, which can be very helpful during development and debugging.

Extension Bundles

Extension bundles provide a way to include common binding extensions with your function app without manually installing them. They are managed by Azure.

Configuring extensionBundle

{
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[3.*, 4.0.0)"
  }
}
Important: Ensure that the version range you specify is compatible with your function runtime version.

HTTP Trigger Configuration

You can customize how HTTP triggers behave, including setting a route prefix for all HTTP-triggered functions.

Configuring HTTP Extension

{
  "extensions": {
    "http": {
      "routePrefix": "api"
    }
  }
}

In this example, all HTTP-triggered functions will be prefixed with /api. So, a function with a route of /greet will be accessible at /api/greet.

Other Configuration Options

durableTask Settings

For Durable Functions, you can configure settings related to the underlying Durable Task Framework.

{
  "extensions": {
    "durableTask": {
      "hubName": "MyDurableTaskHub",
      "storageAccount": "AzureWebJobsStorage",
      "taskEvents": {
        "maxWriteStorageEvents": 1000,
        "maxReadStorageEvents": 1000
      }
    }
  }
}

customHandler

Configure custom handlers for languages not directly supported by Azure Functions. (Primarily for Linux Consumption plan).

{
  "customHandler": {
    "description": {
      "defaultExecutablePath": "node",
      "workingDirectory": "",
      "arguments": [
        "handler.js"
      ]
    },
    "enableForwardingHttpRequest": true
  }
}

Environment Variables

Many configuration settings, especially connection strings and sensitive information, should be managed using environment variables rather than hardcoding them in host.json. These can be set in the Azure portal for your function app.

Note: It's a best practice to use environment variables for secrets and connection strings.