6

I have a C# azure function that is throwing an exception:

[FunctionName("Function1")]
        public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            throw new Exception("Helpful message");
        }

The exception is catched by the runtime and re thrown. In application insight this is logged with the message Exception while executing function: Function1 and the call stack. I am unable to find the "Helpful message" anywhere.

In Application Insights I see this and non of the Properties has the "Helpful message" text: Application Insights of the exception

The callstack shows the location of the error:

Microsoft.Azure.WebJobs.Host.FunctionInvocationException:
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor+<ExecuteWithLoggingAsync>d__19.MoveNext (Microsoft.Azure.WebJobs.Host, Version=3.0.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35Microsoft.Azure.WebJobs.Host, Version=3.0.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.csMicrosoft.Azure.WebJobs.Host, Version=3.0.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: 321)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor+<TryExecuteAsyncCore>d__16.MoveNext (Microsoft.Azure.WebJobs.Host, Version=3.0.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35Microsoft.Azure.WebJobs.Host, Version=3.0.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.csMicrosoft.Azure.WebJobs.Host, Version=3.0.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: 117)
Inner exception System.Exception handled at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw:
   at FunctionApp1.Function1+<Run>d__0.MoveNext (FunctionApp1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=nullFunctionApp1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: C:\Users\sschoof\Documents\Visual Studio 2017\Projects\FunctionApp1\FunctionApp1\Function1.csFunctionApp1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: 20)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`2+<InvokeAsync>d__10.MoveNext (Microsoft.Azure.WebJobs.Host, Version=3.0.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35Microsoft.Azure.WebJobs.Host, Version=3.0.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionInvoker.csMicrosoft.Azure.WebJobs.Host, Version=3.0.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: 52)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor+<InvokeAsync>d__27.MoveNext (Microsoft.Azure.WebJobs.Host, Version=3.0.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35Microsoft.Azure.WebJobs.Host, Version=3.0.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.csMicrosoft.Azure.WebJobs.Host, Version=3.0.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: 584)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor+<ExecuteWithWatchersAsync>d__26.MoveNext (Microsoft.Azure.WebJobs.Host, Version=3.0.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35Microsoft.Azure.WebJobs.Host, Version=3.0.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.csMicrosoft.Azure.WebJobs.Host, Version=3.0.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: 531)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor+<ExecuteWithLoggingAsync>d__25.MoveNext (Microsoft.Azure.WebJobs.Host, Version=3.0.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35Microsoft.Azure.WebJobs.Host, Version=3.0.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.csMicrosoft.Azure.WebJobs.Host, Version=3.0.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: 467)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor+<ExecuteWithLoggingAsync>d__19.MoveNext (Microsoft.Azure.WebJobs.Host, Version=3.0.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35Microsoft.Azure.WebJobs.Host, Version=3.0.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.csMicrosoft.Azure.WebJobs.Host, Version=3.0.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: 277)

My current workaround is:

[FunctionName("Function1")]
        public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            try
            {
                throw new Exception("Helpful message");
            }
            catch (Exception e)
            {
                log.LogError(e, e.Message);
                throw e;
            }
        }

Is there an better way to get the "Helpful message" than adding this to every function?

4
  • We just fixed a bug in UX (getting on its way to production) which results in similar behavior. To check whether this is the same issue - can you please paste a screenshot where you see only top message? Commented Mar 29, 2019 at 8:29
  • @ZakiMa: Thanks for the reply, I added a screenshot Commented Mar 29, 2019 at 8:47
  • yes, this is exactly the issue we fixed. Thank you for reporting it! Commented Mar 29, 2019 at 9:09
  • Should be fixed now. Please let us know if you still cannot see internal messages. Commented Apr 3, 2019 at 5:46

2 Answers 2

2

This is a bug in UX. It was fixed on 3/28 and should be in prod around 4/2. Meanwhile you can access your messages in Analytics.

UX (before the fix):

enter image description here

Logs experience should still show messages:

enter image description here

After the fix (still on its way):

enter image description here

Sign up to request clarification or add additional context in comments.

5 Comments

How to I got to the info in the screenshot "Analytics should still show messages:" ?
Found it in the top navigation of the overview
I have the same issue - where did you find it in the end @sschoof?
@Rodney, are you facing the same bug, i.e. message is not available? Can you please check that you clicked on Exception (and not positioned on Request or other telemetry item)?
To find it in raw view - go to Logs (Analytics got renamed to Logs) and explore Exceptions table.
1

As per this doc, to see detailed message, you'd better use the method TrackException() . Or use the method you mentioned in your question.

The following 2 examples using TrackException() in run.csx in azure portal:

Example 1, not use try-catch block:

#r "Microsoft.ApplicationInsights"

using System;
using Microsoft.ApplicationInsights;

public static void Run(TimerInfo myTimer, ILogger log)
{
    var telemetry = new TelemetryClient();    

    log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
    log.LogInformation("a infor 567");    
    telemetry.TrackException(new Exception("Helpful message zzzzzz"));    

}

Check results in azure portal -> application insights:

enter image description here

Example 2, use try-catch block:

    #r "Microsoft.ApplicationInsights"

    using System;
    using Microsoft.ApplicationInsights;

    public static void Run(TimerInfo myTimer, ILogger log)
    {
        var telemetry = new TelemetryClient();

        try
        {
        log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
        log.LogInformation("a infor 567");
        throw new Exception("Helpful message hahaha yyyyyy");
        }
        catch (Exception ex)
        {
           telemetry.TrackException(ex);      
        }
    }

after execution, you can check the exceptions in azure portal -> application insights:

enter image description here

And if you're using visual studio to develop function app, you can just modify a little of the above code.

5 Comments

Azure Functions collect exceptions automatically. The problem is that it seems a message is lost. Sounds like a bug. For Azure Functions it is not recommended to track manually.
@ZakiMa, yes, I know it will auto collect telemetry. Maybe it's a bug, but not sure. And could you please let me know what's the impact if track manually?
It is most likely a bug. Also, if there is a task of logging exception - the right way is to do by using log.LogError (as author mentioned in a workaround). TrackException is for advanced scenarios (in context of Azure Functions) and not recommended. A link to a doc covers generic exception tracking in environments which don't track automatically.
@ZakiMa, but log.LogError would produce an redundant message, it requires another string message as parameter.
@ZakiMa, and could you please help confirm if this is the same issue? Many thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.