This Todo app demonstrates how to instrument a Node.js application using OpenTelemetry for tracing and sending telemetry data to an observability backend like Elastic APM.
- Automatic instrumentation with OpenTelemetry
- CRUD operations for managing todos
- Traces sent to Elastic APM or other OTEL-compatible backends
- Node.js: v14 or later
- NPM: v6 or later
- Elastic APM Server: Hosted on Elastic Cloud or self-hosted
- Elasticsearch and Kibana: For observing traces and spans
Create a .env file in the root directory and include the following:
PORT=8081
indexName=todos
ELASTICSEARCH_ENDPOINT=https://<your-elasticsearch-url>
ELASTICSEARCH_API_KEY=<your-elasticsearch-api-key>
APM_SERVER_URL=https://<your-apm-server-url>
APM_API_KEY=<your-apm-api-key>
Replace <your-elasticsearch-url>, <your-elasticsearch-api-key>, <your-apm-server-url>, and <your-apm-api-key> with your Elastic Cloud or self-hosted APM details.
-
Clone the Repository
git clone https://github.com/justincastilla/Introduction-to-OpenTelemetry-with-JS cd Introduction-to-OpenTelemetry-with-JS -
Install Dependencies
npm install
Run the app using OpenTelemetry's Node.js instrumentation loader:
npm run telemetry| Method | Endpoint | Description |
|---|---|---|
| GET | / |
Returns the home page. |
| GET | /get_todos |
Fetch all todos. |
| POST | /add_item |
Add a new todo item. |
| DELETE | /delete/:id |
Delete a todo by ID. |
- Traces are automatically collected for HTTP requests and interactions.
- Each trace is sent to the Elastic APM server configured in the
.envfile.
- Open Kibana and navigate to Observability > APM.
- Look for your service (
todo-app) in the Services tab. - Explore traces, spans, and associated metrics.