Se você estiver usando uma Azure Function em contêiner, pode monitorar suas Azure Functions com o agente .NET, o agente Python ou o agente Node.js do New Relic. Isso permite que você monitore o desempenho e a integridade de suas Azure Functions em tempo real.
Pré-requisitos
- Garanta que sua Função do Azure atenda à nossa compatibilidade e requisitos.
- Vincule sua conta do Azure ao New Relic. Para obter mais informações, consulte integraçãoAzure .
Configurar o monitoramento do Azure Functions
Você pode configurar o monitoramento do Azure Functions para diferentes ambientes e várias combinações de tempos de execução e métodos de implantação. As instruções a seguir detalham como configurar o New Relic para Azure Function Apps em contêiner.
Edite seu arquivo de função para adicionar o seguinte código no início do seu arquivo de aplicativo:
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-linksCrie sua imagem do Docket de acordo com os requisitos da sua plataforma executando:
bash$docker buildx build --platform=YOUR_PLATFORM_ARCHITECTURE --tag YOUR_DOCKER_ID/azurefunctionsimage:v1.0.0 --pushImportante
Certifique-se de substituir
YOUR_PLATFORM_ARCHITECTUREpela arquitetura apropriada para sua Azure Function. Por exemplo, uselinux/amd64para Linux de 64 bits oulinux/arm64para arquitetura ARM.Publique sua imagem no Azure Container Registry (ACR) executando:
- Autentique seu Azure Container Registry:
bash$az acr login --name YOUR_CONTAINER_REGISTRY_NAME- Marque sua imagem criada localmente com o servidor de login do ACR executando:
bash$docker tag YOUR_DOCKER_ID/azurefunctionsimage:v1.0.0 YOUR_LOGIN_SERVER/azurefunctionsimage:v1.0.0- Envie a imagem marcada para seu ACR executando:
bash$docker push YOUR_LOGIN_SERVER/azurefunctionsimage:v1.0.0Crie os recursos do Azure necessários para seu Azure Function App usando a documentação do Azure..
Crie e configure o Azure Function App usando a imagem que você enviou para o ACR na etapa anterior. Para obter mais informações, consulte a documentação do Azure.
Recupere a URL do Aplicativo de Função do Azure após a implantação executando:
bash$az functionapp show --name YOUR_APPLICATION_NAME --resource-group NAME_OF_THE_APPS_RESOURCE_GROUP
Para instalar o agente Python do New Relic, adicione as seguintes linhas ao estágio final do seu 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
RUN pip install newrelic
# Install any other dependenciesCOPY requirements.txt /RUN pip install -r /requirements.txtCOPY . /home/site/wwwrootDica
O exemplo acima é para uma Azure Function Python 3.11. Você pode alterar a versão do Python para corresponder aos seus requisitos.
Depois de criar a imagem do Docker, publique a imagem no Registro de Contêiner do Azure. Para obter mais informações, consulte a documentação do Azure.
Para instalar o agente .NET do New Relic, adicione as seguintes linhas ao estágio final do seu arquivo Docker:
# 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/*Ao implantar seu aplicativo, o agente .NET é instalado na pasta /usr/local/newrelic-dotnet-agent .
Configurar variáveis de ambiente
Depois de publicar o aplicativo Azure Function, configure as variáveis de ambiente:
Navegue até suas Funções Azure no portal Azure .
Em Settings , clique em Environment variables e depois em Advanced edit .
Com base no tempo de execução da sua implantação, cole os seguintes valores:
Importante
Certifique-se de adicionar uma vírgula no final da última linha existente e atualize sua chave de licença na seguinte configuração.
{"NODE_OPTIONS": "-r newrelic","NEW_RELIC_LICENSE_KEY": "YOUR_NEW_RELIC_LICENSE_KEY","NEW_RELIC_APP_NAME": "NAME_OF_YOUR_AZURE_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","slotSetting": false},{"name": "NEW_RELIC_LICENSE_KEY","value": "YOUR_NEW_RELIC_LICENSE_KEY","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_LICENSE_KEY","slotSetting": false})
Reinicie suas funções Azure
Depois de adicionar as variáveis de ambiente, reinicie o Azure Functions para aplicar as alterações.
Encontre e use dados
Depois de configurar sua Azure Function, você pode localizar e usar os dados na interface New Relic.
Acesse https://one.newrelic.com > APM & Services.
No banner de pesquisa, defina os critérios de pesquisa como
isAzureFunction = true:
Na lista exibida, selecione sua Função do Azure para visualizar os dados.