Module: Appsignal

Extended by:
Gem::Deprecate
Defined in:
lib/appsignal.rb,
lib/appsignal/cli.rb,
lib/appsignal/demo.rb,
lib/appsignal/hooks.rb,
lib/appsignal/utils.rb,
lib/appsignal/config.rb,
lib/appsignal/marker.rb,
lib/appsignal/system.rb,
lib/appsignal/version.rb,
lib/appsignal/cli/demo.rb,
lib/appsignal/minutely.rb,
lib/appsignal/extension.rb,
lib/appsignal/hooks/que.rb,
lib/appsignal/auth_check.rb,
lib/appsignal/hooks/puma.rb,
lib/appsignal/hooks/rake.rb,
lib/appsignal/cli/helpers.rb,
lib/appsignal/cli/install.rb,
lib/appsignal/hooks/redis.rb,
lib/appsignal/transaction.rb,
lib/appsignal/transmitter.rb,
lib/appsignal/cli/diagnose.rb,
lib/appsignal/hooks/sequel.rb,
lib/appsignal/hooks/sidekiq.rb,
lib/appsignal/hooks/unicorn.rb,
lib/appsignal/hooks/net_http.rb,
lib/appsignal/event_formatter.rb,
lib/appsignal/extension/jruby.rb,
lib/appsignal/hooks/celluloid.rb,
lib/appsignal/hooks/passenger.rb,
lib/appsignal/hooks/shoryuken.rb,
lib/appsignal/hooks/webmachine.rb,
lib/appsignal/integrations/que.rb,
lib/appsignal/hooks/data_mapper.rb,
lib/appsignal/hooks/delayed_job.rb,
lib/appsignal/hooks/action_cable.rb,
lib/appsignal/integrations/grape.rb,
lib/appsignal/integrations/resque.rb,
lib/appsignal/cli/notify_of_deploy.rb,
lib/appsignal/integrations/padrino.rb,
lib/appsignal/integrations/railtie.rb,
lib/appsignal/utils/hash_sanitizer.rb,
lib/appsignal/hooks/mongo_ruby_driver.rb,
lib/appsignal/integrations/webmachine.rb,
lib/appsignal/rack/streaming_listener.rb,
lib/appsignal/integrations/data_mapper.rb,
lib/appsignal/js_exception_transaction.rb,
lib/appsignal/rack/js_exception_catcher.rb,
lib/appsignal/rack/rails_instrumentation.rb,
lib/appsignal/garbage_collection_profiler.rb,
lib/appsignal/rack/generic_instrumentation.rb,
lib/appsignal/rack/sinatra_instrumentation.rb,
lib/appsignal/utils/query_params_sanitizer.rb,
lib/appsignal/integrations/mongo_ruby_driver.rb,
lib/appsignal/integrations/resque_active_job.rb,
lib/appsignal/integrations/delayed_job_plugin.rb,
lib/appsignal/hooks/active_support_notifications.rb,
lib/appsignal/event_formatter/moped/query_formatter.rb,
lib/appsignal/event_formatter/faraday/request_formatter.rb,
lib/appsignal/integrations/capistrano/capistrano_2_tasks.rb,
lib/appsignal/event_formatter/active_record/sql_formatter.rb,
lib/appsignal/event_formatter/action_view/render_formatter.rb,
lib/appsignal/event_formatter/elastic_search/search_formatter.rb,
lib/appsignal/event_formatter/mongo_ruby_driver/query_formatter.rb,
lib/appsignal/event_formatter/active_record/instantiation_formatter.rb,
ext/appsignal_extension.c

Overview

AppSignal for Ruby gem's main module.

Provides method to control the AppSignal instrumentation and the system agent. Also provides instrumentation helpers for ease of use.

Defined Under Namespace

Modules: Grape, Integrations, Rack, System, Utils Classes: AuthCheck, CLI, Capistrano, Config, Demo, EventFormatter, Extension, GarbageCollectionProfiler, Hooks, JSExceptionTransaction, Marker, Minutely, StreamWrapper, Transaction, Transmitter

