module NewRelic::Agent::Instrumentation::MiddlewareTracing
Constants
- CONTENT_LENGTH
the trailing unless is for the benefit for Ruby 1.8.7 and can be removed when it is deprecated.
- CONTENT_TYPE
the trailing unless is for the benefit for Ruby 1.8.7 and can be removed when it is deprecated.
- TXN_STARTED_KEY
Public Instance Methods
_nr_has_middleware_tracing()
click to toggle source
# File lib/new_relic/agent/instrumentation/middleware_tracing.rb, line 30 def _nr_has_middleware_tracing true end
build_transaction_options(env, first_middleware)
click to toggle source
# File lib/new_relic/agent/instrumentation/middleware_tracing.rb, line 34 def build_transaction_options(env, first_middleware) opts = transaction_options opts = merge_first_middleware_options(opts, env) if first_middleware opts end
call(env)
click to toggle source
# File lib/new_relic/agent/instrumentation/middleware_tracing.rb, line 86 def call(env) first_middleware = note_transaction_started(env) state = NewRelic::Agent::TransactionState.tl_get begin Transaction.start(state, category, build_transaction_options(env, first_middleware)) events.notify(:before_call, env) if first_middleware result = (target == self) ? traced_call(env) : target.call(env) if first_middleware capture_response_attributes(state, result) events.notify(:after_call, env, result) end result rescue Exception => e NewRelic::Agent.notice_error(e) raise e ensure Transaction.stop(state) end end
capture_http_response_code(state, result)
click to toggle source
# File lib/new_relic/agent/instrumentation/middleware_tracing.rb, line 52 def capture_http_response_code(state, result) if result.is_a?(Array) && state.current_transaction state.current_transaction.http_response_code = result[0] end end
capture_response_attributes(state, result)
click to toggle source
# File lib/new_relic/agent/instrumentation/middleware_tracing.rb, line 80 def capture_response_attributes(state, result) capture_http_response_code(state, result) capture_response_content_type(state, result) capture_response_content_length(state, result) end
capture_response_content_length(state, result)
click to toggle source
# File lib/new_relic/agent/instrumentation/middleware_tracing.rb, line 73 def capture_response_content_length(state, result) if result.is_a?(Array) && state.current_transaction _, headers, _ = result state.current_transaction.response_content_length = headers[CONTENT_LENGTH] end end
capture_response_content_type(state, result)
click to toggle source
# File lib/new_relic/agent/instrumentation/middleware_tracing.rb, line 62 def capture_response_content_type(state, result) if result.is_a?(Array) && state.current_transaction _, headers, _ = result state.current_transaction.response_content_type = headers[CONTENT_TYPE] end end
events()
click to toggle source
# File lib/new_relic/agent/instrumentation/middleware_tracing.rb, line 111 def events NewRelic::Agent.instance.events end
merge_first_middleware_options(opts, env)
click to toggle source
# File lib/new_relic/agent/instrumentation/middleware_tracing.rb, line 40 def merge_first_middleware_options(opts, env) opts[:apdex_start_time] = QueueTime.parse_frontend_timestamp(env) # this case is for the rare occasion that an app is using Puma::Rack # without having ::Rack as a dependency opts[:request] = ::Rack::Request.new(env) if defined? ::Rack opts end
note_transaction_started(env)
click to toggle source
# File lib/new_relic/agent/instrumentation/middleware_tracing.rb, line 48 def note_transaction_started(env) env[TXN_STARTED_KEY] = true unless env[TXN_STARTED_KEY] end