Giorgio Bozio
Giorgio Bozio

Reputation: 3037

How to get the details of a continuous Azure WebJob invocation

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?

Upvotes: 4

Views: 2822

Answers (3)

Sascha Gottfried
Sascha Gottfried

Reputation: 3329

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);
}

Upvotes: 5

Mike S
Mike S

Reputation: 3169

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

Upvotes: 1

mathewc
mathewc

Reputation: 13558

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.

Upvotes: 0

Related Questions