Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
feat(telemetry): refine telemetry metrics and documentation
Victor Hugo dos Santosc3f6ce003c41
diff --git a/backend/CLAUDE.md b/backend/CLAUDE.mdindex d03ec1116a..ffc63d3a16 100644--- a/backend/CLAUDE.md+++ b/backend/CLAUDE.md@@ -694,8 +694,9 @@ Key plugins in `src/server/plugins/`:OpenTelemetry metric setup lives in `src/lib/telemetry/`. Instruments are defined in `metrics.ts` (resolved lazily so they bind to the real MeterProvider installed by `instrumentation.ts` after boot).**Meter split by cardinality:**-- **`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.+- **`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 choke point for our own call sites: 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.+- **`@opentelemetry/instrumentation-http`** — the second allowlist (`HTTP_INSTRUMENTATION_METER_ATTRIBUTES`). `instrumentation.ts` forces the stable HTTP semconv (`OTEL_SEMCONV_STABILITY_OPT_IN`), because the old conventions label the server metric with the raw `Host` header.**Recording is fire-and-forget.** Every `.add()` / `.record()` and every `record*Metric` helper is wrapped in `safely()` in `metrics.ts`, so a broken exporter, a bad instrument name, or a config read before `initEnvConfig()` can never throw into the code being measured. A measurement is an observation of the work, never a step in it — so call sites do not need their own try/catch, and must not treat a metric as something that can fail. The swallow is silent because the logger is itself initialised from config.diff --git a/backend/src/lib/telemetry/instrumentation.ts b/backend/src/lib/telemetry/instrumentation.tsindex f2e7a0bac4..e33186cf9a 100644--- a/backend/src/lib/telemetry/instrumentation.ts+++ b/backend/src/lib/telemetry/instrumentation.ts@@ -122,7 +122,13 @@ const initTelemetryInstrumentation = ({// a scanner sends. Stable drops it, normalizes the method to a fixed set, and adds error.type.// Assigning it (rather than defaulting it) keeps one metric name across cloud and self-hosted, and shuts// out "http/dup", which would emit both attribute sets and double the cardinality this is here to bound.- process.env.OTEL_SEMCONV_STABILITY_OPT_IN = "http";+ // Other namespace tokens are preserved: the value is a comma-separated list and a future+ // instrumentation may read its own namespace out of it.+ const semconvOptIn = (process.env.OTEL_SEMCONV_STABILITY_OPT_IN ?? "")+ .split(",")+ .map((token) => token.trim())+ .filter((token) => token && token.toLowerCase() !== "http" && token.toLowerCase() !== "http/dup");+ process.env.OTEL_SEMCONV_STABILITY_OPT_IN = [...semconvOptIn, "http"].join(",");registerInstrumentations({instrumentations: [new HttpInstrumentation(), new RuntimeNodeInstrumentation()]diff --git a/backend/src/lib/telemetry/metrics.test.ts b/backend/src/lib/telemetry/metrics.test.tsindex 4eb9694281..9323ee39c5 100644--- a/backend/src/lib/telemetry/metrics.test.ts+++ b/backend/src/lib/telemetry/metrics.test.ts@@ -1,6 +1,6 @@import opentelemetry from "@opentelemetry/api";-import { highCardinalityMeter, shouldRecordHighCardinalityMetrics } from "./metrics";+import { highCardinalityMeter, normalizeHttpMethod, shouldRecordHighCardinalityMetrics } from "./metrics";const mockConfig = {OTEL_TELEMETRY_COLLECTION_ENABLED: true,@@ -101,3 +101,30 @@ describe("highCardinalityMeter", () => {expect(getMeter).toHaveBeenCalledWith(meterName);});});++// KNOWN_HTTP_METHODS is a hand copy of the private KNOWN_METHODS set inside+// @opentelemetry/instrumentation-http. If the library's set changes on an upgrade, the two metrics stop+// agreeing on http.request.method and silently become unjoinable, so pin the whole contract here.+describe("normalizeHttpMethod", () => {+ test.each(["GET", "HEAD", "POST", "PUT", "DELETE", "CONNECT", "OPTIONS", "TRACE", "PATCH", "QUERY"])(+ "keeps the semconv-known method %s",+ (method) => {+ expect(normalizeHttpMethod(method)).toBe(method);+ }+ );++ test("upper-cases a known method given in another case", () => {+ expect(normalizeHttpMethod("get")).toBe("GET");+ expect(normalizeHttpMethod("Patch")).toBe("PATCH");+ });++ // Node's parser accepts 35 methods, so these reach us for real; the semconv vocabulary has 10.+ test.each(["PROPFIND", "MKCOL", "UNLOCK", "M-SEARCH", "PURGE"])("folds %s onto _OTHER", (method) => {+ expect(normalizeHttpMethod(method)).toBe("_OTHER");+ });++ test("defaults to GET when the method is absent, matching the instrumentation", () => {+ expect(normalizeHttpMethod(undefined)).toBe("GET");+ expect(normalizeHttpMethod("")).toBe("GET");+ });+});diff --git a/docs/self-hosting/guides/monitoring-telemetry.mdx b/docs/self-hosting/guides/monitoring-telemetry.mdxindex fa718a2015..70989cfbfa 100644--- a/docs/self-hosting/guides/monitoring-telemetry.mdx+++ b/docs/self-hosting/guides/monitoring-telemetry.mdx@@ -344,11 +344,11 @@ Replace `otel-collector:8889` with the actual hostname and port where your OpenTInfisical emits metrics on two OpenTelemetry meters simultaneously. Choose which to scrape based on your deployment scale.- **High-cardinality, per-actor meters:** the `Infisical` and `API` meters' original metrics (`infisical.http.server.request.*`, `infisical.http.server.error.count`, `infisical.secret.read.count`, `infisical.auth.attempt.count`, `infisical.kmip.operation.count`) include per-actor labels such as `user.email`, `identity.name`, `client.address`, `user_agent.original`, `organization.name`, `project.name`, `secret.path`, and `secret.name`. The `SecretSyncs`, `PkiSyncs`, and `Integrations` meters likewise carry unbounded labels such as `syncId`. Useful for self-hosted deployments where you want per-user visibility directly in Grafana. May become expensive at large scale (many users, identities, or IPs) due to label cardinality.-- **`InfisicalCore` meter (bounded-cardinality):** all newer metrics (queue, audit log, product analytics aggregation, alert dispatch, permission cache, secret cache, rate limit, build info, `infisical.core.http.error.count`, authentication latency, token renewal, SSO config changes, SCIM provisioning, and database connection pool) use **only bounded enums and static route templates** as labels (e.g. HTTP method, parameterized `http.route`, error type, outcome). A strict allowlist drops every other attribute at the SDK level, so **no tenant or actor identifiers are emitted**; no organization ID, project IDs, names, emails, IPs, or user agents. This keeps the series count independent of how many organizations, users, or identities you have. Per-org and per-actor detail is available in audit logs instead.+- **`InfisicalCore` meter (bounded-cardinality):** all newer metrics (queue, audit log, product analytics aggregation, alert dispatch, permission cache, secret cache, rate limit, build info, `infisical.core.http.request.count`, `infisical.core.http.error.count`, authentication latency, token renewal, SSO config changes, SCIM provisioning, and database connection pool) use **only bounded enums and static route templates** as labels (e.g. HTTP method, parameterized `http.route`, error type, outcome). A strict allowlist drops every other attribute at the SDK level, so **no tenant or actor identifiers are emitted**; no organization ID, project IDs, names, emails, IPs, or user agents. This keeps the series count independent of how many organizations, users, or identities you have. Per-org and per-actor detail is available in audit logs instead.All meters emit at the same time. If you're a self-hosted instance and find the per-actor labels useful, keep using the high-cardinality metrics. For larger or multi-tenant deployments, scrape only the `InfisicalCore` metrics to keep cardinality under control.-To eliminate the cost of the high-cardinality meters entirely, set `OTEL_DROP_HIGH_CARDINALITY_METERS=true`. Infisical then stops recording to the `Infisical`, `API`, `SecretSyncs`, `PkiSyncs`, and `Integrations` meters altogether, so nothing is measured, stored, exported, or held in memory for them. The instruments still exist in code, so nothing errors. Only `InfisicalCore` metrics are emitted. Defaults to `false`.+To eliminate the cost of the high-cardinality meters entirely, set `OTEL_DROP_HIGH_CARDINALITY_METERS=true`. Infisical then stops recording to the `Infisical`, `API`, `SecretSyncs`, `PkiSyncs`, and `Integrations` meters altogether, so nothing is measured, stored, exported, or held in memory for them. The instruments still exist in code, so nothing errors. The `InfisicalCore` metrics, the Node runtime metrics, and the HTTP instrumentation metrics are unaffected and keep emitting. Defaults to `false`.<Warning>**With the high-cardinality meters enabled and `OTEL_EXPORT_TYPE=prometheus`, memory use grows with@@ -468,7 +468,9 @@ These metrics track all HTTP API requests to Infisical, including request counts**Unit**: `{request}`- **Description**: Total API requests with bounded labels. The low-cardinality counterpart to `infisical.http.server.request.count`; same request volume, but labels are restricted to the InfisicalCore allowlist so the series count stays independent of org/user/identity count. Divide `infisical.core.http.error.count` by this to get an error rate per route. Unlike its high-cardinality twin, it is emitted even when `OTEL_DROP_HIGH_CARDINALITY_METERS=true`.+ **Description**: Total API requests, carrying only the HTTP method, the parameterized route template, and the status code. The low-cardinality counterpart to `infisical.http.server.request.count`, so the series count stays independent of how many organizations, users, or identities you have. It still emits when `OTEL_DROP_HIGH_CARDINALITY_METERS=true`.++ For HTTP error rate per route, divide the `http.response.status_code >= 400` series by the total on this metric. Do not use `infisical.core.http.error.count` as the numerator: it counts thrown errors, and a response that sets a 4xx or 5xx status without throwing (an unmatched route, for example) never reaches it.**Attributes**:- `http.request.method` (string): HTTP method@@ -1112,12 +1114,14 @@ These low-level HTTP metrics are automatically collected by OpenTelemetry's inst**Unit**: `s` (seconds)- **Description**: Outbound HTTP request duration.+ **Description**: Outbound HTTP request duration, aggregated across every destination.**Attributes**:- `http.request.method` (string): HTTP method, normalized to a fixed set- `http.response.status_code` (int): HTTP status code- `error.type` (string, optional): Present only when the request failed++ The destination host is deliberately omitted. Infisical calls a different set of hosts for every deployment (webhook URLs, secret sync destinations, identity providers), so labelling this metric with the destination would grow the series count without limit. There is no setting that restores it. For per-destination detail, use the secret sync and audit log stream metrics, which are labelled by provider.</Accordion></AccordionGroup>