This interface represent a sampler. Sampling is a mechanism to control the noise and overhead introduced by OpenTelemetry by reducing the number of samples of traces collected and sent to the backend.

interface Sampler {
    shouldSample(
        context: Context,
        traceId: string,
        spanName: string,
        spanKind: SpanKind,
        attributes: Attributes,
        links: Link[],
    ): SamplingResult;
    toString(): string;
}

Implemented by

Methods

  • Checks whether span needs to be created and tracked.

    Parameters

    • context: Context

      Parent Context which may contain a span.

    • traceId: string

      of the span to be created. It can be different from the traceId in the SpanContext. Typically in situations when the span to be created starts a new trace.

    • spanName: string

      of the span to be created.

    • spanKind: SpanKind

      of the span to be created.

    • attributes: Attributes

      Initial set of Attributes 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 SamplingResult.

  • Returns the sampler name or short description with the configuration.

    Returns string