If you are using a containerized Azure Function, you can monitor your Azure Functions with the New Relic .NET agent, Python agent, or Node.js agent. This allows you to monitor the performance and health of your Azure Functions in real-time.
Prerequisites
- Ensure your Azure Function meets our compatibility and requirements.
- Link your Azure account to New Relic. For more information, refer to Azure integration.
Configure Azure Functions monitoring
You can configure Azure Functions monitoring for different environments and various combinations of runtimes and deployment methods. The following instructions detail how to configure New Relic for containerized Azure Function Apps.
Edit your Function file to add the following code at the top of your application file:
ENV NEW_RELIC_LICENSE_KEY=”{YOUR_NEW_RELIC_LICENSE_KEY}”ENV NEW_RELIC_APP_NAME=”{YOUR_APPLICATION_NAME}”# ENV NEW_RELIC_HOST='staging-collector.newrelic.com'# Uncomment the previous line if using staging# Inject the agent in NODE_OPTIONSENV NODE_OPTIONS=”-r newrelic”# Install New Relic without bin linksARG AGENT_VERSION=latestRUN npm install newrelic@${AGENT_VERSION} --no-bin-linksBuild your Docket image as per your platform requirements by running:
docker buildx build --platform={YOUR_PLATFORM_ARCHITECTURE} --tag {YOUR_DOCKER_ID}/azurefunctionsimage:v1.0.0 --push重要
Ensure that you replace
{YOUR_PLATFORM_ARCHITECTURE}
with the appropriate architecture for your Azure Function. For example, uselinux/amd64
for 64-bit Linux orlinux/arm64
for ARM architecture.Publish your image to the Azure Container Registry (ACR) by running:
Authenticate your Azure Container Registry:
az acr login --name <YOUR_CONTAINER_REGISTRY_NAME>Tag your locally built image with the ACR login server by running:
docker tag {YOUR_DOCKER_ID}/azurefunctionsimage:v1.0.0 {YOUR_LOGIN_SERVER}/azurefunctionsimage:v1.0.0Push the tagged image to your ACR by running:
docker push <YOUR_LOGIN_SERVER>/azurefunctionsimage:v1.0.0Create the required Azure resources for your Azure Function App using the Azure documentation..
Create and configure the Azure Function App using the image you pushed to the ACR in the previous step. For more information, refer to the Azure documentation.
Retrieve the Azure Function App URL after deployment by running:
az functionapp show --name <YOUR_APPLICATION_NAME> --resource-group <NAME_OF_THE_APPS_RESOURCE_GROUP>
To install the New Relic Python agent, add the following lines to the final stage of your Dockerfile
:
FROM mcr.microsoft.com/azure-functions/python:4-python3.11
# These commands will not be required once the # New Relic Python Agent releases this featureRUN apt-get updateRUN apt-get -y install git
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \ AzureFunctionsJobHost__Logging__Console__IsEnabled=true
COPY requirements.txt /RUN pip install -r /requirements.txtCOPY . /home/site/wwwroot
ヒント
The above example is for a Python 3.11 Azure Function. You can change the version of Python to match your requirements.
After your have built the Docker image, publish the image to the Azure Container Registry. For more information, refer to Azure documentation.
To install the New Relic .NET agent, add the following lines to the final stage of your Docker file:
# Install the latest New Relic .NET agent using the apt-get package manager# To install a specific version of the .NET agent, add the version number to the apt-get install line (i.e. apt-get install -y newrelic-dotnet-agent=10.38.0)RUN apt-get update && apt-get install -y wget ca-certificates gnupg \ && echo 'deb http://apt.newrelic.com/debian/ newrelic non-free' | tee /etc/apt/sources.list.d/newrelic.list \ && wget https://download.newrelic.com/548C16BF.gpg \ && apt-key add 548C16BF.gpg \ && apt-get update \ && apt-get install -y newrelic-dotnet-agent \ && rm -rf /var/lib/apt/lists/*
When you deploy your application, the .NET agent is installed in the /usr/local/newrelic-dotnet-agent
folder.
Configure environment variables
After you've published the Azure Function app, configure environment variables:
- Navigate to your Azure Function in the Azure portal.
- Under Settings, click Environment variables, and then click Advanced edit.
- Based on your deployment runtime, paste the following values:
重要
Ensure that you add a comma at the end of the last existing line and update your license key in the following configurations.
{ "NODE_OPTIONS": "-r newrelic", "NEW_RELIC_LICENSE_KEY": "YOUR-NEW-RELIC-INGEST-LICENSE-KEY", "NEW_RELIC_APP_NAME": "NAME-OF-THE-FUNCTION-APP"}
({ "name": "PYTHON_ENABLE_WORKER_EXTENSIONS", "value": "1", "slotSetting": false},{ "name": "FUNCTIONS_WORKER_RUNTIME", "value": "python", "slotSetting": false},{ "name": "PYTHONPATH", "value": "${PYTHONPATH}:/home/site/wwwroot:/home/site/wwwroot/.python_packages/lib/site-packages", "slotSetting": false},{ "name": "NEW_RELIC_APP_NAME", "value": "<your New Relic app name here>", "slotSetting": false},{ "name": "NEW_RELIC_LICENSE_KEY", "value": "<your New RElic ingest license key here>", "slotSetting": false})
({ "name": "CORECLR_ENABLE_PROFILING", "value": "1", "slotSetting": false},{ "name": "CORECLR_NEW_RELIC_HOME", "value": "/home/site/wwwroot/newrelic", "slotSetting": false},{ "name": "CORECLR_PROFILER", "value": "{36032161-FFC0-4B61-B559-F6C5D41BAE5A}", "slotSetting": false},{ "name": "CORECLR_PROFILER_PATH", "value": "/home/site/wwwroot/newrelic/libNewRelicProfiler.so", "slotSetting": false},{ "name": "NEW_RELIC_LOG_DIRECTORY", "value": "/home/LogFiles/NewRelic", "slotSetting": false},{ "name": "NEW_RELIC_LICENSE_KEY", "value": "<your New Relic ingest license key here>", "slotSetting": false})
Restart your Azure Function
After you've added the environment variables, restart your Azure Function to apply the changes.
Find and use data
After you have configured your Azure Function, you can find and use the data in the New Relic UI.
- Go to https://one.newrelic.com > APM & Services.
- In the search banner, set the search criteria as
isAzureFunction = true
: - From the displayed list, select your Azure Function to view the data.