Using Gatsby to deliver large websites can speed up end users’ experiences. However, as those projects scale, many development teams are slowed down by long build times. The gatsby-build-newrelic
plugin provides instant observability into the entire Gatsby build process, exporting vital telemetry data from within the belly of the beast. With events, metrics, logs, and traces, we are able to contextualize and identify performance issues within our plugins, 3rd party APIs, and other parts of our website.
-
If you don't already have a New Relic account, sign-up for our free forever tier - no credit-card required!
-
Go to https://one.newrelic.com
-
Select "Api Keys" from the Account Dropdown
-
Your New Relic License Key should be listed here, just click on the settings icon and
Copy Key
-
Your Account Id should also be listed to the left of this. Save both of these for the configuration.
In your Gatsby project, depending on your package manager, run either:
npm i gatsby-build-newrelic
or
yarn add gatsby-build-newrelic
Add the following to the gatsby build
commands in your package.json
:
"gatsby build": "--open-tracing-config-file ./node_modules/gatsby-build-newrelic/zipkin-local.js --graphql-tracing",
If you are deploying to Gatsby Cloud you will also need to set the following environment variable, either in a .env
file in your project or in your Gatsby Cloud Site Settings. See Managing Environment Variables in Gatsby Cloud:
GATSBY_OPEN_TRACING_CONFIG_FILE=node_modules/gatsby-build-newrelic/zipkin-local.js
In gatsby-config.js
, add the following code snippet to configure the plugin
{
resolve: "gatsby-build-newrelic",
options: {
NR_LICENSE_KEY: "LICENSE KEY", // https://docs.newrelic.com/docs/apis/intro-apis/new-relic-api-keys/#ingest-license-key
NR_ACCOUNT_ID: "Account Id",
SITE_NAME: "your-website-name",
collectTraces: true, // This will default to true so you can remove
collectLogs: true, // This will default to true so you can remove
collectMetrics: true, // This will default to true so you can remove
customTags: { // Optional tags you would like to add to your data. For more info see https://docs.newrelic.com/docs/new-relic-one/use-new-relic-one/core-concepts/use-tags-help-organize-find-your-data/
newFeature: 'remove-jank',
}
},
}
- NR_LICENSE_KEY - Your New Relic License Key
- NR_ACCOUNT_ID - Your New Relic Account Id
- SITE_NAME - The name you want your app to appear under in New Relic
collectTraces: Boolean - Whether to collect Trace data or not
- Default:
true
- collectLogs: Boolean - Whether to collect Log events or not
- Default:
true
- Default:
- collectMetrics: Boolean - Whether to collect Metric data or not
- Default:
true
- Default:
- customTags: Object - Optional tags you would like to add to your data as
key:value
pairs. Read more here!
staging: Boolean - To report data to a New Relic Staging account
- Default:
false
Please open an issue here in the GitHub Repo if you encounter any issues :D
We encourage your contributions to improve Gatsby Build New Relic! 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 opensource@newrelic.com.
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.
Gatsby Build New Relic is licensed under the Apache 2.0 License.