Skip to main content

Installation

Install the Koa.js integration package:
Node 18+ required

Basic Setup

Add ApiTraffic middleware to your Koa.js application:

Configuration Options

Configuration Table

OptionEnvironment VariableRequiredTypeDescription
tokenAPI_TRAFFIC_TOKENYesStringIngest token from your ApiTraffic account
bucketAPI_TRAFFIC_BUCKETYesStringBucket ID for data organization
interceptOutboundAPI_TRAFFIC_INTERCEPT_OUTBOUNDNoBooleanMonitor outbound HTTP requests (default: true)
debugAPI_TRAFFIC_DEBUGNoBooleanEnable 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

Middleware Order

Place ApiTraffic middleware early in your middleware stack:

TypeScript Support

The package includes TypeScript definitions:

With Koa Router

Using ApiTraffic with @koa/router:

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

Ensure ApiTraffic middleware is placed before your route handlers and after body parsing middleware.
Verify that API_TRAFFIC_TOKEN and API_TRAFFIC_BUCKET are set in your environment.
Set interceptOutbound: true in your configuration to enable outbound request monitoring.
Make sure you’re using async/await syntax and that ApiTraffic middleware is properly registered.

Debug Mode

Enable debug mode to see detailed logging:

Sample Application

A complete working example is available in the GitHub repository.

Next Steps

Dashboard

View your API traffic data and analytics

Workflow Engine

Create automated workflows based on your API data