Debugging two Azure Functions projects locally - azure

I have two Azure Functions projects.
I have one project, A, running on localhost:7071/api/....
I have changed the other project, B, to run on localhost:8888/api/...
I am calling a function which is running on project A from a function in Project B! How can I debug two Azure Functions projects locally? I cannot find any docs to help me.

To fix the issue add the command line switch --nodeDebugPort 5859 to your launching of func host to set the port for one of the sessions.
If you are launching from within Visual Studio you need to go to Project -> Properties -> Debug, then under Application arguments you need to pass in a value that looks similar to host start --pause-on-error --nodeDebugPort 5859 (again, for one project).
See this issue and this video.

Related

Post-build actions in Python/Linux webapp do not run

I have a Django-based web app deployed from Github, running in Python 3.9. The app deploys and starts successfully.
I need to add post-build actions to complete the deployment; the exceeding common Django task of running "manage.py". Following the general and python-specific docs I have added the an app setting of
POST_BUILD_SCRIPT_PATH=postbuild.sh
There is a shell script, postbuild.sh in the root of my app, which runs fine if I SSH into the running container. The expected behaviour is that after deployment, this should run, and output to the deployment log. Neither of these things happen.
I have tested the app setting POST_BUILD_COMMAND with a very simple echo, and that does nothing either.
Can you tell me either what I need to do to make these app settings work, or suggest an alternative method of running the post-build script?
Please note that this is a Linux app using Oryx, so answers concerning Windows/Kudu like this one aren't related.
I noticed you asked your question over here as well. Your setting needs to be set to a relative path, /postbuild.sh.

Running Azure function as Windows Service for Debug purposes

I have written an Azure (with http trigger method) function and it is hosted in Azure. However when I develop client applications which target the azure function I don't want to call the hosted Azure function, instead I am running the function from Visual studio and redirect the calls to this local copy.
Is there any way to keep this local copy running outside Visual studio environment in local machine? Perhaps like a windows service?
Any reference to an article would be great. Let me know if the question is not clear.
As Kane says, if you dont want to based on Visual Studio, you can use azure function core tools.
https://learn.microsoft.com/en-us/azure/azure-functions/functions-run-local?tabs=windows%2Ccsharp%2Ccmd
After install function core tools, you can use command func host start to run your function app.
Please note that you can only start one function app at a time locally, because the ports occupied by the azure function are all 7071 on local machine. The local is mainly used for testing.
for running it locally you can use the following command template.
I think using it inside Topshelf will run it inside a service
C:\projectFolderPathWithi hostJsonFile> C:\Users\username\AppData\Local\AzureFunctionsTools\Releases\3.16.1\cli_x64\func host start --port 7072 --verbose --functions "func1" "func2"

Set up Azure Application Insights for local environment

We have set up Application Insights for our Dev & Prod environments, not with the SDK but through the Portal. We're now in the process of installing the SDK so we can have more control over customizing logging, what to measure in performance, etc.
I have found how to separate the environments in code (separate Instrumentation Key in different config files etc), but I have found nothing when it comes to my local environment. Which instrumentation key should I use there, the dev one? Wouldn't then this skew our dev metrics everytime one of the developers runs the app locally?
And also, doesn't it make sense to have a separate App Service slot just for the local environment, so I can test everything and see the logs I'm trying out locally, and not have to deploy to dev everytime I want to see what I'm doing?
I've tried creating a separate slot for local, but it generates a weird url based on the name I give, which I can't change later.
I've googled for a couple of days already and couldn't find any (or very little) helpful advice when it comes to this.
I realise there is a "Just add the SDK to try local only mode" option in Visual Studio, but then I would have to use it exclusively locally. What I want is to use all three - my local, dev & prod.
We're using .net core 2.2 for our backend and Angular 7 for front end.
I'm an idiot.
The url set up automatically basically means nothing. I solved the problem by just adding another App Service slot (created from our App Service production one, just like dev), and added this key to the local settings in our project.
Now we can use this key to get real time results as we debug, and use the other two for dev & production.

How to debug Azure Functions using Visual Code

I have an existing set of functions in an Azure Functions App written in C# Script. I've downloaded the zip file from the Azure portal and opened the directory in Visual Code. I can also log on to the Azure account from Visual Code and can see the functions. If I right-click, I get options to start and stop streaming logs
However, I don't know how to configure my environment so that I can edit and debug these functions locally. I've found instructions for creating a new Function App, but haven't found ones that describe how to work with an existing app.
As mentioned in this post, for now we can't debug(add break points to) C# script(.csx) functions in VS Code.
We can only run csx function both on Azure and locally. Open the function app folder in VS code, follow steps below.
Check function runtime version(~1 or ~2) and follow tutorial to install Azure Function core tools.
If we use ~2 runtime, you need to register binding extensions for all triggers/in/output except Http and Timer triggers.
If we want to use settings(like AzureWebJobsStorage) in Application settings, copy them into local.settings.json. Or we can right click on Application settings of the Function app in VS Code, click Download Remote Settings(In this way, some invalid settings for local env are downloaded as well).
Input Ctrl+` to open terminal and input func host start in terminal to run functions.
For local dev, I do recommend you to use C# pre-compiled code instead of C# script, which is much easier to work with. To do this transformation, follow this tutorial, new a c# function app locally, copy your code in .cs files. We basically don't need to modify the logic code except adding some package and namespace references.

Azure Functions publishing

Firstly I would like to describe my local project structure. I have three Azure Functions v2. Locally each function have separate project. The fourth project is library which functions are using.
I would like to publish those functions into one function on Azure ( one App Service). And there's the issue occurs.
Let's start with an example. Let's say the function names are : A, B, C.
Firstly I publish functions in order: A, B, C. Then I've change something in function B, and publish only B. Then the function A, and C are not working.
I've must publish all functions to work again.
My first thought was package incompatibility and resolved that. But the issue still occurs. The web publish file does not contains any info about any additional packages/dlls.
Do you have any tips?
Your intention itself that publishing several Function projects to one Function app is incorrect.
See the official guidance.
In most scenarios, the unit of deployment should be the Function App, and not individual functions. Deploying a Function App is essentially identical to deploying a Web App.
Locally one Function project represents exactly one complete Function app, so one Function app should host only one published Function project. Otherwise we may see inconsistent behavior after publishing which results from content overwritten and so on.
My suggestion is to put functions together in one project, merging usually doesn't bring trouble unless there are specific host settings for each project.

Resources