ProfilesCountSizer mixes samples and profiles, so max_size is not honoured

Author: Narayan201120Created Sep 30, 2026Updated Oct 1, 2026
Labelsbugneeds triage

Component(s)

exporter/exporterhelper/xexporterhelper

What happened?

ProfilesCountSizer reports the request-level size in samples but the per-element sizes in profiles, so max_size is not honoured for profiles.

go
func (s *ProfilesCountSizer) ProfilesSize(pd pprofile.Profiles) int {
	return pd.SampleCount() // samples
}

func (s *ProfilesCountSizer) ResourceProfilesSize(rp pprofile.ResourceProfiles) int {
	count += rp.ScopeProfiles().At(k).Profiles().Len() // profiles
}

func (s *ProfilesCountSizer) ScopeProfilesSize(sp pprofile.ScopeProfiles) int {
	return sp.Profiles().Len() // profiles
}

func (s *ProfilesCountSizer) ProfileSize(_ pprofile.Profile) int {
	return 1 // one profile
}

extractProfiles starts capacityLeft from capacity, and since ProfilesSize of an empty Profiles is 0, that budget is denominated in samples. The per-element sizes subtracted from it are profile counts. A single profile holding 1000 samples costs 1 against the budget, so it is moved whole.

This is separate from #15860, which concerns the bytes sizer. This is the items sizer, which is the default.

Steps to reproduce

One profile carrying 1000 samples, with maxSize of 50 and the items sizer.

What did you expect to see?

Batches capped at 50 samples.

What did you see instead?

payload: 1 profile carrying 1000 samples; maxSize=50
err = "one sample size is greater than max size, dropping items: 0"
emitted 1 request carrying 1000 samples

That is 20x over budget. The error also reports 0 dropped items while the oversized request goes out, so a partial error is reported and an oversized batch is sent.

Why existing tests do not catch it

testdata.GenerateProfiles(n) builds n profiles with exactly one sample each, so SampleCount() and ProfileCount() are equal in every fixture in the repo. The two units are interchangeable in the current test data, so the mix-up cannot be expressed. A test with more than one sample per profile is needed to cover this.

Related

  • #15587 discussed profiles byte sizes drifting after merges.
  • #15860 is open for the bytes sizer behaviour. This is the items sizer, so the fix is separate, but the two are worth linking in case the resolution ends up shared.
  • Found while auditing the batching path for #16061, which reported this along with two other issues that are being split out.

Notes on scope

I have not attempted a fix. The obvious correction is to make the per-element methods count samples as well, so ResourceProfilesSize sums Profiles().At(k).Samples().Len(), ScopeProfilesSize does the same for its profiles, and ProfileSize returns p.Samples().Len(). That is the same asymptotic cost, since the extract loop already visits every profile.

What I am unsure about is whether that is the right shape. #15860 may already be changing how sizes are tracked for profiles, and there is also a Profiles.ProfileCount() in pdata that computes the same thing the current per-element methods do, so the codebase has two competing notions of profile count. I would rather not guess at which one should win.

Collector version

78b98e74f

Environment information

Environment

OS: (e.g., "Ubuntu 20.04") Compiler(if manually compiled): (e.g., "go 14.2")

OpenTelemetry Collector configuration

yaml

Log output

bash

Additional context

No response

Tip

React with to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

Source: open-telemetry/opentelemetry-collector