Skip to main content
This page documents all exported functions, types, and interfaces in vij-sdk.

Functions

init()

Initialize the VIJ SDK with configuration options. Must be called before using other SDK functions.
InitOptions
required
Configuration object for the SDK. See Configuration Guide for detailed documentation.
Example:
Call init() once at application startup, before any other VIJ functions. Calling it multiple times will reinitialize the SDK and may cause data loss.

captureException()

Capture and send an error to VIJ Admin.
Error
required
The error object to capture. Must have name, message, and stack properties.
Record<string, any>
Optional metadata to attach to this error. Merged with global metadata from init().
Severity
default:"error"
Severity level: "error", "warning", or "info".
Example:
Returns: void

captureMessage()

Capture and send a custom log message to VIJ Admin.
string
required
The log message to capture.
Record<string, any>
Optional metadata to attach to this message.
Severity
default:"info"
Severity level: "error", "warning", or "info".
Example:
Returns: void

flush()

Immediately flush all queued logs to the server, bypassing batch settings.
Example:
Returns: Promise<void> - Resolves when all logs are sent
Useful for ensuring logs are sent before page navigation, process exit, or application shutdown.

setMetadata()

Update global metadata that will be attached to all future logs.
Record<string, any>
required
Metadata object to merge with existing global metadata.
Example:
Returns: void
Metadata set via setMetadata() is merged with metadata passed to init(). Later values override earlier ones.

clearMetadata()

Remove specific keys from global metadata.
string[]
required
Array of metadata keys to remove.
Example:
Returns: void

getMetadata()

Retrieve the current global metadata object.
Example:
Returns: Record<string, any> - Current global metadata

Types

InitOptions

Configuration options for the init() function.
string
required
VIJ Admin API endpoint URL (e.g., https://vij.example.com/api/logs)
string
required
Unique identifier for your application
string
required
Environment name (e.g., production, staging, development)
boolean
default:"true"
Enable batching of logs
number
default:"10"
Maximum logs per batch (1-100)
number
default:"5000"
Batch flush interval in milliseconds (1000-60000)
number
default:"100"
Maximum queue size before dropping old logs (10-1000)
Record<string, any>
default:"{}"
Global metadata attached to all logs
Example:

Severity

Severity level for errors and messages.
Values:
  • "error" - Critical errors requiring immediate attention
  • "warning" - Non-critical issues that should be investigated
  • "info" - Informational logs for tracking behavior
Example:

LogEntry

Structure of a log entry sent to VIJ Admin.
string
Error message or custom log message
string
Error name (e.g., Error, TypeError, CustomError)
string
Stack trace of the error
Severity
Severity level: error, warning, or info
string
ISO 8601 timestamp when the error was captured
string
Application identifier from init()
string
Environment name from init()
Record<string, any>
Merged global and per-error metadata
BrowserContext | NodeContext
Automatically collected contextual information
You don’t create LogEntry objects directly. The SDK generates them automatically when you call captureException() or captureMessage().

BrowserContext

Contextual information collected in browser environments.
Example:

NodeContext

Contextual information collected in Node.js environments.
Example:

Advanced Usage

Manual Queue Management

Dynamic Metadata Updates

TypeScript Integration

React Integration

Express Integration

Best Practices

Call init() once when your application starts, before any other code:
Import types for better IDE support and compile-time checking:
Ensure logs are sent before page unload, process exit, or deployments:

Next Steps

Configuration Guide

Learn about all SDK configuration options

Capturing Errors

Understand error and message capture patterns

Dashboard Features

Explore VIJ Admin dashboard capabilities

API Endpoints

View the HTTP API documentation