@talks.converse/js-monitoring
Version:
Express monitoring middleware with Datadog and Prometheus backends, plus conditional logging.
68 lines (49 loc) • 4.18 kB
Markdown
# @talks.converse/js-monitoring
A lightweight monitoring middleware for Node.js applications with support for Datadog and Prometheus.
## Install
```bash
npm i @talks.converse/js-monitoring
# or
yarn add @talks.converse/js-monitoring
```
## How to Use
**Note:** This package currently supports only Express.js applications. Fastify and other frameworks are not supported yet.
In your `index.js` (Express app only, other framework support may come later):
```js
const monitoring = require('@talks.converse/js-monitoring');
const express = require('express');
const app = express();
// One-liner monitoring setup
monitoring(app, {});
app.get('/ping', (req, res) => {
res.send('pong');
});
app.listen(3000, () => {
console.log('Server running on port 3000');
});
```
> **Note**: Currently `@talks.converse/js-monitoring` supports only **Express.js** applications.
This will automatically attach monitoring middleware based on the environment variables you set.
---
## Configurable Environment Variables
| Variable | Description | Accepted Values / Default |
|--------------------------------|-----------------------------------------------------------------------------|--------------------------------------------------------------------------------|
| **MONITORING_METRIC_TYPE** | Defines the type of metric for latency tracking. | `""` (default, gauge) or `histogram` |
| **GROUPING_STATUS_CODE** | Defines whether the status code in metrics grouped or not. | `true` / `false` (default: `false`) |
| **ENABLE_DATADOG** | Enables Datadog integration. | `true` / `false` (default: `false`) |
| **DD_AGENT_HOST** | Hostname of the Datadog agent. | Default: `127.0.0.1` |
| **DD_AGENT_PORT** | Port for the Datadog agent. | Default: `8125` |
| **DATADOG_ENDPOINTS_INCLUDE** | Regex patterns (comma-separated) of endpoints to include in Datadog metrics.| Example: `^/healthz, ^/ping, ^/test/.*, \.ico$` |
| **DATADOG_ENDPOINTS_EXCLUDE** | Regex patterns (comma-separated) of endpoints to exclude from Datadog metrics. Excluded endpoints are grouped as `_others`. | Example: `^/healthz, ^/ping, ^/test/.*, \.ico$` |
| **ENABLE_PROMETHEUS** | Enables Prometheus integration. | `true` / `false` (default: `false`) |
| **PROMETHEUS_METRICS_PATH** | Path where Prometheus metrics are exposed. | Default: `/metrics` |
| **PROMETHEUS_ENDPOINTS_INCLUDE** | Regex patterns (comma-separated) of endpoints to include in Prometheus metrics. | Example: `^/healthz, ^/ping, ^/test/.*, \.ico$` |
| **PROMETHEUS_ENDPOINTS_EXCLUDE** | Regex patterns (comma-separated) of endpoints to exclude from Prometheus metrics. Excluded endpoints are grouped as `_others`. | Example: `^/healthz, ^/ping, ^/test/.*, \.ico$` |
| **LOGGING_ENDPOINTS_INCLUDE** | Regex patterns (comma-separated) of endpoints to include in request logging. | Example: `^/healthz, ^/ping, ^/test/.*, \.ico$` |
| **LOGGING_ENDPOINTS_EXCLUDE** | Regex patterns (comma-separated) of endpoints to exclude from request logging. Excluded endpoints are grouped as `_others`. | Example: `^/healthz, ^/ping, ^/test/.*, \.ico$` |
---
## License
This project is licensed under the [MIT License](./LICENSE).
---
## Contributing
Contributions are welcome! 🎉 See [CONTRIBUTING.md](./CONTRIBUTING.md) for guidelines.