@keelcore/standards 0.9.7 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,9 +2,7 @@
2
2
 
3
3
  These rules govern all code edits in this project. They are non-negotiable.
4
4
 
5
- **Maturity:** Required
6
- **Version:** 1.0.0
7
- **Last Reviewed:** 2026-03-09
5
+ **Maturity:** Required **Version:** 1.0.0 **Last Reviewed:** 2026-03-09
8
6
 
9
7
  ## Core Preservation
10
8
 
@@ -16,141 +14,154 @@ These rules govern all code edits in this project. They are non-negotiable.
16
14
 
17
15
  ## Commenting Rules
18
16
 
19
- 6. Comments explain enduring intent, invariants, contracts, architecture — not patch notes.
20
- 7. No "added this", "fixed this", "temporary workaround" style narration.
21
- 8. Comments are file-local; no broader project lore unless strictly necessary.
22
- 9. Prefer code over commentary for the obvious.
23
- 10. When updating code, update any nearby comment that would become misleading.
17
+ 1. Comments explain enduring intent, invariants, contracts, architecture — not patch notes.
18
+ 2. No "added this", "fixed this", "temporary workaround" style narration.
19
+ 3. Comments are file-local; no broader project lore unless strictly necessary.
20
+ 4. Prefer code over commentary for the obvious.
21
+ 5. When updating code, update any nearby comment that would become misleading.
24
22
 
25
23
  ## Scope Control
26
24
 
27
- 11. All edits to existing files must be surgical — minimum necessary lines/regions/symbols.
28
- 12. No opportunistic widening — no drive-by refactors, renames, formatting sweeps, dead-code cleanup.
29
- 13. Do not introduce dead code — no unreachable branches, unused variables/imports, orphaned helpers.
30
- 14. Do not reflow stable text gratuitously.
31
- 15. Preserve surrounding code shape.
32
- 16. Minimize diff surface area; correctness wins over minimalism when they conflict.
25
+ 1. All edits to existing files must be surgical — minimum necessary lines/regions/symbols.
26
+ 2. No opportunistic widening — no drive-by refactors, renames, formatting sweeps, dead-code cleanup.
27
+ 3. Do not introduce dead code — no unreachable branches, unused variables/imports, orphaned helpers.
28
+ 4. Do not reflow stable text gratuitously.
29
+ 5. Preserve surrounding code shape.
30
+ 6. Minimize diff surface area; correctness wins over minimalism when they conflict.
33
31
 
34
32
  ## Consistency and Reviewability
35
33
 
36
- 17. Human reviewability outranks aesthetic optimization.
37
- 18. Match local conventions: repo/module > file-local > language style guide.
38
- 19. Avoid sweeping rewrites.
39
- 20. Maintain interface stability — no silent signature/flag/config-key changes.
40
- 21. When practical, preserve backward compatibility; do not silently drop old forms.
41
- 22. Preserve blame usefulness — keep unchanged lines untouched.
34
+ 1. Human reviewability outranks aesthetic optimization.
35
+ 2. Match local conventions: repo/module > file-local > language style guide.
36
+ 3. Avoid sweeping rewrites.
37
+ 4. Maintain interface stability — no silent signature/flag/config-key changes.
38
+ 5. When practical, preserve backward compatibility; do not silently drop old forms.
39
+ 6. Preserve blame usefulness — keep unchanged lines untouched.
42
40
 
43
41
  ## Refactoring Rules
44
42
 
45
- 23. Refactoring is opt-in, not ambient.
46
- 24. Required refactors must be local.
47
- 25. Do not bundle unrelated improvements.
48
- 26. Prefer extension over churn.
43
+ 1. Refactoring is opt-in, not ambient.
44
+ 2. Required refactors must be local.
45
+ 3. Do not bundle unrelated improvements.
46
+ 4. Prefer extension over churn.
49
47
 
50
48
  ## File Editing Discipline
51
49
 
52
- 27. Preserve untouched regions exactly.
53
- 28. Do not reorder imports, declarations, functions, keys, or fields unless required.
54
- 29. Do not rename symbols for taste.
55
- 30. Do not change comments/docstrings/whitespace outside the affected area.
56
- 31. Never leave a file in a partially migrated state.
50
+ 1. Preserve untouched regions exactly.
51
+ 2. Do not reorder imports, declarations, functions, keys, or fields unless required.
52
+ 3. Do not rename symbols for taste.
53
+ 4. Do not change comments/docstrings/whitespace outside the affected area.
54
+ 5. Never leave a file in a partially migrated state.
57
55
 
