question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom properties are not logged using Application Insights

See original GitHub issue

Using the guidance from the Application Insights logging with .NET an Azure Function (net6.0 and FUNCTIONS_WORKER_RUNTIME of dotnet-isolated) does not log custom properties.

Steps to reproduce

The function trigger looks as follows:

using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;
using Performance.AuthTokenConfigGenerator.FunctionApp.Error_Responses;
using System;
using System.Collections.Generic;

namespace TokenGenerator.Function
{
    public class TokenGeneratorHttpTrigger
    {
        private readonly ILogger _logger;

        public TokenGeneratorHttpTrigger(ILogger<TokenGeneratorHttpTrigger> logger)
        {
            _logger = logger;
        }

        [Function(Constants.TokenGeneratorHttpTrigger)]
        public IActionResult Run([HttpTrigger(AuthorizationLevel.Function, "get",
            Route="TokenGeneratorHttpTrigger/{emailId}")] HttpRequestData req, string emailId, FunctionContext executionContext)
        {
            try
            {
                using (_logger.BeginScope(new Dictionary<string, object> { ["MyKey"] = "MyValue" }))
                {
                    _logger.LogError("An example of an Error level message");
                }

                return new OkObjectResult(emailId);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "");

                return new InternalServerError(ex.Message);
            }
        }
    }
}

Expected results

I should see a custom property logged in application insights associated with the error message An example of an Error level message

Actual results

The custom properties section does not have the custom property I am trying to log:

image

Additional Information

csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <OutputType>Exe</OutputType>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.3.0" OutputItemType="Analyzer" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.6.0" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

Program.cs

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;

namespace Performance.AuthTokenConfigGenerator.FunctionApp
{
    public static class Program
    {
        public static void Main(string[] args)
        {
            var host = new HostBuilder()
               .ConfigureFunctionsWorkerDefaults()
               .Build();

            host.Run();
        }
    }
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
liliankasemcommented, May 4, 2022

Was able to repro; I’ll follow up with the team on next steps and provide an update

0reactions
fabiocavcommented, May 4, 2022

Duplicate of #7452

Read more comments on GitHub >

github_iconTop Results From Across the Web

The Request Telemetry doesn't log custom properties in ...
I want to log custom properties for both request and page view telemetries in Application Insight. I am working in an asp.net webforms...
Read more >
I cannot see my custom properties being logged to ...
I cannot see my custom properties being logged to application insights only the message. Does it need additional setup?
Read more >
Can you log custom properties with Auto-instrumentation?
Hi, I have a ASP.NET MVC application, I have Application Insights enabled with Auto-Instrumentation and I want to add custom properties on ...
Read more >
How to use Application Insights Custom Properties in ...
The telemetry is logged back to an Application Insights instance in your Azure tenant. You can then view all the reported telemetry via...
Read more >
Application Insights properties
These system properties control the behavior of the Application Insights application. ... Create time cards and log time through Time Sheet Portal.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found