Skip to content

Instantly share code, notes, and snippets.

@rudouglas
Last active June 24, 2021 11:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rudouglas/5bc32285ce6fdb6fa28ac90afa2eec33 to your computer and use it in GitHub Desktop.
Save rudouglas/5bc32285ce6fdb6fa28ac90afa2eec33 to your computer and use it in GitHub Desktop.
Instructions for Instrumenting Gatsby and sending data to New Relic

This guide is for instrumenting Gatsby builds and sending that data as Traces to New Relic. It uses the in-built Jaeger configuration in Gatsby, along with the New Relic OTLP Native Ingest container.

NR Account Setup

See the Internal guide for additional details - https://docs-preview.newrelic.com/docs/otlp-native-ingest/

  1. Generate an api-key insert

  2. Set as Environment Variable in Terminal:

    • export NEW_RELIC_INSERT_KEY=<INSERT_KEY>
  3. To set this permanently on your Mac in Terminal:

    • nano .bash_profile
    • Paste in export NEW_RELIC_INSERT_KEY=<INSERT_KEY> at the bottom
    • CTRL+O then ENTER to save
    • CTRL+X to go back to terminal

Docs Site

The docs site already has the files and commands setup for this in src/telemetry.

  1. Start the Opentelemetry Container:
    • yarn otel
  2. Running either of these will load the jaeger config:
    • yarn develop
    • yarn build:develop

Setup from scratch

OpenTelemetry Container Setup

Create a file called otel-config.yaml, preferably in your working directory, with the following:

extensions:
  health_check:
receivers:
  jaeger:
    protocols:
      thrift_http:
        endpoint: "0.0.0.0:14268"
processors:
  batch:
    timeout: 1s
exporters:
  otlp:
    endpoint: otlp.nr-data.net:4317
    headers:
      api-key: ${NEW_RELIC_INSERT_KEY}
service:
  pipelines:
    traces:
      receivers: [jaeger]
      processors: [batch]
      exporters: [otlp]
  extensions: [health_check]

If you are using a Staging Account, change the endpoint to staging.otlp.nr-data.net:4317

  1. Make sure Docker Daemon is running and run in terminal:
docker run --rm -e NEW_RELIC_INSERT_KEY -p 13133:13133 -p 8888:8888 -p 6831:6831 -p 14268:14268  -p 55680-55681:55680-55681    -v "${PWD}/otel-config.yaml":/otel-config.yaml       --name otelcol otel/opentelemetry-collector       --config otel-config.yaml

Jaeger Setup

  1. Install the jaeger client in your project:

    • yarn add jaeger-client
  2. Config

    • The jaeger-local.js is located in ./node_modules/gatsby/dist/utils/tracer/
      • serviceName - The Entity it reports under in NR
      • Tags - Add your own depending on your needs for filtering
        • These will appear as Attribute in the Distributed Tracing UI

Run Command

You have to add the tracing flag to the build command, this should work with any gatsby related command:

  • yarn build:production --open-tracing-config-file node_modules/gatsby/dist/utils/tracer/jaeger-local.js

Sample Data in NR Staging

https://staging.one.nr/0PoR8nYo3QG

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment