Installation
Basic usage
API Routes (Pages Router)
Wrap your API route handlers withwithSentinel:
pages/api/health.ts
Route Handlers (App Router)
Wrap your route handlers withwithSentinelRouteHandler:
app/api/health/route.ts
The wrapper automatically tracks all incoming requests, captures
request/response metadata, and sends events to Sentinel with minimal
performance impact.
Configuration
The SDK automatically reads configuration from environment variables. You can also pass options directly to the wrapper functions.Configuration options
You can pass configuration options directly when wrapping your handlers:pages/api/health.ts
string
Your Sentinel API key. Overrides the
SENTINEL_API_KEY environment variable
if provided.integer
default:"50"
Maximum number of events to batch before sending to the Sentinel API.
integer
default:"5000"
Time in milliseconds to wait before sending a batch of events, even if the
batch size hasn’t been reached.
string[]
Array of path patterns to exclude from tracking. If you specify
/v1/projects, it will exclude all paths starting with that prefix (e.g.,
/v1/projects, /v1/projects/123, /v1/projects/123/tasks).Setting user context
Identify users making requests by setting theuserId for tracking user behavior:
API Routes (Pages Router)
pages/api/users.ts
Route Handlers (App Router)
app/api/users/route.ts
Tracking steps
Track sub-operations within a request to monitor database queries, external API calls, and other operations.pages/api/users.ts
How it works
The wrapper automatically handles the following:- Request tracking: Captures all incoming requests and their metadata
- Response capture: Records response status codes and timing information
- Event batching: Groups events together to minimize API calls
- Automatic retries: Handles failures gracefully with exponential backoff (up to 3 retries by default)
- Performance optimization: Non-blocking event sending ensures minimal impact on your application