Module: Hoss

Defined in:
lib/hoss/util.rb,
lib/hoss-agent.rb,
lib/hoss/agent.rb,
lib/hoss/error.rb,
lib/hoss/event.rb,
lib/hoss/rails.rb,
lib/hoss/spies.rb,
lib/hoss/config.rb,
lib/hoss/report.rb,
lib/hoss/context.rb,
lib/hoss/logging.rb,
lib/hoss/railtie.rb,
lib/hoss/sinatra.rb,
lib/hoss/version.rb,
lib/hoss/metadata.rb,
lib/hoss/error/log.rb,
lib/hoss/spies/http.rb,
lib/hoss/stacktrace.rb,
lib/hoss/config/bytes.rb,
lib/hoss/context/user.rb,
lib/hoss/deprecations.rb,
lib/hoss/instrumenter.rb,
lib/hoss/error_builder.rb,
lib/hoss/spies/faraday.rb,
lib/hoss/util/throttle.rb,
lib/hoss/central_config.rb,
lib/hoss/config/options.rb,
lib/hoss/internal_error.rb,
lib/hoss/spies/net_http.rb,
lib/hoss/transport/base.rb,
lib/hoss/util/inflector.rb,
lib/hoss/util/lru_cache.rb,
lib/hoss/child_durations.rb,
lib/hoss/config/duration.rb,
lib/hoss/context/request.rb,
lib/hoss/context_builder.rb,
lib/hoss/error/exception.rb,
lib/hoss/context/response.rb,
lib/hoss/naively_hashable.rb,
lib/hoss/stacktrace/frame.rb,
lib/hoss/transport/worker.rb,
lib/hoss/transport/filters.rb,
lib/hoss/transport/headers.rb,
lib/hoss/config/regexp_list.rb,
lib/hoss/stacktrace_builder.rb,
lib/hoss/context/request/url.rb,
lib/hoss/metadata/system_info.rb,
lib/hoss/transport/connection.rb,
lib/hoss/transport/user_agent.rb,
lib/hoss/metadata/process_info.rb,
lib/hoss/metadata/service_info.rb,
lib/hoss/transport/serializers.rb,
lib/hoss/context/request/socket.rb,
lib/hoss/transport/connection/http.rb,
lib/hoss/central_config/cache_control.rb,
lib/hoss/config/wildcard_pattern_list.rb,
lib/hoss/transport/connection/proxy_pipe.rb,
lib/hoss/transport/filters/hash_sanitizer.rb,
lib/hoss/transport/filters/secrets_filter.rb,
lib/hoss/metadata/system_info/container_info.rb,
lib/hoss/transport/serializers/error_serializer.rb,
lib/hoss/transport/serializers/event_serializer.rb,
lib/hoss/transport/serializers/report_serializer.rb,
lib/hoss/transport/serializers/context_serializer.rb,
lib/hoss/transport/serializers/metadata_serializer.rb

Overview

frozen_string_literal: true

Defined Under Namespace

Modules: ChildDurations, Deprecations, Logging, NaivelyHashable, Rails, Sinatra, Spies, Transport, Util Classes: Agent, CentralConfig, Config, Context, ContextBuilder, Error, ErrorBuilder, Event, ExistingTransactionError, Instrumenter, InternalError, Metadata, Railtie, Report, Stacktrace, StacktraceBuilder

Constant Summary collapse

VERSION =
'1.0.11'

Class Method Summary collapse

Class Method Details

.add_filter(key, callback = nil) {|Hash| ... } ⇒ Bool

Provide a filter to transform payloads before sending them off

Parameters:

  • key (Symbol)

    Unique filter key

  • callback (Object, Proc) (defaults to: nil)

    A filter that responds to #call(payload)

Yields:

  • (Hash)

    A filter. Used if provided. Otherwise using ‘callback`

Returns:

  • (Bool)

    true



202
203
204
205
206
207
208
# File 'lib/hoss-agent.rb', line 202

def add_filter(key, callback = nil, &block)
  if callback.nil? && !block_given?
    raise ArgumentError, '#add_filter needs either `callback\' or a block'
  end

  agent&.add_filter(key, block || callback)
end

.agentAgent

Returns Currently running [Agent] if any.

Returns:

  • (Agent)

    Currently running [Agent] if any



78
79
80
# File 'lib/hoss-agent.rb', line 78

def agent
  Agent.instance
end

.build_context(rack_env: nil, for_type: :transaction) ⇒ Context

