Azure / azure-functions-durable-extension

Durable Task Framework extension for Azure Functions
MIT License
717 stars 271 forks source link

Persist ILogger scope for Distributed Tracing feature #466

Open ThomasCronholm opened 6 years ago

ThomasCronholm commented 6 years ago

Hi,

When I create a ILogger Scope in my method with a DurableOrchestrationContext, activities called does not log the scope. I understand why but I am wondering if anything can be done about it, so that the scope is automagically included and is logged when I am in the activity.

using (logger.BeginScope("{SomeId}", someID)
{
    var returnValue = await context.CallActivityAsync<MyObject>("MapCartToMyObject", rawDataForProcessing);
}
...

[FunctionName("MapCartToMyObject")]
public static async Task<string> MapCartToMyObjectAsync([ActivityTrigger] DurableActivityContext inputs, ILogger log)
{
    var rawData = inputs.GetInput<string>();
    log.LogInformation("In {FunctionName}, some logging text: {RawData}", "MapCartToMyObjectAsync", rawData);
}
...

If not, are there any reccomendations, like "pass the logger in as a parameter" etc?

cgillum commented 6 years ago

Unfortunately I'm not familiar with BeginScope or how it's supposed to be used. Can you tell me more about what you're trying to achieve? Maybe there is a better way. I expect there will be problems with methods like this that have global side-effects because of the replay nature of orchestrator functions.

ThomasCronholm commented 6 years ago

Well the idea for us, is to have a mechanism for storing correlation id's so that we easlily can follow a durable execution through all logging we do using one id. Letting replay run as usual is not a problem as the thought of scope is to only couple different log entries together. GetStatusAsync with history is great and we love it, but when looking at logs there is a need to follow the thread, and as far as I have found getting the status with history is not easy from Application Insights. (sorry if I am rambling a bit)

worldspawn commented 5 years ago

@ThomasCronholm I would not expect that durable functions/orchestrators called from an orchestrator would know about the logging scope created in the orchestrator. The function could run on an entirely different host. It sure would be handy if it did and is probably a cool candidate for more durable function "magic".

ConnorMcMahon commented 4 years ago

It sounds unlikely that this is possible, but may be worth investigation.

cgillum commented 4 years ago

FWIW, we're working on adding end-to-end correlation features to Durable Functions that might help address @ThomasCronholm's need. You can track progress here: https://github.com/Azure/azure-functions-durable-extension/issues/939. A PR for this work is expected sometime this week.

adstep commented 3 years ago

I'm interested in a feature like this. This would make it a lot easier to pass around state to keep with the logs. @cgillum it looks like the end-to-end correlation feature has landed, but this didn't make it in with it.

I can see a section related to this in the limitations of the correlation-csharp documentation. It seems like a PR that was blocking support for this has been merged. Is this something that can be reconsidered for support?

The custom property is available for ActivityTrigger once this pull request is accepted and a change added to the Durable Functions side. Track original activity at the Application Insights Logger

czeslav87 commented 1 year ago

Any update on this? It would be huge help for improved tracability, especially in eternal orchestrations and multiple suborchestrations. We'd like to trace each orchestration run (invoked with ContinueAsNew) and suborchestration seperately.