Constant Summary collapse

VERSION =
"2.6.1".freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configConfig?

Accessor for the AppSignal configuration. Return the current AppSignal configuration.

Can return nil if no configuration has been set or automatically loaded by an automatic integration or by calling start.

Examples:

Appsignal.config

Setting the configuration

Appsignal.config = Appsignal::Config.new(Dir.pwd, "production")

Returns:

See Also:



29
30
31
# File 'lib/appsignal.rb', line 29

def config
  @config
end

.extension_loadedBoolean?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Accessor for toggle if the AppSignal C-extension is loaded.

Can be nil if extension has not been loaded yet. See extension_loaded? for a boolean return value.

Returns:

  • (Boolean, nil)

See Also:



39
40
41
# File 'lib/appsignal.rb', line 39

def extension_loaded
  @extension_loaded
end

.loggerLogger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Note:

some classes may have options to set custom loggers. Their defaults are pointed to this attribute.

Accessor for the AppSignal logger.

If no logger has been set, it will return a "in memory logger", using in_memory_log. Once AppSignal is started (using start) the contents of the "in memory logger" is written to the new logger.

Returns:

  • (Logger)

See Also:



52
# File 'lib/appsignal.rb', line 52

attr_writer :logger

Class Method Details

.active?Boolean

Returns the active state of the AppSignal integration.

Conditions apply for AppSignal to be marked as active:

This logic is used within instrument helper such as instrument so it's not necessary to wrap instrument calls with this method.

Examples:

Do this

Appsignal.instrument(..) do
  # Do this
end

Don't do this

if Appsignal.active?
  Appsignal.instrument(..) do
    # Don't do this
  end
end

Returns:

  • (Boolean)

Since:

  • 0.2.7



730
731
732
# File 'lib/appsignal.rb', line 730

def active?
  config && config.active? && extension_loaded?
end

.add_distribution_value(key, value, tags = {}) ⇒ Object



628
629
630
631
632
# File 'lib/appsignal.rb', line 628

def add_distribution_value(key, value, tags = {})
  Appsignal::Extension.add_distribution_value(key.to_s, value.to_f, Appsignal::Utils.data_generate(tags))
rescue RangeError
  Appsignal.logger.warn("Distribution value #{value} for key '#{key}' is too big")
end

.extension_loaded?Boolean

Returns if the C-extension was loaded properly.

Returns:

  • (Boolean)

See Also:

Since:

  • 1.0.0



701
702
703
# File 'lib/appsignal.rb', line 701

def extension_loaded?
  !!extension_loaded
end

.extensionsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



55
56
57
# File 'lib/appsignal.rb', line 55

def extensions
  @extensions ||= []
end

.forkedObject



168
169
170
171
172
173
# File 'lib/appsignal.rb', line 168

def forked
  return unless active?
  Appsignal.start_logger
  logger.debug("Forked process, resubscribing and restarting extension")
  Appsignal::Extension.start
end

.get_server_state(key) ⇒ Object



175
176
177
# File 'lib/appsignal.rb', line 175

def get_server_state(key)
  Appsignal::Extension.get_server_state(key)
end

.in_memory_logStringIO

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

In memory logger used before any logger is started with start_logger.

The contents of this logger are flushed to the logger in start_logger.

Returns:

  • (StringIO)


640
641
642
643
644
645
646
# File 'lib/appsignal.rb', line 640

def in_memory_log
  if defined?(@in_memory_log) && @in_memory_log
    @in_memory_log
  else
    @in_memory_log = StringIO.new
  end
end

.increment_counter(key, value = 1, tags = {}) ⇒ Object



622
623
624
625
626
# File 'lib/appsignal.rb', line 622

def increment_counter(key, value = 1, tags = {})
  Appsignal::Extension.increment_counter(key.to_s, value, Appsignal::Utils.data_generate(tags))
rescue RangeError
  Appsignal.logger.warn("Counter value #{value} for key '#{key}' is too big")
end

.initialize_extensionsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



