RateLimitedSampler class
RateLimitedSampler is responsible for the following:
- Implements a rate-limiting sampling strategy based on a specified number of requests per second.
- Dynamically adjusts the sampling rate based on the time elapsed since the last sample.
- Provides a sampling rate that can be used to determine whether a span should be recorded.
Constructors
| Rate |
Initializes a new instance of the RateLimitedSampler class. |
Methods
| get |
Gets the current sample rate based on the effective window count and nanos.
This method calculates the sampling probability and returns it as a percentage.
If |
| should |
Checks whether span needs to be created and tracked. |
| to |
Return Sampler description |
Constructor Details
RateLimitedSampler(number)
Initializes a new instance of the RateLimitedSampler class.
new RateLimitedSampler(tracesPerSecond: number)
Parameters
- tracesPerSecond
-
number
The maximum number of traces to sample per second.
Method Details
getSampleRate()
Gets the current sample rate based on the effective window count and nanos.
This method calculates the sampling probability and returns it as a percentage.
If roundToNearest is true, it rounds down the sampling percentage to the nearest whole number.
function getSampleRate(): number
Returns
number
The current sample rate as a percentage.
shouldSample(Context, string, string, SpanKind, Attributes, Link[])
Checks whether span needs to be created and tracked.
function shouldSample(context: Context, traceId: string, spanName: string, spanKind: SpanKind, attributes: Attributes, links: Link[]): SamplingResult
Parameters
- context
-
Context
Parent Context which may contain a span.
- traceId
-
string
traceId of the span to be created. It can be different from the traceId in the <xref:SpanContext>. Typically in situations when the span to be created starts a new trace.
- spanName
-
string
Name of the span to be created.
- spanKind
-
SpanKind
Kind of the span to be created.
- attributes
-
Attributes
Initial set of SpanAttributes for the Span being constructed.
- links
-
Link[]
Collection of links that will be associated with the Span to be created. Typically useful for batch operations.
Returns
SamplingResult
a <xref:SamplingResult>.
toString()
Return Sampler description
function toString(): string
Returns
string