Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 18, 2025

Implements Prometheus metrics exporter and Winston structured logging for the web app, matching the bot's existing observability infrastructure.

Changes

Metrics Infrastructure

  • Created MetricsManager, MetricRegistry, and Prometheus exporter following bot's pattern
  • Added /api/metrics endpoint exposing Prometheus-formatted metrics
  • Metrics tracked: HTTP requests, API requests, database operations, application errors
  • Includes default Node.js runtime metrics (heap, GC, event loop)

Logging Infrastructure

  • Integrated Winston with configurable log levels (error/warn/info/verbose/debug)
  • Forwarded Prisma client logs to Winston
  • Added withMetricsAndLogging() wrapper for automatic API route instrumentation

Edge Runtime Compatibility

  • Metrics/logging require Node.js runtime APIs
  • API routes using observability explicitly declare export const runtime = 'nodejs'
  • Middleware simplified to basic console logging (runs in Edge Runtime)

Usage

// API route with automatic logging and metrics
import { withMetricsAndLogging } from '@/app/lib/middleware/withMetricsAndLogging';
import { getLogger } from '@/app/lib/logging/logger';

const logger = getLogger('api/users');
export const runtime = 'nodejs';

async function handler(req: NextRequest) {
    logger.debug('Fetching users');
    const users = await client.user.findMany({ take: 10 });
    logger.info(`Retrieved ${users.length} users`);
    return NextResponse.json({ users });
}

export const GET = withMetricsAndLogging(handler, 'users');

Dependencies

Added: winston, winston-transport, prom-client

Documentation

See web/docs/METRICS_AND_LOGGING.md for complete usage guide and metric definitions.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • fonts.googleapis.com
    • Triggering command: /usr/local/bin/node node /home/REDACTED/work/Monorepo/Monorepo/node_modules/.bin/next build (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

For the webapp, please add a Prometheus exporter, similar to how it's implemented in the bot. Also, add tracking for common events (add a middleware or something to track events), and expose an endpoint at /metrics to get the formatted metrics. In addition, migrate all logging to use Winston, similar to the bot as well.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits December 18, 2025 18:10
Co-authored-by: AlphaGameDeveloper <77273893+AlphaGameDeveloper@users.noreply.github.com>
Co-authored-by: AlphaGameDeveloper <77273893+AlphaGameDeveloper@users.noreply.github.com>
Co-authored-by: AlphaGameDeveloper <77273893+AlphaGameDeveloper@users.noreply.github.com>
Copilot AI changed the title [WIP] Add Prometheus exporter and migrate logging to Winston Add Prometheus metrics and Winston logging to web application Dec 18, 2025
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.

2 participants