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
Summary
Refactor
sendLogs.tsinto a pluggableLogExporterinterface. This is the architectural keystone for OTLP support and custom export targets.Motivation
Currently
sendLogs.tstightly 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
Implementation
src/exporters/types.ts— LogExporter interfacesrc/exporters/http-json.ts— Extract current sendLogs behavior (default)src/exporters/websocket.ts— Extract current WebSocket behaviorsrc/exporters/index.ts— Factory: config → exportersrc/sendLogs.ts— Simplified to batch manager + exporter.export()Config Changes
Backward Compatibility
Existing users who set
url: 'https://my-server/logs'must work identically.HttpJsonExporteris the default. No config change needed.Depends On