Installation
Install the Metlo package from npm:Quick Start
Add Metlo to your Fastify 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 Fastify integration uses theonSend hook to capture request and response data:
- Automatic hook registration - Adds an
onSendhook to every Fastify instance - Captures payload - Intercepts the response payload before it’s sent
- Asynchronous transmission - Sends data to Metlo using a worker pool
- Zero interference - Returns the payload unchanged
Hook Lifecycle
TheonSend hook runs just before the response is sent to the client, allowing Metlo to capture:
- The final response payload
- All headers (including those set by other hooks)
- The final status code
Captured Data
For each request, Metlo captures: Request:- URL (host, path, query parameters)
- HTTP method
- Headers
- Request body (parsed)
- Source IP and port
- Status code
- Headers
- Response payload
- Destination IP and port
- Environment (from
process.env.NODE_ENV) - Source identifier:
node/fastify - Timestamp
Example with Schema Validation
Example with TypeScript
Performance Considerations
Fastify is designed for high performance, and Metlo is optimized to maintain that:- Non-blocking - Data transmission happens asynchronously in a worker pool
- Minimal overhead - Hook execution is lightweight
- Payload passthrough - Response payload is returned unchanged
Troubleshooting
Metlo not capturing requests
Metlo not capturing requests
Verify that:
metlo()is called before requiring Fastify- Your collector URL is accessible from your application
- Your API key is correct
- Check Fastify logs for any error messages
Empty request body
Empty request body
Fastify automatically parses JSON bodies. Ensure your requests have the correct
Content-Type: application/json header.Hook conflicts
Hook conflicts
Metlo’s
onSend hook is designed to coexist with other hooks. If you’re experiencing issues, check the order of hook registration.Requirements
- Node.js >= 11.7.0
- Fastify (any version)
Compatibility
Metlo works with:- Fastify plugins
- Schema validation
- Custom serializers
- All Fastify decorators and hooks
Next Steps
API Inventory
Explore your discovered API endpoints
Security Testing
Run automated security tests on your APIs