Kzryzstof
Kzryzstof

Reputation: 8382

How to get an ILogger from an Activity Function?

I am using Durable Azure Function in a prototype for a future project.

Basically, I have a Client Azure Function triggered by an HTTP POST request that starts the Orchestrator. Then, the Orchestrator decides to trigger an Activity. Nothing complicated.

Here is a sample of what I am doing:

[FunctionName("ClientFunction")]
public static async Task<HttpResponseMessage> OnHttpTriggerAsync([HttpTrigger(AuthorizationLevel.Anonymous, "post")]
            HttpRequestMessage request, [OrchestrationClient] DurableOrchestrationClient starter, ILogger logger)
{
    // Triggers the orchestrator.
    string instanceId = await starter.StartNewAsync("OrchestratorFunction", null);

    return new HttpResponseMessage(HttpStatusCode.OK);
}


[FunctionName("OrchestratorFunction")]
public static async Task DoOrchestrationThingsAsync([OrchestrationTrigger] DurableOrchestrationContext context, ILogger logger)
{
    // Triggers some serious activity.
    await context.CallActivityAsync("ActivityFunction", null);
}

[FunctionName("ActivityFunction")]
public static Task DoAnAwesomeActivity([ActivityTrigger] DurableActivityContext context)
{
    // Short & Sweet activity...
    // Wait... Where's my logger?
}

Both the Orchestrator and the Client Functions are being given an ILogger but not the Activity Function; as stated in the documentation (either a specific parameter or the DurableActivityContext instance), the Activity function only gets one parameter. And I am not under the impression that the static class in which these methods are declared could keep a reference on that ILogger.

I understand that the Activity Function should perform one small job but I would be more comfortable if I was able to log that the activity was called with the appropriate values if something goes wrong (and it will :) ).

Question

How can the Activity access the ILogger?

Upvotes: 2

Views: 1655

Answers (1)

Jerry Liu
Jerry Liu

Reputation: 17790

It is not possible to pass multiple parameters to an activity function directly. The recommendation in this case is to pass in an array of objects or to use ValueTuples objects in .NET.

This restriction you are concerned about is talking about the parameters we pass from Orchestrator to Activity Function. It doesn't mean we could only use one parameter in Activity method signature. Feel free to add ILogger there and complete your job as needed.

Upvotes: 1

Related Questions