---
title: Linux instrumentation
source: https://docs.newrelic.com/docs/serverless-function-monitoring/azure-function-monitoring/linux
---

You can configure New Relic monitoring for Azure Function Apps hosted on Linux. This is achieved by instrumenting your Function App with the appropriate New Relic agent for its runtime such as Node.js, .NET, or Python. This instrumentation allows you to monitor the performance and health of your Azure Functions in real-time within New Relic.

## Prerequisites [#begin]

-   Ensure your Azure Function meets our [compatibility and requirements](https://docs.newrelic.com/docs/serverless-function-monitoring/azure-function-monitoring/compatibility-requirement-azure-monitoring).
-   Link your Azure account to New Relic. For more information, refer to [Azure integration](https://docs.newrelic.com/docs/infrastructure/microsoft-azure-integrations/azure-integrations-list/azure-functions-monitoring-integration/#polling).

## Configure Azure Functions monitoring

You can configure Azure Functions monitoring for different environments and various combinations of runtimes and deployment methods:

### Node.js

1.  In the root directory of your Node.js Azure Function App project, install the New Relic agent as a project dependency by running:

    ```bash
    npm i newrelic
    ```
2.  To ensure that the New Relic agent is installed with your project dependencies during the Azure deployment process, set the `SCM_DO_BUILD_DURING_DEPLOYMENT` to `true` in your application settings by running:

    ```bash
    az functionapp config appsettings set --name NAME_OF_YOUR_AZURE_FUNCTION_APP --settings SCM_DO_BUILD_DURING_DEPLOYMENT=true
    ```
3.  Publish your Azure Function App using the Azure CLI or your preferred publishing method. You can use one of the following commands to publish your Azure Function App:

    ```bash
    func azure functionapp publish NAME_OF_YOUR_AZURE_FUNCTION_APP
    ```

    OR

    ```bash
    az functionapp app up
    ```

    OR

    ```bash
    az functionapp deploy
    ```

    > #### ⚠️ IMPORTANT
    >
    > The commands shown here are examples and may require additional parameters based on your specific Azure configuration and deployment strategy such as `OS`, `Node.js version`, `Azure resource group`, `Azure subscription`, `Azure storage account`, `Azure region`, and so on. Refer to Azure documentation to know more about these parameters for [`func azure functionapp publish`](https://learn.microsoft.com/en-us/azure/azure-functions/functions-core-tools-reference?tabs=v2#func-azure-functionapp-publish), [`az functionapp up`](https://learn.microsoft.com/en-us/cli/azure/functionapp/app?view=azure-cli-latest#az-functionapp-app-up), and [`az functionapp deploy`](https://learn.microsoft.com/en-us/cli/azure/functionapp?view=azure-cli-latest#az-functionapp-deploy) methods.

### Python

1.  In the root directory of your Python Azure Function App project, open the `requirements.txt` file.

2.  Add the following line to your `requirements.txt` file to install the New Relic agent for Azure Function instrumentation:

    ```bash
    newrelic
    ```

3.  Initialize and register the New Relic agent in your Azure Function code using one of the following methods:

    **Option 1: Manually update the function_app.py file**

    1.  Open the your `function_app.py` file in your project.
    2.  To import the New Relic agent, add the following statement to the top of the file:

        ```python
        import newrelic.agent
        ```
    3.  Initialize the New Relic agent. For more information, refer to [Initialize Python agent.](https://docs.newrelic.com/docs/apm/agents/python-agent/python-agent-api/initialize-python-agent-api/)
    4.  Register the New Relic agent with your Azure Function. For more information, refer to [Register Python agent.](https://docs.newrelic.com/docs/apm/agents/python-agent/python-agent-api/registerapplication-python-agent-api/)

        > #### ⚠️ IMPORTANT
        >
        > The New Relic agent uses environment variables to name your application in the New Relic UI. Ensure that either `NEW_RELIC_APP_NAME` (recommended) or `WEBSITE_SITE_NAME` (Azure's default site name variable) is available as an environment variable for your Function App.

        Your `function_app.py` file should resemble the following structure:

        ```python
        import newrelic.agent
        import os
        import azure.functions as func

        ...
        newrelic.agent.initialize()
        app_name = os.environ.get(
            "NEW_RELIC_APP_NAME", os.environ.get("WEBSITE_SITE_NAME", None)
        )
        newrelic.agent.register_application(app_name)
        # Code here
        ```

    **Option 2: Using New Relic provided one-time script**

    1.  In the root directory of your Python Azure Function App project, create a new file named `initialization.sh`.

    2.  Add the following script content to the `initialization.sh` file:

        ```shell
        #!/bin/bash
        # initialization.sh

        #####################################################################
        #
        # This one-time use script performs the following tasks:
        # 1. Creates a new function_app.py file with New Relic  
        #   initialization and registration
        # 2. Moves the original function_app.py file into a directory
        #    named "original". 
        # 3. Adds the "original" directory to the .funcignore file
        #   to prevent duplication in published files.
        #
        #####################################################################

        mkdir original
        mv function_app.py ./original/

        echo -e 'import newrelic.agent\nimport os\n\nnewrelic.agent.initialize()\napp_name = os.environ.get("NEW_RELIC_APP_NAME", os.environ.get("WEBSITE_SITE_NAME", None))\nnewrelic.agent.register_application(app_name)\n' | cat - ./original/function_app.py > function_app.py

        echo 'original' >> .funcignore
        ```

    3.  Save the `initialization.sh` file.

    4.  Provide the permissions to script file by running:

        ```bash
        chmod 755 initialization.sh
        ```

    5.  Run the script from the root directory of your project:

        ```bash
        ./initialization.sh
        ```

4.  Publish your Azure Function App using the Azure CLI or your preferred publishing method. You can use the following command to publish your Azure Function App:

    ```bash
    func azure functionapp publish $NAME_OF_YOUR_AZURE_FUNCTION_APP
    ```

### .NET

1.  Add the latest version of the `NewRelic.Agent` NuGet package to your application project.
2.  Use your preferred publishing mechanism to deploy your updated application to Azure.

    When you deploy your application, the .NET agent is installed in the `/home/site/wwwroot/newrelic` folder.

## Configure environment variables

After you've published the Azure Function app, [configure environment variables](https://docs.newrelic.com/docs/serverless-function-monitoring/azure-function-monitoring/env-variables-azure):

1.  Navigate to your Azure Function in the Azure portal.
2.  Under **Settings**, click **Environment variables**, and then click **Advanced edit**.
3.  Based on your deployment runtime, paste the following values:

> #### ⚠️ IMPORTANT
>
> Ensure that you add a comma at the end of the last existing line and update your license key in the following configurations.

### Node.js

```json
{
  "NODE_OPTIONS": "-r newrelic",
  "NEW_RELIC_LICENSE_KEY": "YOUR_NEW_RELIC_LICENSE_KEY",
  "NEW_RELIC_APP_NAME": "NAME_OF_YOUR_AZURE_FUNCTION_APP"
}
```

### Python

```json
{
  "NEW_RELIC_LICENSE_KEY": "YOUR_NEW_RELIC_LICENSE_KEY",  
  "NEW_RELIC_APP_NAME":  "NAME_OF_YOUR_AZURE_FUNCTION_APP",  
  "PYTHONPATH": "${PYTHONPATH}:/home/site/wwwroot:/home/site/wwwroot/.python_packages/lib/site-packages",  
  "FUNCTIONS_WORKER_RUNTIME": "python",  
  "PYTHON_ENABLE_WORKER_EXTENSIONS": 1 
}
```

### .NET

```json
{
  "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_LICENSE_KEY",
  "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 [#find-data]

After you have configured your Azure Function, you can find and use the data in the New Relic UI.

1.  Go to <https://one.newrelic.com> > **APM & Services**.
2.  In the search banner, set the search criteria as `isAzureFunction = true`:
    ![A screenshot showing the Azure Function search](https://docs.newrelic.com/images/azure_filters.webp "Azure Function Search")
3.  From the displayed list, select your Azure Function to view the data.

## Related articles [#related-docs]

[Compatibility and requirements](https://docs.newrelic.com/docs/serverless-function-monitoring/azure-function-monitoring/compatibility-requirement-azure-monitoring)

Requirements for your Azure Functions

[Windows instrumentation](https://docs.newrelic.com/docs/serverless-function-monitoring/azure-function-monitoring/windows)

Learn how to set up your Azure Functions for Windows to monitor them in New Relic.

[Container instrumentation](https://docs.newrelic.com/docs/serverless-function-monitoring/azure-function-monitoring/container)

Learn how to set up your Azure Functions for Containers to monitor them in New Relic.
