This is a simple web application that calculates and visualizes Fibonacci numbers. The app is built using Node.js, Express, and Chart.js.
Requires:
- Node.js 14+
- A New Relic account
- Calculate the nth Fibonacci number (1 <= n <= 90)
- Display the calculated Fibonacci number
- Visualize the Fibonacci sequence up to the nth number using a line chart
The application is divided into two main parts:
- Backend: A Node.js/Express server that exposes a REST API to calculate Fibonacci numbers.
- Frontend: A browser-based single-page application that utilizes the REST API to fetch Fibonacci numbers and visualize the sequence using Chart.js.
The frontend code is organized in the following manner:
index.html
: The HTML structure of the single-page application.app.js
: The JavaScript code responsible for handling user input, interacting with the backend REST API, and updating the chart.styles.css
: The CSS file containing the styles for the frontend.
The server-side code is organized in the following manner:
server.js
: The main entry point of the server that sets up the Express app and listens for incoming connections.routes.js
: A separate module containing the Express routes for handling the Fibonacci REST API.
- Clone the repository or download the source code:
git clone https://github.com/newrelic/newrelic-opentelemetry-examples.git
- Navigate to the project folder:
cd getting-started-guides/javascript/instrumented
- Install the required dependencies:
npm install
- Start the app:
npm start
The above command will use parcel to build the frontend and start the server.
- Open your browser and navigate to http://localhost:8080 to access the app.
To enable OpenTelemetry auto instrumentation for the web, the following modules have been installed:
npm install @opentelemetry/auto-instrumentations-web \
@opentelemetry/sdk-trace-web \
@opentelemetry/sdk-trace-base \
@opentelemetry/instrumentation \
@opentelemetry/context-zone \
@opentelemetry/exporter-trace-otlp-proto \
@opentelemetry/resources \
@opentelemetry/semantic-conventions
Refer to the auto-otel-web.js file for the implementation details.
To enable OpenTelemetry custom/manual instrumentation for the web, the following modules have been installed:
npm install @opentelemetry/api \
@opentelemetry/sdk-trace-web \
@opentelemetry/sdk-trace-base \
@opentelemetry/instrumentation \
@opentelemetry/context-zone \
@opentelemetry/instrumentation-document-load \
@opentelemetry/instrumentation-user-interaction \
@opentelemetry/instrumentation-fetch \
@opentelemetry/exporter-trace-otlp-proto \
@opentelemetry/resources \
@opentelemetry/semantic-conventions
Refer to the manual-otel-web.js file for the implementation details.
To enable OpenTelemetry auto instrumentation for the backend, the following modules have been installed:
npm install @opentelemetry/auto-instrumentations-node \
@opentelemetry/sdk-node \
@opentelemetry/sdk-trace-node \
@opentelemetry/sdk-metrics \
@opentelemetry/resources \
@opentelemetry/semantic-conventions
To be able to send traces and metrics to New Relic, exporter modules have to be installed:
npm install @opentelemetry/exporter-trace-otlp-proto \
@opentelemetry/exporter-metrics-otlp-proto
And the New Relic Api Key has been added to the .env
file:
NEW_RELIC_LICENSE_INGEST_KEY=<NEW_RELIC_LICENSE_INGEST_KEY>
Refer to the auto-otel-node.js file for the implementation details.
Notice the npm server
command has been updated to include the -r
option to load the auto-otel-node.js
file.
// package.json
"scripts": {
...
"server": "node -r ./src/auto-otel-node.js src/server.js",
...
},
To enable OpenTelemetry custom/manual instrumentation for the backend, the following modules have been installed:
npm install @opentelemetry/api \
@opentelemetry/sdk-trace-node \
@opentelemetry/sdk-metrics \
@opentelemetry/instrumentation \
@opentelemetry/resources \
@opentelemetry/semantic-conventions
To be able to send traces and metrics to New Relic, exporter modules have to be installed:
npm install @opentelemetry/exporter-trace-otlp-proto \
@opentelemetry/exporter-metrics-otlp-proto
And the New Relic Api Key has been added to the .env
file:
NEW_RELIC_LICENSE_INGEST_KEY=<NEW_RELIC_LICENSE_INGEST_KEY>
Refer to the manual-otel-node.js file for the implementation details.
Notice the npm server
command has been updated to include the -r
option to load the manual-otel-node.js
file.
// package.json
"scripts": {
...
"server": "node -r ./src/manual-otel-node.js src/server.js",
...
},
Custom Instrumentation for the backend logic can be found in the API README.md file
This project is MIT licensed.