Instrummenting your BattleSnake with New Relic using NodeJS
Learn how to instrument your BattleSnake with New Relic using the NodeJS agent. For this repository we are using BattleSnake JavaScript starter from the BattleSnake Official.
Intrumentation
- Create a free account at New Relic,
- On the New Relic One home page, select the + Add more data button on the top right, and choose Node.js under App Monitoring,
- On the next page click on Begin installation and choose how you will be installing your Node.js agent, here we are using a Package Manager,
- Name your application,
- On your cloned or forked repository, first change into the directory and execute the following commands in your terminal to install the agent:
npm install newrelic --save
- Download the custom configuration file (example here), and add it to the root of your Node.js application,
- Add New Relic to your application's main module, pasting the following command on the first line of your app's main module:
require('newrelic');
- Start your application and as soon as it is running, New Relic is collecting your BattleSnake data.
Usage
Using dotenv
When you download the newrelic.js file, it will have your New Relic license key on it. To use it safely, we will work with dotenv.
- First, install:
npm i dotenv
- Then in your index.js file, require and configure the package like this:
require('dotenv').config()
- Once you have DotEnv installed and configured, make a file called .env at the root of your app, this is where you will create all of your New Relic license key environment variable:
NEW_RELIC_LICENSE_KEY={your key}
- Now go to the newrelic.js file, copy your license key and substitute it with:
env.NEW_RELIC_LICENSE_KEY
Deploying to Heroku
You can deploy the application directly from this GitHub repository by clicking on the Deploy to Heroku
button at the top of this README. Once you do that you still must set your New Relic License key in Heroku. You can either do so at the time you are initializing your application after you have the clicked the Deploy to Heroku
button above, or after from within the Heroku Dashboard.
After you have clicked the above Deploy to Heroku
button, you will see one option for the config vars
in the Heroku deployment settings. Add your New Relic License Key before clicking the final Deploy app
button. This will ensure your application is deployed to Heroku with your information.
Alternatively, you can do so from with your Heroku Dashboard's application settings by managing the config vars for your Battlesnake after deploying. You will need to add the environment variable: NEW_RELIC_LICENSE_KEY
.
Support
New Relic has open-sourced this project. This project is provided AS-IS WITHOUT WARRANTY OR DEDICATED SUPPORT. Issues and contributions should be reported to the project here on GitHub.
We encourage you to bring your experiences and questions to the Explorers Hub where our community members collaborate on solutions and new ideas.
Contributing
We encourage your contributions to improve this demo app! Keep in mind when you submit your pull request, you'll need to sign the CLA via the click-through using CLA-Assistant. You only have to sign the CLA one time per project. If you have any questions, or to execute our corporate CLA, required if your contribution is on behalf of a company, please drop us an email at [email protected].
A note about vulnerabilities
As noted in our security policy, New Relic is committed to the privacy and security of our customers and their data. We believe that providing coordinated disclosure by security researchers and engaging with the security community are important means to achieve our security goals.
If you believe you have found a security vulnerability in this project or any of New Relic's products or websites, we welcome and greatly appreciate you reporting it to New Relic through HackerOne.
License
This project is licensed under the Apache 2.0 License.