Search code examples
azureazure-functionsazure-application-insightsazure-monitoring

Monitoring Azure function


I have timer triggered Function. It is executed every minute but I don't see any logs in Monitor section in Azure Portal.

Monitor

However when I click "Run query in Application Insights" and fix cloudRoleName in query (by default it is set to name of application but we changed it with ITelemetryInitializer) it displays all executions correctly.

App insights query

EDIT: This is my startup code

public class Startup : IWebJobsStartup
{
    public void Configure(IWebJobsBuilder builder)
    {
        builder.Services
            .AddSingleton<ITelemetryInitializer, CloudRoleNameInitializer>();

        // more registrations
    }

and CloudRoleNameInitializer

 public class CloudRoleNameInitializer : ITelemetryInitializer
 {
    public void Initialize(ITelemetry telemetry)
    {
        telemetry.Context.Cloud.RoleName = "EmailPuller";
    }
 }

When I click run query in application Insights the query generated is

requests
| project timestamp, id, operation_Name, success, resultCode, duration, operation_Id, cloud_RoleName, invocationId=customDimensions['InvocationId']
| where timestamp > ago(30d)
| where cloud_RoleName =~ 'emailpuller-UNIQUE_ID_FROM_ARM_TEMPLATE' and operation_Name =~ 'OurOperationName'
| order by timestamp desc
| take 20

So you can see cloud_RoleName is different than set by ITelemetryInitializer. If I update query to use 'emailpuller' it returns information on executions


Solution

  • Your guess is right. The Monitor UI uses the default CloudRoleName to query the logs.

    It's easy to find the root cause. The steps are as below:

    1.Nav to azure portal -> your azure function -> Monitor -> press F12 to open the Develop Tool of the browser.

    2.then click the Refresh button -> then in the Develop tool, select the api -> then in the Request Payload, you can see this api uses the default CloudRoleName to query the logs.

    Here is the screenshot:

    enter image description here

    This may be a bug, you can raise an issue in github of Azure function.