Skip to content

Add structured logging infrastructure: replace all console.* calls with levelled, module-scoped Logger#45

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/feature-add-observability-infrastructure
Draft

Add structured logging infrastructure: replace all console.* calls with levelled, module-scoped Logger#45
Copilot wants to merge 3 commits intomainfrom
copilot/feature-add-observability-infrastructure

Conversation

Copy link

Copilot AI commented Mar 17, 2026

The extension had no observability — 99+ raw console.* calls scattered across 14 files with no levels, timestamps, context, or ability to suppress in production.

New: src/utils/logger.ts

A lightweight structured logger with no external dependencies:

import { createLogger } from '@/utils/logger';
const logger = createLogger('UploadService');

logger.debug('Asset already queued', { assetId: asset.id });   // suppressed in prod
logger.info('Upload successful', { assetId, resultId });
logger.warn('Insufficient balance detected, pausing uploads');
logger.error('Failed to restore upload queue', error);
  • LogLevel enum: DEBUG=0 | INFO=1 | WARN=2 | ERROR=3
  • Default level: DEBUG in dev (import.meta.env.DEV), INFO in production builds — debug noise is silenced without code changes
  • Every entry: [ISO timestamp] [LEVEL] [Module] message {context} error
  • error(msg, error?, context?) accepts an optional error object as a distinct second arg

Replaced across 12 source files

File Calls replaced
src/background/service-worker.ts ~40
src/services/UploadService.ts ~15
src/services/NumbersApiManager.ts 4
src/services/AuthService.ts 1
src/offscreen/offscreen.ts 3
src/services/ScreenshotService.ts 2
src/popup/popup.tsx 9
src/popup/AuthForm.tsx 2
src/options/options.tsx 2
src/share/share.tsx 1
src/config/environment.ts 1 (lazy import to avoid circular dep)

Additional: unhandled rejection capture

service-worker.ts now registers a self.addEventListener('unhandledrejection', ...) handler so silent async failures in the service worker are surfaced via logger.error rather than disappearing silently.

Original prompt

This section details on the original issue you should resolve

<issue_title>[Feature][High] Add observability infrastructure: structured logging, error reporting, and performance telemetry</issue_title>
<issue_description>## Summary

The extension has zero observability — no structured logging, no error reporting service, no performance telemetry, and no usage metrics. All 99 console statements use raw console.log/warn/error with no log levels, filtering, remote reporting, or ability to disable in production. This makes it impossible to diagnose user-reported issues, measure upload success rates, or detect regressions.

Evidence

No structured logging framework

All logging is via raw console.* calls scattered across the codebase:

  • src/background/service-worker.ts — 30+ console statements
  • src/services/UploadService.ts — 15+ console statements
  • src/services/AuthService.ts — 10+ console statements
  • src/popup/popup.tsx — 10+ console statements

Example (service-worker.ts):

console.log('Message received:', message.type, message.payload);
console.error('Screenshot capture error:', error);

No log levels, no timestamps, no context enrichment, no filtering.

No error reporting service

  • No Sentry, Bugsnag, or similar integration
  • Extension errors are only visible in browser DevTools
  • Users cannot easily share error context
  • No automated alerting on error spikes

Missing performance metrics

No measurement of critical paths:

  • Screenshot capture latency
  • Watermark processing time
  • Upload queue depth and processing speed
  • API response times
  • IndexedDB read/write latency
  • Service worker wake-up time

No usage analytics

  • Cannot measure feature adoption (visible capture vs selection mode vs Hunt Mode)
  • No upload success/failure rate tracking
  • No auth flow completion metrics

Proposed Implementation

1. Structured Logger Module (src/utils/logger.ts)

enum LogLevel { DEBUG, INFO, WARN, ERROR }

class Logger {
  constructor(private module: string) {}
  debug(msg: string, context?: Record<string, unknown>) { ... }
  info(msg: string, context?: Record<string, unknown>) { ... }
  warn(msg: string, context?: Record<string, unknown>) { ... }
  error(msg: string, error?: Error, context?: Record<string, unknown>) { ... }
}
  • Configurable log level per environment (debug in dev, warn in prod)
  • Context enrichment (module name, timestamp, session ID)
  • Replace all 99 console.* calls

2. Error Reporting Integration

  • Integrate lightweight error reporter (e.g., Sentry browser SDK or custom endpoint)
  • Capture unhandled promise rejections in service worker
  • Include breadcrumb trail of recent actions before error

3. Performance Timing

  • Use performance.mark() / performance.measure() for critical paths
  • Track: capture→watermark→store→upload pipeline latency
  • Store metrics locally, optionally report to backend

4. Feature Usage Metrics (privacy-preserving)

  • Count events locally: captures, uploads, auth events
  • No PII collection
  • Optional opt-in remote reporting

Impact

  • Enables data-driven debugging of user-reported issues
  • Provides visibility into upload reliability and performance
  • Supports informed prioritization of performance improvements
  • Essential foundation before scaling user base

Files to modify

  • New: src/utils/logger.ts
  • All files with console.* calls (~17 files)
  • src/background/service-worker.ts (add unhandled rejection handler)
  • package.json (add error reporting dependency if chosen)</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits March 17, 2026 12:18
…nsole.* calls

Co-authored-by: numbers-official <181934381+numbers-official@users.noreply.github.com>
… to dynamic import

Co-authored-by: numbers-official <181934381+numbers-official@users.noreply.github.com>
Copilot AI changed the title [WIP] [Feature] Add observability infrastructure for logging and reporting Add structured logging infrastructure: replace all console.* calls with levelled, module-scoped Logger Mar 17, 2026
Copilot AI requested a review from numbers-official March 17, 2026 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature][High] Add observability infrastructure: structured logging, error reporting, and performance telemetry

2 participants