Observability

From WrongStack/WrongStack · View interactive version

Observability is an AI agent skill from the GitHub repository WrongStack/WrongStack. Logging, metrics and tracing with OpenTelemetry: structured logs, correlation ids, spans, alerts, and undiagnosable production bugs. Use this skill when adding or reviewing logging, metrics, or tracing in an application, or when a production problem can't be diagnosed from the signals that exist tod

How to use this skill

Skill file

Observability

Selection card

Overview

Instrument so that the next incident can be answered from telemetry instead of

by adding logs and redeploying. Work with what the project already has — its

logger (pino, winston, structlog, slog, log/zap), metrics client, and any

OpenTelemetry setup. Adding a second logging stack is almost always wrong.

Rules

  1. Use the project's existing logger and conventions; find how a neighbouring

module logs before adding a line.

  1. Log structured events, not sentences: a stable event name plus fields

(logger.info({ orderId, durationMs }, 'order.charged')), so logs can be

filtered and aggregated.

  1. Levels mean something: error needs a human, warn is degraded but

handled, info is a meaningful business or lifecycle event, debug is

off in production.

  1. Correlate: carry a request or trace id through async boundaries

(OpenTelemetry context or AsyncLocalStorage) and attach it to every log line.

  1. Never log secrets, tokens, credentials, or personal data. Configure redaction

once in the logger (for example pino redact paths), not per call site.

  1. Log an error once, where it is handled, with the error object and context —

not at every layer it passes through.

  1. Metrics use bounded label values. User ids, raw URLs, and error messages as

labels explode cardinality; use route templates and error classes.

  1. Trace the I/O: spans around outbound HTTP, database, queue, and cache calls,

with status recorded on failure. Prefer auto-instrumentation where it exists.

What to instrument

| Signal | For | Examples |

|---|---|---|

| Logs | What happened to one request or job | payment.failed with order id, provider code, attempt |

| Metrics | How the system behaves in aggregate | Request rate, error rate, latency histogram per route (RED); queue depth, pool saturation (USE) |

| Traces | Where the time went across calls | Span per inbound request and per outbound dependency |

Start from the question an on-call engineer will ask — "why did checkout fail

for this customer?", "which dependency made p99 spike?" — and make sure the

answer is recorded.

Patterns

// Redaction configured once, at the logger.
const logger = pino({
  level: process.env.LOG_LEVEL ?? 'info',
  redact: ['req.headers.authorization', 'req.headers.cookie', '*.password', '*.token'],
});

// One structured event, with correlation and the error object.
try {
  await chargeCard(order);
  logger.info({ orderId: order.id, durationMs: Date.now() - started }, 'order.charged');
} catch (err) {
  logger.error({ err, orderId: order.id, traceId: currentTraceId() }, 'order.charge_failed');
  throw new PaymentError('charge failed', { cause: err });
}
// A span around an outbound dependency.
const tracer = trace.getTracer('checkout');

export async function reserveStock(sku: string, qty: number): Promise<void> {
  await tracer.startActiveSpan('inventory.reserve', async (span) => {
    span.setAttributes({ 'inventory.sku': sku, 'inventory.qty': qty });
    try {
      await inventoryClient.reserve(sku, qty);
    } catch (err) {
      span.recordException(err as Error);
      span.setStatus({ code: SpanStatusCode.ERROR });
      throw err;
    } finally {
      span.end();
    }
  });
}

Anti-patterns

latency, not on CPU.

Before returning

Trace continuity and shutdown

Verify context propagation across queues, callbacks and detached tasks rather

than assuming an id on the inbound log reaches every span. Trace links may

represent asynchronous causality better than a false parent-child relation.

Bound exporter buffers and shutdown flush; telemetry failure must not create

unbounded work or silently break the primary task. Record sampling and missing

signals when interpreting incident counts or latency distributions.

Skills in scope

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.