Introduction to host.json

The host.json file is a configuration file that controls global settings for your Azure Functions host. It allows you to define settings for logging, extensions, retry policies, and much more. This file is located at the root of your function app project.

Each version of the Functions runtime might have a different schema and available settings. It's crucial to consult the documentation for the specific runtime version your function app is targeting.

Schema and Versioning

The schema for host.json evolves with new releases of Azure Functions. You can specify the schema version in the $schema property at the root of the file.

Example of specifying the schema version:


{
  "$schema": "http://json.schemas.microsoft.com/azure/functions/2.0.0/host.json",
  // ... other settings
}
                    

The schema version often dictates which settings are available and how they behave. Always ensure your host.json aligns with the expected schema for your runtime.

Common Settings

Logging

Configure how your function app logs events. This includes settings for application logging, HTTP request logging, and log levels.


{
  "$schema": "http://json.schemas.microsoft.com/azure/functions/2.0.0/host.json",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    },
    "logLevel": {
      "default": "Information",
      "Host.Startup": "Trace",
      "Function.MyFunction": "Debug"
    }
  }
}
                    
  • applicationInsights: Configures settings for Azure Application Insights integration.
  • samplingSettings: Controls the sampling of telemetry data to reduce costs and improve performance.
  • logLevel: Defines the minimum log level for different categories (e.g., default, specific hosts, or functions).

Extensions

Manage the configuration of various Azure Functions extensions, such as Storage, Event Hubs, and Service Bus bindings.


{
  "$schema": "http://json.schemas.microsoft.com/azure/functions/2.0.0/host.json",
  "extensions": {
    "queues": {
      "batchSize": 16,
      "newBatchThreshold": 8
    },
    "storage": {
      "options": {
        "noDefaultLa": true
      }
    }
  }
}
                    
  • queues: Settings for Azure Queue Storage triggers and bindings.
  • storage: General settings for storage-related operations.

Singleton

Configure singleton execution for functions, ensuring only one instance of a function runs at a time across multiple instances of your app.


{
  "$schema": "http://json.schemas.microsoft.com/azure/functions/2.0.0/host.json",
  "singleton": {
    "connections": [
      "AzureWebJobsStorage"
    ],
    "mode": "Automatic"
  }
}
                    
  • connections: Specifies the app setting name(s) that contain connection strings used for singleton coordination.
  • mode: Sets the singleton mode (e.g., Automatic, Manual).

Health Checker

Enable and configure a health check endpoint for your function app, allowing external services to monitor its health.


{
  "$schema": "http://json.schemas.microsoft.com/azure/functions/2.0.0/host.json",
  "healthChecker": {
    "interval": "00:00:30",
    "timeout": "00:00:15",
    "enabled": true
  }
}
                    
  • interval: The frequency at which the health check is performed.
  • timeout: The timeout for the health check request.
  • enabled: Whether the health checker is active.

HTTP

Configure settings related to HTTP triggers and responses.


{
  "$schema": "http://json.schemas.microsoft.com/azure/functions/2.0.0/host.json",
  "http": {
    "routePrefix": "api",
    "maxOutstandingRequests": 200,
    "maxConcurrentRequests": 100
  }
}
                    
  • routePrefix: A prefix for all HTTP-triggered functions.
  • maxOutstandingRequests: Maximum number of outstanding HTTP requests.
  • maxConcurrentRequests: Maximum number of concurrent HTTP requests.

Queues

Specific settings for Azure Queue Storage integration.


{
  "$schema": "http://json.schemas.microsoft.com/azure/functions/2.0.0/host.json",
  "queues": {
    "batchSize": 16,
    "newBatchThreshold": 8,
    "maxPollingInterval": "00:01:00",
    "visibilityTimeout": "00:00:30",
    "messageHandlerTimeout": "00:05:00",
    "maxDequeueCount": 5
  }
}
                    
  • batchSize: Number of messages to process in a single batch.
  • newBatchThreshold: Threshold for triggering a new batch.
  • maxPollingInterval: Maximum interval between polling for new messages.
  • visibilityTimeout: How long a message is invisible after being dequeued.
  • messageHandlerTimeout: Timeout for the message handler.
  • maxDequeueCount: Maximum number of times a message can be dequeued.

Timers

Configure the behavior of timer triggers.


{
  "$schema": "http://json.schemas.microsoft.com/azure/functions/2.0.0/host.json",
  "timers": {
    "maxRunningTimers": 20,
    "tolerance": "00:00:00"
  }
}
                    
  • maxRunningTimers: Maximum number of timer triggers that can run concurrently.
  • tolerance: A time span to allow for slight deviations in schedule execution.

Example Configuration

A comprehensive host.json file might combine several settings:


{
  "$schema": "http://json.schemas.microsoft.com/azure/functions/2.0.0/host.json",
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    },
    "logLevel": {
      "default": "Information",
      "Host.Results": "Error"
    }
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[3.*, 4.0.0)"
  },
  "extensions": {
    "queues": {
      "batchSize": 32,
      "newBatchThreshold": 16
    },
    "sendGrid": {
      "from": "notifications@example.com"
    }
  },
  "singleton": {
    "mode": "Automatic"
  },
  "http": {
    "routePrefix": "api/v1"
  }
}