Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

chore(telemetry): enhance ESLint rules and documentation for OpenTelemetry usage

Victor Hugo dos Santosb78ec715c316
diff --git a/backend/.eslintrc.js b/backend/.eslintrc.js
index ba9d6e37de..1df84d6b15 100644
--- a/backend/.eslintrc.js
+++ b/backend/.eslintrc.js
@@ -26,10 +26,23 @@ module.exports = {
files: ["./src/**/*"],
excludedFiles: ["./src/lib/telemetry/*"],
rules: {
+ "no-restricted-imports": [
+ "error",
+ {
+ patterns: [
+ {
+ group: ["@opentelemetry/*"],
+ message:
+ "OpenTelemetry may only be imported from src/lib/telemetry. Record through the instruments exported by @app/lib/telemetry/metrics, or add your instrument there."
+ }
+ ]
+ }
+ ],
"no-restricted-syntax": [
"error",
{
- selector: "MemberExpression[property.name='getMeter']",
+ selector:
+ "MemberExpression[property.name='getMeter'], MemberExpression[property.value='getMeter'], ObjectPattern > Property[key.name='getMeter']",
message:
"Do not acquire an OpenTelemetry meter directly. Use highCardinalityMeter (per-actor labels) or resolveCoreMeter (observable gauges) from @app/lib/telemetry/metrics."
}
diff --git a/backend/CLAUDE.md b/backend/CLAUDE.md
index 6f5c071900..6be602e79a 100644
--- a/backend/CLAUDE.md
+++ b/backend/CLAUDE.md
@@ -403,7 +403,9 @@ OpenTelemetry metric setup lives in `src/lib/telemetry/`. Instruments are define
- **`InfisicalCore`** — the meter for all new metrics. A strict attribute allowlist (`INFISICAL_CORE_METER_ATTRIBUTES` in `telemetry-attributes.ts`) is applied via an SDK View, so **only bounded labels survive** — HTTP method, parameterized `http.route` template, and low-cardinality enums. This is the single choke point: any attribute passed at a call site that isn't in the allowlist is silently dropped.
- **Legacy `Infisical` / `API` / `SecretSyncs` / `PkiSyncs` / `Integrations`** — carry unbounded per-actor labels (`HIGH_CARDINALITY_METER_NAMES`). Disabled wholesale via `OTEL_DROP_HIGH_CARDINALITY_METERS=true` in multi-tenant/cloud.
-**Never let an unbounded attribute reach the SDK's `record()`, and never acquire a meter outside `src/lib/telemetry/`.** An attributes processor (the allowlist View) bounds memory because the SDK filters attributes *before* hashing them; a `DROP` aggregation does not, because it is consulted *after*. Under cumulative temporality — which `OTEL_EXPORT_TYPE=prometheus` mandates — `TemporalMetricProcessor` retains one map entry per distinct attribute set with no cardinality cap, for the lifetime of the process. So a dropped meter that is still recorded to leaks heap, which is why `OTEL_DROP_HIGH_CARDINALITY_METERS` gates at the call site (`highCardinalityMeter` / `shouldRecordHighCardinalityMetrics` in `metrics.ts`) *and* strips attributes in the View. A `no-restricted-syntax` ESLint rule blocks `getMeter` outside `src/lib/telemetry/` so a new meter can't bypass the gate; use `highCardinalityMeter` for per-actor instruments and `resolveCoreMeter` for `InfisicalCore` observable gauges.
+**A new instrument goes on `InfisicalCore` and carries only bounded attributes.** The per-actor labels on the legacy meters are a deliberate exception, not a precedent: they are allowed only through `highCardinalityMeter`, so that `OTEL_DROP_HIGH_CARDINALITY_METERS` can switch them off. Do not put unbounded attributes on any other meter, and do not acquire a meter outside `src/lib/telemetry/` — ESLint blocks both `@opentelemetry/*` imports and `getMeter` access there, so use `highCardinalityMeter` for per-actor instruments and `resolveCoreMeter` for `InfisicalCore` observable gauges.
+
+The gate has to sit at the call site because **a `DROP` aggregation does not bound memory; only an attributes processor does.** The SDK filters attributes *before* hashing them (so the allowlist View is bounded) but consults the aggregator *after* (so a dropped data point has already been keyed by its full attribute set). Under cumulative temporality — which `OTEL_EXPORT_TYPE=prometheus` mandates — `TemporalMetricProcessor` then retains one entry per distinct attribute set, with no cardinality cap, for the lifetime of the process. A meter whose data points are dropped therefore still leaks heap if anything records to it, which is why the flag stops the recording (`shouldRecordHighCardinalityMetrics` in `metrics.ts`) *and* the View strips attributes. With the flag off — the self-hosted default — that retention is the operator's informed choice; the tradeoff is documented in the monitoring guide.
**Rules for InfisicalCore metrics:**
- **No per-tenant / per-actor identifiers** as labels — no org id, user id/email, identity id, ip, user agent, request id, or free-form values (e.g. environment slug). These scale series count with customer count, which breaks CloudWatch's 1000-datapoint-per-OTLP-request limit and drives per-GB ingestion cost. Use the **audit log table** for per-org / per-actor breakdowns.
diff --git a/docs/self-hosting/guides/monitoring-telemetry.mdx b/docs/self-hosting/guides/monitoring-telemetry.mdx
index dc90647058..2e157e20fd 100644
--- a/docs/self-hosting/guides/monitoring-telemetry.mdx
+++ b/docs/self-hosting/guides/monitoring-telemetry.mdx
@@ -357,10 +357,13 @@ To eliminate the cost of the high-cardinality meters entirely, set `OTEL_DROP_HI
ceiling, so on a busy instance this shows up as heap that climbs with uptime and longer garbage
collection pauses.
- This is fine for a single-organization deployment with a stable set of users, IP addresses, and
- clients: the label combinations converge and the memory does too. If you serve many organizations,
- many source IPs, or many client versions, set `OTEL_DROP_HIGH_CARDINALITY_METERS=true` and get
- per-actor detail from audit logs instead. Restarting the instance releases the memory.
+ Whether that matters depends on churn rather than on how many organizations you have. If your secret
+ paths and names, users, source IP addresses, and client versions are all largely stable, the growth
+ is slow enough to ignore. It keeps going as long as any one of them keeps turning over: secrets
+ created, renamed, or reorganized over time; clients on dynamic or short-lived IP addresses such as CI
+ runners and autoscaled pods; or a fleet that upgrades often. If any of those describe your
+ deployment, set `OTEL_DROP_HIGH_CARDINALITY_METERS=true` and get per-actor detail from audit logs
+ instead. Restarting the instance releases the memory.
`OTEL_EXPORT_TYPE=otlp` is not affected: it exports delta metrics, so each push interval starts
fresh and nothing accumulates across the process lifetime.