4

Looking at the Kudu Azure WebJobs API docs https://github.com/projectkudu/kudu/wiki/WebJobs-API I see there are several calls I can do to manage WebJobs programmatically.

What is missing is a call to get, for a continuous webjob, the details of a single invocation. With invocation I mean the single execution of the function for a given message.

What I am trying to do is, for a message getting in the poison queue, to get the exception message of the parent invocation. In the poison message I get the id of the parent invocation with the json prop $AzureWebJobsParentId.

I would like to manage the poison queue with a function that emails the details of the error and moves the message in a dead-letter queue.

Any idea if this is possible?

Giorgio Bozio
  • 2,982
  • 3
  • 20
  • 20
  • Not that the API you link to above is the general WebJobs API, and it knows nothing about the SDK. But your question is SDK specific. You may want to tweak the title to make the clearer. – David Ebbo May 09 '16 at 16:29
  • Ok @DavidEbbo you mean that the Api I refer to is the Kudu Api and it's not the place to look at? I thought it was, since there's a call to get details of a triggered job. Any suggestion on where to look instead? Would be strange if there was no way. It looks a useful scenario to me. Anyway, thanks for the comment. – Giorgio Bozio May 09 '16 at 18:43
  • The Kudu API only knows about continuous and triggered WebJobs. If the continuous WebJob happens to use the SDK, Kudu has no knowledge of that. So your question is more: when using the SDK, is there an API to get the details. – David Ebbo May 14 '16 at 21:09
  • @GiorgioBozio how about accepting the answer mentioning Azure WebJobs SDK Extensions? This is still the way to go. – Sascha Gottfried Apr 19 '18 at 14:12

3 Answers3

5

The Azure WebJobs SDK Core extensions contain a binding for ExecutionContext which allows you to access invocation specific system information in your function. An example showing how to access the function Invocation ID:

public static void ProcessOrder(
    [QueueTrigger("orders")] Order order,
    TextWriter log,
    ExecutionContext context)
{
    log.WriteLine("InvocationId: {0}", context.InvocationId);
}

The invocation ID is used in the Dashboard logs, so having access to this programatically allows you to correlate an invocation to those logs.

Create a function specific error handler that will only handle errors for one function. This is done by naming convention based on an "ErrorHandler" suffix.

public static void ProcessOrderErrorHandler(
    [ErrorTrigger()] TraceFilter filter,
    TextWriter log)
{

    var lastMessage = filter.Message;
    var lastMessages = filter.GetDetailedMessage(5);
}

For email notifications

public static void ErrorMonitor(
    [ErrorTrigger("0:30:00", 10, Throttle = "1:00:00")] TraceFilter filter,
    [SendGrid] SendGridMessage message)
{
    message.Subject = "WebJobs Error Alert";
    message.Text = filter.GetDetailedMessage(5);
}
Sascha Gottfried
  • 3,303
  • 20
  • 30
1

There's not an official way to do this yet, but there's an issue to track exposing stable APIs (C# and REST) for reading the individual function instances: See https://github.com/Azure/azure-webjobs-sdk/issues/880 for status

Mike S
  • 3,058
  • 1
  • 22
  • 12
  • Thanks Mike. It would be a nice feature to add and perhaps it's not that hard to do. It would make poison queue handling easier. – Giorgio Bozio Oct 24 '16 at 08:04
0

Given a WebJobs SDK invocation ID, you can access the details of that execution via the WebJobs Dashboard. You can access the Dashboard via the WebJobs blade in the portal (the link will be in the "LOGS" column).

Or in the browser you can form the URL yourself, for example (substituting your app name and invocation ID):

https://<yourapp>.scm.azurewebsites.net/azurejobs/#/functions/invocations/<invocation-id>

That is how you would access these details manually.

mathewc
  • 13,312
  • 2
  • 45
  • 53
  • Yeah, I looked a way to have the same info through some API call to use it in a automatic email alert when a message goes to poison queue. – Giorgio Bozio May 20 '16 at 09:00