Module: Opbeat

Defined in:
lib/opbeat.rb,
lib/opbeat/util.rb,
lib/opbeat/error.rb,
lib/opbeat/trace.rb,
lib/opbeat/client.rb,
lib/opbeat/filter.rb,
lib/opbeat/worker.rb,
lib/opbeat/logging.rb,
lib/opbeat/version.rb,
lib/opbeat/injections.rb,
lib/opbeat/line_cache.rb,
lib/opbeat/middleware.rb,
lib/opbeat/subscriber.rb,
lib/opbeat/http_client.rb,
lib/opbeat/normalizers.rb,
lib/opbeat/transaction.rb,
lib/opbeat/configuration.rb,
lib/opbeat/data_builders.rb,
lib/opbeat/error_message.rb,
lib/opbeat/trace_helpers.rb,
lib/opbeat/sql_summarizer.rb,
lib/opbeat/util/inspector.rb,
lib/opbeat/injections/json.rb,
lib/opbeat/injections/redis.rb,
lib/opbeat/util/constantize.rb,
lib/opbeat/injections/sequel.rb,
lib/opbeat/error_message/http.rb,
lib/opbeat/error_message/user.rb,
lib/opbeat/injections/sinatra.rb,
lib/opbeat/data_builders/error.rb,
lib/opbeat/injections/net_http.rb,
lib/opbeat/error_message/exception.rb,
lib/opbeat/normalizers/action_view.rb,
lib/opbeat/error_message/stacktrace.rb,
lib/opbeat/normalizers/active_record.rb,
lib/opbeat/data_builders/transactions.rb,
lib/opbeat/normalizers/action_controller.rb

Defined Under Namespace

Modules: TraceHelpers Classes: BodyProxy, Configuration, ErrorMessage, Middleware, Trace, Transaction

Constant Summary collapse

VERSION =
"3.0.10"

Class Method Summary collapse

Class Method Details

.capture(&block) ⇒ Object

Captures any exceptions raised inside the block



133
134
135
136
137
138
139
140
# File 'lib/opbeat.rb', line 133

def self.capture &block
  unless client
    return yield if block_given?
    return nil
  end

  client.capture(&block)
end

.flush_transactionsObject



72
73
74
75
76
77
78
79
# File 'lib/opbeat.rb', line 72

def self.flush_transactions
  unless client
    return yield if block_given?
    return nil
  end

  client.flush_transactions
end

.release(rel, opts = {}) ⇒ Net::HTTPResponse

Notify Opbeat of a release

Parameters:

  • rel (Hash)

Options Hash (rel):

  • :rev (String)

    Revision

  • :branch (String)

Returns:

  • (Net::HTTPResponse)


148
149
150
151
152
153
154
155
# File 'lib/opbeat.rb', line 148

def self.release rel, opts = {}
  unless client
    return yield if block_given?
    return nil
  end

  client.release rel, opts
end

.report(exception, opts = {}) ⇒ Net::HTTPResponse

Send an exception to Opbeat

Parameters:

  • exception (Exception)
  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :rack_env (Hash)

    A rack env object

Returns:

  • (Net::HTTPResponse)


108
109
110
111
112
113
114
115
# File 'lib/opbeat.rb', line 108

def self.report exception, opts = {}
  unless client
    return yield if block_given?
    return nil
  end

  client.report exception, opts
end

.report_message(message, opts = {}) ⇒ Net::HTTPResponse

Send an exception to Opbeat

Parameters:

  • message (String)
  • opts (Hash) (defaults to: {})

Returns:

  • (Net::HTTPResponse)


122
123
124
125
126
127
128
129
# File 'lib/opbeat.rb', line 122

def self.report_message message, opts = {}
  unless client
    return yield if block_given?
    return nil
  end

  client.report_message message, opts
end

.set_context(context) ⇒ Object

Sets context for future errors

Parameters:

  • context (Hash)


84
85
86
87
# File 'lib/opbeat.rb', line 84

def self.set_context context
  return nil unless client
  client.set_context context
end

.start!(conf) ⇒ Object

Start the Opbeat client

Parameters:



27
28
29
# File 'lib/opbeat.rb', line 27

def self.start! conf
  Client.start! conf
end

.started?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/opbeat.rb', line 36

def self.started?
  !!Client.inst
end

.stop!Object

Stop the Opbeat client



32
33
34
# File 'lib/opbeat.rb', line 32

def self.stop!
  Client.stop!
end

.trace(signature, kind = nil, extra = nil) {|Trace| ... } ⇒ Trace

Starts a new trace under the current Transaction

Parameters:

  • signature (String)

    A description of the trace, eq ‘SELECT FROM “users”`

  • kind (String) (defaults to: nil)

    The kind of trace, eq ‘db.mysql2.query`

  • extra (Hash) (defaults to: nil)

    Extra information about the trace

Yields:

  • (Trace)

    Optional block encapsulating trace

Returns:

  • (Trace)

    Unless block given



63
64
65
66
67
68
69
70
# File 'lib/opbeat.rb', line 63

def self.trace signature, kind = nil, extra = nil, &block
  unless client
    return yield if block_given?
    return nil
  end

  client.trace signature, kind, extra, &block
end

.transaction(endpoint, kind = nil, result = nil) {|Transaction| ... } ⇒ Transaction

Start a new transaction or return the currently running

Parameters:

  • endpoint (String)

    A description of the transaction, eg ‘ExamplesController#index`

  • kind (String) (defaults to: nil)

    The kind of the transaction, eg ‘app.request.get` or `db.mysql2.query`

  • result (Object) (defaults to: nil)

    Result of the transaction, eq ‘200` for a HTTP server

Yields:

  • (Transaction)

    Optional block encapsulating transaction

Returns:



47
48
49
50
51
52
53
54
# File 'lib/opbeat.rb', line 47

def self.transaction endpoint, kind = nil, result = nil, &block
  unless client
    return yield if block_given?
    return nil
  end

  client.transaction endpoint, kind, result, &block
end

.with_context(context) {|Trace| ... } ⇒ Object

Updates context for errors within the block

Parameters:

  • context (Hash)

Yields:

  • (Trace)

    Block in which the context is used



93
94
95
96
97
98
99
100
# File 'lib/opbeat.rb', line 93

def self.with_context context, &block
  unless client
    return yield if block_given?
    return nil
  end

  client.context context, &block
end