58
56
  ## New File Discipline
59
57
 
60
- 32. Follow naming, package structure, header conventions of adjacent files.
61
- 33. Creating a new file requires explicit justification; prefer extending existing files.
62
- 34. Test files may use longer functions, explicit repetition, table-driven patterns — do not compress.
58
+ 1. Follow naming, package structure, header conventions of adjacent files.
59
+ 2. Creating a new file requires explicit justification; prefer extending existing files.
60
+ 3. Test files may use longer functions, explicit repetition, table-driven patterns — do not compress.
63
61
 
64
62
  ## Style
65
63
 
66
- 35. Prefer boring, conventional, long-lived patterns over novelty.
67
- 36. Follow language style guide unless local style clearly overrides.
68
- 37. Conservative house style: readability, portability, diff minimization, explicitness, reviewer clarity.
69
- 38. Style must be consistent within the file and stable across future edits.
64
+ 1. Prefer boring, conventional, long-lived patterns over novelty.
65
+ 2. Follow language style guide unless local style clearly overrides.
66
+ 3. Conservative house style: readability, portability, diff minimization, explicitness, reviewer clarity.
67
+ 4. Style must be consistent within the file and stable across future edits.
70
68
 
71
69
  ## Security
72
70
 
73
- 39. No hardcoded credentials, tokens, private keys, disabled TLS verification, open CORS, permissive file modes.
74
- Note existing violations and raise them rather than propagating them.
71
+ 1. No hardcoded credentials, tokens, private keys, disabled TLS verification, open CORS, permissive file modes. Note
72
+ existing violations and raise them rather than propagating them.
75
73
 
76
74
  ## Documentation
77
75
 
78
- 40. When observable behavior/flags/config/API/errors change, note that external docs may need updating.
76
+ 1. When observable behavior/flags/config/API/errors change, note that external docs may need updating.
79
77
 
80
78
  ## Formatting and Linting Automation
81
79
 
82
- 41. Format and lint via project scripts, not ad-hoc commands.
83
- 42. Propose `scripts/format.sh` and `scripts/lint.sh` if they do not exist.
84
- 43. Do not embed formatter/linter invocations in YAML or Makefiles when a script can be the entry point.
80
+ 1. Format and lint via project scripts, not ad-hoc commands.
81
+ 2. Propose `scripts/format.sh` and `scripts/lint.sh` if they do not exist.
82
+ 3. Do not embed formatter/linter invocations in YAML or Makefiles when a script can be the entry point.
85
83
 
86
84
  ## Git Hook Integration
87
85
 
88
- 44. Pre-commit hook calls a single stable entry point: `scripts/git_precommit.sh`.
89
- 45. `scripts/git_precommit.sh` invokes format + lint scripts; no logic duplicated in the hook itself.
86
+ 1. Pre-commit hook calls a single stable entry point: `scripts/git_precommit.sh`.
87
+ 2. `scripts/git_precommit.sh` invokes format + lint scripts; no logic duplicated in the hook itself.
90
88
 
91
89
  ## Change Justification
92
90
 
93
- 46. Every non-trivial change must be justifiable as necessary.
94
- 47. No speculative fixes.
95
- 48. No silent cleanup of unconventional-but-correct code.
96
- 49. Preserve intent over stylistic purity.
91
+ 1. Every non-trivial change must be justifiable as necessary.
92
+ 2. No speculative fixes.
93
+ 3. No silent cleanup of unconventional-but-correct code.
94
+ 4. Preserve intent over stylistic purity.
97
95
 
98
96
  ## Completeness and Consistency
99
97
 
100
- 50. Do not leave referenced functions/variables/imports/code paths broken.
101
- 51. No partial renames, partial signature migrations, inconsistent call-site updates.
102
- 52. Changed code must remain internally consistent with the rest of the file.
103
- 53. Prefer a complete narrow fix over an ambitious broad rewrite.
98
+ 1. Do not leave referenced functions/variables/imports/code paths broken.
99
+ 2. No partial renames, partial signature migrations, inconsistent call-site updates.
100
+ 3. Changed code must remain internally consistent with the rest of the file.
101
+ 4. Prefer a complete narrow fix over an ambitious broad rewrite.
104
102
 
