Telemetry design and alerting
Measure distributions and volume
The mean can hide a slow minority. In a synthetic sample of 100 requests, 94 take 100 ms, five take 800 ms, and one takes 2,000 ms. The mean is (94 × 100 + 5 × 800 + 2,000) / 100 = 154 ms. Using the nearest-rank definition, sort the observations and take rank ceil(p × N / 100), starting at one. p95 = 800 ms; p99 = 800 ms; p100 = 2,000 ms. Percentile definitions and histogram approximations vary, so identify your method. Never average p95 values across hosts to obtain global p95; aggregate compatible distributions or raw observations instead.
Define the population, time window and units before comparing. For 200 requests with eight failures, the rate is 4%. For a second window of 800 requests with eight failures, the rate is 1%. Across both windows the weighted rate is 16 / 1,000 = 1.6%, not the unweighted average 2.5%. Zero requests means the failure rate is undefined, not automatically zero.
Build a useful dashboard and alerts
Start with traffic (requests per second), errors (failed/eligible requests), latency (p50/p95/p99), and saturation (queue depth, CPU or connection pool utilization). Split by bounded route template, region and service. Mark deployments and configuration changes without claiming causation. Show sample counts and missing telemetry explicitly. Include a link to the relevant runbook and traces.
An alert is a signal that investigation or action is required, not a diagnosis. For the fictional checkout service, page if at least 100 requests arrive in each of the last three complete five-minute windows and each has at least 5% failures. Use a separate telemetry-gap alert for missing windows; low volume is insufficient evidence for this particular rule. Define a resolution rule (for example two healthy complete windows), deduplicate incidents, route to an owner, and document what to inspect. Real thresholds must reflect service objectives and traffic. A three-window delay can miss short incidents; combine with critical symptoms as appropriate.
Control sampling and cardinality
Head sampling decides early whether to retain a trace; tail sampling can use later evidence such as errors or latency, but needs sufficient buffering and can lose incomplete traces. If 10,000 traces/day are independently selected with probability 0.1, the expected retained count is 1,000, not a guaranteed exact count. Sampling preferentially for failures changes the observed population: do not treat the error fraction of a biased trace sample as the service-wide error rate. Prefer suitable unsampled counters for that calculation and track sampling policies and dropped data.
Cardinality is the number of distinct time series. Three services × four route templates × two regions × five status classes yields at most 120 combinations under this simplified model. Adding 10,000 unique request IDs could raise that bound to 1,200,000; real combinations may be sparse. Keep request IDs in access-controlled structured logs and traces rather than metric labels. Histograms and resource dimensions can introduce additional series or billing dimensions.
Budget retention and privacy
Fictional rates only: 20 GB/day ingested for a 30-day month at $0.50/GB costs $300. With constant ingestion and 15 days of retention, steady-state storage is 300 GB. At $0.03 per GB-month, modeled storage costs $9, so the simplified total is $309/month. This assumes storage is charged separately from ingestion and uses a steady-state average. Actual providers differ in free allowances, included retention, tiers, indexing, queries, transfer, metrics and traces. Reduce unnecessary collection before ingestion where feasible; a shorter retention period does not necessarily reduce ingestion charges.
Collect only necessary fields. Use allowlisted keys, redaction before export, encryption, role-restricted access, deletion schedules and separated audit retention. Never log authorization headers, secret values, payment data or raw personal identifiers unnecessarily. Do not sample away mandatory audit events merely to save cost. Check policy and retention requirements with the responsible owners; no legal conclusion is implied. Test collector failures and monitor dropped records, queue pressure, export errors and ingestion lag.
Run a local alert and percentile model
The following Python 3 example uses only the standard library and no network. Each alert input is a complete window or a missing marker. The model is stateless: PAGE describes the current evaluation, not an incident lifecycle. Invalid or low-volume windows produce an explicit insufficient-data state. It does not implement a provider's query language.
from math import ceil
def nearest_rank(values, percentile): if not values or not 0 < percentile <= 100: raise ValueError("invalid sample or percentile") ordered = sorted(values) return ordered[ceil(len(ordered) * percentile / 100) - 1]
def alert(windows): # Each tuple: (total requests, failed requests), or None for missing. if len(windows) < 3: return "INSUFFICIENT_DATA" recent = windows[-3:] if any(w is None for w in recent): return "INSUFFICIENT_DATA" if any(n <= 0 or e < 0 or e > n for n, e in recent): return "INSUFFICIENT_DATA" if any(n < 100 for n, e in recent): return "INSUFFICIENT_DATA" return "PAGE" if all(e * 100 >= 5 * n for n, e in recent) else "OK"
latencies = [100] * 94 + [800] * 5 + [2000]print("p95:", nearest_rank(latencies, 95), "ms")print("p99:", nearest_rank(latencies, 99), "ms")print(alert([(100, 5), (200, 12), (100, 7)]))print(alert([(100, 5), None, (100, 7)]))Expected output:
p95: 800 msp99: 800 msPAGEINSUFFICIENT_DATAThe first three windows have failure rates of 5%, 6% and 7%; all pass the volume floor. The second scenario has a missing window and cannot establish three consecutive violations. The integer comparison avoids floating-point error at the threshold.
Practice
Design a dashboard for checkout; compute the fictional ingestion/storage bill and series bound, then test the model with (100, 4) in the last window and with (99, 99). Explain why neither should page using this rule, and describe a separate low-volume strategy. Include a retention and sampling plan, an owner, missing-data handling and a runbook link placeholder. Do not change real alerting or logging settings.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Telemetry design and alerting — knowledge check
Choose the best answer for each offline scenario.
What is nearest-rank p95 of the lesson sample?
How should error rates from different traffic volumes be combined?
What does missing telemetry mean in the model?
What is the risk of retaining mostly failed traces?
Which charge changes directly in the simplified model if retention drops but ingestion stays constant?