Installation
Install the Hapi.js integration package:Node 18+ required
Basic Setup
Register ApiTraffic as a plugin in your Hapi.js application:Configuration Options
Configuration Table
Option | Environment Variable | Required | Type | Description |
---|---|---|---|---|
token | API_TRAFFIC_TOKEN | Yes | String | Ingest token from your ApiTraffic account |
bucket | API_TRAFFIC_BUCKET | Yes | String | Bucket ID for data organization |
interceptOutbound | API_TRAFFIC_INTERCEPT_OUTBOUND | No | Boolean | Monitor outbound HTTP requests (default: true) |
debug | API_TRAFFIC_DEBUG | No | Boolean | Enable debug logging (default: false) |
Advanced Usage
Custom Tagging
Add custom tags to requests for better organization and searchability:Request Tracing
Add trace messages for debugging and monitoring:Error Handling
ApiTraffic automatically captures errors, but you can add additional context:Environment Variables
Configure using environment variables:.env
Plugin Registration Order
Register ApiTraffic early in your plugin registration sequence:TypeScript Support
The package includes TypeScript definitions:Security Features
Data Redaction
ApiTraffic automatically redacts sensitive data based on your account settings. No code changes required - configure redaction rules in your ApiTraffic dashboard.Request Exclusions
Exclude specific endpoints from monitoring by configuring exclusion rules in your ApiTraffic account. Common exclusions include:- Health check endpoints
- Static asset requests
- Internal monitoring endpoints
Troubleshooting
Plugin not capturing requests
Plugin not capturing requests
Ensure ApiTraffic is registered before your route handlers and other plugins that might interfere with request processing.
Missing environment variables
Missing environment variables
Verify that
API_TRAFFIC_TOKEN
and API_TRAFFIC_BUCKET
are set in your environment.Outbound requests not being tracked
Outbound requests not being tracked
Set
interceptOutbound: true
in your plugin options to enable outbound request monitoring.Plugin registration errors
Plugin registration errors
Make sure you’re using the correct plugin registration syntax for your version of Hapi.js.