105
103
  ## Default Operating Principle
106
104
 
107
- 54. Treat every edit as a constrained maintenance operation, not a redesign opportunity.
108
- 55. Ideal change: minimal, correct, legible, locally consistent, unsurprising.
105
+ 1. Treat every edit as a constrained maintenance operation, not a redesign opportunity.
106
+ 2. Ideal change: minimal, correct, legible, locally consistent, unsurprising.
109
107
 
110
108
  ## Concurrency and Shared-State Safety
111
109
 
112
- 56. Do not remove synchronization primitives or introduce unprotected shared state.
113
- 57. Do not introduce goroutines/threads/async into previously synchronous code paths.
114
- 58. Do not move code across concurrency boundaries without preserving ordering and safety.
110
+ 1. Do not remove synchronization primitives or introduce unprotected shared state.
111
+ 2. Do not introduce goroutines/threads/async into previously synchronous code paths.
112
+ 3. Do not move code across concurrency boundaries without preserving ordering and safety.
115
113
 
116
114
  ## Type and Contract Safety
117
115
 
118
- 59. Do not widen specific types to any/interface{}/generic containers.
119
- 60. No unsafe casts, reflection-driven access, or dynamic fallbacks where typed alternatives exist.
120
- 61. Do not remove type checks, assertions, validation, or boundary contracts without equal replacement.
116
+ 1. Do not widen specific types to any/interface{}/generic containers.
117
+ 2. No unsafe casts, reflection-driven access, or dynamic fallbacks where typed alternatives exist.
118
+ 3. Do not remove type checks, assertions, validation, or boundary contracts without equal replacement.
121
119
 
122
120
  ## Ambiguity Control
123
121
 
124
- 62. When ambiguous, prefer the narrowest conservative interpretation consistent with literal text and intent.
125
- 63. Seek clarification only when conservative interpretation produces broken, incomplete, or unsafe output.
122
+ 1. When ambiguous, prefer the narrowest conservative interpretation consistent with literal text and intent.
123
+ 2. Seek clarification only when conservative interpretation produces broken, incomplete, or unsafe output.
126
124
 
127
125
  ## Complexity Preservation
128
126
 
129
- 64. Do not introduce worse asymptotic complexity where a better one existed.
130
- 65. Do not replace indexed/cached/streaming/incremental behavior with full scans or redundant allocation.
127
+ 1. Do not introduce worse asymptotic complexity where a better one existed.
128
+ 2. Do not replace indexed/cached/streaming/incremental behavior with full scans or redundant allocation.
129
+
130
+ ## Locale and Reproducibility
131
+
132
+ 1. Builds, tests, and tooling MUST be reproducible independent of the developer's or CI runner's
133
+ locale. Never depend on an inherited `LANG`/`LC_*` for program behavior.
134
+ 2. Any locale-sensitive operation — collation/sort order, numeric or date formatting, case-folding —
135
+ MUST pin an explicit, deterministic locale (`LC_ALL=C`, or an equivalent language-native
136
+ invariant) rather than rely on the ambient default.
137
+ 3. Pin at the outermost boundary that covers all subprocesses (e.g. the build entrypoint exports
138
+ `LC_ALL=C`) so that tools you do not own inherit the deterministic locale too.
139
+ 4. Where a locale dependency is load-bearing, add a test that runs the path under a hostile `LC_*`
140
+ and asserts the invariant holds. Language-specific mechanics live in the per-language standards
141
+ (e.g. bash.md, "Locale Determinism").
131
142
 
132
143
  ## Source File Trailing Newlines
133
144
 
134
- 66. Every text source file (`.go`, `.sh`, `.md`, `.yml`, `.yaml`, `.toml`, `.json`,
135
- `.gitignore`, `.gitattributes`) MUST end with a single trailing newline character.
136
- 67. Verify and fix trailing newlines before handing off any file edits.
137
- 68. Adding a new text-format type to the repo requires updating `scripts/lint/newlines.sh`
138
- and the pre-commit hook in the same commit.
145
+ 1. Every text source file (`.go`, `.sh`, `.md`, `.yml`, `.yaml`, `.toml`, `.json`, `.gitignore`, `.gitattributes`) MUST
146
+ end with a single trailing newline character.
147
+ 2. Verify and fix trailing newlines before handing off any file edits.
148
+ 3. Adding a new text-format type to the repo requires updating `scripts/lint/newlines.sh` and the pre-commit hook in the
149
+ same commit.
139
150
 
140
151
  ## Go Module Version Format
141
152
 
142
- 69. The `go` directive in `go.mod` MUST use the two-component form: `go 1.25` — never `go 1.25.0`.
143
- 70. After every `go mod tidy` or `go get`, verify the `go` directive and strip any trailing `.0`.
153
+ 1. The `go` directive in `go.mod` MUST use the two-component form: `go 1.25` — never `go 1.25.0`.
154
+ 2. After every `go mod tidy` or `go get`, verify the `go` directive and strip any trailing `.0`.
144
155
 
145
156
  ## Static Analysis Suppression
146
157
 
147
- 71. The standalone `staticcheck` binary does NOT respect `//nolint:staticcheck` directives.
148
- Use `//lint:ignore SA1019 <reason>` instead.
149
- 72. Place the `//lint:ignore` directive on its own line immediately above the flagged statement —
150
- inline (end-of-line) placement may be silently ignored.
158
+ 1. The standalone `staticcheck` binary does NOT respect `//nolint:staticcheck` directives. Use
159
+ `//lint:ignore SA1019 <reason>` instead.
160
+ 2. Place the `//lint:ignore` directive on its own line immediately above the flagged statement — inline (end-of-line)
161
+ placement may be silently ignored.
151
162
 
152
163
  ## Program Entry Points
153
164
 
154
- 73. `main` (and any program entry point) must be KISS: orchestration and wiring only.
155
- 74. No default behaviors, business logic, or configuration in `main` — those belong in the library.
156
- 75. A correct `main` is ~15 lines: parse flags, call library, handle exit.
165
+ 1. `main` (and any program entry point) must be KISS: orchestration and wiring only.
166
+ 2. No default behaviors, business logic, or configuration in `main` — those belong in the library.
167
+ 3. A correct `main` is ~15 lines: parse flags, call library, handle exit.
@@ -2,148 +2,139 @@
2
2
 
3
3
  These rules govern metrics, logging, tracing, and alerting across all services. They are non-negotiable.
4
4
 
5
- **Maturity:** Required
6
- **Version:** 1.0.0
7
- **Last Reviewed:** 2026-03-09
5
+ **Maturity:** Required **Version:** 1.0.0 **Last Reviewed:** 2026-03-09
8
6
 
9
7
  ## Metrics
10
8
 
11
9
  ### Vendors and Retention
12
10
 
13
- 1. The approved metrics vendor(s) are documented in the internal vendor registry. No additional metrics
14
- backends are introduced without ARB approval.
15
- 2. Metrics retention: real-time resolution (≤60s) for 15 days; 5-minute rollup for 90 days;
16
- 1-hour rollup for 13 months.
11
+ 1. The approved metrics vendor(s) are documented in the internal vendor registry. No additional metrics backends are
12
+ introduced without ARB approval.
13
+ 2. Metrics retention: real-time resolution (≤60s) for 15 days; 5-minute rollup for 90 days; 1-hour rollup for 13 months.
17
14
  3. Long-term retention beyond 13 months requires explicit data classification and archival approval.
18
15
 
19
16
  ### Taxonomy and Namespace Schema
20
17
 
21
- 4. All metric names follow the schema: `{org}_{service}_{noun}_{unit}` (e.g., `keelcore_auth_requests_total`).
22
- 5. Metric namespaces are registered centrally; unregistered namespaces are rejected at the ingestion layer.
23
- 6. Label keys are lowercase snake_case. Label values must not contain high-cardinality free-text (e.g.,
24
- user IDs, trace IDs, URLs). Cardinality limit per metric: 10,000 distinct label value combinations.
18
+ 1. All metric names follow the schema: `{org}_{service}_{noun}_{unit}` (e.g., `keelcore_auth_requests_total`).
19
+ 2. Metric namespaces are registered centrally; unregistered namespaces are rejected at the ingestion layer.
20
+ 3. Label keys are lowercase snake_case. Label values must not contain high-cardinality free-text (e.g., user IDs, trace
21
+ IDs, URLs). Cardinality limit per metric: 10,000 distinct label value combinations.
25
22
 
