module Google::Cloud::Trace::LabelKey

A collection of well-known label keys for trace spans.

Constants

AGENT
COMPONENT
ERROR_MESSAGE
ERROR_NAME
GAE_APPLICATION_ERROR
GAE_APP_MODULE
GAE_APP_MODULE_VERSION
GAE_APP_VERSION
GAE_DATASTORE_COUNT
GAE_DATASTORE_CURSOR
GAE_DATASTORE_ENTITY_WRITES
GAE_DATASTORE_HAS_ANCESTOR
GAE_DATASTORE_HAS_CURSOR
GAE_DATASTORE_HAS_TRANSACTION
GAE_DATASTORE_INDEX_WRITES
GAE_DATASTORE_KIND
GAE_DATASTORE_LIMIT
GAE_DATASTORE_MORE_RESULTS
GAE_DATASTORE_OFFSET
GAE_DATASTORE_REQUESTED_ENTITY_DELETES
GAE_DATASTORE_REQUESTED_ENTITY_PUTS
GAE_DATASTORE_SIZE
GAE_DATASTORE_SKIPPED
GAE_DATASTORE_TRANSACTION_HANDLE
GAE_ERROR_MESSAGE
GAE_MEMCACHE_COUNT
GAE_MEMCACHE_SIZE
GAE_REQUEST_LOG_ID
HTTP_CLIENT_CITY
HTTP_CLIENT_COUNTRY
HTTP_CLIENT_PROTOCOL
HTTP_CLIENT_REGION
HTTP_HOST
HTTP_METHOD
HTTP_REDIRECTED_URL
HTTP_REQUEST_SIZE
HTTP_RESPONSE_SIZE
HTTP_STATUS_CODE
HTTP_URL
HTTP_USER_AGENT
PID
RPC_HOST
RPC_REQUEST_SIZE
RPC_REQUEST_TYPE
RPC_RESPONSE_SIZE
RPC_STATUS_CODE
STACKTRACE
TID

Public Class Methods

set_stack_trace(labels, stack_frames: nil, skip_frames: 1, truncate_stack: nil, filter_stack: nil) click to toggle source

Set the stack trace label in the given labels hash. The current call stack is formatted so the Stackdriver UI will display it.

@param [Hash] labels The labels hash in which to set the stack trace

label value.

@param [Array<Thread::Backtrace::Location>] stack_frames The current

caller stack as returned from `::Kernel.caller_locations`. If
not set, `::Kernel.caller_locations` is called internally.

@param [Integer] skip_frames Passed to the internal invocation of

`::Kernel.caller_locations` if one is needed.

@param [Proc] truncate_stack A procedure that allows skipping of

the "topmost" stack frames. Stack frames, represented by
instances of `Thread::Backtrace::Location`, are passed to this
proc beginning with the topmost frame. As long as the proc
returns a falsy value, those frames are dropped. Once the proc
returns true for the first time, that frame and all remaining
frames (possibly subject to `filter_stack`) are used. If not set,
no frames are skipped.

@param [Proc] filter_stack A procedure that allows skipping of

stack frames in the middle of the stack trace. After possibly
skipping frames using `truncate_stack`, all remaining frames are
passed to this proc as `Thread::Backtrace::Location` objects.
Those for whom the proc returns a falsy value are skipped. If
this parameter is not set, no filtering is done and all frames
are presented in the stack trace.

@example

require "google/cloud/trace"

trace_record = Google::Cloud::Trace::TraceRecord.new "my-project"
span = trace_record.create_span "root_span"
Google::Cloud::Trace::LabelKey.set_stack_trace span.labels
# File lib/google/cloud/trace/label_key.rb, line 114
def self.set_stack_trace labels,
                         stack_frames: nil, skip_frames: 1,
                         truncate_stack: nil, filter_stack: nil
  stack_frames ||= ::Kernel.caller_locations skip_frames
  json_frames = []
  collecting_frames = !truncate_stack
  stack_frames.each do |frame|
    collecting_frames ||= truncate_stack.call frame
    next unless collecting_frames
    next unless !filter_stack || filter_stack.call(frame)
    json_frames <<
      {
        file_name: frame.absolute_path,
        line_number: frame.lineno,
        method_name: frame.label
      }
  end
  json_object = { stack_frame: json_frames }
  labels[STACKTRACE] = JSON.generate json_object
end