Skip to content

Example of dev Node.js microservices setup using Docker, Docker-Compose and OpenTelemetry

License

Notifications You must be signed in to change notification settings

dimitrisfinas/nodejs-microservices-example

 
 

Repository files navigation

nodejs-microservices-example with OpenTelemetry

Example of Node.js microservices setup using Docker, Docker-Compose and OpenTelemetry.

This is inspired from project: https://github.com/ashleydavis/nodejs-microservices-example

Need to build a microservices application? Learn how to do this with Bootstrapping Microservices.

Requirements

Starting the microservices application

Follow the steps in this section to boot the microservices application for development using Docker.

Change directory to the microservices application:

cd nodejs-microservices-example

Use Docker Compose to start the microservices application:

docker compose up

To build after you change code:

docker compose up --build

Useful URLs for test

Once deployed:

Installing OpenTelemetry

You can follow the step by step approach below to install OpenTelemetry and instrument the application

If you want to rollback your files to initial application with no instrumentation, you can do it by using this release

  • v0 are the original files without any Otel instrumentation

Step 1 - Add auto-instrumentation to your code

In this step, you will auto-instrument the NodeJS application with Otel libraries and send traces output to each component console logs

Step 2 - Add custom attributes, log events and spans

In this step, we will add some manual instrumentation in addition to auto-instrumentation. We will add some custom attributes, log events and also create new spans.

Step 3 - Send traces to OpenTelemetry Collector

In this step, you will redirect the traces output collected before to an OpenTelemetry Collector and understand how to debug Collector behavior using console and zpages extension

  • Follow instructions in file INSTALL_OTEL_STEP3.md

  • For solution, you can download release

    • v3a is using HTTP protocol to forward traces
    • v3b is using GRPC protocol to forward traces

Step 4 - Send traces to External backends

In this step, we will redirect the traces output from Otel-collector to external backends (Jaeger deployed locally and Lightstep in SaaS)

Step 5 - Add resources metrics

(TBD)

Step 6 - Add custom metrics to your traces

(TBD)

Resources

OpenTelemetry for nodeJS

Official OpenTelemetry Collector containers in docker hub

OpenTelemetry Collector Github Project

OpenTelemetry NodeJS Github project

OpenTelemetry eLearning video (1h10min)

For more information regarding original project, please refer to file ORIGINAL_README.md

Troubleshoot

  • Due to reordering of the steps, release package are not in correct order:
    • v1 is still correct
    • v2 applies to step 3 (collector)
    • v3 applies to step 4 (backends)
    • v4 applies to step 2 (manual instrumentation), except that it publishes directly to backends

=> this will be corrected soon

  • getting error "error": "Permanent error: rpc error: code = Internal desc = unexpected HTTP status code received from server: 400 (Bad Request); malformed header: missing HTTP content-type" when sending spans to Lightstep

    • check value of your LIGHTSTEP_ACCESS_TOKEN with echo $LIGHTSTEP_ACCESS_TOKEN
    • if not set, initialize it with export LIGHTSTEP_ACCESS_TOKEN=<YOUR_VALUE> then deploy again with docker-compose up
  • getting error host path ("/Users/dimitris.finas/git/nodejs-microservices-example/tmp/npm") not allowed as volume source, you need to reference an Azure File Share defined in the 'volumes' section or Port mapping is not supported with ACI, cannot map port 4002 to 27017 for container db

    • check that you are in default context with docker context list
    • if not, permute context to default with docker context use default
  • on MacOS, when starting docker compose, got error error getting credentials - err: exec: "docker-credential-gcloud": executable file not found in $PATH

About

Example of dev Node.js microservices setup using Docker, Docker-Compose and OpenTelemetry

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 49.3%
  • HCL 28.2%
  • Shell 18.9%
  • Python 3.1%
  • Dockerfile 0.5%