Skip to content

[processor/tailsampling] Added bytes_limiting policy type#42509

Merged
atoulme merged 40 commits intoopen-telemetry:mainfrom
portertech:bytes_limiting
Nov 20, 2025
Merged

[processor/tailsampling] Added bytes_limiting policy type#42509
atoulme merged 40 commits intoopen-telemetry:mainfrom
portertech:bytes_limiting

Conversation

@portertech
Copy link
Contributor

@portertech portertech commented Sep 4, 2025

This pull-request introduces a new tailsampling processor sampling policy type, bytes_limiting.

Bytes Limiting Policy

The bytes_limiting policy uses a token bucket algorithm implemented by golang.org/x/time/rate to control the rate of data throughput.

This policy is particularly useful for:

  • Volume control: Limiting the total amount of trace data processed per unit time
  • Burst handling: Allowing short-term spikes in data volume while maintaining long-term rate limits
  • Memory protection: Preventing downstream systems from being overwhelmed by large traces

Configuration

The bytes_limiting policy supports the following configuration parameters:

  • bytes_per_second: The sustained rate at which bytes are allowed through (required)
  • burst_capacity: The maximum number of bytes that can be processed in a burst (optional, defaults to 2x bytes_per_second)

Token Bucket Algorithm

The policy implements a token bucket algorithm where:

  1. Tokens represent bytes: Each token in the bucket represents one byte of trace data
  2. Continuous refill: Tokens are added to the bucket at the configured bytes_per_second rate
  3. Burst capacity: The bucket can hold up to burst_capacity tokens for handling traffic bursts
  4. Consumption: When a trace arrives, tokens equal to the trace size are consumed from the bucket
  5. Rejection: If insufficient tokens are available, the trace is not sampled

Example Configuration

processors:                                                                                                                                                                                          
  tail_sampling:                                                                                                                                                                                     
    policies:                                                                                                                                                                                        
      - name: volume-control                                                                                                                                                                         
        type: bytes_limiting                                                                                                                                                                         
        bytes_limiting:                                                                                                                                                                              
          bytes_per_second: 1048576    # 1 MB/second sustained rate
          burst_capacity: 5242880      # 5 MB burst capacity                                                                                                                                         

Signed-off-by: Sean Porter <portertech@gmail.com>
Signed-off-by: Sean Porter <portertech@gmail.com>
Signed-off-by: Sean Porter <portertech@gmail.com>
Signed-off-by: Sean Porter <portertech@gmail.com>
Signed-off-by: Sean Porter <portertech@gmail.com>
@portertech portertech changed the title [tailsamplingprocessor] Added bytes_limiting policy type [processor/tailsampling] Added bytes_limiting policy type Sep 5, 2025
Signed-off-by: Sean Porter <portertech@gmail.com>
Signed-off-by: Sean Porter <portertech@gmail.com>
Signed-off-by: Sean Porter <portertech@gmail.com>
Signed-off-by: Sean Porter <portertech@gmail.com>
Signed-off-by: Sean Porter <portertech@gmail.com>
Signed-off-by: Sean Porter <portertech@gmail.com>
@portertech portertech marked this pull request as ready for review September 5, 2025 21:23
@portertech portertech requested a review from a team as a code owner September 5, 2025 21:23
@portertech portertech requested a review from songy23 September 5, 2025 21:23
@github-actions github-actions bot added the processor/tailsampling Tail sampling processor label Sep 5, 2025
Signed-off-by: Sean Porter <portertech@gmail.com>
Signed-off-by: Sean Porter <portertech@gmail.com>
@portertech portertech marked this pull request as ready for review October 11, 2025 12:54
Signed-off-by: Sean Porter <portertech@gmail.com>
Signed-off-by: Sean Porter <portertech@gmail.com>
@github-actions github-actions bot removed the Stale label Oct 12, 2025
Copy link
Contributor

@Logiraptor Logiraptor left a comment

Choose a reason for hiding this comment

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

The actual change looks good to me, nice and simple. Looks like there's some extra stuff in here though

Signed-off-by: Sean Porter <portertech@gmail.com>
Signed-off-by: Sean Porter <portertech@gmail.com>
@github-actions github-actions bot requested a review from jackgopack4 October 14, 2025 22:13
Signed-off-by: Sean Porter <portertech@gmail.com>
Signed-off-by: Sean Porter <portertech@gmail.com>
Signed-off-by: Sean Porter <portertech@gmail.com>
Signed-off-by: Sean Porter <portertech@gmail.com>
@portertech portertech requested a review from Logiraptor October 15, 2025 17:47
// Use the OpenTelemetry Collector's built-in method for accurate size calculation
// This gives us the exact protobuf marshaled size
marshaler := &ptrace.ProtoMarshaler{}
return int64(marshaler.TracesSize(trace.ReceivedBatches))
Copy link
Contributor

Choose a reason for hiding this comment

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

this makes the assumption that the traces will be serialized to proto format, is there a way to allow a different encoding, for example using the encoding extension?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

curious, when would this processor encounter other encodings?

Copy link
Contributor

Choose a reason for hiding this comment

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

OTLP JSON is one. Splunk HEC another. You can see all the encodings we support under extensions/encoding.

Copy link
Contributor

Choose a reason for hiding this comment

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

Opening #44416 to follow up.

Copy link
Contributor

@atoulme atoulme left a comment

Choose a reason for hiding this comment

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

I think this can get in, just need to have an issue open to follow up on the marshaling strategy to count bytes.

@atoulme atoulme merged commit 6a0b915 into open-telemetry:main Nov 20, 2025
189 checks passed
@github-actions github-actions bot added this to the next release milestone Nov 20, 2025
andrzej-stencel pushed a commit that referenced this pull request Nov 20, 2025
#42509 introduced a regression ; this fixes the issue and the main build
RealAnna pushed a commit to RealAnna/opentelemetry-collector-contrib that referenced this pull request Nov 20, 2025
open-telemetry#42509 introduced a regression ; this fixes the issue and the main build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

connector/datadog exporter/datadog Datadog components processor/tailsampling Tail sampling processor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants