Cloud Trace API - Class Google::Cloud::Trace::TimeSampler (v0.42.0)

Reference documentation and code samples for the Cloud Trace API class Google::Cloud::Trace::TimeSampler.

A sampler determines whether a given request's latency trace should actually be reported. It is usually not necessary to trace every request, especially for an application serving heavy traffic. You may use a sampler to decide, for a given request, whether to report its trace. A sampler is simply a Proc that takes the Rack environment as an argument and returns a boolean indicating whether or not to sample the current request. Alternately, it could be an object that duck-types the Proc interface by implementing the call method.

TimeSampler is the default sampler. It bases its sampling decision on two considerations:

  1. It allows you to blacklist certain URI paths that should never be traced. For example, the Google App Engine health check request path /_ah/health is blacklisted by default. Kubernetes default health check /healthz is also ignored.
  2. It spaces samples out by delaying a minimum time between each sample. This enforces a maximum QPS for this Ruby process.

Inherits

  • Object

Methods

.default

def self.default() -> TimeSampler

Get the default global TimeSampler.

Returns

#call

def call(env) -> Boolean

Implements the sampler contract. Checks to see whether a sample should be taken at this time.

Parameter
  • env (Hash) — Rack environment.
Returns
  • (Boolean) — Whether to sample at this time.

#initialize

def initialize(qps: 0.1, path_blacklist: DEFAULT_PATH_BLACKLIST) -> TimeSampler

Create a TimeSampler for the given QPS.

Parameters
  • qps (Number) (defaults to: 0.1) — Samples per second. Default is 0.1.
  • path_blacklist (Array{String,Regex}) (defaults to: DEFAULT_PATH_BLACKLIST) — An array of paths or path patterns indicating URIs that should never be traced. Default is DEFAULT_PATH_BLACKLIST.
Returns

Constants

DEFAULT_PATH_BLACKLIST

value: ["/_ah/health", "/healthz"].freeze
Default list of paths for which to disable traces. Currently includes App Engine Flex health checks.