@yuno-payments/sdk-event-log
v1.12.0
Published
Register application logs and events
Maintainers
Keywords
Readme
@yuno-payments/sdk-event-log
SDK library for registering application logs, events, and metrics from Yuno's frontend SDKs.
Installation
npm install @yuno-payments/sdk-event-logPeer dependency: axios ^1.13.6
Usage
import { EventLog } from '@yuno-payments/sdk-event-log'
const eventLog = new EventLog({
organizationName: 'my-org',
publicApiKey: 'your-public-api-key',
enableEvents: true,
enableLogs: true,
enableCron: true,
batchTime: 5000,
})Events
eventLog.event({
source: 'checkout',
event: 'payment_started',
description: 'User started payment flow',
original_created_at: new Date().toISOString(),
sdk_version: '1.0.0',
application_name: 'checkout-sdk',
application_session: 'session-123',
environment: 'production',
})Logs
eventLog.logger.info({
original_created_at: new Date().toISOString(),
sdk_version: '1.0.0',
application_name: 'checkout-sdk',
application_session: 'session-123',
environment: 'production',
step_name: 'payment',
step_function: 'submitPayment',
step_location: 'checkout.ts',
})
eventLog.logger.error({ /* same shape */ })
eventLog.logger.debug({ /* same shape */ })Metrics
eventLog.setMetric({
environment: 'production',
dynamic_sdk: false,
original_created_at: new Date().toISOString(),
original_created_at_ms: Date.now(),
flow_trace_id: 'trace-abc',
sdk_version: '1.0.0',
type: 'performance',
metadata: {
public_api_key: 'your-key',
},
payload: { loadTime: 1200 },
})Manual batch send
await eventLog.sendBatch() // Send queued logs/events
await eventLog.sendMetricBatch() // Send queued metricsRuntime configuration
eventLog.setConfig({
enableEvents: true,
enableLogs: false,
enableCron: true,
batchTime: 10000,
maxBatchQueued: 50,
})Constructor options
| Option | Type | Default | Description |
|---|---|---|---|
| organizationName | string | required | Organization identifier |
| publicApiKey | string | required | Public API key for authentication |
| enableEvents | boolean | true | Enable event tracking |
| enableLogs | boolean | true | Enable log tracking |
| enableCron | boolean | undefined | Enable automatic batch sending |
| batchTime | number | undefined | Interval (ms) for cron batch sends |
| maxBatchQueued | number | 30 | Max items before auto-flush |
| platform | string | 'Web' | Platform identifier |
| language | string | undefined | Accept-Language header value |
| country | string | undefined | Country code |
| xVersion | string | undefined | SDK version header |
| workflow | string | 'SDK_CHECKOUT' | Workflow identifier |
| cookieName | string | 'yuno' | Cookie name for device ID |
| deviceId | string | auto-generated | Override device ID |
| clientAppDomain | string | undefined | Override client app domain |
| enableMetrics | boolean | false | Enable metrics collection |
| debug | boolean | false | Enable console debug output |
Storage
Events are queued locally before being sent in batches:
- Browser: Uses
localStorage(key:YUNO_EVENT_LOGS_{orgName}) - Non-browser: Uses in-memory storage
Both storages cap at 200 items to prevent unbounded growth.
Development
npm test # Run tests
npm run test:dev # Run tests in watch mode
npm run build # Test + clean + build (CJS + ESM)Local testing with npm link
# In this repo
npm run build && npm link
# In the consuming project
npm link @yuno-payments/sdk-event-log