Send and verify events with NestJS request and workflow telemetry
Use NestJS request and workflow telemetry where your app knows the final result. Collect only the fields you need, then verify a test event before building charts.
- 1
Choose the outcome
NestJS API monitoring
- 2
Define the contract
request_id, controller, handler, route_template, and method
- 3
Log the final result
Apply an interceptor at the narrowest useful scope and derive route_template from framework metadata rather than req.originalUrl.
- 4
Check the stored event
Exercise a known fixture, then inspect api_request_completed for one correctly typed terminal row.
Before you start
Before you start
- telemetry-sh initialized in a server-only NestJS provider or module
- A route-template resolver that avoids raw URLs and path identifiers
- Defined error categories and a policy for best-effort delivery or persisted retries
Delivery setup
Install and initialize server-side
Import telemetry-sh in server-only code and initialize it once with process.env.TELEMETRY_API_KEY. Keep ingestion credentials out of browser bundles, client-visible environment variables, source control, logs, and exception messages.
npm installation
npm install telemetry-sh- 1Create one reusable server-side client. Set its timeout and retry limit.
- 2Log an event when the operation succeeds, fails, retries, or times out.
- 3Send test events with known results and inspect the stored rows before enabling an alert.
Snippet
Start with one structured event
Add this shape where the workflow completes, fails, or retries. Then build the dashboard from real fields.
NestJS request and workflow telemetry event
@Injectable()
export class OutcomeInterceptor implements NestInterceptor {
intercept(context: ExecutionContext, next: CallHandler) {
const request = context.switchToHttp().getRequest();
const response = context.switchToHttp().getResponse();
const startedAt = performance.now();
let errorType: string | undefined;
return next.handle().pipe(
catchError((error) => {
errorType = classifyError(error);
throw error;
}),
finalize(() => {
const statusCode = response.statusCode;
void telemetry.log("api_request_completed", {
request_id: request.id,
controller: context.getClass().name,
handler: context.getHandler().name,
route_template: resolveRouteTemplate(context),
method: request.method,
status_code: statusCode,
status: statusCode >= 500 ? "failed" : "success",
latency_ms: Math.round(performance.now() - startedAt),
error_type: errorType,
release: process.env.APP_RELEASE,
}).catch(recordTelemetryFailure);
}),
);
}
}Event schema
request_id, controller, handler, route_template, and method
status, status_code, latency_ms, error_type, and release
tenant_id, plan, or feature only when explicitly approved
Check your setup
Checkpoint 1
Apply an interceptor at the narrowest useful scope and derive route_template from framework metadata rather than req.originalUrl.
Checkpoint 2
The example accounts for the delivery promise but does not delay the HTTP response; use an application-owned outbox when the event is compliance or billing critical.
Checkpoint 3
Keep exception objects, request bodies, authorization headers, cookies, query strings, and raw path parameters out of the payload.
Verification
Prove the event arrived
Run this after exercising known success and failure cases. Replace the fallback table name if your final event contract differs from the snippet.
NestJS request and workflow telemetry verification query
SELECT *
FROM api_request_completed
ORDER BY timestamp_utc DESC
LIMIT 20;Implementation references
Review the event contract, data-safety guidance, and upstream primary documentation before enabling a new production path.
Where to log
Keep the outcome event small and recoverable
This pattern provides
- Record the outcome as an event you can query with SQL.
- Stable fields for dashboards, alerts, and cross-event correlation.
- Test events for checking success, failure, retries, and timeouts.
This pattern does not provide
- An OTLP exporter, automatic collection pipeline, or replacement for detailed traces and diagnostic logs.
- Exactly-once delivery merely because the payload contains an event ID.
- Permission to collect raw provider payloads, user content, credentials, or regulated data.
Example event schemas
Event schemas for this workflow
Check what each event records, when to send it, and which field types it needs. Review the example payload and privacy checklist before using it in production.
Use these queries in Telemetry
Learn about Alerts
Add a threshold and recipients to your reliability query to get alerts.
Related SQL recipes
More SQL recipes
Run the query using this workflow's event fields and check the example result. Save the result to a dashboard or set up an alert.
Calculate API request throughput by route
Which API routes are processing the most requests per minute?
Open recipeCalculate API error rate by route
Which API routes have the highest 5xx error rate with at least 20 requests?
Open recipeCalculate p50, p95, and p99 API latency
Which endpoints have the worst tail latency?
Open recipeCalculate API timeout rate by route
Which API routes time out often enough to affect users?
Open recipeCompare API reliability by release
Which releases coincide with worse API errors or tail latency?
Open recipeBrowse by implementation family
Compare related integration patterns
Templates to pair with this integration
More integrations
Pino structured event analytics
Keep Pino diagnostic logs and send selected completion events to Telemetry to analyze Node.js requests, jobs, and product reliability.
Open guideElixir Phoenix telemetry integration
Listen for Phoenix request lifecycle events and forward the final request result with approved fields. Exclude connection data, parameters, and exception text.
Open guideGo HTTP server structured logging
Add typed request-outcome events to Go HTTP services for route error rates, latency percentiles, and release comparisons.
Open guide