Skip to content

Latest commit

 

History

History
124 lines (75 loc) · 4.19 KB

functions-monitor-log-analytics.md

File metadata and controls

124 lines (75 loc) · 4.19 KB
title description author ms.topic ms.date ms.author ms.custom
Monitoring Azure Functions with Azure Monitor Logs
Learn how to use Azure Monitor Logs with Azure Functions to monitor function executions.
craigshoemaker
conceptual
04/15/2020
cshoe
devx-track-csharp, devx-track-python

Monitoring Azure Functions with Azure Monitor Logs

Azure Functions offers an integration with Azure Monitor Logs to monitor functions. This article shows you how to configure Azure Functions to send system-generated and user-generated logs to Azure Monitor Logs.

Azure Monitor Logs gives you the ability to consolidate logs from different resources in the same workspace, where it can be analyzed with queries to quickly retrieve, consolidate, and analyze collected data. You can create and test queries using Log Analytics in the Azure portal and then either directly analyze the data using these tools or save queries for use with visualizations or alert rules.

Azure Monitor uses a version of the Kusto query language used by Azure Data Explorer that is suitable for simple log queries but also includes advanced functionality such as aggregations, joins, and smart analytics. You can quickly learn the query language using multiple lessons.

Note

Integration with Azure Monitor Logs is currently in public preview. Not supported for function apps running on version 1.x.

Setting up

  1. From the Monitoring section of your function app in the Azure portal, select Diagnostic settings, and then select Add diagnostic setting.

    :::image type="content" source="media/functions-monitor-log-analytics/diagnostic-settings-add.png" alt-text="Select diagnostic settings":::

  2. In the Diagnostics settings page, under Category details and log, choose FunctionAppLogs.

    The FunctionAppLogs table contains the desired logs.

  3. Under Destination details, choose Send to Log Analytics.and then select your Log Analytics workspace.

  4. Enter a Diagnostic settings name, and then select Save.

    :::image type="content" source="media/functions-monitor-log-analytics/choose-table.png" alt-text="Add a diagnostic setting":::

User-generated logs

To generate custom logs, use the logging statement specific to your language. Here are sample code snippets:

log.LogInformation("My app logs here.");
context.getLogger().info("My app logs here.");
context.log('My app logs here.');
Write-Host "My app logs here."
logging.info('My app logs here.')

Querying the logs

To query the generated logs:

  1. From your function app, select Diagnostic settings.

  2. From the Diagnostic settings list, select the Log Analytics workspace that you configured to send the function logs to.

  3. From the Log Analytics workspace page, select Logs.

    Azure Functions writes all logs to the FunctionAppLogs table under LogManagement.

    :::image type="content" source="media/functions-monitor-log-analytics/querying.png" alt-text="Query window in Log Analytics workspace":::

Here are some sample queries:

All logs


FunctionAppLogs
| order by TimeGenerated desc

Specific function logs


FunctionAppLogs
| where FunctionName == "<Function name>" 

Exceptions


FunctionAppLogs
| where ExceptionDetails != ""  
| order by TimeGenerated asc

Next steps