fix: mem leak due to unbounded metrics cardinality#1931
Conversation
✅ Deploy Preview for polite-licorice-3db33c canceled.
|
| interceptor, err := otelconnect.NewInterceptor(otelconnect.WithTrustRemote()) | ||
| interceptor, err := otelconnect.NewInterceptor( | ||
| otelconnect.WithTrustRemote(), | ||
| otelconnect.WithoutServerPeerAttributes(), |
| // limit metric attribute cardinality to prevent unbounded memory growth from | ||
| // high-cardinality attributes (OTel spec recommends 2000, Go SDK defaults to unlimited) | ||
| // 2000 is recommended by OTel spec and is a reasonable default for our use case, | ||
| // but can be overridden with the OTEL_GO_X_CARDINALITY_LIMIT environment variable | ||
| msdk.WithCardinalityLimit(2000), |
There was a problem hiding this comment.
Additional guard to prevent metrics leak for some other custom metrics, etc.
There was a problem hiding this comment.
Could you please mention this in the docs too?
There was a problem hiding this comment.
Code Review
This pull request updates telemetry settings by disabling server peer attributes in the connect interceptor and attempting to implement a metric cardinality limit. A critical issue was identified where the msdk.WithCardinalityLimit function is not available in the stable OpenTelemetry Go SDK, which will cause a compilation failure. The feedback suggests removing this programmatic configuration and instead relying on the OTEL_GO_X_CARDINALITY_LIMIT environment variable for cardinality management.
juanparadox
left a comment
There was a problem hiding this comment.
Thank you for jumping on this 😄
Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
|
🤖 I have created a release *beep* *boop* --- <details><summary>flagd: 0.15.1</summary> ## [0.15.1](flagd/v0.15.0...flagd/v0.15.1) (2026-04-07) ### 🐛 Bug Fixes * object flags without `defaultVaraint` dont default in RPC ([#1925](#1925)) ([17f833e](17f833e)) * **security:** update module github.com/go-jose/go-jose/v4 to v4.1.4 [security] ([#1929](#1929)) ([cf22a11](cf22a11)) * zombie process on metrics server fail ([#1926](#1926)) ([0271068](0271068)) * mem leak due to unbounded metrics cardinality ([#1931](#1931)) ([176866e](176866e)) </details> <details><summary>flagd-proxy: 0.9.3</summary> ## [0.9.3](flagd-proxy/v0.9.2...flagd-proxy/v0.9.3) (2026-04-07) ### 🐛 Bug Fixes * **security:** update module github.com/go-jose/go-jose/v4 to v4.1.4 [security] ([#1929](#1929)) ([cf22a11](cf22a11)) </details> <details><summary>core: 0.15.1</summary> ## [0.15.1](core/v0.15.0...core/v0.15.1) (2026-04-07) ### 🐛 Bug Fixes * mem leak due to unbounded metrics cardinality ([#1931](#1931)) ([176866e](176866e)) * **security:** update module github.com/go-jose/go-jose/v4 to v4.1.4 [security] ([#1929](#1929)) ([cf22a11](cf22a11)) </details> --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). --------- Signed-off-by: OpenFeature Bot <109696520+openfeaturebot@users.noreply.github.com> Signed-off-by: Todd Baert <todd.baert@dynatrace.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Todd Baert <todd.baert@dynatrace.com>



Fixes a memory leak that can be seen with many remote clients due to default OTel metrics attributes included remote peer and ephemeral port.
See: https://github.com/connectrpc/otelconnect-go?tab=readme-ov-file#reducing-metrics-and-tracing-cardinality
I tested this with this integration test (I can see the memory leak and confirmed this fixes it).
Details