Build a [Context] from a Rack ‘env`. The context may include information about the request, response, current user and more

Parameters:

  • rack_env (Rack::Env) (defaults to: nil)

    A Rack env

Returns:



127
128
129
130
131
132
# File 'lib/hoss-agent.rb', line 127

def build_context(
  rack_env: nil,
  for_type: :transaction
)
  agent&.build_context(rack_env: rack_env, for_type: for_type)
end

.current_eventObject



116
117
118
# File 'lib/hoss-agent.rb', line 116

def current_event
  agent&.current_event
end

.end_eventObject



98
99
100
# File 'lib/hoss-agent.rb', line 98

def end_event
  agent&.end_event
end

.log_ids {|String|nil, String|nil, String|nil| ... } ⇒ String

Get a formatted string containing transaction, span, and trace ids. If a block is provided, the ids are yielded.

and trace ids.

Yields:

  • (String|nil, String|nil, String|nil)

    The transaction, span,

Returns:

  • (String)

    Unless block given



88
89
90
91
# File 'lib/hoss-agent.rb', line 88

def log_ids
  ids = []
  ids.join(' ')
end

.report(exception, context: nil, handled: true) ⇒ String

Report and exception to APM

Parameters:

  • exception (Exception)

    The exception

  • context (Context) (defaults to: nil)

    An optional [Context]

  • handled (Boolean) (defaults to: true)

    Whether the exception was rescued

Returns:

  • (String)

    ID of the generated [Error]



142
143
144
# File 'lib/hoss-agent.rb', line 142

def report(exception, context: nil, handled: true)
  agent&.report(exception, context: context, handled: handled)
end

.report_message(message, context: nil, **attrs) ⇒ String

Report a custom string error message to APM

Parameters:

  • message (String)

    The message

  • context (Context) (defaults to: nil)

    An optional [Context]

Returns:

  • (String)

    ID of the generated [Error]



151
152
153
154
155
156
157
158
# File 'lib/hoss-agent.rb', line 151

def report_message(message, context: nil, **attrs)
  agent&.report_message(
    message,
    context: context,
    backtrace: caller,
    **attrs
  )
end

.restart(config = nil) ⇒ Object

Restarts the Hoss Agent using the same config or a new one, if it is provided. Starts the agent if it is not running. Stops and starts the agent if it is running.



66
67
68
69
70
# File 'lib/hoss-agent.rb', line 66

def restart(config = nil)
  config ||= agent&.config
  stop if running?
  start(config)
end

.running?Boolean

Returns Whether there’s an [Agent] running.

Returns:

  • (Boolean)

    Whether there’s an [Agent] running



73
74
75
# File 'lib/hoss-agent.rb', line 73

def running?
  Agent.running?
end

.set_custom_context(custom) ⇒ Hash

Provide further context for the current transaction

Parameters:

  • custom (Hash)

    A hash with custom information. Can be nested.

Returns:

  • (Hash)

    The current custom context



184
185
186
# File 'lib/hoss-agent.rb', line 184

def set_custom_context(custom)
  agent&.set_custom_context(custom)
end

.set_label(key, value) ⇒ Object

Set a label value for the current transaction

Parameters:

  • key (String, Symbol)

    A key

  • value (Object)

    A value

Returns:

  • (Object)

    The given value



167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/hoss-agent.rb', line 167

def set_label(key, value)
  case value
  when TrueClass,
       FalseClass,
       Numeric,
       NilClass,
       String
    agent&.set_label(key, value)
  else
    agent&.set_label(key, value.to_s)
  end
end

.set_user(user) ⇒ Object

Provide a user to the current transaction

Parameters:

  • user (Object)

    An object representing a user

Returns:

  • (Object)

    Given user



192
193
194
# File 'lib/hoss-agent.rb', line 192

def set_user(user)
  agent&.set_user(user)
end

.start(config = {}) ⇒ Agent

Starts the Hoss Agent

Parameters:

  • config (Config) (defaults to: {})

    An instance of Config

Returns:

  • (Agent)

    The resulting [Agent]



53
54
55
# File 'lib/hoss-agent.rb', line 53

def start(config = {})
  Agent.start config
end

.start_eventObject



93
94
95
96
# File 'lib/hoss-agent.rb', line 93

def start_event
  agent&.start_event.tap do |event|
  end
end

.stopObject

Stops the Hoss Agent



58
59
60
# File 'lib/hoss-agent.rb', line 58

def stop
  Agent.stop
end

.with_eventObject



102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/hoss-agent.rb', line 102

def with_event
  unless block_given?
    raise ArgumentError,
      'expected a block. Do you want `start_event\' instead?'
  end

  begin
    event = start_event
    yield event
  ensure
    end_event
  end
end