Module: NewRelic::Agent::Instrumentation::Memcache::Tracer
- Defined in:
- lib/new_relic/agent/instrumentation/memcache/instrumentation.rb
Constant Summary collapse
- SLASH =
'/'
- UNKNOWN =
'unknown'
- LOCALHOST =
'localhost'
- MULTIGET_METRIC_NAME =
'get_multi_request'
- MEMCACHED =
'Memcached'
- INSTRUMENTATION_NAME =
'Dalli'
Instance Method Summary collapse
- #assign_instance_to(segment, server) ⇒ Object
- #get_multi_with_newrelic_tracing(method_name) ⇒ Object
- #send_multiget_with_newrelic_tracing(keys) ⇒ Object
- #server_for_key_with_newrelic_tracing ⇒ Object
- #with_newrelic_tracing(operation, *args) ⇒ Object
Instance Method Details
#assign_instance_to(segment, server) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/new_relic/agent/instrumentation/memcache/instrumentation.rb', line 83 def assign_instance_to(segment, server) host = port_path_or_id = nil if server.hostname.start_with?(SLASH) host = LOCALHOST port_path_or_id = server.hostname else host = server.hostname port_path_or_id = server.port end segment.set_instance_info(host, port_path_or_id) rescue => e ::NewRelic::Agent.logger.debug("Failed to retrieve memcached instance info: #{e.}") segment.set_instance_info(UNKNOWN, UNKNOWN) end |
#get_multi_with_newrelic_tracing(method_name) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/new_relic/agent/instrumentation/memcache/instrumentation.rb', line 50 def get_multi_with_newrelic_tracing(method_name) NewRelic::Agent.record_instrumentation_invocation(INSTRUMENTATION_NAME) segment = NewRelic::Agent::Tracer.start_segment( name: "Ruby/Memcached/Dalli/#{method_name}" ) begin NewRelic::Agent::Tracer.capture_segment_error(segment) { yield } ensure ::NewRelic::Agent::Transaction::Segment.finish(segment) end end |
#send_multiget_with_newrelic_tracing(keys) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/new_relic/agent/instrumentation/memcache/instrumentation.rb', line 64 def send_multiget_with_newrelic_tracing(keys) NewRelic::Agent.record_instrumentation_invocation(INSTRUMENTATION_NAME) segment = ::NewRelic::Agent::Tracer.start_datastore_segment( product: MEMCACHED, operation: MULTIGET_METRIC_NAME ) begin assign_instance_to(segment, self) NewRelic::Agent::Tracer.capture_segment_error(segment) { yield } ensure if ::NewRelic::Agent.config[:capture_memcache_keys] segment.notice_nosql_statement("#{MULTIGET_METRIC_NAME} #{keys.inspect}") end ::NewRelic::Agent::Transaction::Segment.finish(segment) end end |
#server_for_key_with_newrelic_tracing ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/new_relic/agent/instrumentation/memcache/instrumentation.rb', line 33 def server_for_key_with_newrelic_tracing NewRelic::Agent.record_instrumentation_invocation(INSTRUMENTATION_NAME) yield.tap do |server| begin if txn = ::NewRelic::Agent::Tracer.current_transaction segment = txn.current_segment if ::NewRelic::Agent::Transaction::DatastoreSegment === segment assign_instance_to(segment, server) end end rescue => e ::NewRelic::Agent.logger.warn("Unable to set instance info on datastore segment: #{e.}") end end end |
#with_newrelic_tracing(operation, *args) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/new_relic/agent/instrumentation/memcache/instrumentation.rb', line 15 def with_newrelic_tracing(operation, *args) NewRelic::Agent.record_instrumentation_invocation(INSTRUMENTATION_NAME) segment = NewRelic::Agent::Tracer.start_datastore_segment( product: MEMCACHED, operation: operation ) begin NewRelic::Agent::Tracer.capture_segment_error(segment) { yield } ensure if NewRelic::Agent.config[:capture_memcache_keys] segment.notice_nosql_statement("#{operation} #{args.first.inspect}") end ::NewRelic::Agent::Transaction::Segment.finish(segment) end end |