When One HTTP Metric Took Down Our Observability Stack
A Prometheus high-cardinality incident caused by raw HTTP route labels, examining OpenTelemetry failures, OOM restarts, and mitigation strategies.
Two services were sending the raw path for the endpoints “/user/918273” as the attribute for the http.route metric, instead of using the corresponding route template “/user/{unique_id}” for http.route. In the incident described in this case study, the shared OpenTelemetry Collector pods failed and reinitialized.
Later, both Prometheus replicas in the HA/Thanos setup failed due to out-of-memory (OOM) terminations. At the same time, a high volume of trace-export errors was stuffed into Sentry, consuming the quotas for the errors there. In this case study, we describe the scenario in detail, explain how to find unsafe dimensions on a metric, investigate cross-signal effects, and finally, explain why a Collector-side rewrite is only an emergency fix for such problems.
The First Symptom Was a Sentry Quota Alarm
The very first notification in this incident was a hit to the application team’s Sentry event quota limit. The events looked something like this: “Failed to export OpenTelemetry traces via HTTP to /v1/traces”.
Transient error ... HTTPConnectionPool(host='<redacted>', port=<redacted>):
Max retries exceeded with url: /v1/traces ...
Failed to establish a new connection ...
The /v1/traces path is used to identify OTLP/HTTP trace-export attempts. This connection error indicates that telemetry delivery has failed for some reason. We don’t know yet whether the cause is DNS, network issues, or somewhere else in the delivery path to the Collector.
In addition to OpenTelemetry Collector pod failures, we also observed that both Prometheus replicas in our HA/Thanos configuration restarted after running and experiencing out-of-memory (OOM) terminations. This, combined with trace-export errors now filling the Sentry error quotas, created a medium-to-high level of infrastructure pain, along with an unusual set of noisy application-level metrics.
The Shared Pipeline and Its Failure Boundaries
The two applications in question were instrumenting metrics and traces on the application side. These were then sent to the OpenTelemetry Collectors for the various applications (the shared gateway in the center). In addition to sending metrics to the application-specific monitoring services (in this case, Prometheus for metrics and a tracing back-end for traces), Sentry also collected application errors as events.
Figure 1. Conceptual pre-incident telemetry flow and shared failure boundaries; exact ingestion and Thanos components require deployment confirmation.
A sketch of the used setup is shown in Figure 1. The issues occurred at the level of the shared telemetry gateway, the gating firewall. However, the two levels are not clearly separate, as both collect and send metrics and traces, and both are ingested by applications for Analytics/Log insight in addition to the alerts already mentioned in the DZone Monitoring article.
The Metric Attribute That Broke the Cardinality Budget
Application services are emitting raw URI paths in the http.route metric attribute instead of bounded route templates (e.g.,/user/{unique_id} for http.route == "/user/{unique_id}"). This will result in every unique ID being another attribute combination.
Expected: http.route="/user/{unique_id}"
Observed: http.route="/user/918273"
Observed: http.route="/user/918274"
Observed: http.route="/user/918275"
The http.route OpenTelemetry semantic convention for HTTP metrics defines a low-cardinality route template, http.route. The raw URI path is used as the metric value as a last resort. But as mentioned previously, the raw path of a request is not a substitute for a route template for http.route. Each unique user ID is another attribute dimension that results in another time series for each affected metric and all the other labels.
This sets out the key metrics that were recorded for the more affected service:
|
Observation |
Reported value |
|
Distinct route values in one snapshot |
Approximately 4,800 |
|
Distinct route values across three hours |
Approximately 24,000 |
|
Metric series associated with one pod |
More than 38,000 |
Note that the number of measurements and the original query (e.g., Prometheus query language), as well as the time frame of the measurement (e.g., a specific time window), the name of the measurement (e.g., the name of the metric), and the label definitions have to be provided as well. Distinct route count over time vs. number of time series: They are not equivalent.
The Histogram buckets, status-code labels, HTTP method labels, and instance labels can multiply the number of time series a lot. The number to look at for problems is the total number of metric-label combinations, not just the number of URI dimensions.
Figure 2. Reported route-cardinality observations, observed restarts and OOM terminations, and possible propagation paths (dashed).
Diagnose Cardinality Before Restarting Everything
Step 1: Identify the Metric and Raw Route Label
Check which metric contains the problematic dimension. With Prometheus naming conventions, http.route may appear as http_route; the metric itself varies with instrumentation and translation settings.
# Illustration only: replace metric and labels with deployed names.
count by (job) (
count by (job, http_route) (
http_server_request_duration_seconds_count
)
)
This graph shows the number of distinct route-label combinations, not the total number of series, for each job over time. This can be compared with other services, and the anonymous labels are expanded to look at the ID present on each.
Step 2: Check Prometheus TSDB Pressure
# Active series in each Prometheus instance
prometheus_tsdb_head_series
# Rate of new series creation, when exposed
rate(prometheus_tsdb_head_series_created_total[5m])
Add both Prometheus replicas to the incident timeline and add a graph for their memory working set (with limits), as well as their restart times and their Kubernetes lastState.terminated.reason. This will let you see whether the URI-label explosion caused the 2 applications to be OOM-killed before they were OOM-killed.
Step 3: Inspect Collector Health and Trace-Export Failures
Compare application exporter errors with the Collector pod lifecycle, receiver/refusal metrics, exporter queue pressure, and memory utilization. A connection failure to /v1/traces is consistent with a temporarily unavailable gateway, but it is not exclusive proof of OOM or readiness failure.
Useful Kubernetes checks (replace labels and namespaces):
kubectl -n observability get pods -l app=otel-collector
kubectl -n observability describe pod <collector-pod>
kubectl -n observability describe pod <prometheus-pod>
The termination reasons for the Collector must be recorded separately from those of Prometheus. The case described here includes only Prometheus OOM restarts.
Step 4: Understand Why HA and Thanos Did Not Prevent the Outage
While Thanos Query can usually deduplicate overlapping series from multiple, healthy Prometheus instances and even fill in some “gaps” left by down instances, Thanos Query cannot prevent two instances of Prometheus from running amok and exhausting their memory when both instances are reading in the same unsafe metric dimensions. This kind of cardinality mitigation happens at query time, not on a per-replica basis.
Don’t mistake this for Thanos Crash: Just because two Prometheus hosts went down simultaneously due to OOM, that doesn’t necessarily mean Thanos Query, the Thanos Sidecar, or even Thanos Dashboard went down. Notice the availability of the /v1/traces endpoint (which is a totally separate service) and the two hosts running Prometheus in this case study.
The Collector-Side Emergency Mitigation
During the incident, we addressed the high-cardinality dimension http.route for the OpenTelemetry Collector by normalizing the ID-like values to /user/{unique_id} as a centralized mitigation on top of the already affected application.
Below is an example transform processor to undertake emergency correction for high-cardinality dimension in http.route.
processors:
transform/normalize_http_route:
error_mode: ignore
metric_statements:
- context: datapoint
statements:
# /user/918273 -> /user/{unique_id}
- replace_pattern(attributes["http.route"], "^/user/[0-9]+$", "/user/{unique_id}")
service:
pipelines:
metrics:
receivers: [otlp]
processors: [memory_limiter, transform/normalize_http_route, batch]
exporters: [prometheus]
Note that this is NOT the actual configuration used for the incident and should NOT be deployed without proper testing and verification against your specific scenario.
This is just a sample; please test it and make sure all components are up and running (availability of the Collector component, choice of exporter, support for specific functions by the version of the Collector installed). In addition, the processor order may differ.
Just because you have normalized your ID-like attributes (e.g. http.route to /user/{unique_id}) does not mean you have correctly aggregated your metrics. Each distinct cumulative counter/histogram will now have the same attributes but be separate series of data. This must then be handled by your downstream pipeline to correctly sum up these series of data.
Instead of re-writing safe, existing metric streams from applications with frameworks like Express.js or Django (e.g., their matched route template for /http.route instead of their raw path), a simple configuration change to these existing streams could ensure they are correctly, completely, and precisely aggregated downstream (or dropped if a durable resolution isn’t possible in the midst of an incident).
Why Sentry Was Involved
The Sentry integration for the Python OpenTelemetry SDK logs the exporter’s errors as application errors in Sentry. This means Sentry error-event quota is consumed for repeated failures of trace-export path /v1/traces errors even though no business requests failed.
Note that, although the above path may have occurred for the above-described incident, you should always verify the information (logger name, log level, SDK integration, quota consumption) in Sentry events, and be very careful to distinguish quota exhaustion from Sentry discard/stamping of really erroring business cases.
Architectural guardrails that prevent kinds of errors from propagating into application error budgets, even though they are errors in your metrics pipelines, are important. In this case, just silencing the logger is not going to be sufficient.
Guardrails That Would Contain the Next Incident
As a layered set of checks as opposed to a single line of code.
- Emit only route templates in http.route. Do not substitute raw paths for unmatched routes.
- SDK / reporter: check for the correct version of the SDK (plus the metric views, attribute caps, etc. as applicable for the respective programming language + instrumentation used here).
- At the Collector level, ensure all filtering and transformation are correctly done and that there is sufficient monitoring of refused/dropped metrics as well as pressure on the Collector’s queues; validate that correct aggregation is being done.
- Monitor active-series growth, new series creation, low memory, and replica restarts; track sample volume per target replica in Prometheus for the health of re-routed and unaffected trace pipelines.
- In topology: Change layout of noisy workloads vs. critical trace export to prevent failure of one signal type from affecting other signals.
- In CI/CD tests: Also test routes with lots of unique IDs and assert that the corresponding route-attribute values stay within a reasonable boundary.
- For Sentry: route telemetry-exporter failures to the operational channel for the product, while keeping all application error events for the product at the quota for defects in the application.
These recommendations were not incorporated into the protocol for the above incident. The normalization that was done in the Collector to handle the high volume of data is the “workaround” that is described in the above account.
What This Incident Changed About the Design Review
There are two lessons in this for high availability of independent replicas, such as two possible OpenTelemetry collector instances. First, high availability alone does not solve the problem of a workload that exceeds the memory of all replicas. Second, shared collectors for metrics and traces couple the two signals, such that high load in metrics and failed delivery of traces can surface as errors in completely different products, like Sentry.
In the long run, it might be easier to do the engineering to ensure that the route attribute is created correctly at the application level, enforce a set of contractual obligations for telemetry, track cardinality budgets, and test for failure. One would expect observability to help discover an incident, not cause it.
Technical References
- OpenTelemetry HTTP metrics semantic conventions: https://opentelemetry.io/docs/specs/semconv/http/http-metrics/
- OpenTelemetry Collector transform processor: https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/processor/transformprocessor/README.md
- Prometheus storage: https://prometheus.io/docs/prometheus/latest/storage/
- Thanos Query and HA replica deduplication: https://thanos.io/tip/components/query.md/
- Sentry Python logging integration: https://docs.sentry.io/platforms/python/integrations/logging/
Opinions expressed by DZone contributors are their own.