26
23
  ### Required Metric Ontologies
27
24
 
28
- 7. Every service exposes RED metrics: **R**ate (requests per second), **E**rrors (error rate),
29
- **D**uration (latency distribution — p50, p95, p99).
30
- 8. Every resource-bound component (database, cache, message queue, worker pool) exposes USE metrics:
31
- **U**tilization, **S**aturation, **E**rrors.
32
- 9. RED and USE dashboards are provisioned automatically from the service's metric registration.
25
+ 1. Every service exposes RED metrics: **R**ate (requests per second), **E**rrors (error rate), **D**uration (latency
26
+ distribution — p50, p95, p99).
27
+ 2. Every resource-bound component (database, cache, message queue, worker pool) exposes USE metrics: **U**tilization,
28
+ **S**aturation, **E**rrors.
29
+ 3. RED and USE dashboards are provisioned automatically from the service's metric registration.
33
30
 
34
31
  ### SLOs and SLAs
35
32
 
36
- 10. Every public-facing service defines at least one SLO expressed as an error budget (e.g., 99.9%
37
- availability over a 30-day rolling window).
38
- 11. SLO burn-rate alerts fire at 2× and 10× burn rates and are routed to the on-call rotation.
39
- 12. SLAs, where contractually defined, are backed by SLOs with sufficient headroom. SLA breach
40
- thresholds are stricter than internal SLO thresholds.
41
- 13. Service dashboards are published to the central dashboard registry and linked from the service runbook.
33
+ 1. Every public-facing service defines at least one SLO expressed as an error budget (e.g., 99.9% availability over a
34
+ 30-day rolling window).
35
+ 2. SLO burn-rate alerts fire at 2× and 10× burn rates and are routed to the on-call rotation.
36
+ 3. SLAs, where contractually defined, are backed by SLOs with sufficient headroom. SLA breach thresholds are stricter
37
+ than internal SLO thresholds.
38
+ 4. Service dashboards are published to the central dashboard registry and linked from the service runbook.
42
39
 
43
40
  ## Logging
44
41
 
45
42
  ### Format
46
43
 
47
- 14. All log output is structured JSON. Human-readable plain text logs are prohibited in staging and
48
- production. Development environments may use formatted output via a local flag.
49
- 15. Log lines are single-line JSON objects terminated by `\n`. Multi-line log entries are prohibited;
50
- stack traces are serialized into a single string field.
44
+ 1. All log output is structured JSON. Human-readable plain text logs are prohibited in staging and production.
45
+ Development environments may use formatted output via a local flag.
46
+ 2. Log lines are single-line JSON objects terminated by `\n`. Multi-line log entries are prohibited; stack traces are
47
+ serialized into a single string field.
51
48
 
52
49
  ### Required Fields
53
50
 
54
- 16. Every log entry must include:
55
- - `timestamp` — RFC 3339 with nanosecond precision (e.g., `2026-03-09T12:00:00.000000000Z`)
56
- - `level` — one of: `debug`, `info`, `warn`, `error`, `fatal`
57
- - `service` — the service identifier (matches the metric namespace prefix)
58
- - `version` — the deployed artifact version (SemVer)
59
- - `trace_id` — W3C TraceContext trace ID (zero value if no active trace)
60
- - `span_id` — W3C TraceContext span ID (zero value if no active trace)
61
- - `message` — human-readable description of the event
62
- 17. Additional fields are encouraged but must not collide with the reserved field list above.
51
+ 1. Every log entry must include:
52
+ - `timestamp` — RFC 3339 with nanosecond precision (e.g., `2026-03-09T12:00:00.000000000Z`)
53
+ - `level` — one of: `debug`, `info`, `warn`, `error`, `fatal`
54
+ - `service` — the service identifier (matches the metric namespace prefix)
55
+ - `version` — the deployed artifact version (SemVer)
56
+ - `trace_id` — W3C TraceContext trace ID (zero value if no active trace)
57
+ - `span_id` — W3C TraceContext span ID (zero value if no active trace)
58
+ - `message` — human-readable description of the event
59
+ 2. Additional fields are encouraged but must not collide with the reserved field list above.
63
60
 
64
61
  ### SDK-Level Enforcement
