Module: D13n::Metric::Instrumentation::Sinatra

Includes:
ControllerInstrumentation
Defined in:
lib/d13n/metric/instrumentation/sinatra.rb,
lib/d13n/metric/instrumentation/sinatra/stream_namer.rb

Defined Under Namespace

Modules: ClassMethods, StreamNamer

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ControllerInstrumentation

#perform_action_with_d13n_stream

Class Method Details

.included(descendance) ⇒ Object



67
68
69
# File 'lib/d13n/metric/instrumentation/sinatra.rb', line 67

def self.included(descendance)
  descendance.extend(ClassMethods)
end

Instance Method Details

#dispatch_and_notice_errors_with_d13n_instrumentationObject



146
147
148
149
150
151
# File 'lib/d13n/metric/instrumentation/sinatra.rb', line 146

def dispatch_and_notice_errors_with_d13n_instrumentation
  dispatch_without_d13n_instrumentation
ensure
  had_error = env.has_key?('sinatra.error')
  ::D13n::Metric::Manager.notice_error(env['sinatra.error']) if had_error
end

#dispatch_with_d13n_instrumentationObject



135
136
137
138
139
140
141
142
143
144
# File 'lib/d13n/metric/instrumentation/sinatra.rb', line 135

def dispatch_with_d13n_instrumentation
  request_params = get_request_params
  name = StreamNamer.initial_stream_name(request)
  filter_params = get_filter_parames(request_params)
  perform_action_with_d13n_stream(:category => :sinatra,
                                  :name => name,
                                  :params => filter_params) do
    dispatch_and_notice_errors_with_d13n_instrumentation
  end
end

#get_filter_parames(request_params) ⇒ Object



161
162
163
# File 'lib/d13n/metric/instrumentation/sinatra.rb', line 161

def get_filter_parames(request_params)
  request_params
end

#get_request_paramsObject



153
154
155
156
157
158
159
# File 'lib/d13n/metric/instrumentation/sinatra.rb', line 153

def get_request_params
  begin
    @request.params
  rescue => e
    D13n.logger.debug("Failed to get params from Rack request.", e)
  end
end

#process_route_with_d13n_instrumentation(*args, &block) ⇒ Object



111
112
113
114
115
116
117
118
119
# File 'lib/d13n/metric/instrumentation/sinatra.rb', line 111

def process_route_with_d13n_instrumentation(*args, &block)
  begin
    env["d13n.last_route"] = args[0]
  rescue => e
    D13n.logger.debug("Failed determining last route in Sinatra", e)
  end

  process_route_without_d13n_instrumentation(*args, &block)
end

#route_eval_with_d13n_instrumentation(*args, &block) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/d13n/metric/instrumentation/sinatra.rb', line 121

def route_eval_with_d13n_instrumentation(*args, &block)
  begin
    stream_name = StreamNamer.for_route(env, request)
    
    unless stream_name.nil?
      ::D13n::Metric::Stream.set_default_stream_name("#{self.class.name}.#{stream_name}", :sinatra)
    end
  rescue => e
    D13n.logger.debug("Failed during route_eval to set stream name", e)
  end

  route_eval_without_d13n_instrumentation(*args, &block)
end