SDK Overview

Core logging API, methods, and concepts for the Apperio SDK.

Logging API

The Apperio SDK provides six log level methods that map directly to standard severity levels. Each method accepts a message string and an optional data object.

TypeScript
import Apperio from class="syntax-string">"apperio";

class="syntax-comment">// Trace - very detailed diagnostic info
Apperio.trace(class="syntax-string">"Entering function processOrder", { orderId: class="syntax-string">"abc123" });

class="syntax-comment">// Debug - diagnostic information
Apperio.debug(class="syntax-string">"Cache miss for user preferences", { userId: class="syntax-string">"user_1" });

class="syntax-comment">// Info - general operational events
Apperio.info(class="syntax-string">"Order completed successfully", { total: class="syntax-number">49.99 });

class="syntax-comment">// Warn - unexpected but non-critical events
Apperio.warn(class="syntax-string">"API rate limit approaching", { remaining: class="syntax-number">5 });

class="syntax-comment">// Error - error events that should be investigated
Apperio.error(class="syntax-string">"Payment processing failed", {
  error: new Error(class="syntax-string">"Card declined"),
  orderId: class="syntax-string">"abc123",
});

class="syntax-comment">// Fatal - critical failures requiring immediate action
Apperio.fatal(class="syntax-string">"Database connection lost", { host: class="syntax-string">"db.example.com" });

Log Levels

Log levels follow standard severity ordering. You can configure a minimum level to filter out lower-severity messages.

LevelValueUse Case
trace0Finest-grained diagnostic info, function entry/exit
debug1Detailed diagnostic data useful during development
info2General operational events, successful operations
warn3Unexpected events that are not errors but need attention
error4Error events that should be investigated
fatal5Critical failures requiring immediate action

Info

The SDK uses smart log level assignment for auto-captured events. For example, uncaught errors are automatically logged at the error level, while performance metrics use info.

Structured Data

Every log method accepts an optional second argument for structured data. This data is stored as JSON and is fully searchable in the dashboard.

TypeScript
class="syntax-comment">// Simple key-value data
Apperio.info(class="syntax-string">"User action", {
  action: class="syntax-string">"click",
  element: class="syntax-string">"submit-button",
  page: class="syntax-string">"/checkout",
});

class="syntax-comment">// Nested objects
Apperio.info(class="syntax-string">"API response received", {
  endpoint: class="syntax-string">"/api/users",
  method: class="syntax-string">"GET",
  response: {
    status: class="syntax-number">200,
    duration: class="syntax-number">145,
    cached: false,
  },
});

class="syntax-comment">// Error objects are automatically serialized
try {
  await riskyOperation();
} catch (err) {
  Apperio.error(class="syntax-string">"Operation failed", {
    error: err,           class="syntax-comment">// Stack trace captured automatically
    context: { step: class="syntax-number">3 },
  });
}

Warning

The SDK handles circular references in data objects automatically. You do not need to pre-process your data before logging.

Event Types

Each log entry can be tagged with an event type for categorization and filtering in the dashboard:

Event TypeSourceDescription
errorAuto / ManualJavaScript errors, unhandled rejections
performanceAutoCore Web Vitals, page load metrics
networkAutoXHR and Fetch request/response tracking
consoleAutoConsole.log, warn, error interceptions
pageviewAutoPage navigation and route changes
interactionAutoClick events and form submissions

Batching and Delivery

The SDK batches log entries to minimize network requests. By default, logs are sent when either condition is met:

  • Batch size threshold: 10 log entries accumulated
  • Time interval: 5 seconds since last flush
TypeScript
Apperio.init({
  projectId: class="syntax-string">"my-project",
  apiKey: class="syntax-string">"my-key",
  batchSize: class="syntax-number">20,        class="syntax-comment">// Send when class="syntax-number">20 logs accumulate
  flushInterval: class="syntax-number">10000, class="syntax-comment">// Or every class="syntax-number">10 seconds
});

The SDK also implements retry logic with exponential backoff. Failed requests are retried up to 3 times with increasing delay between attempts.

SDK Lifecycle

The SDK provides lifecycle methods for proper initialization and cleanup:

TypeScript
class="syntax-comment">// Initialize - call once at app startup
Apperio.init({ projectId: class="syntax-string">"...", apiKey: class="syntax-string">"..." });

class="syntax-comment">// The SDK is now active and capturing events.

class="syntax-comment">// Flush - manually send all buffered logs
await Apperio.flush();

class="syntax-comment">// Destroy - clean up listeners and send remaining logs
Apperio.destroy();

Tip

Call Apperio.flush() before critical navigation events (like page unload) to ensure all buffered logs are sent. The SDK attempts to flush automatically on beforeunload, but this is not guaranteed by all browsers.