65
62
 
66
- 18. Services must use the organization-approved logging SDK. Calls to raw `fmt.Println`,
67
- `console.log`, `print()`, or equivalent bypass the structured logger and are prohibited.
68
- 19. The logging SDK enforces required fields at construction time. A log entry missing a required
69
- field must fail at build time or panic at startup, not silently emit a malformed log.
63
+ 1. Services must use the organization-approved logging SDK. Calls to raw `fmt.Println`, `console.log`, `print()`, or
64
+ equivalent bypass the structured logger and are prohibited.
65
+ 2. The logging SDK enforces required fields at construction time. A log entry missing a required field must fail at
66
+ build time or panic at startup, not silently emit a malformed log.
70
67
 
71
68
  ### Aggregation and Retention
72
69
 
73
- 20. All logs from all environments (staging, production) are shipped to the central log aggregation
74
- platform. Local-only logging is prohibited in staging and production.
75
- 21. Log retention: 90 days at full fidelity; 13 months for `warn` and above; 7 years for `audit`
76
- classified logs.
77
- 22. Log access is role-gated. Read access to production logs requires an approved role. Queries
78
- on `audit`-classified logs are themselves logged.
70
+ 1. All logs from all environments (staging, production) are shipped to the central log aggregation platform. Local-only
71
+ logging is prohibited in staging and production.
72
+ 2. Log retention: 90 days at full fidelity; 13 months for `warn` and above; 7 years for `audit` classified logs.
73
+ 3. Log access is role-gated. Read access to production logs requires an approved role. Queries on `audit`-classified
74
+ logs are themselves logged.
79
75
 
80
76
  ### Redaction and Privacy
81
77
 
82
- 23. Personally identifiable information (PII) must not appear in log fields except `audit`-classified
83
- logs with explicit data handling approval.
84
- 24. Secrets, tokens, passwords, and private keys must never be logged, even at `debug` level.
85
- 25. The logging SDK must provide a redaction hook that masks known-sensitive field patterns before
86
- emission. Services must register PII-bearing fields with the redaction registry.
87
- 26. Audit logs that require PII (e.g., access logs for compliance) are stored in a segregated
88
- audit log store with stricter access controls and encryption-at-rest.
78
+ 1. Personally identifiable information (PII) must not appear in log fields except `audit`-classified logs with explicit
79
+ data handling approval.
80
+ 2. Secrets, tokens, passwords, and private keys must never be logged, even at `debug` level.
81
+ 3. The logging SDK must provide a redaction hook that masks known-sensitive field patterns before emission. Services
82
+ must register PII-bearing fields with the redaction registry.
83
+ 4. Audit logs that require PII (e.g., access logs for compliance) are stored in a segregated audit log store with
84
+ stricter access controls and encryption-at-rest.
89
85
 
90
86
  ## Distributed Tracing
91
87
 
92
88
  ### Framework
93
89
 
94
- 27. All services instrument using OpenTelemetry (OTel). Vendor-specific tracing SDKs are prohibited
95
- as the primary instrumentation layer. OTel exporters may target any approved backend.
96
- 28. Trace context is propagated using the W3C TraceContext standard (`traceparent`, `tracestate` headers).
97
- Proprietary propagation formats (B3, X-Cloud-Trace-Context) are acceptable as secondary propagation
98
- only for legacy integration.
90
+ 1. All services instrument using OpenTelemetry (OTel). Vendor-specific tracing SDKs are prohibited as the primary
91
+ instrumentation layer. OTel exporters may target any approved backend.
92
+ 2. Trace context is propagated using the W3C TraceContext standard (`traceparent`, `tracestate` headers). Proprietary
93
+ propagation formats (B3, X-Cloud-Trace-Context) are acceptable as secondary propagation only for legacy integration.
99
94
 
100
95
  ### Propagation Policy
101
96
 
102
- 29. Every inbound request must extract trace context from headers if present, or generate a new root
103
- span if absent.
104
- 30. Every outbound call must inject the current trace context into request headers.
105
- 31. Internal background jobs and queue consumers must attach to the trace context embedded in the
106
- job/message payload.
107
- 32. Trace context must cross service, database, queue, and cache boundaries. Traces that terminate
108
- at a service boundary rather than propagating downstream are a defect.
97
+ 1. Every inbound request must extract trace context from headers if present, or generate a new root span if absent.
98
+ 2. Every outbound call must inject the current trace context into request headers.
99
+ 3. Internal background jobs and queue consumers must attach to the trace context embedded in the job/message payload.
100
+ 4. Trace context must cross service, database, queue, and cache boundaries. Traces that terminate at a service boundary
101
+ rather than propagating downstream are a defect.
109
102
 
