Skip to main content

Node.js

DebuggAI's Node.js SDK provides powerful logging and monitoring capabilities for your AI applications. This guide will help you get started with the Node.js SDK.

Installation

Install the DebuggAI Node.js SDK using npm:

npm install @debugg-ai/node

Prerequisites

Before using the DebuggAI Node.js SDK, make sure you have:

  • Node.js 12.x or later
  • An Ingestion URL from DebuggAI (sign up at app.debugg.ai)

Basic Usage

Here's a simple example of how to use the DebuggAI Node.js SDK:

// Import the DebuggAI SDK
const debuggAI = require('debugg-ai-sdk');

// Initialize DebuggAI Logger
const DEBUGG_AI_DSN = 'your-dsn-here';
const DEBUGG_AI_HOST = 'johns-macbook-pro';

debuggAI.init({
dsn: DEBUGG_AI_DSN,
environment: process.env.DEBUGG_AI_ENVIRONMENT || 'local',
hostName: DEBUGG_AI_HOST,
});

// The function will now automatically log:
// - Input prompts
// - Output responses
// - Performance metrics
// - Any errors that occur

Advanced Configuration

Context Management

Add context to your logs using the context manager:

log.info('Your message', { user_id: '123', session_id: 'abc' });

Manual Logging

You can also log events manually:

// Log an error
try {
// Your code here
throw new Error('An example error');
} catch (e) {
debuggAI.error(e, { step: 'processing' });
}

// OR
try {
// Your code here
throw new Error('Another example error');
} catch (e) {
debuggAI.log('error', e, { step: 'processing' });
}

Best Practices

  1. Initialize Early: Initialize the SDK as early as possible in your application
  2. Add Context: Use context to add relevant information to your logs
  3. Handle Errors: Always log errors with appropriate context
  4. Monitor Performance: Use the performance monitoring features for your AI functions
  5. Redact Sensitive Data: Enable redaction for production environments

Troubleshooting

If you encounter issues:

  1. Check your Ingestion URL is valid
  2. Verify your Node.js version meets the requirements
  3. Ensure you have network connectivity
  4. Check the SDK logs for detailed error messages

Next Steps

  • Learn about Error Tracing to see how DebuggAI helps you debug issues
  • Explore Analytics to understand your AI application's performance
  • Check out Click to Fix to automatically fix common issues