Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Durable Function with ILogger #1144

Closed
eddynaka opened this issue Jan 7, 2020 · 5 comments
Closed

Durable Function with ILogger #1144

eddynaka opened this issue Jan 7, 2020 · 5 comments

Comments

@eddynaka
Copy link

eddynaka commented Jan 7, 2020

Description

I created an Azure Durable Function with Application Insights (just enabled it in the portal).
Created the code above to inject ILogger:

public ConstructorFunction(ILogger<ConstructorFunction> logger)
{
    _logger = logger;
}

With that, when debugging, it shows in the Console windows. But, when I publish to Azure, it doesn't log it in Application Insights.

Expected behavior

When using ILogger from DI, it should log in Application Insights

Actual behavior

Today, it's only logging in this scenario:

[FunctionName("Function_HttpStart")]
public async Task HttpStart(
    [TimerTrigger("0 0 8 * * 2,3,4,5,6")]TimerInfo myTimer,
    [DurableClient]IDurableOrchestrationClient starter,
    ILogger log)
{
    // Function input comes from the request content.
    string instanceId = await starter.StartNewAsync("MyFunction", null);

    log.LogInformation($"Started orchestration with ID = '{instanceId}'.");
}

App Details

  • Durable Functions extension version (e.g. v1.8.3): 2.1.0
  • Azure Functions runtime version (1.0 or 2.0): 3
  • Programming language used: C#

Screenshots

If applicable, add screenshots to help explain your problem.

If deployed to Azure

We have access to a lot of telemetry that can help with investigations. Please provide as much of the following information as you can to help us investigate!

  • Timeframe issue observed:
  • Function App name:
  • Function name(s):
  • Azure region:
  • Orchestration instance ID(s):
  • Azure storage account name:

If you don't want to share your Function App or storage account name GitHub, please at least share the orchestration instance ID. Otherwise it's extremely difficult to look up information.

@ghost ghost added the Needs: Triage 🔍 label Jan 7, 2020
@ltouro
Copy link

ltouro commented Jan 7, 2020

@eddynaka I don't think it is recommended to have the Logger on the class level. It is specific to each function execution.

Also, I don't think you need DI for that as the framework will provide this dependency for you. Each function execution will receive a new logger instance automatically.

But if you really need the log on class level, my guess is your DI will have to setup it for you. You may use the same env vars as the framework to get your logs to the same App Insights instance (not sure which keys they use, but you may look at the configuration screen on Azure platform).

@cgillum
Copy link
Collaborator

cgillum commented Jan 9, 2020

@eddynaka can you explain more why you need to use the constructor ILogger<T> instead of the ILogger in the function signature? As @ltouro says, the ILogger you get from the function parameter already allows you to log to Application Insights.

@cgillum cgillum added Needs: Author Feedback Waiting for the author of the issue to respond to a question and removed Needs: Triage 🔍 labels Jan 9, 2020
@eddynaka
Copy link
Author

eddynaka commented Jan 9, 2020

hi @cgillum , i was using ILogger because i'm using DI everywhere. So, i thought that removing that and adding the DI would work fine.

When we add a new Azure Durable Function to a project, it creates this:

[FunctionName("Function1")]
public static async Task<List<string>> RunOrchestrator(
    [OrchestrationTrigger] DurableOrchestrationContext context)
{
    var outputs = new List<string>();

    // Replace "hello" with the name of your Durable Activity Function.
    outputs.Add(await context.CallActivityAsync<string>("Function1_Hello", "Tokyo"));

    // returns ["Hello Tokyo!", "Hello Seattle!", "Hello London!"]
    return outputs;
}

Can I add the ILogger here as well?

@ghost ghost added Needs: Attention 👋 and removed Needs: Author Feedback Waiting for the author of the issue to respond to a question labels Jan 9, 2020
@cgillum
Copy link
Collaborator

cgillum commented Jan 9, 2020

@eddynaka Yeah, you can use ILogger in the orchestrator function too. One thing to be aware of when using it in orchestrator function is the impact of replay behavior. More information, including how to properly handle this can be found here: https://docs.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-diagnostics#logging

@cgillum cgillum added Needs: Author Feedback Waiting for the author of the issue to respond to a question and removed Needs: Attention 👋 labels Jan 9, 2020
@eddynaka
Copy link
Author

eddynaka commented Jan 9, 2020

I see...thanks for the response!

@ghost ghost added Needs: Attention 👋 and removed Needs: Author Feedback Waiting for the author of the issue to respond to a question labels Jan 9, 2020
@eddynaka eddynaka closed this as completed Jan 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants