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:
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.
It spaces samples out by delaying a minimum time between each
sample. This enforces a maximum QPS for this Ruby process.
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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["# Cloud Trace API - Class Google::Cloud::Trace::TimeSampler (v0.45.0)\n\nVersion latestkeyboard_arrow_down\n\n- [0.45.0 (latest)](/ruby/docs/reference/google-cloud-trace/latest/Google-Cloud-Trace-TimeSampler)\n- [0.44.1](/ruby/docs/reference/google-cloud-trace/0.44.1/Google-Cloud-Trace-TimeSampler)\n- [0.43.0](/ruby/docs/reference/google-cloud-trace/0.43.0/Google-Cloud-Trace-TimeSampler)\n- [0.42.2](/ruby/docs/reference/google-cloud-trace/0.42.2/Google-Cloud-Trace-TimeSampler)\n- [0.41.4](/ruby/docs/reference/google-cloud-trace/0.41.4/Google-Cloud-Trace-TimeSampler) \nReference documentation and code samples for the Cloud Trace API class Google::Cloud::Trace::TimeSampler.\n\nA sampler determines whether a given request's latency trace should\nactually be reported. It is usually not necessary to trace every\nrequest, especially for an application serving heavy traffic. You may\nuse a sampler to decide, for a given request, whether to report its\ntrace. A sampler is simply a Proc that takes the Rack environment as an\nargument and returns a boolean indicating whether or not to sample the\ncurrent request. Alternately, it could be an object that duck-types the\nProc interface by implementing the `call` method.\n\nTimeSampler is the default sampler. It bases its sampling decision on\ntwo considerations:\n\n1. 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.\n2. It spaces samples out by delaying a minimum time between each sample. This enforces a maximum QPS for this Ruby process. \n\nInherits\n--------\n\n- Object\n\nMethods\n-------\n\n### .default\n\n def self.default() -\u003e TimeSampler\n\nGet the default global TimeSampler. \n**Returns**\n\n- ([TimeSampler](./Google-Cloud-Trace-TimeSampler))\n\n### #call\n\n def call(env) -\u003e Boolean\n\nImplements the sampler contract. Checks to see whether a sample\nshould be taken at this time. \n**Parameter**\n\n- **env** (Hash) --- Rack environment. \n**Returns**\n\n- (Boolean) --- Whether to sample at this time.\n\n### #initialize\n\n def initialize(qps: 0.1, path_blacklist: DEFAULT_PATH_BLACKLIST) -\u003e TimeSampler\n\nCreate a TimeSampler for the given QPS. \n**Parameters**\n\n- **qps** (Number) *(defaults to: 0.1)* --- Samples per second. Default is 0.1.\n- **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. \n**Returns**\n\n- ([TimeSampler](./Google-Cloud-Trace-TimeSampler)) --- a new instance of TimeSampler\n\nConstants\n---------\n\n### DEFAULT_PATH_BLACKLIST\n\n**value:** \\[\"/_ah/health\", \"/healthz\"\\].freeze \nDefault list of paths for which to disable traces. Currently includes\nApp Engine Flex health checks."]]