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.
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.
| Level | Value | Use Case |
|---|---|---|
trace | 0 | Finest-grained diagnostic info, function entry/exit |
debug | 1 | Detailed diagnostic data useful during development |
info | 2 | General operational events, successful operations |
warn | 3 | Unexpected events that are not errors but need attention |
error | 4 | Error events that should be investigated |
fatal | 5 | Critical failures requiring immediate action |
Info
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.
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
Event Types
Each log entry can be tagged with an event type for categorization and filtering in the dashboard:
| Event Type | Source | Description |
|---|---|---|
error | Auto / Manual | JavaScript errors, unhandled rejections |
performance | Auto | Core Web Vitals, page load metrics |
network | Auto | XHR and Fetch request/response tracking |
console | Auto | Console.log, warn, error interceptions |
pageview | Auto | Page navigation and route changes |
interaction | Auto | Click 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
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:
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
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.