Thibault ROHMER
Thibault ROHMER

Reputation: 33

Azure function TimerTrigger result code in Application Insights is always success

I've got a simple C# Azure Function using a timer trigger to run every X minutes. No output binding.

In application insights, the function is always in success with a result code of 0:

Here

[Despite having called the .Error() of the TraceWriter several times.]

I'd like to get the correct final status in application insights but I don't see how to do it. Documentation never talks about that :-/ Can someone guide me how to do it in C# ?

I tried to set Environment.ExiCode but same result. I also tried to change return type to int but then the function isn't called anymore. I suppose because its the way to declare an output binding for the azure function itself.

Here is my function:

[FunctionName("SendToOfflineArchive")]
public static void Run([TimerTrigger("%TimerInterval%")]TimerInfo myTimer, TraceWriter log)
{
    log.Info($"C# Timer trigger function executed at: {DateTime.Now}");

    // do stuff

    int nbErrors = 7;
    //return nbErrors;
}

It would be great to have a result code other than 0... Like the number of errors (an integer).

Upvotes: 3

Views: 2575

Answers (1)

Dmitry Matveev
Dmitry Matveev

Reputation: 2679

Azure Function is considered failed if it threw an exception (there is an embedded integration between AF and AI and it considers successfully executed function a "success"). Logging an error as a trace should yield corresponding Trace message in Application Insights if logging forwarding is enabled.

Upvotes: 2

Related Questions