diff --git a/CHANGELOG.md b/CHANGELOG.md index c64e0c13..93c85ad0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - feat: Add APIExecutor for calling arbitrary API endpoints (#298), thanks @Abishek-Newar - fix: use current SDK version in telemetry meter (#335) +- fix: disable httprequestduration metric by default to avoid high cardinality (#344) ## v0.9.2 diff --git a/docs/opentelemetry.md b/docs/opentelemetry.md index 5f7460d1..e1072ee4 100644 --- a/docs/opentelemetry.md +++ b/docs/opentelemetry.md @@ -10,11 +10,12 @@ In cases when metrics events are sent, they will not be viewable outside of infr ### Supported Metrics -| Metric Name | Type | Enabled by default | Description | -|---------------------------------|-----------|--------------------|---------------------------------------------------------------------------------| -| `fga-client.request.duration` | Histogram | Yes | The total request time for FGA requests | -| `fga-client.query.duration` | Histogram | Yes | The amount of time the FGA server took to process the request | -|` fga-client.credentials.request`| Counter | Yes | The total number of times a new token was requested when using ClientCredentials| +| Metric Name | Type | Enabled by default | Description | +|------------------------------------|-----------|--------------------|---------------------------------------------------------------------------------| +| `fga-client.request.duration` | Histogram | Yes | The total request time for FGA requests | +| `fga-client.query.duration` | Histogram | Yes | The amount of time the FGA server took to process the request | +| `fga-client.http_request.duration` | Histogram | No | The time for a single HTTP request to complete (including retries) | +|` fga-client.credentials.request` | Counter | Yes | The total number of times a new token was requested when using ClientCredentials| ### Supported attributes @@ -42,6 +43,8 @@ Not all attributes are enabled by default. Some attributes, like `fga-client.user` have been disabled by default due to their high cardinality, which may result in very high costs when using some SaaS metric collectors. If you expect high cardinality for a specific attribute, you can disable it by updating the telemetry configuration accordingly. +Similarly, the `fga-client.http_request.duration` metric is disabled by default because it tracks every individual HTTP request (including each retry attempt), which can generate a high volume of telemetry data and result in increased costs. You can enable it explicitly in your configuration if you need granular per-request metrics. + If your configuration does not specify a given metric, the default attributes for that metric will be used. @@ -81,7 +84,16 @@ const telemetryConfig = { TelemetryAttribute.FgaClientRequestModelId, TelemetryAttribute.HttpRequestResendCount, ]) - } + }, + // Optional: Enable per-HTTP-request metrics (disabled by default due to high cardinality) + // histogramHttpRequestDuration: { + // attributes: new Set([ + // TelemetryAttribute.HttpHost, + // TelemetryAttribute.HttpResponseStatusCode, + // TelemetryAttribute.HttpRequestMethod, + // TelemetryAttribute.UserAgentOriginal, + // ]) + // } } }; diff --git a/telemetry/configuration.ts b/telemetry/configuration.ts index 82851da5..ba9e770d 100644 --- a/telemetry/configuration.ts +++ b/telemetry/configuration.ts @@ -114,7 +114,8 @@ export class TelemetryConfiguration implements TelemetryConfig { [TelemetryMetric.CounterCredentialsRequest]: {attributes: TelemetryConfiguration.defaultAttributes}, [TelemetryMetric.HistogramRequestDuration]: {attributes: TelemetryConfiguration.defaultAttributes}, [TelemetryMetric.HistogramQueryDuration]: {attributes: TelemetryConfiguration.defaultAttributes}, - [TelemetryMetric.HistogramHttpRequestDuration]: {attributes: TelemetryConfiguration.defaultAttributes}, + // HistogramHttpRequestDuration is disabled by default + [TelemetryMetric.HistogramHttpRequestDuration]: undefined, }; } else { this.metrics = { diff --git a/tests/telemetry/configuration.test.ts b/tests/telemetry/configuration.test.ts index ade0081b..4beccb8c 100644 --- a/tests/telemetry/configuration.test.ts +++ b/tests/telemetry/configuration.test.ts @@ -33,7 +33,9 @@ describe("TelemetryConfiguration", () => { expect(config.metrics?.counterCredentialsRequest?.attributes).toEqual(TelemetryConfiguration.defaultAttributes); expect(config.metrics?.histogramQueryDuration?.attributes).toEqual(TelemetryConfiguration.defaultAttributes); expect(config.metrics?.histogramRequestDuration?.attributes).toEqual(TelemetryConfiguration.defaultAttributes); - }); + // histogramHttpRequestDuration is disabled by default due to high cardinality + expect(config.metrics?.histogramHttpRequestDuration?.attributes).toEqual(undefined); + }); test("should be undefined if empty object passed", () => { const config = new TelemetryConfiguration({}); @@ -41,5 +43,6 @@ describe("TelemetryConfiguration", () => { expect(config.metrics?.counterCredentialsRequest?.attributes).toEqual(undefined); expect(config.metrics?.histogramQueryDuration?.attributes).toEqual(undefined); expect(config.metrics?.histogramRequestDuration?.attributes).toEqual(undefined); - }); + expect(config.metrics?.histogramHttpRequestDuration?.attributes).toEqual(undefined); + }); });