[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6D1PADSCGP1S8SCT58W7S0M":3,"skill-same:01M6D1PADSCGP1S8SCT58W7S0M":67},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":39,"linkOnly":40,"markdownContent":41,"markdownBody":42,"frontMatter":43,"refName":44,"commitSha":45,"skillDirectory":46,"forksCount":47,"repositoryHtmlUrl":48,"repositoryHomepageUrl":49,"ownerHtmlUrl":50,"ownerBlogUrl":49,"ownerDescription":51,"updatedAt":52,"install":53,"resources":66},"01M6D1PADSCGP1S8SCT58W7S0M","backend-observability",null,"Running a backend: configuration read and checked at start, structured logs with request and trace ids, log levels, OpenTelemetry traces and metrics per stack, RED metrics, health and readiness checks, graceful shutdown with timings, timeouts, feature flags, and error tracking with Sentry. Read when starting a service, adding config, logs, metrics or tracing, or making one easier to run and debug.","enowdev\u002Fenowxcli","enowdev","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F179420349?v=4","01M6D1MVX2KC0X3Z9NESE7P22K","Enow Dev.","01M6D1MW1FMZGBDKWAJY4GQX81",67,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Fenowdev\u002Fenowxcli\u002Fblob\u002Fmain\u002Fcrates\u002Fenowx-core\u002Fskills\u002Fbackend-observability\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38],"backend observability","observability","backend","ids","feature","flags","error tracking","shutdown","log","read","stack","config","OpenTelemetry","start","logs","tracing","metrics","sentry","run","debug","2026-11-10 10:12:30",false,"---\nname: backend-observability\ndescription: \"Running a backend: configuration read and checked at start, structured logs with request and trace ids, log levels, OpenTelemetry traces and metrics per stack, RED metrics, health and readiness checks, graceful shutdown with timings, timeouts, feature flags, and error tracking with Sentry. Read when starting a service, adding config, logs, metrics or tracing, or making one easier to run and debug.\"\n---\n\n# Running it\n\nThe generated service reads `process.env` in twenty files, logs with\n`console.log` and the raw URL, answers `\u002Fhealth` by querying every\ndependency, drops requests in flight on every deploy, and gives no way to\ntell one request's lines from another's. One part of the backend; the whole\nis in the `backend` skill, and the pipeline behind it (collector, dashboards,\nSLOs, alerts) is in `devops-observability`. This is what the service itself\ndoes so it can be configured, found, debugged and replaced safely.\n\n## 1. Configuration\n\n- Read every setting from the environment once, at start, in one module,\n  checked with a schema: types parsed, required values present, URLs valid.\n  A missing or malformed value stops the process at start with a message\n  naming it (the name, never the value), not a crash on the first request\n  that needs it.\n- The rest of the code imports that module; nothing else reads\n  `process.env` or `os.environ` (and in Laravel, `env()` is called only in\n  `config\u002F`).\n- `.env.example` lists every variable with a comment and a safe example;\n  defaults only for values that are safe everywhere (a port, a log level),\n  never for secrets.\n- Secrets typed so they cannot be printed: pydantic `SecretStr`, Rust\n  `secrecy::SecretString`, a Go type with a `LogValue` method returning\n  `[redacted]`. Config is read-only after start; changing it is a restart,\n  and a switch that must change at runtime is a feature flag (section 9).\n\n| Stack | Checked at start with |\n|---|---|\n| Node, Next.js | zod (`z.object(...).safeParse(process.env)`), or `@t3-oss\u002Fenv-core` \u002F `env-nextjs` |\n| Python | pydantic-settings (`BaseSettings`) |\n| Go | `caarlos0\u002Fenv` or `sethvargo\u002Fgo-envconfig` (`kelseyhightower\u002Fenvconfig` works but is unmaintained since 2019); koanf when files and env are layered |\n| Rust | figment or the `config` crate into a serde struct |\n| Laravel | `config\u002F*.php`, `php artisan config:cache` in production |\n| Java, .NET | `@ConfigurationProperties` with `@Validated` (`backend-stack-java`); options with `ValidateOnStart()` (`backend-stack-dotnet`) |\n\n```ts\nconst parsed = Env.safeParse(process.env); \u002F\u002F Env: a z.object of every variable\nif (!parsed.success) {\n  const names = parsed.error.issues.map((i) => i.path.join(\".\"));\n  console.error(`Invalid or missing environment variables: ${names.join(\", \")}`);\n  process.exit(1);\n}\nexport const config = parsed.data;\n```\n\n## 2. Logs\n\n- Structured (JSON in production, readable in development) through the\n  project's logger, never bare `console.log` or `print`, to stdout for the\n  platform to collect (no log files or rotation code in a container).\n\n| Stack | Logger |\n|---|---|\n| Node | pino (Fastify's built-in one; `pino-pretty` only in development) |\n| Python | structlog, or `logging` with a JSON formatter |\n| Go | `log\u002Fslog` with `slog.NewJSONHandler` |\n| Rust | `tracing` with `tracing-subscriber`'s JSON output |\n| Laravel | Monolog: `LOG_CHANNEL=stderr`, `LOG_STDERR_FORMATTER=Monolog\\Formatter\\JsonFormatter` |\n| Java, .NET | Logback JSON via Boot's structured logging; Serilog or the JSON console logger |\n\n- One line per request at the end: method, route pattern (not the raw URL\n  with ids and tokens), status, duration, request id, user id. Plus a line\n  for each decision worth finding later (a payment captured, a job failed),\n  not for every step.\n- Levels mean something: `error` needs someone to look, `warn` is unusual\n  but handled, `info` is the story of normal work, `debug` is off in\n  production and switchable without a redeploy (`LOG_LEVEL`). A client's\n  `4xx` is `info` or `warn`; an error is logged once, where it is handled\n  (`backend-errors`).\n- Never passwords, tokens, keys, card numbers, cookies, `Authorization`\n  headers or whole personal records (`backend-security`). Redact in the\n  logger (pino `redact`, a structlog processor, slog `ReplaceAttr`), and keep\n  exception locals out: structlog's default `dict_tracebacks` prints them;\n  use `ExceptionRenderer(ExceptionDictTransformer(show_locals=False))`.\n- An audit trail (who changed which record, when, from what to what) is\n  data: a table written in the same transaction, not log lines that expire.\n\n## 3. Request ids and trace context\n\n- A request id on every line of a request: taken from `X-Request-Id` when a\n  trusted proxy sets it, generated otherwise, returned in the response, and\n  passed on to jobs and outbound calls.\n- With tracing, W3C trace context is the correlation:\n  `traceparent: 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01`\n  (version, 32-hex trace id, 16-hex parent span id, flags). Every log line\n  carries `trace_id` and `span_id` through the logger's OpenTelemetry\n  integration; `X-Request-Id` stays for people quoting it. Continue trace\n  context from your own services; at the public edge, start a fresh trace.\n- Carry the ids in the request's context, not in arguments: Node\n  `AsyncLocalStorage` with a pino `mixin`, `structlog.contextvars`, Go\n  `context.Context`, Rust `tracing` spans, Laravel `Context::add()` (which\n  lands in every log record and travels into queued jobs by itself).\n- Across a queue, the producer puts the request id and trace context in the\n  job's metadata and the worker restores them before it logs.\n\n## 4. Traces with OpenTelemetry\n\nAdd a telemetry vendor only when the project has one or the task asks; say\nin the report where it would help. When it is there, configure it by the\nstandard `OTEL_*` variables (`devops-observability`), not values in code,\nand start the SDK before any instrumented module loads, or nothing is patched.\n\n| Stack | Setup |\n|---|---|\n| Node | `@opentelemetry\u002Fsdk-node` with `@opentelemetry\u002Fauto-instrumentations-node`, loaded by `node --import .\u002Fdist\u002Finstrumentation.js dist\u002Findex.js`; route names from `@hono\u002Fotel` or `@fastify\u002Fotel` |\n| Next.js | `instrumentation.ts` exporting `register()` that calls `registerOTel(\"app\")` from `@vercel\u002Fotel` |\n| Python | `opentelemetry-distro`, `opentelemetry-bootstrap -a install`, run under `opentelemetry-instrument uvicorn app.main:app`; under gunicorn, start the SDK in the `post_fork` hook |\n| Go | `otelhttp.NewHandler(mux, \"api\")`, `otelpgx.NewTracer()` on the pool config, a `TracerProvider` with a batcher, `propagation.TraceContext{}` |\n| Rust | `tracing` spans exported through `tracing-opentelemetry` and `opentelemetry-otlp`, versions that match each other |\n| Laravel | OpenTelemetry's PHP SDK with its Laravel auto-instrumentation, or the vendor's agent |\n\n```ts\n\u002F\u002F src\u002Finstrumentation.ts\nimport { register } from \"node:module\";\nimport { NodeSDK } from \"@opentelemetry\u002Fsdk-node\";\nimport { getNodeAutoInstrumentations } from \"@opentelemetry\u002Fauto-instrumentations-node\";\n\n\u002F\u002F ES modules need the loader hook, or pg, ioredis and the rest are not patched.\nregister(\"@opentelemetry\u002Finstrumentation\u002Fhook.mjs\", import.meta.url);\n\nexport const sdk = new NodeSDK({ \u002F\u002F exporters come from the OTEL_* variables\n  instrumentations: [\n    getNodeAutoInstrumentations({ \"@opentelemetry\u002Finstrumentation-fs\": { enabled: false } }),\n  ],\n});\nsdk.start();\n```\n\n- Auto-instrumentation covers inbound and outbound HTTP, database drivers,\n  Redis and most queues. Add a manual span only around work worth timing on\n  its own (pricing a basket, rendering a PDF); attributes are ids and\n  counts, never personal data or secrets; span names stay low-cardinality\n  (`POST \u002Forders\u002F{id}\u002Frefunds`).\n- Exporters batch: call `shutdown()` on the way out (section 7) or the last\n  seconds of spans are lost.\n\n## 5. Metrics\n\n- RED per route: rate, errors, duration as a histogram\n  (`http.server.request.duration` in seconds, with `http.request.method`,\n  `http.route` and `http.response.status_code`). HTTP auto-instrumentation\n  or the framework's metrics usually give these for free.\n- USE for what the service holds: pool connections in use, idle and\n  waiting, and acquire time; queue depth and the age of the oldest job;\n  Node's event loop delay (`perf_hooks.monitorEventLoopDelay`), Go's\n  goroutines, GC pauses; duration and errors per outbound dependency.\n- A few business counters that show breakage (orders placed, payments\n  failed, sign-ups). Labels stay low-cardinality: the route template, the\n  method, the status; never user ids, raw paths, emails or error messages.\n- Pushed over OTLP or scraped from `\u002Fmetrics` on an internal port, as the\n  platform does it; never on the public listener. Dashboards, SLOs and\n  alerts: `devops-observability`. Profiling: `performance-profiling`.\n\n## 6. Health\n\n| Endpoint | Answers | Checks | When it fails |\n|---|---|---|---|\n| `GET \u002Fhealthz` (liveness) | `200` while the process can serve at all | nothing outside the process | the platform restarts the instance |\n| `GET \u002Freadyz` (readiness) | `200`, or `503` while any need is down | what a request needs: `SELECT 1` on the database, the cache, with a short timeout | traffic stops going to this instance |\n| startup (optional) | `200` once warmed up | caches loaded, migrations present | liveness waits instead of killing a slow start |\n\n- Neither needs auth, and neither says anything secret: at most\n  `{\"status\":\"ok\",\"checks\":{\"db\":\"ok\"}}` and the release. Checks finish inside\n  the probe's timeout (Kubernetes defaults: 1 second, every 10 seconds, 3\n  failures), a few hundred milliseconds per dependency.\n- Liveness never touches the database: a database blip would restart every\n  instance at once. Readiness never checks a third-party API: its outage\n  would take every instance out of rotation; that failure is a `503` per\n  request (`backend-integrations`).\n- Use the framework's own where it has one: Laravel's `\u002Fup`, Spring\n  Actuator's probes, ASP.NET Core `MapHealthChecks`.\n\n## 7. Starting and stopping\n\n- On start: config checked, logger, telemetry, pools created and checked,\n  routes, then listen. Migrations are applied by a separate step (a release\n  command, a job), not by every instance racing at boot.\n- The process is PID 1 or receives signals from it: `CMD [\"node\",\n  \"dist\u002Findex.js\"]` in exec form, not `npm start` or a shell-form command,\n  which may not pass `SIGTERM` on; or `tini` (`docker run --init`).\n\nOn `SIGTERM` (sent on every deploy) and `SIGINT`:\n\n1. Readiness turns `503`, and the process keeps serving for 5 to 10 seconds\n   while the load balancer notices (or a Kubernetes `preStop` sleep).\n2. Stop accepting new connections and close idle keep-alive ones; let\n   requests in flight finish, with a limit of about 10 to 25 seconds.\n3. Stop the workers after their current job; a longer job must be safe to\n   run again (`backend-jobs`).\n4. Flush telemetry and error tracking (`sdk.shutdown()`,\n   `Sentry.close(2000)`).\n5. Close the pools, then exit `0`; exit non-zero if the limit was hit.\n\nThe whole sequence fits inside the platform's grace period: 30 seconds by\ndefault in Kubernetes (`terminationGracePeriodSeconds`), 10 in `docker\nstop`, 10 on Cloud Run.\n\n- Timeouts on the server itself (request and header timeouts, body size\n  limits) as well as on the database and outbound calls. The idle keep-alive\n  timeout is longer than the load balancer's (65 seconds behind an AWS ALB's\n  60), or it reuses a closed connection and reports a `502`.\n\n## 8. Error tracking\n\n- When the project has a tracker, use it: `5xx` and crashes (never a\n  client's `4xx`) with the request id and without personal data.\n- Sentry (or GlitchTip, API-compatible): initialised before the app code\n  (Node: in the file loaded by `--import`), with `release` set to the\n  deployed git SHA, `environment`, `sendDefaultPii: false`\n  (`send_default_pii=False`), a `beforeSend` that scrubs, users by id only,\n  source maps uploaded at build, and `tracesSampleRate` 0.05 to 0.2 when\n  OpenTelemetry already traces.\n- Per stack: `@sentry\u002Fnode` (`setupExpressErrorHandler`,\n  `setupFastifyErrorHandler`), `@sentry\u002Fnextjs`, `sentry-sdk` (FastAPI and\n  Django integrations turn on by themselves), `sentry-go`, the `sentry` crate\n  (keep the guard from `sentry::init` alive for all of `main`),\n  `sentry\u002Fsentry-laravel`.\n- Sentry's SDK and your own OpenTelemetry SDK must not both register a\n  global tracer provider: follow the installed SDK's guide for the pair.\n  Flush on shutdown, or the crash that ended the process is never reported.\n\n## 9. Feature flags\n\n- Code talks to OpenFeature, a vendor-neutral API; the provider (flagd,\n  LaunchDarkly, Unleash, Flagsmith, GrowthBook, ConfigCat, PostHog) is\n  chosen in one place.\n\n```ts\nimport { OpenFeature } from \"@openfeature\u002Fserver-sdk\";\n\nawait OpenFeature.setProviderAndWait(provider); \u002F\u002F at start, in one module\nconst flags = OpenFeature.getClient();\n\n\u002F\u002F The default (false) is what runs when the flag service is unreachable.\nexport const useNewCheckout = (userId: string) =>\n  flags.getBooleanValue(\"new-checkout\", false, { targetingKey: userId });\n```\n\n- Evaluated on the server with a context (user id, tenant), the safe old\n  behaviour as the default, the evaluated variant recorded on the request's\n  span or log line.\n- Each flag has an owner and a removal date and goes within weeks of full\n  rollout; a kill switch in front of each risky dependency; never a flag in\n  place of an authorisation check. Environment variables only for coarse\n  switches changed with a restart.\n\n## Check it\n\n- Start with a required variable missing: the process exits non-zero at\n  once and names it.\n- `curl -si localhost:8080\u002Freadyz` answers `200`; stop the database and it\n  answers `503` within the check timeout while `\u002Fhealthz` stays `200`.\n- One request writes exactly one request line with the route template,\n  status, duration and request id, and the same id is in the response\n  header. Search the logs for a test password, token and email: nothing.\n- `kill -TERM` the process during a slow request: it completes, the log\n  shows the shutdown steps, the exit code is `0`, inside the grace period.\n- With tracing on, one request is one trace with its database spans inside,\n  and its log lines carry the trace id.\n\n## Avoid\n\n`process.env.X` read all over the code; a missing variable found by the\nfirst user who needs it; `console.log` as the logger; logs with the raw URL,\nthe body, a token or exception locals; a health check that queries everything\nand times out; liveness that checks the database; a process that drops\nrequests in flight on every deploy; `npm start` as PID 1; migrations run by\neach instance at boot; user ids as metric labels; the tracing SDK started\nafter the app's imports; 100% trace sampling in production; a flag nobody\nremoves.\n","# Running it\n\nThe generated service reads `process.env` in twenty files, logs with\n`console.log` and the raw URL, answers `\u002Fhealth` by querying every\ndependency, drops requests in flight on every deploy, and gives no way to\ntell one request's lines from another's. One part of the backend; the whole\nis in the `backend` skill, and the pipeline behind it (collector, dashboards,\nSLOs, alerts) is in `devops-observability`. This is what the service itself\ndoes so it can be configured, found, debugged and replaced safely.\n\n## 1. Configuration\n\n- Read every setting from the environment once, at start, in one module,\n  checked with a schema: types parsed, required values present, URLs valid.\n  A missing or malformed value stops the process at start with a message\n  naming it (the name, never the value), not a crash on the first request\n  that needs it.\n- The rest of the code imports that module; nothing else reads\n  `process.env` or `os.environ` (and in Laravel, `env()` is called only in\n  `config\u002F`).\n- `.env.example` lists every variable with a comment and a safe example;\n  defaults only for values that are safe everywhere (a port, a log level),\n  never for secrets.\n- Secrets typed so they cannot be printed: pydantic `SecretStr`, Rust\n  `secrecy::SecretString`, a Go type with a `LogValue` method returning\n  `[redacted]`. Config is read-only after start; changing it is a restart,\n  and a switch that must change at runtime is a feature flag (section 9).\n\n| Stack | Checked at start with |\n|---|---|\n| Node, Next.js | zod (`z.object(...).safeParse(process.env)`), or `@t3-oss\u002Fenv-core` \u002F `env-nextjs` |\n| Python | pydantic-settings (`BaseSettings`) |\n| Go | `caarlos0\u002Fenv` or `sethvargo\u002Fgo-envconfig` (`kelseyhightower\u002Fenvconfig` works but is unmaintained since 2019); koanf when files and env are layered |\n| Rust | figment or the `config` crate into a serde struct |\n| Laravel | `config\u002F*.php`, `php artisan config:cache` in production |\n| Java, .NET | `@ConfigurationProperties` with `@Validated` (`backend-stack-java`); options with `ValidateOnStart()` (`backend-stack-dotnet`) |\n\n```ts\nconst parsed = Env.safeParse(process.env); \u002F\u002F Env: a z.object of every variable\nif (!parsed.success) {\n  const names = parsed.error.issues.map((i) => i.path.join(\".\"));\n  console.error(`Invalid or missing environment variables: ${names.join(\", \")}`);\n  process.exit(1);\n}\nexport const config = parsed.data;\n```\n\n## 2. Logs\n\n- Structured (JSON in production, readable in development) through the\n  project's logger, never bare `console.log` or `print`, to stdout for the\n  platform to collect (no log files or rotation code in a container).\n\n| Stack | Logger |\n|---|---|\n| Node | pino (Fastify's built-in one; `pino-pretty` only in development) |\n| Python | structlog, or `logging` with a JSON formatter |\n| Go | `log\u002Fslog` with `slog.NewJSONHandler` |\n| Rust | `tracing` with `tracing-subscriber`'s JSON output |\n| Laravel | Monolog: `LOG_CHANNEL=stderr`, `LOG_STDERR_FORMATTER=Monolog\\Formatter\\JsonFormatter` |\n| Java, .NET | Logback JSON via Boot's structured logging; Serilog or the JSON console logger |\n\n- One line per request at the end: method, route pattern (not the raw URL\n  with ids and tokens), status, duration, request id, user id. Plus a line\n  for each decision worth finding later (a payment captured, a job failed),\n  not for every step.\n- Levels mean something: `error` needs someone to look, `warn` is unusual\n  but handled, `info` is the story of normal work, `debug` is off in\n  production and switchable without a redeploy (`LOG_LEVEL`). A client's\n  `4xx` is `info` or `warn`; an error is logged once, where it is handled\n  (`backend-errors`).\n- Never passwords, tokens, keys, card numbers, cookies, `Authorization`\n  headers or whole personal records (`backend-security`). Redact in the\n  logger (pino `redact`, a structlog processor, slog `ReplaceAttr`), and keep\n  exception locals out: structlog's default `dict_tracebacks` prints them;\n  use `ExceptionRenderer(ExceptionDictTransformer(show_locals=False))`.\n- An audit trail (who changed which record, when, from what to what) is\n  data: a table written in the same transaction, not log lines that expire.\n\n## 3. Request ids and trace context\n\n- A request id on every line of a request: taken from `X-Request-Id` when a\n  trusted proxy sets it, generated otherwise, returned in the response, and\n  passed on to jobs and outbound calls.\n- With tracing, W3C trace context is the correlation:\n  `traceparent: 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01`\n  (version, 32-hex trace id, 16-hex parent span id, flags). Every log line\n  carries `trace_id` and `span_id` through the logger's OpenTelemetry\n  integration; `X-Request-Id` stays for people quoting it. Continue trace\n  context from your own services; at the public edge, start a fresh trace.\n- Carry the ids in the request's context, not in arguments: Node\n  `AsyncLocalStorage` with a pino `mixin`, `structlog.contextvars`, Go\n  `context.Context`, Rust `tracing` spans, Laravel `Context::add()` (which\n  lands in every log record and travels into queued jobs by itself).\n- Across a queue, the producer puts the request id and trace context in the\n  job's metadata and the worker restores them before it logs.\n\n## 4. Traces with OpenTelemetry\n\nAdd a telemetry vendor only when the project has one or the task asks; say\nin the report where it would help. When it is there, configure it by the\nstandard `OTEL_*` variables (`devops-observability`), not values in code,\nand start the SDK before any instrumented module loads, or nothing is patched.\n\n| Stack | Setup |\n|---|---|\n| Node | `@opentelemetry\u002Fsdk-node` with `@opentelemetry\u002Fauto-instrumentations-node`, loaded by `node --import .\u002Fdist\u002Finstrumentation.js dist\u002Findex.js`; route names from `@hono\u002Fotel` or `@fastify\u002Fotel` |\n| Next.js | `instrumentation.ts` exporting `register()` that calls `registerOTel(\"app\")` from `@vercel\u002Fotel` |\n| Python | `opentelemetry-distro`, `opentelemetry-bootstrap -a install`, run under `opentelemetry-instrument uvicorn app.main:app`; under gunicorn, start the SDK in the `post_fork` hook |\n| Go | `otelhttp.NewHandler(mux, \"api\")`, `otelpgx.NewTracer()` on the pool config, a `TracerProvider` with a batcher, `propagation.TraceContext{}` |\n| Rust | `tracing` spans exported through `tracing-opentelemetry` and `opentelemetry-otlp`, versions that match each other |\n| Laravel | OpenTelemetry's PHP SDK with its Laravel auto-instrumentation, or the vendor's agent |\n\n```ts\n\u002F\u002F src\u002Finstrumentation.ts\nimport { register } from \"node:module\";\nimport { NodeSDK } from \"@opentelemetry\u002Fsdk-node\";\nimport { getNodeAutoInstrumentations } from \"@opentelemetry\u002Fauto-instrumentations-node\";\n\n\u002F\u002F ES modules need the loader hook, or pg, ioredis and the rest are not patched.\nregister(\"@opentelemetry\u002Finstrumentation\u002Fhook.mjs\", import.meta.url);\n\nexport const sdk = new NodeSDK({ \u002F\u002F exporters come from the OTEL_* variables\n  instrumentations: [\n    getNodeAutoInstrumentations({ \"@opentelemetry\u002Finstrumentation-fs\": { enabled: false } }),\n  ],\n});\nsdk.start();\n```\n\n- Auto-instrumentation covers inbound and outbound HTTP, database drivers,\n  Redis and most queues. Add a manual span only around work worth timing on\n  its own (pricing a basket, rendering a PDF); attributes are ids and\n  counts, never personal data or secrets; span names stay low-cardinality\n  (`POST \u002Forders\u002F{id}\u002Frefunds`).\n- Exporters batch: call `shutdown()` on the way out (section 7) or the last\n  seconds of spans are lost.\n\n## 5. Metrics\n\n- RED per route: rate, errors, duration as a histogram\n  (`http.server.request.duration` in seconds, with `http.request.method`,\n  `http.route` and `http.response.status_code`). HTTP auto-instrumentation\n  or the framework's metrics usually give these for free.\n- USE for what the service holds: pool connections in use, idle and\n  waiting, and acquire time; queue depth and the age of the oldest job;\n  Node's event loop delay (`perf_hooks.monitorEventLoopDelay`), Go's\n  goroutines, GC pauses; duration and errors per outbound dependency.\n- A few business counters that show breakage (orders placed, payments\n  failed, sign-ups). Labels stay low-cardinality: the route template, the\n  method, the status; never user ids, raw paths, emails or error messages.\n- Pushed over OTLP or scraped from `\u002Fmetrics` on an internal port, as the\n  platform does it; never on the public listener. Dashboards, SLOs and\n  alerts: `devops-observability`. Profiling: `performance-profiling`.\n\n## 6. Health\n\n| Endpoint | Answers | Checks | When it fails |\n|---|---|---|---|\n| `GET \u002Fhealthz` (liveness) | `200` while the process can serve at all | nothing outside the process | the platform restarts the instance |\n| `GET \u002Freadyz` (readiness) | `200`, or `503` while any need is down | what a request needs: `SELECT 1` on the database, the cache, with a short timeout | traffic stops going to this instance |\n| startup (optional) | `200` once warmed up | caches loaded, migrations present | liveness waits instead of killing a slow start |\n\n- Neither needs auth, and neither says anything secret: at most\n  `{\"status\":\"ok\",\"checks\":{\"db\":\"ok\"}}` and the release. Checks finish inside\n  the probe's timeout (Kubernetes defaults: 1 second, every 10 seconds, 3\n  failures), a few hundred milliseconds per dependency.\n- Liveness never touches the database: a database blip would restart every\n  instance at once. Readiness never checks a third-party API: its outage\n  would take every instance out of rotation; that failure is a `503` per\n  request (`backend-integrations`).\n- Use the framework's own where it has one: Laravel's `\u002Fup`, Spring\n  Actuator's probes, ASP.NET Core `MapHealthChecks`.\n\n## 7. Starting and stopping\n\n- On start: config checked, logger, telemetry, pools created and checked,\n  routes, then listen. Migrations are applied by a separate step (a release\n  command, a job), not by every instance racing at boot.\n- The process is PID 1 or receives signals from it: `CMD [\"node\",\n  \"dist\u002Findex.js\"]` in exec form, not `npm start` or a shell-form command,\n  which may not pass `SIGTERM` on; or `tini` (`docker run --init`).\n\nOn `SIGTERM` (sent on every deploy) and `SIGINT`:\n\n1. Readiness turns `503`, and the process keeps serving for 5 to 10 seconds\n   while the load balancer notices (or a Kubernetes `preStop` sleep).\n2. Stop accepting new connections and close idle keep-alive ones; let\n   requests in flight finish, with a limit of about 10 to 25 seconds.\n3. Stop the workers after their current job; a longer job must be safe to\n   run again (`backend-jobs`).\n4. Flush telemetry and error tracking (`sdk.shutdown()`,\n   `Sentry.close(2000)`).\n5. Close the pools, then exit `0`; exit non-zero if the limit was hit.\n\nThe whole sequence fits inside the platform's grace period: 30 seconds by\ndefault in Kubernetes (`terminationGracePeriodSeconds`), 10 in `docker\nstop`, 10 on Cloud Run.\n\n- Timeouts on the server itself (request and header timeouts, body size\n  limits) as well as on the database and outbound calls. The idle keep-alive\n  timeout is longer than the load balancer's (65 seconds behind an AWS ALB's\n  60), or it reuses a closed connection and reports a `502`.\n\n## 8. Error tracking\n\n- When the project has a tracker, use it: `5xx` and crashes (never a\n  client's `4xx`) with the request id and without personal data.\n- Sentry (or GlitchTip, API-compatible): initialised before the app code\n  (Node: in the file loaded by `--import`), with `release` set to the\n  deployed git SHA, `environment`, `sendDefaultPii: false`\n  (`send_default_pii=False`), a `beforeSend` that scrubs, users by id only,\n  source maps uploaded at build, and `tracesSampleRate` 0.05 to 0.2 when\n  OpenTelemetry already traces.\n- Per stack: `@sentry\u002Fnode` (`setupExpressErrorHandler`,\n  `setupFastifyErrorHandler`), `@sentry\u002Fnextjs`, `sentry-sdk` (FastAPI and\n  Django integrations turn on by themselves), `sentry-go`, the `sentry` crate\n  (keep the guard from `sentry::init` alive for all of `main`),\n  `sentry\u002Fsentry-laravel`.\n- Sentry's SDK and your own OpenTelemetry SDK must not both register a\n  global tracer provider: follow the installed SDK's guide for the pair.\n  Flush on shutdown, or the crash that ended the process is never reported.\n\n## 9. Feature flags\n\n- Code talks to OpenFeature, a vendor-neutral API; the provider (flagd,\n  LaunchDarkly, Unleash, Flagsmith, GrowthBook, ConfigCat, PostHog) is\n  chosen in one place.\n\n```ts\nimport { OpenFeature } from \"@openfeature\u002Fserver-sdk\";\n\nawait OpenFeature.setProviderAndWait(provider); \u002F\u002F at start, in one module\nconst flags = OpenFeature.getClient();\n\n\u002F\u002F The default (false) is what runs when the flag service is unreachable.\nexport const useNewCheckout = (userId: string) =>\n  flags.getBooleanValue(\"new-checkout\", false, { targetingKey: userId });\n```\n\n- Evaluated on the server with a context (user id, tenant), the safe old\n  behaviour as the default, the evaluated variant recorded on the request's\n  span or log line.\n- Each flag has an owner and a removal date and goes within weeks of full\n  rollout; a kill switch in front of each risky dependency; never a flag in\n  place of an authorisation check. Environment variables only for coarse\n  switches changed with a restart.\n\n## Check it\n\n- Start with a required variable missing: the process exits non-zero at\n  once and names it.\n- `curl -si localhost:8080\u002Freadyz` answers `200`; stop the database and it\n  answers `503` within the check timeout while `\u002Fhealthz` stays `200`.\n- One request writes exactly one request line with the route template,\n  status, duration and request id, and the same id is in the response\n  header. Search the logs for a test password, token and email: nothing.\n- `kill -TERM` the process during a slow request: it completes, the log\n  shows the shutdown steps, the exit code is `0`, inside the grace period.\n- With tracing on, one request is one trace with its database spans inside,\n  and its log lines carry the trace id.\n\n## Avoid\n\n`process.env.X` read all over the code; a missing variable found by the\nfirst user who needs it; `console.log` as the logger; logs with the raw URL,\nthe body, a token or exception locals; a health check that queries everything\nand times out; liveness that checks the database; a process that drops\nrequests in flight on every deploy; `npm start` as PID 1; migrations run by\neach instance at boot; user ids as metric labels; the tracing SDK started\nafter the app's imports; 100% trace sampling in production; a flag nobody\nremoves.\n",{"name":5,"description":7},"main","38293fe1b096e6bf3646c7344c38786ed688f464","crates\u002Fenowx-core\u002Fskills\u002Fbackend-observability",21,"https:\u002F\u002Fgithub.com\u002Fenowdev\u002Fenowxcli","https:\u002F\u002Fenowx.ai","https:\u002F\u002Fgithub.com\u002Fenowdev","Pretending to be a Developer","2026-10-06 02:05:35",{"source":8,"skillName":5,"commands":54,"prompt":64,"zipAvailable":65},[55,58,61],{"tool":56,"command":57},"npx","npx skills add enowdev\u002Fenowxcli --skill backend-observability",{"tool":59,"command":60},"bunx","bunx skills add enowdev\u002Fenowxcli --skill backend-observability",{"tool":62,"command":63},"pnpm","pnpm dlx skills add enowdev\u002Fenowxcli --skill backend-observability","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fenowdev\u002Fenowxcli\u002Fblob\u002Fmain\u002Fcrates\u002Fenowx-core\u002Fskills\u002Fbackend-observability\u002FSKILL.md",true,[],[68,79,96,109,130,149],{"skillNo":69,"name":70,"nameZh":6,"description":71,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":72,"categories":73,"keywords":74,"publishedAt":39},"01M6D2HQYSQD9N7MTNDT4A7CBM","demo-skill","Project-scope demo skill for tests.","https:\u002F\u002Fgithub.com\u002Fenowdev\u002Fenowxcli\u002Fblob\u002Fmain\u002Fworkspace\u002F.agents\u002Fskills\u002Fdemo-skill\u002FSKILL.md",[],[75,76,77,78,28],"demo skill","demo","tests","project",{"skillNo":80,"name":81,"nameZh":6,"description":82,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":83,"categories":84,"keywords":85,"publishedAt":39},"01M6D2HM0GCPM0TM2HPG9HHR2R","writing","Writing words people read: the specific thing instead of claims, words to drop, sentences, interface copy (buttons, labels, errors, empty states, confirmations), page copy, notifications and emails, alt text and link text, numbers and dates, words that translate well, documentation and voice. Read before writing a page's copy, an interface's text or a document.","https:\u002F\u002Fgithub.com\u002Fenowdev\u002Fenowxcli\u002Fblob\u002Fmain\u002Fcrates\u002Fenowx-core\u002Fskills\u002Fwriting\u002FSKILL.md",[],[81,86,87,88,89,90,28,91,92,93,94,95],"text","emails","empty","drop","document","page","voice","notifications","documentation","translate",{"skillNo":97,"name":98,"nameZh":6,"description":99,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":100,"categories":101,"keywords":102,"publishedAt":39},"01M6D2HG07YS49NM196Q0R3AZ8","ui","Designing or restyling an interface: direction, layout, type, colour, icons, components, states, responsive behaviour. Read before building a page, a screen or a set of components.","https:\u002F\u002Fgithub.com\u002Fenowdev\u002Fenowxcli\u002Fblob\u002Fmain\u002Fcrates\u002Fenowx-core\u002Fskills\u002Fui\u002FSKILL.md",[],[98,103,104,105,106,91,107,28,108],"icons","components","SET","responsive","layout","before building",{"skillNo":110,"name":111,"nameZh":6,"description":112,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":113,"categories":114,"keywords":115,"publishedAt":39},"01M6D2HB59HZHWG1RYZDV4SJ91","ui-themes","Light and dark themes, and colour that holds in both: tokens with a value per theme, and what each kind of content needs to stay visible (icons, SVG drawings and line art, logos, photos, screenshots, charts, code, maps, borders, shadows, focus, form controls), switching without a flash, and checking both. Read before building a second theme or a theme toggle, and before any drawing, logo or chart on a page that has two themes.","https:\u002F\u002Fgithub.com\u002Fenowdev\u002Fenowxcli\u002Fblob\u002Fmain\u002Fcrates\u002Fenowx-core\u002Fskills\u002Fui-themes\u002FSKILL.md",[],[98,116,117,118,119,120,121,122,123,28,108,124,91,125,126,127,103,128,129],"ui themes","switching","photos","tokens","drawing","focus","maps","Art","flash","code","Charts","content","screenshots","logo",{"skillNo":131,"name":132,"nameZh":6,"description":133,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":134,"categories":135,"keywords":136,"publishedAt":39},"01M6D2H5R5KRAE524C8QX0T7Q0","ui-structure","Structure before styling: the blueprint written before any interface code (the screen's job, the regions its kind of page needs, their order and why, the layout skeleton in numbers, the components and their states), the anatomy and order of a homepage, a dashboard, a list, a detail page, settings, a form, sign-in, pricing, docs, an article and a checkout, and how to turn the blueprint into code (tokens, layout primitives, components, sections, page). Read first, before building or rebuilding any page or screen.","https:\u002F\u002Fgithub.com\u002Fenowdev\u002Fenowxcli\u002Fblob\u002Fmain\u002Fcrates\u002Fenowx-core\u002Fskills\u002Fui-structure\u002FSKILL.md",[],[137,98,138,104,139,140,125,141,142,143,107,119,144,145,146,28,108,91,147,148],"structure","ui structure","pricing","dashboard","Blueprint","article","anatomy","styling","primitives","list","why","how",{"skillNo":150,"name":151,"nameZh":6,"description":152,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":153,"categories":154,"keywords":155,"publishedAt":39},"01M6D2H0ZZBJG77MBGPZHA6MWD","ui-stack-vue","Building interfaces in Vue 3 and Nuxt: project layout, script setup with typed defineProps, defineEmits and defineModel, attribute fallthrough, slots and scoped slots, template refs, ref, reactive and computed, watch versus watchEffect, composables and VueUse, provide and inject, Pinia, keyed v-for, transitions, Nuxt 4 (app directory, pages, layouts, useFetch and useAsyncData keys, $fetch in handlers, server routes, runtime config, useSeoMeta, NuxtImg, middleware), VeeValidate forms, Reka UI and Nuxt UI, testing, vue-tsc, and the traps. Read when the project uses Vue or Nuxt.","https:\u002F\u002Fgithub.com\u002Fenowdev\u002Fenowxcli\u002Fblob\u002Fmain\u002Fcrates\u002Fenowx-core\u002Fskills\u002Fui-stack-vue\u002FSKILL.md",[],[98,156,29,157,158,159,160,161,107,78,162,163,28,164,165,166,167,30,168,169],"vue","ui stack vue","forms","pages","watch","runtime","transitions","fetch","pinia","nuxt","template","server","directory","testing"]