module Honeycomb::Rack
Rack
specific methods for building middleware
Constants
- RACK_FIELDS
Attributes
app[R]
client[R]
Public Class Methods
new(app, client:)
click to toggle source
# File lib/honeycomb/integrations/rack.rb, line 29 def initialize(app, client:) @app = app @client = client end
Public Instance Methods
add_package_information(_env) { |"package", "rack"| ... }
click to toggle source
# File lib/honeycomb/integrations/rack.rb, line 65 def add_package_information(_env) yield "meta.package", "rack" yield "meta.package_version", ::Rack::VERSION.join(".") end
call(env)
click to toggle source
# File lib/honeycomb/integrations/rack.rb, line 34 def call(env) req = ::Rack::Request.new(env) client.start_span( name: "http_request", serialized_trace: env, ) do |span| add_field = lambda do |key, value| unless value.nil? || (value.respond_to?(:empty?) && value.empty?) span.add_field(key, value) end end extract_fields(env, RACK_FIELDS, &add_field) span.add_field("request.secure", req.ssl?) span.add_field("request.xhr", req.xhr?) begin status, headers, body = call_with_hook(env, span, &add_field) ensure add_package_information(env, &add_field) extract_user_information(env, &add_field) end span.add_field("response.status_code", status) span.add_field("response.content_type", headers["Content-Type"]) [status, headers, body] end end
extract_fields(env, fields) { |value, env| ... }
click to toggle source
# File lib/honeycomb/integrations/rack.rb, line 70 def extract_fields(env, fields) fields.each do |key, value| yield value, env[key] end end
Private Instance Methods
call_with_hook(env, _span, &_add_field)
click to toggle source
# File lib/honeycomb/integrations/rack.rb, line 78 def call_with_hook(env, _span, &_add_field) app.call(env) end