Skip to content

Enable and monitor tracing on your Express.js application using OpenTelemetry and Zipkin

License

Notifications You must be signed in to change notification settings

kovid-r/opentelemetry-express-zipkin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Automatic Instrumentation for Express.js using OpenTelemetry and Zipkin

This is a sample application which deploys a mock Express.js server along with a mock client to send requests to the server. OpenTelemetry is used to build in automatic instrumentation for this app. Zipkin is used to expose the instrumentation data via the browser.

Repository

Start by cloning the current repository using the following command:

git clone git@github.com:kovid-r/opentelemetry-express-zipkin.git

Setup

Run Zipkin on Docker

Assuming that you have Docker installed on your system, you can quickly spin up a Zipkin Docker container which runs on port 9411 using the following command:

docker run -d -p 9411:9411 openzipkin/zipkin

Alternatively, you can run Zipkin using Java or build it from source.

Start Express.js Server

After cloning the repository, head over to the directory and run the following command to start the Express.js server on port 8080:

# Open the cloned directory
cd opentelemetry-express-zipkin

# Start the Express.js server
npm run server

Send Requests to the Server

Open another terminal tab and run the following command to start the client which will send mock HTTP requests to the Express.js server:

npm run client

The sendRequest method will be called ten times at an interval of one second each.

Search and Analyse Traces on Zipkin

Zipkin runs on port 9411, by default. Log onto http://localhost:9411/zipkin to search the traces just generated by the OpenTelemetry for all the requests received from the client and served by the server.

Here's what a part of the trace will look like:

{
  "traceId": "608174b6dc21ab4cea706cad484142fc",
  "parentId": "30798d2f44f2cfe8",
  "id": "a6f99f3c493b30ab",
  "name": "middleware - jsonparser",
  "timestamp": 1638184172048735,
  "duration": 277,
  "localEndpoint": {},
  "tags": {
    "express.name": "jsonParser",
    "express.type": "middleware",
    "http.route": "/",
    "ot.status_code": "UNSET",
    "service.name": "express-zipkin-opentelemetry",
    "telemetry.sdk.language": "nodejs",
    "telemetry.sdk.name": "opentelemetry",
    "telemetry.sdk.version": "0.25.0"
    }
}

Here's what the summary of the trace would look like on Zipkin:

Screen Shot 2021-12-01 at 1 56 57 am

License

Apache 2.0

About

Enable and monitor tracing on your Express.js application using OpenTelemetry and Zipkin

Topics

Resources

License

Stars

Watchers

Forks