60
61
62
63
64
65
66
# File 'lib/appsignal.rb', line 60

def initialize_extensions
  Appsignal.logger.debug("Initializing extensions")
  extensions.each do |extension|
    Appsignal.logger.debug("Initializing #{extension}")
    extension.initializer
  end
end

.instrument(name, title = nil, body = nil, body_format = Appsignal::EventFormatter::DEFAULT) { ... } ⇒ Object

Instrument helper for AppSignal.

For more help, read our custom instrumentation guide, listed under "See also".

Examples:

Simple instrumentation

Appsignal.instrument("fetch.issue_fetcher") do
  # To be instrumented code
end

Instrumentation with title and body

Appsignal.instrument(
  "fetch.issue_fetcher",
  "Fetching issue",
  "GitHub API"
) do
  # To be instrumented code
end

Parameters:

Yields:

  • yields the given block of code instrumented in an AppSignal event.

Returns:

  • (Object)

    Returns the block's return value.

See Also:

Since:

  • 1.3.0



566
567
568
569
570
571
# File 'lib/appsignal.rb', line 566

def instrument(name, title = nil, body = nil, body_format = Appsignal::EventFormatter::DEFAULT)
  Appsignal::Transaction.current.start_event
  yield if block_given?
ensure
  Appsignal::Transaction.current.finish_event(name, title, body, body_format)
end

.instrument_sql(name, title = nil, body = nil) { ... } ⇒ Object

Instrumentation helper for SQL queries.

This helper filters out values from SQL queries so you don't have to.

Examples:

SQL query instrumentation

Appsignal.instrument_sql("perform.query", nil, "SELECT * FROM ...") do
  # To be instrumented code
end

SQL query instrumentation

Appsignal.instrument_sql("perform.query", nil, "WHERE email = 'foo@..'") do
  # query value will replace 'foo..' with a question mark `?`.
end

Parameters:

  • name (String)

    Name of the instrumented event. Read our event naming guide listed under "See also".

  • title (String, nil) (defaults to: nil)

    Human readable name of the event.

  • body (String, nil) (defaults to: nil)

    SQL query that's being executed.

Yields:

  • yields the given block of code instrumented in an AppSignal event.

Returns:

  • (Object)

    Returns the block's return value.

See Also:

Since:

  • 2.0.0



600
601
602
# File 'lib/appsignal.rb', line 600

def instrument_sql(name, title = nil, body = nil, &block)
  instrument(name, title, body, Appsignal::EventFormatter::SQL_BODY_FORMAT, &block)
end

.is_ignored_action?(action) ⇒ Boolean

Deprecated.

No replacement

Returns:

  • (Boolean)


742
743
744
# File 'lib/appsignal.rb', line 742

def is_ignored_action?(action) # rubocop:disable Naming/PredicateName
  Appsignal.config[:ignore_actions].include?(action)
end

.is_ignored_error?(error) ⇒ Boolean Also known as: is_ignored_exception?

Deprecated.

No replacement

Returns:

  • (Boolean)


735
736
737
# File 'lib/appsignal.rb', line 735

def is_ignored_error?(error) # rubocop:disable Naming/PredicateName
  Appsignal.config[:ignore_errors].include?(error.class.name)
end

.listen_for_error(tags = nil, namespace = Appsignal::Transaction::HTTP_REQUEST) { ... } ⇒ Object Also known as: listen_for_exception

Listen for an error to occur and send it to AppSignal.

Uses send_error to directly send the error in a separate transaction. Does not add the error to the current transaction.

Make sure that AppSignal is integrated in your application beforehand. AppSignal won't record errors unless Appsignal::Config#active? is true.

Examples:

# my_app.rb
# setup AppSignal beforehand

Appsignal.listen_for_error do
  # my code
  raise "foo"
end

Parameters:

  • tags (Hash, nil) (defaults to: nil)
  • namespace (String) (defaults to: Appsignal::Transaction::HTTP_REQUEST)

    the namespace for this error.

Yields:

  • yields the given block.

