Skip to content

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

refactor: remove KMS crypto metrics and related telemetry from instrumentation

Victor Hugo dos Santos51e50c17b905
diff --git a/backend/src/lib/telemetry/instrumentation.ts b/backend/src/lib/telemetry/instrumentation.ts
index f6ea83819f..d80fd8fb8e 100644
--- a/backend/src/lib/telemetry/instrumentation.ts
+++ b/backend/src/lib/telemetry/instrumentation.ts
@@ -52,8 +52,6 @@ const INFISICAL_CORE_METER_ATTRIBUTES = [
"audit_log.backend",
"audit_log.drop_reason",
"audit_log_stream.provider",
- "kms.operation",
- "kms.key_type",
"scim.operation",
"sso.provider",
"sso.action",
diff --git a/backend/src/lib/telemetry/metrics.ts b/backend/src/lib/telemetry/metrics.ts
index 108d5b146a..134c539b3c 100644
--- a/backend/src/lib/telemetry/metrics.ts
+++ b/backend/src/lib/telemetry/metrics.ts
@@ -265,44 +265,6 @@ export const auditLogStreamAlertFiredCounter = infisicalCoreMeter.createCounter(
}
);
-// KMS crypto metrics. Wired in kms-service.ts by wrapping the encryptor/decryptor returned by
-// encryptWithKmsKey / decryptWithKmsKey. Captures per-operation latency including external KMS network calls.
-export enum KmsCryptoOperation {
- ENCRYPT = "encrypt",
- DECRYPT = "decrypt"
-}
-
-export enum KmsKeyType {
- INTERNAL = "internal",
- AWS = "aws",
- GCP = "gcp"
-}
-
-export const kmsCryptoDurationHistogram = infisicalCoreMeter.createHistogram("infisical.kms.crypto.duration", {
- description:
- "External KMS (AWS/GCP) encrypt/decrypt latency including network round trip (use _count for operation volume).",
- unit: "s"
-});
-
-export const recordKmsCryptoMetric = (params: {
- operation: KmsCryptoOperation;
- keyType: KmsKeyType;
- outcome: "success" | "failure";
- durationSeconds: number;
- errorType?: string;
-}) => {
- if (!isTelemetryEnabled()) return;
- if (params.keyType === KmsKeyType.INTERNAL) return;
- const attributes = {
- ...buildBaseAttributes(),
- "kms.operation": params.operation,
- "kms.key_type": params.keyType,
- outcome: params.outcome,
- ...(params.errorType ? { "error.type": params.errorType } : {})
- };
- kmsCryptoDurationHistogram.record(params.durationSeconds, attributes);
-};
-
// Permission cache metrics. Wired in lib/cache/with-cache.ts withCacheFingerprint().
export const permissionCacheLookupCounter = infisicalCoreMeter.createCounter(
"infisical.permission_cache.lookup.count",
diff --git a/backend/src/services/kms/kms-service.ts b/backend/src/services/kms/kms-service.ts
index 513bf8b765..4bf4c44b6d 100644
--- a/backend/src/services/kms/kms-service.ts
+++ b/backend/src/services/kms/kms-service.ts
@@ -20,12 +20,10 @@ import { crypto } from "@app/lib/crypto/cryptography";
import { detectPqcVariantFromDer } from "@app/lib/crypto/pqc/pqc-crypto";
import { AsymmetricKeyAlgorithm, isPqcKeyAlgorithm, KMS_TO_OPENSSL_NAME, signingService } from "@app/lib/crypto/sign";
import { BadRequestError, ForbiddenRequestError, NotFoundError } from "@app/lib/errors";
-import { classifyError } from "@app/lib/errors/classify";
import { logger } from "@app/lib/logger";
import { alphaNumericNanoId } from "@app/lib/nanoid";
import { requestMemoKeys } from "@app/lib/request-context/memo-keys";
import { requestMemoize } from "@app/lib/request-context/request-memoizer";
-import { KmsCryptoOperation, KmsKeyType, recordKmsCryptoMetric } from "@app/lib/telemetry/metrics";
import {
getByteLengthForSymmetricEncryptionAlgorithm,
KMS_ROOT_CONFIG_UUID,
@@ -337,27 +335,10 @@ export const kmsServiceFactory = ({
throw new BadRequestError({ message: "Invalid KMS provider." });
}
- const externalKeyType = kmsDoc.externalKms.provider === KmsProviders.Aws ? KmsKeyType.AWS : KmsKeyType.GCP;
return async ({ cipherTextBlob }: Pick<TDecryptWithKmsDTO, "cipherTextBlob">) => {
- const cryptoStart = Date.now();
try {
const { data } = await externalKms.decrypt(cipherTextBlob);
- recordKmsCryptoMetric({
- operation: KmsCryptoOperation.DECRYPT,
- keyType: externalKeyType,
- outcome: "success",
- durationSeconds: (Date.now() - cryptoStart) / 1000
- });
return data;
- } catch (err) {
- recordKmsCryptoMetric({
- operation: KmsCryptoOperation.DECRYPT,
- keyType: externalKeyType,
- outcome: "failure",
- durationSeconds: (Date.now() - cryptoStart) / 1000,
- errorType: classifyError(err)
- });
- throw err;
} finally {
await externalKms.cleanup();
}
@@ -636,27 +617,10 @@ export const kmsServiceFactory = ({
throw new BadRequestError({ message: "Invalid KMS provider." });
}
- const externalKeyType = kmsDoc.externalKms.provider === KmsProviders.Aws ? KmsKeyType.AWS : KmsKeyType.GCP;
return async ({ plainText }: Pick<TEncryptWithKmsDTO, "plainText">) => {
- const cryptoStart = Date.now();
try {
const { encryptedBlob } = await externalKms.encrypt(plainText);
- recordKmsCryptoMetric({
- operation: KmsCryptoOperation.ENCRYPT,
- keyType: externalKeyType,
- outcome: "success",
- durationSeconds: (Date.now() - cryptoStart) / 1000
- });
return { cipherTextBlob: encryptedBlob };
- } catch (err) {
- recordKmsCryptoMetric({
- operation: KmsCryptoOperation.ENCRYPT,
- keyType: externalKeyType,
- outcome: "failure",
- durationSeconds: (Date.now() - cryptoStart) / 1000,
- errorType: classifyError(err)
- });
- throw err;
} finally {
await externalKms.cleanup();
}
diff --git a/docs/self-hosting/guides/monitoring-telemetry.mdx b/docs/self-hosting/guides/monitoring-telemetry.mdx
index 8f7d78057c..19d968808d 100644
--- a/docs/self-hosting/guides/monitoring-telemetry.mdx
+++ b/docs/self-hosting/guides/monitoring-telemetry.mdx
@@ -343,7 +343,7 @@ Replace `otel-collector:8889` with the actual hostname and port where your OpenT
Infisical emits metrics on two OpenTelemetry meters simultaneously. Choose which to scrape based on your deployment scale.
- **Legacy meters (high-cardinality):** 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 small self-hosted deployments where you want per-user visibility directly in Grafana. May become expensive at large scale due to label cardinality.
-- **`InfisicalCore` meter (bounded-cardinality):** all newer metrics (queue, audit log, KMS, 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 IDs and bounded enums as labels. No names, emails, IPs, or user agents. Designed for large or multi-tenant deployments. Per-actor detail is available in audit logs instead.
+- **`InfisicalCore` meter (bounded-cardinality):** all newer metrics (queue, audit log, 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 IDs and bounded enums as labels. No names, emails, IPs, or user agents. Designed for large or multi-tenant deployments. Per-actor detail is available in audit logs instead.
All meters emit at the same time. If you are a small self-hosted instance and find the per-actor labels useful, keep using the legacy-meter metrics. For larger deployments, scrape only the `InfisicalCore` metrics to keep cardinality under control.
@@ -857,40 +857,6 @@ Per-provider observability for the audit-log stream feature (Datadog, Splunk, Cu
</Accordion>
</AccordionGroup>
-### KMS Crypto Metrics (InfisicalCore)
-
-KMS encrypt/decrypt is the hottest path in the system (every secret read and write touches it). These metrics capture per-operation latency, including the network round trip for external KMS providers (AWS / GCP).
-
-<AccordionGroup>
- <Accordion title="KMS Crypto Count">
- **Metric Name**: `infisical.kms.crypto.count`
-
- **Type**: Counter
-
- **Unit**: `{operation}`
-
- **Description**: KMS encrypt/decrypt operations by key type and outcome.
-
- **Attributes**:
- - `kms.operation` (string): `encrypt` or `decrypt`
- - `kms.key_type` (string): `internal`, `aws`, `gcp`
- - `outcome` (string): `success` or `failure`
- - `error.type` (string, only on failure)
- </Accordion>
-
- <Accordion title="KMS Crypto Duration">
- **Metric Name**: `infisical.kms.crypto.duration`
-
- **Type**: Histogram
-
- **Unit**: `s`
-
- **Description**: Per-operation latency. Internal KMS is local AES-GCM (sub-millisecond). External KMS includes a network round trip (typically 50-200ms).
-
- **Attributes**: `kms.operation`, `kms.key_type`, `outcome`, `error.type` (on failure)
- </Accordion>
-</AccordionGroup>
-
### Permission Cache Metrics (InfisicalCore)
The CASL permission cache uses a fingerprint-based two-tier scheme. These metrics tell you whether the cache is doing its job.