29
loading...
This website collects cookies to deliver better user experience
movies
service provides the name of movies and their genre in JSON format, while the dashboard
service returns the results from the movies service.$ npm i
$ node dashboard.js
$ node movies.js
delay
, built into the movies microservice that causes random delays returning the JSON.const express = require('express')
const app = express()
const port = 3000
app.get('/movies', async function (req, res) {
res.type('json')
+ var delay = Math.floor( ( Math.random() * 2000 ) + 100);
+ setTimeout((() => {
res.send(({movies: [
{ name: 'Jaws', genre: 'Thriller'},
{ name: 'Annie', genre: 'Family'},
{ name: 'Jurassic Park', genre: 'Action'},
]}))
+ }), delay)
})
$ npm install @opentelemetry/node
@opentelemetry/node
module provides auto-instrumentation for Node.js applications, which automatically identifies frameworks (Express), common protocols (HTTP), databases, and other libraries within your application. This module uses other community-contributed plugins to automatically instrument your application to automatically produce spans and provide end-to-end tracing with just a few lines of code.$ npm install @opentelemetry/plugin-http
$ npm install @opentelemetry/plugin-express
@opentelemetry/plugin-http
plugin generates trace data. The @opentelemetry/plugin-express
plugin generates trace data from requests sent through the Express framework.const { NodeTracerProvider } = require('@opentelemetry/node');
const { ConsoleSpanExporter, SimpleSpanProcessor } = require('@opentelemetry/tracing');
const provider = new NodeTracerProvider();
const consoleExporter = new ConsoleSpanExporter();
const spanProcessor = new SimpleSpanProcessor(consoleExporter);
provider.addSpanProcessor(spanProcessor);
provider.register()
http://localhost:3001/dashboard
, we should get something like this - beautiful things on the terminal. $ docker run -d -p 9411:9411 openzipkin/zipkin
const { NodeTracerProvider } = require('@opentelemetry/node')
const { ConsoleSpanExporter, SimpleSpanProcessor } = require('@opentelemetry/tracing')
+ const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin')
const provider = new NodeTracerProvider()
const consoleExporter = new ConsoleSpanExporter()
const spanProcessor = new SimpleSpanProcessor(consoleExporter)
provider.addSpanProcessor(spanProcessor)
provider.register()
+ const zipkinExporter = new ZipkinExporter({
+ url: 'http://localhost:9411/api/v2/spans',
+ serviceName: 'movies-service'
})
+ const zipkinProcessor = new SimpleSpanProcessor(zipkinExporter)
+ provider.addSpanProcessor(zipkinProcessor)
<INSERT-API-KEY-HERE>
in the code snippet below with your API key.export NEW_RELIC_API_KEY=<INSERT-API-KEY-HERE>
docker-compose -f docker-compose.yaml up
💡 Make sure to change the reporting URL from http://localhost:9411/api/v2/spans
to http://localhost:9411/
in both dashboard.js
and movies.js
const zipkinExporter = new ZipkinExporter({
- url: 'http://localhost:9411/api/v2/spans',
+ url: 'http://localhost:9411',
serviceName: 'movies-service'
})