Skip to content

matewilk/nestjs-test-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

New Relic Experimental header

New Relic NestJs Integration Example

Warning Please note that using a custom interceptor is unnecessary when instrumenting with the latest versions of the New Relic Node agent. In fact, using a custom interceptor may cause conflicts and lead to unexpected behavior (starting with 10.1.0 released May 4th, 2023). Please see instead this example on how to enable New Relic instrumentation for Nest.js. That said, you can still use this repository to experiment with NestJs and the New Relic agent, and easily send data to the New Relic platform.

App Architecture

NestJs_NewRelic_architecture

The above diagram shows the (dockerized) architecture of the example app with the following components:

  • nest network - where all the microservices reside
  • parent container - the outer left
  • child container - in the middle
  • booth parent and child have New Relic NodeJs Agent installed (and required by each of the microservices)

Hot to run

Prerequisites

  • New Relic Account (sign up here)
  • New Relic License Key (find instructions here)
  • Docker` is installed on your machine.

Setup

Find two newrelic.ts config file in /src directory inside both parent and child

Change two config variables in each file

app_name: ['YOUR_APP_NAME'],
license_key: 'YOUR_LICENSE_KEY'

to a desired app_name and paste your New Relic License Key acquired in previous steps to license_key variable.

Start

Run docker-compose up and wait for all images to install and start the app.

Use

The parent service has the following endpoints:

  • GET localhost:3000/
    • just to confirm the app works
  • POST localhost:3000/cats/create
    • to create a cat
    • with a json body payload containing 3 properties name, age & breed
      // for example 
      {
          "name": "Tom",
          "age": 3,
          "breed": "Persian"
      }
      
  • GET localhost:3000/cats/getAll
    • to get all cats

Call any of these endpoints and you'll see a message (similar to the one below) in the console: Screenshot 2021-03-11 at 20 04 34

This particular example is a console log showing the flow of the GET localhost:3000/cats/create request. It's visible that parent calls child and gets a response back intercepting child's response carrying a mongodb record being created by child's interaction with mongodb service.

New Relic Observability Platform

Once you make a few calls, go to you New Relic account where the app data is being send and navigate to Explorer and find the app (by the name you gave it to during the setup) Go to Distributed Tracing and click on one of Root Entry Spans

You should be able to see Distributed Tracing spans captureg by New Relic Agents installed in both parent and child Screenshot 2021-03-11 at 20 15 50

Contributing

We encourage your contributions to improve New Relic NestJs Integration Example! 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

New Relic NestJs Integration Example is licensed under the Apache 2.0 License.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published