110
103
  ### Sampling
111
104
 
112
- 33. Production sampling: head-based sampling at 1% for high-volume steady-state traffic, with tail-based
113
- sampling capturing 100% of error traces and traces exceeding the p99 latency threshold.
114
- 34. Sampling configuration is centralized (not per-service). Services do not configure their own sampling
115
- rates without approval.
116
- 35. Staging and development environments use 100% sampling.
105
+ 1. Production sampling: head-based sampling at 1% for high-volume steady-state traffic, with tail-based sampling
106
+ capturing 100% of error traces and traces exceeding the p99 latency threshold.
107
+ 2. Sampling configuration is centralized (not per-service). Services do not configure their own sampling rates without
108
+ approval.
109
+ 3. Staging and development environments use 100% sampling.
117
110
 
118
111
  ## Audit Logging
119
112
 
120
113
  ### Immutability and Trail Requirements
121
114
 
122
- 36. Sensitive actions (authentication events, authorization decisions, configuration changes, data
123
- exports, administrative actions) must emit an `audit`-classified log entry.
124
- 37. Audit logs are written to an append-only, tamper-evident store. Application processes have write-only
125
- access; no application process may read, modify, or delete audit log entries.
126
- 38. Every audit log entry includes: `timestamp`, `actor_id`, `actor_type` (human or service),
127
- `action`, `resource_type`, `resource_id`, `outcome` (success or failure), `client_ip`, `trace_id`.
128
- 39. Access to resources and modifications to data are logged, including read access to sensitive data.
115
+ 1. Sensitive actions (authentication events, authorization decisions, configuration changes, data exports,
116
+ administrative actions) must emit an `audit`-classified log entry.
117
+ 2. Audit logs are written to an append-only, tamper-evident store. Application processes have write-only access; no
118
+ application process may read, modify, or delete audit log entries.
119
+ 3. Every audit log entry includes: `timestamp`, `actor_id`, `actor_type` (human or service), `action`, `resource_type`,
120
+ `resource_id`, `outcome` (success or failure), `client_ip`, `trace_id`.
121
+ 4. Access to resources and modifications to data are logged, including read access to sensitive data.
129
122
 
130
123
  ### Retention
131
124
 
132
- 40. Audit logs are retained for a minimum of 7 years unless a longer period is required by applicable
133
- regulation.
134
- 41. Audit log exports for compliance review require dual-approval and are themselves logged.
125
+ 1. Audit logs are retained for a minimum of 7 years unless a longer period is required by applicable regulation.
126
+ 2. Audit log exports for compliance review require dual-approval and are themselves logged.
135
127
 
136
128
  ## Alerting
137
129
 
138
130
  ### Thresholds and Routing
139
131
 
140
- 42. Every SLO has an associated burn-rate alert. Alerts fire at 2× burn (page candidate) and 10× burn
141
- (immediate page).
142
- 43. `error` and `fatal` log events that exceed a per-service threshold trigger an alert.
143
- 44. Alert routing follows the on-call schedule managed in the central incident management platform.
144
- 45. Alerts include: service name, environment, metric/log source, threshold breached, current value,
145
- link to the relevant dashboard, and link to the runbook.
146
- 46. Runbook links in alerts must resolve. Broken runbook links are treated as a P2 incident.
132
+ 1. Every SLO has an associated burn-rate alert. Alerts fire at 2× burn (page candidate) and 10× burn (immediate page).
133
+ 2. `error` and `fatal` log events that exceed a per-service threshold trigger an alert.
134
+ 3. Alert routing follows the on-call schedule managed in the central incident management platform.
135
+ 4. Alerts include: service name, environment, metric/log source, threshold breached, current value, link to the relevant
136
+ dashboard, and link to the runbook.
137
+ 5. Runbook links in alerts must resolve. Broken runbook links are treated as a P2 incident.
147
138
 
148
139
  ## Do Not
149
140