logbee-sdk-js
v1.0.1
Published
<div align="center"> <img src="https://products-wilbby.s3.eu-west-3.amazonaws.com/1747753527279-assets-wilbby" alt="Logbee Logo" width="200" />
Readme
🚀 Logbee SDK
📋 Table of Contents
- 🚀 Installation
- ⚙️ Quick Setup
- 🧩 Frameworks
- 🛠️ Configuration Options
- 🔐 Security
- 📊 Dashboard
- 📚 API Reference
- ❓ FAQ
🚀 Installation
Logbee SDK is extremely easy to integrate into your application. Start by installing the package:
# Using NPM
npm install logbee-sdk-js
# Using Yarn
yarn add logbee-sdk-js
# Using PNPM
pnpm add logbee-sdk-js
# Using bun
bun install logbee-sdk-js⚙️ Quick Setup
To start using Logbee SDK in your application, you only need a few lines of code. The connection URL is predefined, you only need to provide your authentication token:
import { LogbeeHttpMonitor } from 'logbee-sdk-js';
// Create monitor with just your authentication token
const monitor = new LogbeeHttpMonitor({
clientId: "proj_esdcsd";
clientSecret: "secret_sdhcbjshdbc";
});Then, simply integrate the middlewares in your application according to the framework you're using.
🧩 Frameworks
Express
import express from 'express';
import { LogbeeHttpMonitor } from 'logbee-sdk-js';
const app = express();
// Basic middlewares
app.use(express.json());
// Initialize Logbee
const monitor = new LogbeeHttpMonitor({
clientId: "proj_esdcsd";
clientSecret: "secret_sdhcbjshdbc";
captureBody: true,
captureHeaders: true,
environment: process.env.NODE_ENV || 'development',
serviceName: 'my-express-api'
});
// Middleware to capture all requests (before routes)
app.use(monitor.middleware());
// Application routes
app.get('/', (req, res) => {
res.json({ message: 'Hello World!' });
});
// Error middleware (after all routes)
app.use(monitor.errorMiddleware());
app.listen(3000, () => {
console.log('Express server running on port 3000');
});NestJS
Request middleware (logger.middleware.ts)
import { Injectable, NestMiddleware } from '@nestjs/common';
import { LogbeeHttpMonitor } from 'logbee-sdk-js';
@Injectable()
export class LogbeeMiddleware implements NestMiddleware {
private monitor: LogbeeHttpMonitor;
constructor() {
this.monitor = new LogbeeHttpMonitor({
clientId: "proj_esdcsd";
clientSecret: "secret_sdhcbjshdbc";
captureBody: true,
environment: process.env.NODE_ENV,
serviceName: 'my-nestjs-api'
});
}
use(req: any, res: any, next: () => void) {
return this.monitor.middleware()(req, res, next);
}
}Exception filter (logbee-exception.filter.ts)
import { ExceptionFilter, Catch, ArgumentsHost, HttpException } from '@nestjs/common';
import { LogbeeHttpMonitor } from 'logbee-sdk-js';
@Catch()
export class LogbeeExceptionFilter implements ExceptionFilter {
private monitor: LogbeeHttpMonitor;
constructor() {
this.monitor = new LogbeeHttpMonitor({
clientId: "proj_esdcsd";
clientSecret: "secret_sdhcbjshdbc";
captureBody: true,
environment: process.env.NODE_ENV,
serviceName: 'my-nestjs-api'
});
}
catch(exception: unknown, host: ArgumentsHost) {
const ctx = host.switchToHttp();
const req = ctx.getRequest();
const res = ctx.getResponse();
// Send error to Logbee
this.monitor.errorMiddleware()(exception, req, res, () => {});
// Normal error response
const status =
exception instanceof HttpException
? exception.getStatus()
: 500;
res.status(status).json({
statusCode: status,
timestamp: new Date().toISOString(),
message: exception instanceof Error ? exception.message : 'Internal Server Error',
});
}
}Module configuration (app.module.ts)
import { Module, MiddlewareConsumer, RequestMethod } from '@nestjs/common';
import { LogbeeMiddleware } from './logbee.middleware';
import { APP_FILTER } from '@nestjs/core';
import { LogbeeExceptionFilter } from './logbee-exception.filter';
@Module({
providers: [
{
provide: APP_FILTER,
useClass: LogbeeExceptionFilter,
},
],
})
export class AppModule {
configure(consumer: MiddlewareConsumer) {
consumer
.apply(LogbeeMiddleware)
.forRoutes({ path: '*', method: RequestMethod.ALL });
}
}Koa
import Koa from 'koa';
import Router from 'koa-router';
import bodyParser from 'koa-bodyparser';
import { LogbeeHttpMonitor } from 'logbee-sdk-js';
const app = new Koa();
const router = new Router();
// Initialize Logbee
const monitor = new LogbeeHttpMonitor({
clientId: "proj_esdcsd";
clientSecret: "secret_sdhcbjshdbc";
serviceName: 'my-koa-api',
environment: process.env.NODE_ENV
});
// Middleware to capture all requests
app.use(async (ctx, next) => {
const req = ctx.req;
const res = ctx.res;
const koaNext = async () => {
try {
await next();
} catch (error) {
// Capture and forward the error
monitor.errorMiddleware()(error, req, res, () => {});
throw error;
}
};
// Adapt to Logbee middleware
monitor.middleware()(req, res, koaNext);
});
app.use(bodyParser());
app.use(router.routes());
app.use(router.allowedMethods());
// Routes
router.get('/', (ctx) => {
ctx.body = { message: 'Hello World!' };
});
app.listen(3000, () => {
console.log('Koa server running on port 3000');
});Fastify
import fastify from 'fastify';
import { LogbeeHttpMonitor } from 'logbee-sdk-js';
const app = fastify({ logger: true });
// Initialize Logbee
const monitor = new LogbeeHttpMonitor({
clientId: "proj_esdcsd";
clientSecret: "secret_sdhcbjshdbc";
serviceName: 'my-fastify-api',
environment: process.env.NODE_ENV
});
// Adapter for Fastify
app.addHook('onRequest', (request, reply, done) => {
// Adapt Fastify objects to Logbee's expected format
const req = {
...request.raw,
method: request.method,
originalUrl: request.url,
body: request.body,
headers: request.headers,
query: request.query,
params: request.params
};
const res = reply.raw;
// Apply middleware
monitor.middleware()(req, res, done);
});
// Error handler
app.setErrorHandler((error, request, reply) => {
// Adaptation for error monitor
const req = {
...request.raw,
method: request.method,
originalUrl: request.url,
body: request.body,
headers: request.headers
};
const res = reply.raw;
// Send error to Logbee
monitor.errorMiddleware()(error, req, res, () => {});
// Normal response to client
reply
.status(error.statusCode || 500)
.send({
statusCode: error.statusCode || 500,
error: error.name,
message: error.message
});
});
// Routes
app.get('/', async () => {
return { message: 'Hello World!' };
});
// Test error route
app.get('/error', async () => {
throw new Error('Test error');
});
// Start server
app.listen({ port: 3000 }, (err) => {
if (err) {
app.log.error(err);
process.exit(1);
}
});Hapi
import Hapi from '@hapi/hapi';
import { LogbeeHttpMonitor } from 'logbee-sdk-js';
async function start() {
const server = Hapi.server({
port: 3000,
host: 'localhost'
});
// Initialize Logbee
const monitor = new LogbeeHttpMonitor({
clientId: "proj_esdcsd";
clientSecret: "secret_sdhcbjshdbc";
serviceName: 'my-hapi-api',
environment: process.env.NODE_ENV
});
// Plugin for Logbee
const logbeePlugin = {
name: 'logbee',
register: async (server) => {
// Extension for requests
server.ext('onRequest', (request, h) => {
const req = {
method: request.method,
originalUrl: request.url.href,
headers: request.headers,
body: request.payload
};
const res = {
statusCode: 200,
headersSent: false,
setHeader: (name, value) => {},
on: (event, callback) => {}
};
monitor.middleware()(req, res, () => {});
return h.continue;
});
// Extension for errors
server.events.on('request', (request, event, tags) => {
if (tags.error) {
const error = event.error;
const req = {
method: request.method,
originalUrl: request.url.href,
headers: request.headers,
body: request.payload
};
const res = {
statusCode: 500,
headersSent: false,
setHeader: (name, value) => {},
on: (event, callback) => {}
};
monitor.errorMiddleware()(error, req, res, () => {});
}
});
}
};
await server.register(logbeePlugin);
// Routes
server.route({
method: 'GET',
path: '/',
handler: () => {
return { message: 'Hello World!' };
}
});
// Test error route
server.route({
method: 'GET',
path: '/error',
handler: () => {
throw new Error('Test error');
}
});
await server.start();
console.log('Hapi server running at', server.info.uri);
}
start().catch(err => {
console.error('Error starting server:', err);
process.exit(1);
});🛠️ Configuration Options
Logbee SDK offers numerous options to customize its behavior:
| Option | Type | Default Value | Description |
|--------|------|--------------|-------------|
| clientId | string | undefined | Project ID for the Logbee API |
| clientSecret | string | undefined | Project secret for the Logbee API |
| captureBody | boolean | false | Captures the request body |
| captureHeaders | boolean | false | Captures the request headers |
| captureQueryParams | boolean | false | Captures query parameters |
| maskSensitiveData | boolean | true | Hides sensitive data like passwords |
| sensitiveFields | string[] | ['password', 'token', ...] | Fields to hide |
| environment | string | 'development' | Application environment |
| serviceName | string | 'api' | Service name |
| minStatusCodeToCapture | number | 400 | Minimum status code to capture |
| captureAllRequests | boolean | false | Captures all requests, not just errors |
| retryAttempts | number | 3 | Retry attempts if sending fails |
| retryDelay | number | 1000 | Milliseconds between retries |
| timeout | number | 5000 | Timeout for requests to Logbee |
Complete configuration example:
const monitor = new LogbeeHttpMonitor({
clientId: 'your-clientId',
clientSecret: 'your-clientSecret',
captureBody: true,
captureHeaders: true,
captureQueryParams: true,
maskSensitiveData: true,
sensitiveFields: ['password', 'token', 'secret', 'authorization', 'key', 'apiKey', 'credit_card'],
environment: 'production',
serviceName: 'payment-api',
minStatusCodeToCapture: 400,
captureAllRequests: false,
retryAttempts: 3,
retryDelay: 1000,
timeout: 5000
});🔐 Security
Logbee SDK is designed with security as a priority:
- ✅ Sensitive data is automatically masked
- ✅ Communications are done over HTTPS
- ✅ No information is stored on disk
- ✅ Secure token authentication
- ✅ Does not affect your application's performance
📊 Dashboard
With your Logbee account, you get access to a comprehensive dashboard where you can:
- 📈 View real-time error graphs
- 🔍 Search and filter logs by various criteria
- 🔔 Configure custom alerts
- 👥 Manage teams and permissions
- 📱 Receive notifications via Slack, Teams, email, or SMS
📚 API Reference
For complete details on available methods and properties, see our complete API documentation.
Main methods:
constructor(options)- Creates a new monitor instancemiddleware()- Returns a middleware to capture requestserrorMiddleware()- Returns a middleware to capture errorssetToken(token)- Updates the authentication tokensetEndpoint(url)- Changes the Logbee endpoint
❓ FAQ
Website • Documentation • Blog • Twitter • Discord
