NestJS
Set up OneMinute Logs in NestJS.
Install the NestJS SDK, register its global module once, and inject the type-safe logging service into controllers, providers, or background workers.
1. Install the SDK
Add the OneMinute Logs SDK for this framework.
npm install @oneminutelogs/nestjs2. Create an API key
Create an API key from your OneMinute Logs dashboard and add it to your environment variables. Open the API key guide.
ONE_MINUTE_LOGS_API_KEY=your_oml_api_key3. Create src/app.module.ts
Initialize the logger once and import it anywhere you need to send events.
import { Module } from "@nestjs/common";
import { OneMinuteLogsModule } from "@oneminutelogs/nestjs";
@Module({
imports: [
OneMinuteLogsModule.forRoot({
apiKey: process.env.ONE_MINUTE_LOGS_API_KEY!,
projectName: "my-nest-api",
environment: process.env.NODE_ENV || "development",
}),
],
})
export class AppModule {}OneMinuteLogsModule is global — register it once in your root module and inject OneMinuteLogsService anywhere.
Optional: log HTTP requests automatically
Enable autoLogRequests on the module config, then bind the interceptor. It emits one http.server.request event per completed request.
import { NestFactory } from "@nestjs/core";
import {
OneMinuteLogsInterceptor,
OneMinuteLogsService,
} from "@oneminutelogs/nestjs";
import { AppModule } from "./app.module";
async function bootstrap() {
const app = await NestFactory.create(AppModule);
const oml = app.get(OneMinuteLogsService);
app.useGlobalInterceptors(
new OneMinuteLogsInterceptor(oml, { autoLogRequests: true }),
);
await app.listen(process.env.PORT ?? 3000);
}
void bootstrap();4. Send events
Log at a level — trace, debug, info, warn, error, or fatal — and attach a stable eventName plus structured attributes for anything you might filter or alert on.
import { Body, Controller, Post } from "@nestjs/common";
import { OneMinuteLogsService } from "@oneminutelogs/nestjs";
@Controller("orders")
export class OrdersController {
constructor(private readonly logs: OneMinuteLogsService) {}
@Post()
async create(@Body() body: any) {
try {
const order = await this.orders.create(body);
await this.logs.info({
message: "Order created",
eventName: "order.created",
attributes: {
"order.id": order.id,
"order.total": order.total,
"user.id": body.userId,
},
});
return order;
} catch (error) {
await this.logs.error({
message: "Order fulfillment failed",
eventName: "order.fulfillment.failed",
attributes: {
"error.type": (error as Error).name,
"user.id": body.userId,
},
});
throw error;
}
}
}What's next?
Alerts
Investigate automatic alerts and add optional custom rules.
Live Events
Stream incoming events into your own dashboard.
Search & Filters
Query stored events with filters and search terms.
After events are flowing, automatic alerts, live dashboards, and search all work from the same event pipeline.