Installation
Install the Metlo package from npm:Quick Start
Add Metlo to your Koa application by requiring it at the start of your main script:Configuration
Required Parameters
Your Metlo API key for authentication with the collector
The URL of your Metlo collector instance (e.g.,
https://collector.metlo.com)Optional Configuration
Override the host value sent in trace data. Useful when your application is behind a proxy or load balancer.
How It Works
Metlo’s Koa integration automatically injects middleware that:- Runs first - Positioned at index 0 in the middleware chain
- Executes after response - Uses
await next()to capture the final response - Self-managing - Automatically repositions itself if other middleware is added
- Asynchronous - Sends data to Metlo without blocking the response
Middleware Behavior
The integration patchesapp.use() to ensure Metlo’s middleware:
- Is always executed first in the chain
- Captures the complete request/response cycle
- Doesn’t interfere with other middleware
Captured Data
For each request, Metlo captures: Request:- URL (host, path, query parameters)
- HTTP method
- Headers
- Request body (from
ctx.request.body) - Source IP and port
- Status code
- Headers
- Response body (from
ctx.body) - Destination IP and port
- Environment (from
process.env.NODE_ENV) - Source identifier:
node/koa - Timestamp
Example with Body Parser
If you’re using
koa-bodyparser, make sure to install it separately. Metlo will automatically capture the parsed body from ctx.request.body.Example with TypeScript
Troubleshooting
Request body is empty
Request body is empty
Metlo captures the body from
ctx.request.body. Make sure you’re using a body parser middleware like koa-bodyparser before your route handlers.Middleware order issues
Middleware order issues
Metlo automatically positions its middleware first. If you’re experiencing issues, check that
metlo() is called before requiring Koa.Response not captured
Response not captured
Ensure your routes set
ctx.body. Metlo captures whatever value is assigned to ctx.body after all middleware completes.Requirements
- Node.js >= 11.7.0
- Koa (any version)
Async/Await Support
Koa’s async/await-based middleware model is fully supported. Metlo’s middleware properly awaits the completion of downstream middleware before capturing the response.Next Steps
View API Inventory
See your discovered APIs in the Metlo dashboard
Sensitive Data Detection
Identify PII and sensitive data in your APIs