This project is a simple log forwarder that reads logs from a file and sends them to New Relic.
The purpose of this project is to provide a simple way to forward logs to New Relic from Azure services. This project is heavily inspired by the New Relic Log Forwarder ↗ but contains modifications to handle specific use cases in Azure in order to provide logs in context within the New Relic platform.
In order to run locally or deploy the samples in this repository, you will need the following tools:
- nvm (↗)
- Azure Functions Core Tools (↗)
- Azure CLI (↗)
- Azure Bicep (↗)
- New Relic account (↗)
- Visual Studio Code (VSCode ↗) with the Azure Functions extension
Read the REQUIREMENTS.md ↗ file for more information.
The principal components of this repository are organized as follows:
.
├── scripts
└── src
scripts
: Contains scripts to automate the deployment to Azure.src
: Contains the source code for the Log Forwarder.
To use this project, you will need to follow these steps:
-
Clone this repository to your local machine.
git clone https://github.com/dynovaio/newrelic-sb-azure-forwarder.git
-
Open a terminal and navigate to the root of the repository.
cd newrelic-log-forwarder
-
Read the
REQUIREMENTS.md
file and meet the requirements. -
Deploy the sample to azure using the scripts provided in the
scripts
directory. This scripts can be run using the following command:# Modify the values of the variables according to your requirements location="eastus" resource_group_name="my-resource-group" function_app_runtime_version="20" new_relic_license_key="YOUR_NEW_RELIC_LICENSE_KEY" source_service_type="my_source_service_type" ./scripts/create_resourcegroup.sh \ $resource_group_name \ $location ./scripts/create_functionapp.sh \ $function_app_runtime_version \ $resource_group_name \ $location ./scripts/create_eventhub.sh \ $resource_group_name \ $location ./scripts/configure_functionapp.sh \ $function_app_name \ $resource_group_name \ $source_service_type \ $new_relic_license_key ./scripts/publish_functionapp.sh \ $function_app_name \ $function_app_runtime \ $resource_group_name
-
Configure your target Azure component to send logs to the Azure Event Hub using the following command:
# Modify the values of the variables according to your requirements resource_id = "my-resource-id" resource_group_name = "my-resource-group" log_configuration = "my-log-configuration" metrics_configuration = "my-metrics-configuration" ./scripts/stream_logs_to_eventhub.sh \ $resource_id \ $resource_group_name \ $log_configuration \ $metrics_configuration
The variables must be replaced with the correct values according to your target resource. The
resource_id
is the id of the resource that you want to stream logs from. Thelog_configuration
andmetrics_configuration
are the log and metrics configurations that you want to stream to the Event Hub.For example, in the case of azure functions, you can use the following
resource_id=$( az functionapp show --name $function_app_name --resource-group $function_app_resource_group_name --query id --output tsv ) log_configuration="'[{\\\"category\\\": \\\"FunctionAppLogs\\\", \\\"enabled\\\": true}]'" metrics_configuration="'[{\\\"category\\\": \\\"AllMetrics\\\", \\\"enabled\\\": true}]'"
-
Check the logs in New Relic.
-
Clean up the resources using the following command:
az group delete --name $resource_group_name --yes
Sugestions and contributions are welcome!
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
For more information, please refer to the Code of Conduct ↗.
This project is licensed under the terms of the BSD-3-Clause ↗ license.