newrelic-experimental / gatsby-build-newrelic

Get Telemetry Data from your Gatsby build process
Apache License 2.0
9 stars 4 forks source link

New Relic Experimental header

Gatsby Build Newrelic

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.

Getting Started

Account Setup and Required Variables

  1. If you don't already have a New Relic account, sign-up for our free forever tier - no credit-card required!

  2. Go to https://one.newrelic.com

  3. Select "Api Keys" from the Account Dropdown

  4. Your New Relic License Key should be listed here, just click on the settings icon and Copy Key lic-key

  5. Your Account Id should also be listed to the left of this. Save both of these for the configuration.

Installation

In your Gatsby project, depending on your package manager, run either:

npm i gatsby-build-newrelic

or

yarn add gatsby-build-newrelic

Build Command

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

Configuration

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',
    }
  },
}

Required Fields

Optional Fields

collectTraces: Boolean - Whether to collect Trace data or not

New Relic Only Fields

staging: Boolean - To report data to a New Relic Staging account

Support

Please open an issue here in the GitHub Repo if you encounter any issues :D

Contributing

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.

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

Gatsby Build New Relic is licensed under the Apache 2.0 License.