Skip to content

feat(export): introduce LogExporter interface #139

Description

@brucearctor

Summary

Refactor sendLogs.ts into a pluggable LogExporter interface. This is the architectural keystone for OTLP support and custom export targets.

Motivation

Currently sendLogs.ts tightly couples batch management, transport (XHR/fetch/sendBeacon), and auth header construction. This makes it impossible to add new output formats (OTLP, custom backends) without duplicating the batch logic.

Proposed Interface

interface LogExporter {
  export(logs: Logging.Log[]): Promise<ExportResult>;
  flush(): Promise<void>;
  shutdown(): Promise<void>;
}

Implementation

  • src/exporters/types.ts — LogExporter interface
  • src/exporters/http-json.ts — Extract current sendLogs behavior (default)
  • src/exporters/websocket.ts — Extract current WebSocket behavior
  • src/exporters/index.ts — Factory: config → exporter
  • src/sendLogs.ts — Simplified to batch manager + exporter.export()

Config Changes

exporterType?: 'http-json' | 'otlp' | 'websocket' | 'custom';
exporter?: LogExporter;  // for custom exporters

Backward Compatibility

Existing users who set url: 'https://my-server/logs' must work identically. HttpJsonExporter is the default. No config change needed.

Depends On

Metadata

Metadata

Assignees

No one assigned

    Labels

    UseralePull requests that update Userale codeenhancement

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions