Feature Flag Service Tutorial · Module 07 of 10

Observability & Monitoring

Instrument the service with structured logging, Prometheus metrics, and distributed tracing. Build Grafana dashboards showing evaluation rate, cache hit rate, rule matching patterns, and flag usage. By the end, you have full visibility into flag behavior.

~4–5 hrsAdvancedObservability focus
← Back to Module 07 overview
What You'll Have at the End

Definition of Done

  • Structured JSON logging with trace IDs and context.
  • Prometheus metrics: evaluation_total, cache_hit_rate, evaluation_latency, rule_matches, flag_updates.
  • OpenTelemetry traces for flag evaluation requests.
  • Grafana dashboard: evaluation throughput, cache performance, rule distribution.
  • Can answer: "Which flags are used most?" "What's the cache hit rate?" "How long does evaluation take?"
  • Audit events logged for all flag changes with user context.
The Steps

Build It

STEP 1

Add structured logging

Install: npm install pino pino-pretty

Create src/logger.ts:

import pino from 'pino';

const logger = pino({
  level: process.env.LOG_LEVEL || 'info',
  transport: {
    target: 'pino-pretty',
    options: { colorize: true, translateTime: 'SYS:standard' }
  }
});

export default logger;