This repository contains a simple Express.js application that demonstrates the integration of OpenTelemetry for observability. The app provides basic CRUD operations for managing items and showcases how to instrument a Node.js application using the @middleware.io/node-apm package.
- RESTful API for managing items (Create, Read, Update, Delete)
- OpenTelemetry integration for tracing and monitoring
- Custom span creation and attribute setting
- Error logging and handling
- Dockerized application for easy deployment
- Kubernetes deployment configuration
- Node.js 18 or later
- Docker (for containerization)
- Kubernetes cluster (for deployment)
-
Clone the repository:
git clone https://github.com/your-username/simple-express-app.git cd simple-express-app
-
Install dependencies:
npm install
-
Set up environment variables: Copy the
.env.example
file to.env
and fill in the required values:cp .env.example .env
To start the application in development mode:
npm start
To start the application with the Middleware.io agent:
npm run start-agent
The server will start on http://localhost:3000
.
GET /items
: Retrieve all itemsGET /items/:id
: Retrieve a specific itemPOST /items
: Create a new itemPUT /items/:id
: Update an existing itemDELETE /items/:id
: Delete an item
To build and run the Docker image:
docker build -t simple-express-app .
docker run -p 3000:3000 simple-express-app
To deploy the application to Kubernetes:
kubectl apply -f deployment.yaml
This application uses the @middleware.io/node-apm package to integrate OpenTelemetry. Key features include:
- Automatic instrumentation of Express.js routes
- Custom span creation for specific operations
- Error logging and tracking
- Configuration of service name and API key through environment variables
The application can be configured using the following environment variables:
MW_SERVICE_NAME
: Name of the service (default: "simple-express-app")MW_API_KEY
: API key for Middleware.ioMW_TARGET
: Target URL for sending telemetry dataMW_DEBUG
: Enable debug mode (set to "true" to enable)PORT
: Port on which the server will run (default: 3000)
For detailed information on configuring and using the Middleware.io Node.js APM:
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.