一键导入
observability
Use when adding logging, metrics, tracing, or error tracking to Go, Python, or React applications — structured observability from day one
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Use when adding logging, metrics, tracing, or error tracking to Go, Python, or React applications — structured observability from day one
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Use when the user wants to free disk space, investigate disk usage, clean caches, remove unused artifacts, or when disk capacity is high. Also use when asked to "clean up", "free space", "disk full", or "what's using disk space". Always uses AskUserQuestion for every deletion decision.
Use at the start of every conversation and for every user message — orchestrates the full engineering skills suite by understanding intent, clarifying requirements interactively, and invoking the right skills
Use when refactoring Go code, cleaning up legacy codebases, optimizing performance, or enforcing clean architecture boundaries in a Go/Fiber backend
Use when refactoring Python code, cleaning up legacy codebases, optimizing performance, enforcing type safety, or improving clean architecture in a FastAPI backend
Use when refactoring React components, cleaning up legacy frontends, optimizing performance, improving component architecture, or reducing bundle size
Use when reviewing changed code before committing or after completing a feature — checks performance, architecture, type safety, and code quality against project standards
| name | observability |
| description | Use when adding logging, metrics, tracing, or error tracking to Go, Python, or React applications — structured observability from day one |
Structured logging, distributed tracing, metrics, and error tracking. Without observability, you're debugging in the dark.
Core principle: If it's not logged, traced, and measured, it doesn't exist in production.
Never use unstructured log messages. Always key-value pairs.
Go (slog — standard library):
import "log/slog"
// Setup (in main.go)
logger := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
Level: slog.LevelInfo,
}))
slog.SetDefault(logger)
// Usage
slog.Info("user created",
"user_id", user.ID,
"email", user.Email,
"org_id", orgID,
)
slog.Error("failed to create user",
"error", err,
"email", input.Email,
)
// With request context (middleware injects request_id)
slog.InfoContext(ctx, "processing request",
"request_id", middleware.GetRequestID(ctx),
"method", c.Method(),
"path", c.Path(),
)
Python (structlog):
import structlog
# Setup
structlog.configure(
processors=[
structlog.processors.TimeStamper(fmt="iso"),
structlog.processors.JSONRenderer(),
],
)
logger = structlog.get_logger()
# Usage
logger.info("user_created", user_id=str(user.id), email=user.email)
logger.error("user_creation_failed", error=str(err), email=input.email)
# With request context (bind request_id in middleware)
logger = logger.bind(request_id=request_id)
logger.info("processing_request", method=request.method, path=request.url.path)
Logging rules:
Log levels:
| Level | When |
|---|---|
ERROR | Operation failed, needs attention |
WARN | Unexpected but handled (retry succeeded, fallback used) |
INFO | Business events, request lifecycle |
DEBUG | Detailed debugging info (disabled in prod) |
Go:
import (
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/trace"
)
// Create span for a unit of work
tracer := otel.Tracer("service-name")
func (uc *CreateUserUseCase) Execute(ctx context.Context, input CreateUserInput) (*User, error) {
ctx, span := tracer.Start(ctx, "CreateUser")
defer span.End()
span.SetAttributes(
attribute.String("user.email", input.Email),
)
user, err := uc.repo.Create(ctx, input)
if err != nil {
span.RecordError(err)
span.SetStatus(codes.Error, err.Error())
return nil, err
}
return user, nil
}
Fiber middleware:
import fiberotel "github.com/gofiber/contrib/v3/otel"
app.Use(fiberotel.Middleware())
Python (FastAPI):
from opentelemetry import trace
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
tracer = trace.get_tracer("service-name")
# Auto-instrument FastAPI
FastAPIInstrumentor.instrument_app(app)
# Manual spans for business logic
async def create_user(self, input: CreateUserInput) -> User:
with tracer.start_as_current_span("CreateUser") as span:
span.set_attribute("user.email", input.email)
try:
return await self._repo.create(input)
except Exception as e:
span.record_exception(e)
raise
What to trace:
Go:
import "github.com/prometheus/client_golang/prometheus"
var (
httpRequestsTotal = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "http_requests_total",
Help: "Total HTTP requests",
},
[]string{"method", "path", "status"},
)
httpRequestDuration = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Name: "http_request_duration_seconds",
Help: "HTTP request duration",
Buckets: prometheus.DefBuckets,
},
[]string{"method", "path"},
)
)
Key metrics to track:
| Metric | Type | What |
|---|---|---|
http_requests_total | Counter | Request count by method, path, status |
http_request_duration_seconds | Histogram | Latency distribution |
db_query_duration_seconds | Histogram | Database query time |
db_connections_active | Gauge | Connection pool usage |
business_events_total | Counter | Domain events (signups, payments) |
errors_total | Counter | Errors by type |
Expose metrics endpoint:
// Go: /metrics endpoint
import "github.com/prometheus/client_golang/prometheus/promhttp"
app.Get("/metrics", adaptor.HTTPHandler(promhttp.Handler()))
// Go
import "github.com/getsentry/sentry-go"
sentry.Init(sentry.ClientOptions{
Dsn: os.Getenv("SENTRY_DSN"),
TracesSampleRate: 0.1,
Environment: os.Getenv("APP_ENV"),
})
// In error handler middleware
sentry.CaptureException(err)
# Python
import sentry_sdk
from sentry_sdk.integrations.fastapi import FastApiIntegration
sentry_sdk.init(
dsn=os.getenv("SENTRY_DSN"),
traces_sample_rate=0.1,
integrations=[FastApiIntegration()],
)
React:
import * as Sentry from '@sentry/react'
Sentry.init({
dsn: import.meta.env.VITE_SENTRY_DSN,
integrations: [Sentry.browserTracingIntegration()],
tracesSampleRate: 0.1,
})
// Wrap app
<Sentry.ErrorBoundary fallback={<ErrorPage />}>
<App />
</Sentry.ErrorBoundary>
Every service must expose a health endpoint that checks all dependencies:
// GET /health
{
"status": "ok", // or "degraded" or "error"
"database": "connected",
"redis": "connected",
"version": "1.2.3",
"uptime": "24h30m"
}
/metrics)claude-md)go-scaffold or py-scaffolddebug skill uses these signals for investigation