Class: Fluent::AirbrakePythonOutput

Inherits:
Output
  • Object
show all
Defined in:
lib/fluent/plugin/out_airbrake_python.rb

Defined Under Namespace

Classes: Notice

Constant Summary collapse

PY_LOGLEVEL_MAP =
{
  'CRITICAL' => 50,
  'FATAL'    => 50,
  'ERROR'    => 40,
  'WARNING'  => 30,
  'WARN'     => 30,
  'INFO'     => 20,
  'DEBUG'    => 10,
  'NOTSET'   =>  0
}

Instance Method Summary collapse

Instance Method Details

#build_action_name_py(record) ⇒ Object



120
121
122
# File 'lib/fluent/plugin/out_airbrake_python.rb', line 120

def build_action_name_py(record)
  record['sys_funcname']
end

#build_cgi_data_dump(record) ⇒ Object



128
129
130
131
132
133
134
# File 'lib/fluent/plugin/out_airbrake_python.rb', line 128

def build_cgi_data_dump(record)
  if @cgi_data_dump_key
    record[@cgi_data_dump_key]
  else
    nil
  end
end

#build_component_name_py(record) ⇒ Object



116
117
118
# File 'lib/fluent/plugin/out_airbrake_python.rb', line 116

def build_component_name_py(record)
  record['sys_name']
end

#build_message_py(record) ⇒ Object



124
125
126
# File 'lib/fluent/plugin/out_airbrake_python.rb', line 124

def build_message_py(record)
  record['message'].sub(@message_regexp, @message_template)
end

#build_notice(tag, time, record) ⇒ Object



183
184
185
186
187
# File 'lib/fluent/plugin/out_airbrake_python.rb', line 183

def build_notice(tag, time, record)
  if notification_needed(tag, time, record)
    notice_from_py_record(@aconf, tag, record)
  end
end

#build_parameters_dump(record) ⇒ Object



136
137
138
139
140
141
142
# File 'lib/fluent/plugin/out_airbrake_python.rb', line 136

def build_parameters_dump(record)
  if @parameters_dump_key
    record[@parameters_dump_key]
  else
    nil
  end
end

#build_session_dump(record) ⇒ Object



144
145
146
147
148
149
150
# File 'lib/fluent/plugin/out_airbrake_python.rb', line 144

def build_session_dump(record)
  if @session_dump_key
    record[@session_dump_key]
  else
    nil
  end
end

#configure(conf) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/fluent/plugin/out_airbrake_python.rb', line 79

def configure(conf)
  super

  aconf = Airbrake::Configuration.new
  aconf.host = @host
  aconf.port = @port ? @port: (@secure ? 443: 80)
  aconf.proxy_host = @proxy_host
  aconf.proxy_port = @proxy_port
  aconf.proxy_user = @proxy_user
  aconf.proxy_pass = @proxy_pass
  aconf.param_filters = @param_filters.split(/\s+/) if @param_filters
  aconf.development_environments = @development_environments.split(/\s+/) if @development_environments
  aconf.development_lookup = @development_lookup
  aconf.environment_name = @environment_name
  aconf.project_root = @project_root
  aconf.notifier_name = @notifier_name if @notifier_name
  aconf.notifier_version = @notifier_version if @notifier_version
  aconf.notifier_url = @notifier_url if @notifier_url
  aconf.user_information = @user_information if @user_information
  aconf.framework = @framework if @framework
  aconf.secure = @secure
  aconf.use_system_ssl_cert_chain = @use_system_ssl_cert_chain
  aconf.http_open_timeout = @http_open_timeout if @http_open_timeout
  aconf.http_read_timeout = @http_read_timeout if @http_read_timeout
  aconf.project_id = @project_id
  aconf.api_key = @api_key

  @aconf = aconf
  @sender = Airbrake::Sender.new(aconf)
  @message_regexp = Regexp.new(@message_regexp, Regexp::MULTILINE)
  @loglevel = Integer(@loglevel) rescue PY_LOGLEVEL_MAP[@loglevel]
end

#emit(tag, es, chain) ⇒ Object



189
190
191
192
193
194
195
# File 'lib/fluent/plugin/out_airbrake_python.rb', line 189

def emit(tag, es, chain)
  es.each do |time, record|
    notice = build_notice(tag, time, record)
    @sender.send_to_airbrake(notice) if notice
  end
  chain.next
end

#notice_from_py_record(aconf, tag, record) ⇒ Object



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/fluent/plugin/out_airbrake_python.rb', line 152

def notice_from_py_record(aconf, tag, record)
  exc_info_rec = record['sys_exc_info']
  return nil unless exc_info_rec
  error_class = nil
  backtrace = nil
  if exc_info_rec
    error_class = exc_info_rec['type']
    backtrace = Airbrake::Backtrace.new(
      exc_info_rec['traceback'].map { |f|
        Airbrake::Backtrace::Line.new(f[0], f[1], f[2])
      }
    )
  end

  Notice.new(
    aconf.merge(
      :error_class    => error_class,
      :backtrace      => backtrace,
      :error_message  => build_message_py(record),
      :component      => build_component_name_py(record),
      :action         => build_action_name_py(record),
      :hostname       => record['sys_host'],
      :project_id     => aconf[:project_id] || tag,
      :cgi_data       => build_cgi_data_dump(record) || {},
      :session_data   => build_session_dump(record) || {},
      :parameters     => build_parameters_dump(record) || {},
    )
  )
end

#notification_needed(tag, time, record) ⇒ Object



112
113
114
# File 'lib/fluent/plugin/out_airbrake_python.rb', line 112

def notification_needed(tag, time, record)
  record['sys_levelno'] >= @loglevel
end