Subscribes to the given event type or any type matching the given
pattern. When an event is raised, a span is generated in the current
thread's trace. The event payload is exposed as labels on the span.
If there is no active trace for the current thread, then no span is
generated.
Parameters
type (String, Regex) — A specific type or pattern to select
notifications to listen for.
max_length (Integer) (defaults to: DEFAULT_MAX_DATA_LENGTH) — The maximum length for label values.
If a label value exceeds this length, it is truncated.
If the length is nil, no truncation takes place.
label_namespace (String) (defaults to: DEFAULT_LABEL_NAMESPACE) — A string to prepend to all label
keys.
capture_stack (Boolean) (defaults to: false) — Whether traces should include the
call stack.
value: 1024 The default max length for label data.
DEFAULT_LABEL_NAMESPACE
value: "/ruby/".freeze The default prefix for label keys
REMOVE_NOTIFICATION_FRAMEWORK
value: lambda do |frame|
frame.absolute_path !~ %r{/lib/active_support/notifications}
end Stack truncation method that removes the ActiveSupport::Notifications
calls from the top.
[[["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 - Module Google::Cloud::Trace::Notifications (v0.45.0)\n\nVersion latestkeyboard_arrow_down\n\n- [0.45.0 (latest)](/ruby/docs/reference/google-cloud-trace/latest/Google-Cloud-Trace-Notifications)\n- [0.44.1](/ruby/docs/reference/google-cloud-trace/0.44.1/Google-Cloud-Trace-Notifications)\n- [0.43.0](/ruby/docs/reference/google-cloud-trace/0.43.0/Google-Cloud-Trace-Notifications)\n- [0.42.2](/ruby/docs/reference/google-cloud-trace/0.42.2/Google-Cloud-Trace-Notifications)\n- [0.41.4](/ruby/docs/reference/google-cloud-trace/0.41.4/Google-Cloud-Trace-Notifications) \nReference documentation and code samples for the Cloud Trace API module Google::Cloud::Trace::Notifications.\n\nUtility methods for configuring ActiveSupport notifications to generate\nspans in the current trace.\n\nMethods\n-------\n\n### .instrument\n\n def self.instrument(type, max_length: DEFAULT_MAX_DATA_LENGTH, label_namespace: DEFAULT_LABEL_NAMESPACE, capture_stack: false)\n\nSubscribes to the given event type or any type matching the given\npattern. When an event is raised, a span is generated in the current\nthread's trace. The event payload is exposed as labels on the span.\nIf there is no active trace for the current thread, then no span is\ngenerated. \n**Parameters**\n\n- **type** (String, Regex) --- A specific type or pattern to select notifications to listen for.\n- **max_length** (Integer) *(defaults to: DEFAULT_MAX_DATA_LENGTH)* --- The maximum length for label values. If a label value exceeds this length, it is truncated. If the length is nil, no truncation takes place.\n- **label_namespace** (String) *(defaults to: DEFAULT_LABEL_NAMESPACE)* --- A string to prepend to all label keys.\n- **capture_stack** (Boolean) *(defaults to: false)* --- Whether traces should include the call stack.\n**Example** \n\n```ruby\nrequire \"google/cloud/trace\"\nrequire \"active_record\"\n\nGoogle::Cloud::Trace::Notifications.instrument \"sql.activerecord\"\n\ntrace_record = Google::Cloud::Trace::TraceRecord.new \"my-project\"\nGoogle::Cloud::Trace.set trace_record\n\nActiveRecord::Base.connection.execute \"SHOW TABLES\"\n```\n\nConstants\n---------\n\n### DEFAULT_MAX_DATA_LENGTH\n\n**value:** 1024 \nThe default max length for label data.\n\n### DEFAULT_LABEL_NAMESPACE\n\n**value:** \"/ruby/\".freeze \nThe default prefix for label keys\n\n### REMOVE_NOTIFICATION_FRAMEWORK\n\n**value:** lambda do \\|frame\\|\nframe.absolute_path !\\~ %r{/lib/active_support/notifications}\nend \nStack truncation method that removes the ActiveSupport::Notifications\ncalls from the top."]]