Returns:

  • (Object)

    returns the return value of the given block.

See Also:



304
305
306
307
308
309
# File 'lib/appsignal.rb', line 304

def listen_for_error(tags = nil, namespace = Appsignal::Transaction::HTTP_REQUEST)
  yield
rescue Exception => error # rubocop:disable Lint/RescueException
  send_error(error, tags, namespace)
  raise error
end

.log_formatter(prefix = nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



656
657
658
659
660
661
662
# File 'lib/appsignal.rb', line 656

def log_formatter(prefix = nil)
  pre = "#{prefix}: " if prefix
  proc do |severity, datetime, _progname, msg|
    "[#{datetime.strftime("%Y-%m-%dT%H:%M:%S")} (process) "\
      "##{Process.pid}][#{severity}] #{pre}#{msg}\n"
  end
end

.monitor_single_transaction(name, env = {}, &block) ⇒ Object

Monitor a transaction, stop AppSignal and wait for this single transaction to be flushed.

Useful for cases such as Rake tasks and Resque-like systems where a process is forked and immediately exits after the transaction finishes.



271
272
273
274
275
# File 'lib/appsignal.rb', line 271

def monitor_single_transaction(name, env = {}, &block)
  monitor_transaction(name, env, &block)
ensure
  stop("monitor_single_transaction")
end

.monitor_transaction(name, env = {}) { ... } ⇒ Object

Creates an AppSignal transaction for the given block.

If AppSignal is not active? it will still execute the block, but not create a transaction for it.

A event is created for this transaction with the name given in the name argument. The event name must start with either perform_job or process_action to differentiate between the "web" and "background" namespace. Custom namespaces are not supported by this helper method.

This helper method also captures any exception that occurs in the given block.

Examples:

Appsignal.monitor_transaction("perform_job.nightly_update") do
  # your code
end

with an environment

Appsignal.monitor_transaction(
  "perform_job.nightly_update",
  :metadata => { "user_id" => 1 }
) do
  # your code
end

Parameters:

  • name (String)

    main event name.

  • env (Hash<Symbol, Object>) (defaults to: {})

Options Hash (env):

  • :params (Hash<Symbol/String, Object>)

    Params for the monitored request/job, see Appsignal::Transaction#params= for more information.

  • :controller (String)

    name of the controller in which the transaction was recorded.

  • :class (String)

    name of the Ruby class in which the transaction was recorded. If :controller is also given, :controller is used instead.

  • :action (String)

    name of the controller action in which the transaction was recorded.

  • :method (String)

    name of the Ruby method in which the transaction was recorded. If :action is also given, :action is used instead.

  • :queue_start (Integer)

    the moment the request/job was queued. Used to track how long requests/jobs were queued before being executed.

  • :metadata (Hash<Symbol/String, String/Fixnum>)

    Additional metadata for the transaction, see Appsignal::Transaction#set_metadata for more information.

Yields:

  • the block to monitor.

Returns:

  • (Object)

    the value of the given block is returned.

Raises:

  • (Exception)

    any exception that occurs within the given block is re-raised by this method.

Since:

  • 0.10.0



230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
# File 'lib/appsignal.rb', line 230

def monitor_transaction(name, env = {})
  unless active?
    return yield
  end

  if name.start_with?("perform_job".freeze)
    namespace = Appsignal::Transaction::BACKGROUND_JOB
    request   = Appsignal::Transaction::GenericRequest.new(env)
  elsif name.start_with?("process_action".freeze)
    namespace = Appsignal::Transaction::HTTP_REQUEST
    request   = ::Rack::Request.new(env)
  else
    logger.error("Unrecognized name '#{name}'")
    return
  end
  transaction = Appsignal::Transaction.create(
    SecureRandom.uuid,
    namespace,
    request
  )
  begin
    Appsignal.instrument(name) do
      yield
    end
  rescue Exception => error # rubocop:disable Lint/RescueException
    transaction.set_error(error)
    raise error
  ensure
    transaction.set_http_or_background_action(request.env)
    transaction.set_http_or_background_queue_start
    Appsignal::Transaction.complete_current!
  end
end

.send_error(error, tags = nil, namespace = Appsignal::Transaction::HTTP_REQUEST) ⇒ void Also known as: send_exception

This method returns an undefined value.

Send an error to AppSignal regardless of the context.

Records and send the exception to AppSignal.

This instrumentation helper does not require a transaction to be active, it starts a new transaction by itself.

Use set_error if your want to add an exception to the current transaction.

Note: Does not do anything if AppSignal is not active or when the "error" is not a class extended from Ruby's Exception class.

Examples:

Send an exception

begin
  raise "oh no!"
rescue => e
  Appsignal.send_error(e)
end

Send an exception with tags

begin
  raise "oh no!"
rescue => e
  Appsignal.send_error(e, :key => "value")
end

Parameters:

  • error (Exception)

    The error to send to AppSignal.

  • tags (Hash{String, Symbol => String, Symbol, Integer}) (defaults to: nil)

    Additional tags to add to the error. See also tag_request.

  • namespace (String) (defaults to: Appsignal::Transaction::HTTP_REQUEST)

    The namespace in which the error occurred. See also set_namespace.

See Also:

Since:

  • 0.6.0



351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
# File 'lib/appsignal.rb', line 351

def send_error(error, tags = nil, namespace = Appsignal::Transaction::HTTP_REQUEST)
  return unless active?
  unless error.is_a?(Exception)
    logger.error("Can't send error, given value is not an exception")
    return
  end
  transaction = Appsignal::Transaction.new(
    SecureRandom.uuid,
    namespace,
    Appsignal::Transaction::GenericRequest.new({})
  )
  transaction.set_tags(tags) if tags
  transaction.set_error(error)
  transaction.complete
end

.set_action(action) ⇒ void

This method returns an undefined value.

Set a custom action name for the current transaction.

When using an integration such as the Rails or Sinatra AppSignal will try to find the action name from the controller or endpoint for you.

If you want to customize the action name as it appears on AppSignal.com you can use this method. This overrides the action name AppSignal generates in an integration.

Examples:

in a Rails controller

class SomeController < ApplicationController
  before_action :set_appsignal_action

  def set_appsignal_action
    Appsignal.set_action("DynamicController#dynamic_method")
  end
end

Parameters:

  • action (String)

See Also:

Since:

  • 2.2.0



440
441
442
443
444
445
# File 'lib/appsignal.rb', line 440

def set_action(action)
  return if !active? ||
      Appsignal::Transaction.current.nil? ||
      action.nil?
  Appsignal::Transaction.current.set_action(action)
end

.set_error(exception, tags = nil, namespace = nil) ⇒ void Also known as: set_exception, add_exception

This method returns an undefined value.

Set an error on the current transaction.

Note: Does not do anything if AppSignal is not active, no transaction is currently active or when the "error" is not a class extended from Ruby's Exception class.

Examples:

Manual instrumentation of set_error.

# Manually starting AppSignal here
# Manually starting a transaction here.
begin
  raise "oh no!"
rescue => e
  Appsignal.set_error(error)
end
# Manually completing the transaction here.
# Manually stopping AppSignal here

In a Rails application

class SomeController < ApplicationController
  # The AppSignal transaction is created by our integration for you.
  def create
    # Do something that breaks
  rescue => e
    Appsignal.set_error(e)
  end
end

Parameters:

  • exception (Exception)

    The error to add to the current transaction.

  • tags (Hash{String, Symbol => String, Symbol, Integer}) (defaults to: nil)

    Additional tags to add to the error. See also tag_request.

  • namespace (String) (defaults to: nil)

    The namespace in which the error occurred. See also set_namespace.

See Also:

Since:

  • 0.6.6



406
407
408
409
410
411
412
413
414
# File 'lib/appsignal.rb', line 406

def set_error(exception, tags = nil, namespace = nil)
  return if !active? ||
      Appsignal::Transaction.current.nil? ||
      exception.nil?
  transaction = Appsignal::Transaction.current
  transaction.set_error(exception)
  transaction.set_tags(tags) if tags
  transaction.set_namespace(namespace) if namespace
end

.set_gauge(key, value, tags = {}) ⇒ Object



604
605
606
607
608
# File 'lib/appsignal.rb', line 604

def set_gauge(key, value, tags = {})
  Appsignal::Extension.set_gauge(key.to_s, value.to_f, Appsignal::Utils.data_generate(tags))
rescue RangeError
  Appsignal.logger.warn("Gauge value #{value} for key '#{key}' is too big")
end

.set_host_gauge(key, value) ⇒ Object



610
611
612
613
614
# File 'lib/appsignal.rb', line 610

def set_host_gauge(key, value)
  Appsignal::Extension.set_host_gauge(key.to_s, value.to_f)
rescue RangeError
  Appsignal.logger.warn("Host gauge value #{value} for key '#{key}' is too big")
end

.set_namespace(namespace) ⇒ void

This method returns an undefined value.

Set a custom namespace for the current transaction.

When using an integration such as Rails or Sidekiq AppSignal will try to find a appropriate namespace for the transaction.

A Rails controller will be automatically put in the "http_request" namespace, while a Sidekiq background job is put in the "background_job" namespace.

Note: The "http_request" namespace gets transformed on AppSignal.com to "Web" and "background_job" gets transformed to "Background".

If you want to customize the namespace in which transactions appear you can use this method. This overrides the namespace AppSignal uses by default.

A common request we've seen is to split the administration panel from the main application.

Examples:

create a custom admin namespace

class AdminController < ApplicationController
  before_action :set_appsignal_namespace

  def set_appsignal_namespace
    Appsignal.set_namespace("admin")
  end
end

Parameters:

  • namespace (String)

See Also:

Since:

  • 2.2.0



479
480
481
482
483
484
# File 'lib/appsignal.rb', line 479

def set_namespace(namespace)
  return if !active? ||
      Appsignal::Transaction.current.nil? ||
      namespace.nil?
  Appsignal::Transaction.current.set_namespace(namespace)
end

.set_process_gauge(key, value) ⇒ Object



616
617
618
619
620
# File 'lib/appsignal.rb', line 616

def set_process_gauge(key, value)
  Appsignal::Extension.set_process_gauge(key.to_s, value.to_f)
rescue RangeError
  Appsignal.logger.warn("Process gauge value #{value} for key '#{key}' is too big")
end

.startvoid

This method returns an undefined value.

Start the AppSignal integration.

Starts AppSignal with the given configuration. If no configuration is set yet it will try to automatically load the configuration using the environment loaded from environment variables and the currently working directory.

This is not required for the automatic integrations AppSignal offers, but this is required for all non-automatic integrations and pure Ruby applications. For more information, see our integrations list and our Integrating AppSignal guide.

To start the logger see start_logger.

Examples:

Appsignal.start

with custom loaded configuration

Appsignal.config = Appsignal::Config.new(Dir.pwd, "production")
Appsignal.start

Since:

  • 0.7.0



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/appsignal.rb', line 98

def start
  unless extension_loaded?
    logger.info("Not starting appsignal, extension is not loaded")
    return
  end

  logger.debug("Starting appsignal")

  @config ||= Config.new(
    Dir.pwd,
    ENV["APPSIGNAL_APP_ENV"] || ENV["RAILS_ENV"] || ENV["RACK_ENV"]
  )

  if config.valid?
    logger.level =
      if config[:debug]
        Logger::DEBUG
      else
        Logger::INFO
      end
    if config.active?
      logger.info "Starting AppSignal #{Appsignal::VERSION} "\
        "(#{$PROGRAM_NAME}, Ruby #{RUBY_VERSION}, #{RUBY_PLATFORM})"
      config.write_to_environment
      Appsignal::Extension.start
      Appsignal::Hooks.load_hooks
      Appsignal::EventFormatter.initialize_deprecated_formatters
      initialize_extensions

      if config[:enable_allocation_tracking] && !Appsignal::System.jruby?
        Appsignal::Extension.install_allocation_event_hook
      end

      if config[:enable_gc_instrumentation]
        GC::Profiler.enable
        Appsignal::Minutely.add_gc_probe
      end

      Appsignal::Minutely.start if config[:enable_minutely_probes]
    else
      logger.info("Not starting, not active for #{config.env}")
    end
  else
    logger.error("Not starting, no valid config for this environment")
  end
end

.start_logger(path_arg = nil) ⇒ void

This method returns an undefined value.

Start the AppSignal logger.

Sets the log level and sets the logger. Uses a file-based logger or the STDOUT-based logger. See the :log configuration option.

Parameters:

  • path_arg (nil) (defaults to: nil)

    Deprecated param. Use the :log_path configuration option instead.

Since:

  • 0.7.0



673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
# File 'lib/appsignal.rb', line 673

def start_logger(path_arg = nil)
  if config && config[:log] == "file" && config.log_file_path
    start_file_logger(config.log_file_path)
  else
    start_stdout_logger
  end

  logger.level =
    if config && config[:debug]
      Logger::DEBUG
    else
      Logger::INFO
    end

  if in_memory_log
    logger << in_memory_log.string
  end

  if path_arg
    logger.info("Setting the path in start_logger has no effect anymore, set it in the config instead")
  end
end

.stop(called_by = nil) ⇒ void

This method returns an undefined value.

Stop AppSignal's agent.

Stops the AppSignal agent. Call this before the end of your program to make sure the agent is stopped as well.

Examples:

Appsignal.start
# Run your application
Appsignal.stop

Parameters:

  • called_by (String) (defaults to: nil)

    Name of the thing that requested the agent to be stopped. Will be used in the AppSignal log file.

Since:

  • 1.0.0



159
160
161
162
163
164
165
166
# File 'lib/appsignal.rb', line 159

def stop(called_by = nil)
  if called_by
    logger.debug("Stopping appsignal (#{called_by})")
  else
    logger.debug("Stopping appsignal")
  end
  Appsignal::Extension.stop
end

.tag_request(tags = {}) ⇒ void Also known as: tag_job

This method returns an undefined value.

Set tags on the current transaction.

Tags are extra bits of information that are added to transaction and appear on sample details pages on AppSignal.com.

Examples:

Appsignal.tag_request(:locale => "en")
Appsignal.tag_request("locale" => "en")
Appsignal.tag_request("user_id" => 1)

Nested hashes are not supported

# Bad
Appsignal.tag_request(:user => { :locale => "en" })

in a Rails controller

class SomeController < ApplicationController
  before_action :set_appsignal_tags

  def set_appsignal_tags
    Appsignal.tag_request(:locale => I18n.locale)
  end
end

Parameters:

  • tags (Hash) (defaults to: {})

    Collection of tags.

Options Hash (tags):

  • :any (String, Symbol, Integer)

    The name of the tag as a Symbol.

  • "any" (String, Symbol, Integer)

    The name of the tag as a String.

See Also:



519
520
521
522
523
524
# File 'lib/appsignal.rb', line 519

def tag_request(tags = {})
  return unless active?
  transaction = Appsignal::Transaction.current
  return false unless transaction
  transaction.set_tags(tags)
end

.testing?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


69
70
71
# File 'lib/appsignal.rb', line 69

def testing?
  false
end

.without_instrumentation { ... } ⇒ Object

Convenience method for skipping instrumentations around a block of code.

Examples:

Appsignal.without_instrumentation do
  # Complex code here
end

Yields:

  • block of code that shouldn't be instrumented.

Returns:

  • (Object)

    Returns the return value of the block.

Since:

  • 0.8.7



757
758
759
760
761
762
# File 'lib/appsignal.rb', line 757

def without_instrumentation
  Appsignal::Transaction.current.pause! if Appsignal::Transaction.current
  yield
ensure
  Appsignal::Transaction.current.resume! if Appsignal::Transaction.current
end