Skip to content

fix(semconv): clear pooled slices to enable GC - #8352

Merged
pellared merged 4 commits into
open-telemetry:mainfrom
pellared:fix-8320
May 21, 2026
Merged

pellared merged 4 commits into
open-telemetry:mainfrom
pellared:fix-8320

Conversation

@pellared

@pellared pellared commented May 20, 2026 •

Copy link
Copy Markdown
Member

Fixes #8320

Credits to @ash2k

@pellared pellared added this to the v1.44.0 milestone May 20, 2026
@pellared pellared added the Skip Changelog PRs that do not require a CHANGELOG.md entry label May 20, 2026
@XSAM
XSAM requested a review from Copilot May 20, 2026 16:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the generated semantic-convention metric helper code to proactively clear pooled option-slice contents before reusing them, allowing referenced objects to be garbage-collected instead of being retained by sync.Pool.

Changes:

  • Clear []metric.AddOption and []metric.RecordOption slices (via clear) before resetting length and returning them to the pool.
  • Apply the change across the generated semconv/v1.41.0/*conv/metric.go files.
  • Update the Go codegen template (semconv/templates/registry/go/instrument.j2) so future regenerations keep the same behavior.

Reviewed changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated no comments.

Show a summary per file
File Description
semconv/v1.41.0/azureconv/metric.go Clear pooled add/record option slices before putting them back in the pool.
semconv/v1.41.0/cicdconv/metric.go Clear pooled add/record option slices before putting them back in the pool.
semconv/v1.41.0/containerconv/metric.go Clear pooled add/record option slices before putting them back in the pool.
semconv/v1.41.0/dbconv/metric.go Clear pooled add/record option slices before putting them back in the pool.
semconv/v1.41.0/dnsconv/metric.go Clear pooled add/record option slices before putting them back in the pool.
semconv/v1.41.0/faasconv/metric.go Clear pooled add/record option slices before putting them back in the pool.
semconv/v1.41.0/genaiconv/metric.go Clear pooled add/record option slices before putting them back in the pool.
semconv/v1.41.0/goconv/metric.go Clear pooled add/record option slices before putting them back in the pool.
semconv/v1.41.0/httpconv/metric.go Clear pooled add/record option slices before putting them back in the pool.
semconv/v1.41.0/hwconv/metric.go Clear pooled add/record option slices before putting them back in the pool.
semconv/v1.41.0/k8sconv/metric.go Clear pooled add/record option slices before putting them back in the pool.
semconv/v1.41.0/mcpconv/metric.go Clear pooled add/record option slices before putting them back in the pool.
semconv/v1.41.0/messagingconv/metric.go Clear pooled add/record option slices before putting them back in the pool.
semconv/v1.41.0/nfsconv/metric.go Clear pooled add/record option slices before putting them back in the pool.
semconv/v1.41.0/openshiftconv/metric.go Clear pooled add/record option slices before putting them back in the pool.
semconv/v1.41.0/otelconv/metric.go Clear pooled add/record option slices before putting them back in the pool.
semconv/v1.41.0/processconv/metric.go Clear pooled add/record option slices before putting them back in the pool.
semconv/v1.41.0/rpcconv/metric.go Clear pooled add/record option slices before putting them back in the pool.
semconv/v1.41.0/signalrconv/metric.go Clear pooled add/record option slices before putting them back in the pool.
semconv/v1.41.0/systemconv/metric.go Clear pooled add/record option slices before putting them back in the pool.
semconv/v1.41.0/vcsconv/metric.go Clear pooled add/record option slices before putting them back in the pool.
semconv/templates/registry/go/instrument.j2 Ensure generated metric helper code clears pooled slices prior to reuse.

@ash2k

ash2k commented May 21, 2026

Copy link
Copy Markdown
Member

A further improvement would be to consolidate all those pools into a single pool (to rule them all!) per slice type. That way all the pooled objects are shared and, hence, there are fewer of them i.e. higher efficiency and less RAM usage. Less code bloat/duplication too!

@codecov

codecov Bot commented May 21, 2026 •

Copy link
Copy Markdown

Codecov Report

โœ… All modified and coverable lines are covered by tests.
โœ… Project coverage is 82.9%. Comparing base (597532c) to head (1984709).

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #8352   +/-   ##
=====================================
  Coverage   82.9%   82.9%           
=====================================
  Files        314     314           
  Lines      25083   25083           
=====================================
  Hits       20799   20799           
  Misses      3910    3910           
  Partials     374     374           
๐Ÿš€ New features to boost your workflow:
  • โ„๏ธ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@pellared
pellared merged commit 4e7ae49 into open-telemetry:main May 21, 2026
31 of 32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Skip Changelog PRs that do not require a CHANGELOG.md entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clear cached objects in instrument.j2

5 participants