question

DavidBuckell avatar image
0 Votes"
DavidBuckell asked DavidBuckell answered

Azure Function Apps with dependency injection

I have an existing function app with multiple functions, which all work as expected when declared with the default static class method signature.
I now want to rebuild this to make use of dependency injection and make asynchronous calls to blob storage.
Having followed this guide https://docs.microsoft.com/en-us/azure/azure-functions/functions-dotnet-dependency-injection, my function apps don't appear to do anything and i'm having issues trying to debug them.
I previously would use https://<functionappname>.scm.azurewebsites.net/ and use the debug option but this no longer appears to exist.
I noticed that a couple of packages had pending nuget updates so I upgraded the latest packages to their latest versions:
- microsoft.extensions.configuration.usersecrets
- microsoft.extensions.dependencyinjection
- microsoft.extensions.dependencyinjection.abstractions

now when i add a message to my queue in order to test my queue trigger function and view the monitor section i sometimes see a function failed log entry with no specific details, but nothing appears in the invocations list. my logging info from my app was not displayed so it appears the function just immediately bombed out even though the queuetrigger picked up the queue msg.

my next step will be to create a fresh function app and implement it step by step, for example just try ILogger first and then add my own dependencies one by one.

in the interim i was wondering whether anyone else has stumbled across this and has any experience with resolving this.

i am developing my function app in .net core 3.1 & and attempting to deploy to a linux hosted consumption plan.

so things that would help:

1) how can i now debug this? application insights does not appear to be an option
2) any pointers to implementing DI within function apps? i saw an alternative post suggesting having your startup class inherit from IWebJobsStartup instead, but that doesn't appear to help at all
3) does anyone have a better guide to follow? the microsoft blog post i followed was only written 2 weeks ago so i would expect to work

thanks

azure-functions
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DavidBuckell avatar image
0 Votes"
DavidBuckell answered

ah i have done a little more digging and have stumbled across the Investigate -> Failures section within the application insights section of the portal.
initially loading this page displays "error displaying your content" with the following details so assumed this would not be able to help:

Error: Failed to retrieve the blade definition for 'AspNetOverviewV3' from the server. Manual require of the following modules failed; ["_generated/Blades/AspNetOverviewV3" : {Error: Couldn't load "_generated/Blades/AspNetOverviewV3" at "https://afd.hosting.portal.azure.net/appinsights/Content/Dynamic/iE-E1AhCnKyg.js" as the following dependencies failed to load; ["Overview/ViewModels/AspNetOverviewBlade" : {Error: Couldn't load "Overview/ViewModels/AspNetOverviewBlade" at "https://afd.hosting.portal.azure.net/appinsights/Content/Dynamic/5I1DBHoYhADo.js" as the following dependencies failed to load; ["FxInternal/Controls/ProgressBar" : {Error: Couldn't load "FxInternal/Controls/ProgressBar"; error code 503},"FxInternal/Controls/ProgressBar" : {Error: Couldn't load "FxInternal/Controls/ProgressBar"; error code 503}];

but the failures section does display the top 3 exception types and drilling down into this I can see a dependency of my dependency is null.
having added this extra dependency to my startup class my function is now behaving as expected.

i still did not see any output in the logs so would still like to know how to access these logs since the kudu webpage no longer appears to offer this option

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DavidBuckell avatar image
0 Votes"
DavidBuckell answered DavidBuckell edited

I set up a simple example that injects a service that simply logs to the console.
Documented here: https://www.davidbuckell.com/blogs/development/azure/function-apps/creating-function-apps-with-dependency-injection-support

My findings are that I am only able to reliably view my debug output via the emulator or the invocations tab. I would prefer to be able to access the full log files somehow.

If anyone knows how to access function app log files I would be interested in learning how.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DavidBuckell avatar image
0 Votes"
DavidBuckell answered

Having played with application insights I have discovered how to run custom queries & this has provided me with a reliable way of viewing the debug output.
I have updated the above blog post with details on how I achieved this.

Hope this helps others in future.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.