instana 1.0.3 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e4988b08659f80e1f76d21135af688030ee190a0
4
- data.tar.gz: c773f6f64f7559da3e10dbfef73d1ca8012bd289
3
+ metadata.gz: 83702cf490019361b99d4c0096e4e12297a915e4
4
+ data.tar.gz: a7d1b3d505cc1466d1bf5bf784641bf07228f91c
5
5
  SHA512:
6
- metadata.gz: 2b6c215de5684fffe16f8338958b47b8b09cc8b17e6a15b4e2e8a6361f9eb14ba8ca343d8b7ca6a08c7b8d92d95a6ea5a368cd21d4211194c1175ef0a2f796bd
7
- data.tar.gz: 9e22ce676e64dd9eb0adab68ea0a9933e1343f83356f88a0796ac6aa3f89582d76fe01d3dc4636afe62b2f6e77cdeca38d7e3a61861dd328e24aa00828cb2dbc
6
+ metadata.gz: a3950247007e4aa9b70d08257e7b9fbb5ccf99e211f454415edd1a9140840745b11e81e045b3596c22383c3d3405a0d4594a2858419b44bed49d3114af7c0c11
7
+ data.tar.gz: cf9910fa2bfa9bfd5e80b24f64539fadb9d235b523f7f9bf4f6d81ba0daf10627b117d62d6c2502af8ee45e0b4d9064c2cd53af22335c9ceb9d2b0e9359259e5
@@ -19,6 +19,9 @@ before_install:
19
19
 
20
20
  script: "bundle exec rake test"
21
21
 
22
+ services:
23
+ - memcached
24
+
22
25
  notifications:
23
26
  slack:
24
27
  rooms:
data/Gemfile CHANGED
@@ -22,6 +22,9 @@ group :development, :test do
22
22
  # HTTP Clients
23
23
  gem 'excon'
24
24
 
25
+ # Memcache
26
+ gem 'dalli'
27
+
25
28
  # Rack v2 dropped support for Ruby 2.2 and higher.
26
29
  if RUBY_VERSION < '2.2'
27
30
  gem 'rack', '< 2.0'
data/Rakefile CHANGED
@@ -17,6 +17,8 @@ task :environment do
17
17
  end
18
18
 
19
19
  task :console => :environment do
20
+ # Possible debug levels: :agent, :agent_comm, :trace, :agent_response, :tracing
21
+ # ::Instana.logger.debug_level = [ :agent, :agent_comm ]
20
22
  ARGV.clear
21
23
  Pry.start
22
24
  end
@@ -21,6 +21,7 @@ module Instana
21
21
  @config[:eum_baggage] = {}
22
22
 
23
23
  # HTTP Clients
24
+ @config[:dalli] = { :enabled => true }
24
25
  @config[:excon] = { :enabled => true }
25
26
  @config[:nethttp] = { :enabled => true }
26
27
  @config[:'rest-client'] = { :enabled => true }
@@ -0,0 +1,78 @@
1
+ module Instana
2
+ module Instrumentation
3
+ module Dalli
4
+ def self.included(klass)
5
+ ::Instana::Util.method_alias(klass, :perform)
6
+ ::Instana::Util.method_alias(klass, :get_multi)
7
+ end
8
+
9
+ def perform_with_instana(*args, &blk)
10
+ if !::Instana.tracer.tracing? || ::Instana.tracer.tracing_span?(:memcache)
11
+ do_skip = true
12
+ return perform_without_instana(*args, &blk)
13
+ end
14
+
15
+ op, key, *_opts = args
16
+
17
+ entry_payload = { :memcache => {} }
18
+ entry_payload[:memcache][:namespace] = @options[:namespace] if @options.key?(:namespace)
19
+ entry_payload[:memcache][:command] = op
20
+ entry_payload[:memcache][:key] = key
21
+
22
+ ::Instana.tracer.log_entry(:memcache, entry_payload)
23
+ result = perform_without_instana(*args, &blk)
24
+
25
+ kv_payload = { :memcache => {}}
26
+ if op == :get
27
+ kv_payload[:memcache][:hit] = result ? 1 : 0
28
+ end
29
+ result
30
+ rescue => e
31
+ ::Instana.tracer.log_error(e)
32
+ raise
33
+ ensure
34
+ ::Instana.tracer.log_exit(:memcache, kv_payload) unless do_skip
35
+ end
36
+
37
+ def get_multi_with_instana(*keys)
38
+ entry_payload = { :memcache => {} }
39
+ entry_payload[:memcache][:namespace] = @options[:namespace] if @options.key?(:namespace)
40
+ entry_payload[:memcache][:command] = :get_multi
41
+ entry_payload[:memcache][:keys] = keys.flatten.join(", ")
42
+
43
+ ::Instana.tracer.log_entry(:memcache, entry_payload)
44
+ result = get_multi_without_instana(*keys)
45
+
46
+ exit_payload = { :memcache => {} }
47
+ exit_payload[:memcache][:hits] = result.length
48
+ result
49
+ rescue => e
50
+ ::Instana.tracer.log_error(e)
51
+ raise
52
+ ensure
53
+ ::Instana.tracer.log_exit(:memcache, exit_payload)
54
+ end
55
+ end
56
+
57
+ module DalliServer
58
+ def self.included(klass)
59
+ ::Instana::Util.method_alias(klass, :request)
60
+ end
61
+
62
+ def request_with_instana(op, *args)
63
+ if ::Instana.tracer.tracing? || ::Instana.tracer.tracing_span?(:memcache)
64
+ info_payload = { :memcache => {} }
65
+ info_payload[:memcache][:server] = "#{@hostname}:#{@port}"
66
+ ::Instana.tracer.log_info(info_payload)
67
+ end
68
+ request_without_instana(op, *args)
69
+ end
70
+ end
71
+ end
72
+ end
73
+
74
+ if defined?(::Dalli) && ::Instana.config[:dalli][:enabled]
75
+ ::Instana.logger.warn "Instrumenting Dalli"
76
+ ::Dalli::Client.send(:include, ::Instana::Instrumentation::Dalli)
77
+ ::Dalli::Server.send(:include, ::Instana::Instrumentation::DalliServer)
78
+ end
@@ -73,6 +73,7 @@ module Instana
73
73
  #
74
74
  def log_start_or_continue(name, kvs = {}, incoming_context = {})
75
75
  return unless ::Instana.agent.ready?
76
+ ::Instana.logger.debug "#{__method__} passed a block. Use `start_or_continue` instead!" if block_given?
76
77
  self.current_trace = ::Instana::Trace.new(name, kvs, incoming_context)
77
78
  end
78
79
 
@@ -307,6 +308,20 @@ module Instana
307
308
  self.current_trace ? true : false
308
309
  end
309
310
 
311
+ # Indicates if we're tracing and the current span name matches
312
+ # <name>
313
+ #
314
+ # @param name [Symbol] the name to check against the current span
315
+ #
316
+ # @return [Boolean]
317
+ #
318
+ def tracing_span?(name)
319
+ if self.current_trace
320
+ return self.current_trace.current_span.name == name
321
+ end
322
+ false
323
+ end
324
+
310
325
  # Retrieve the current context of the tracer.
311
326
  #
312
327
  # @return [SpanContext] or nil if not tracing
@@ -1,6 +1,6 @@
1
1
  module Instana
2
2
  class Span
3
- REGISTERED_SPANS = [ :rack, :'net-http', :excon ].freeze
3
+ REGISTERED_SPANS = [ :rack, :'net-http', :excon, :memcache ].freeze
4
4
  ENTRY_SPANS = [ :rack ].freeze
5
5
  EXIT_SPANS = [ :'net-http', :excon ].freeze
6
6
  HTTP_SPANS = ENTRY_SPANS + EXIT_SPANS
@@ -7,7 +7,8 @@ module Instana
7
7
  # @param method [Symbol] The name of the method to be aliased.
8
8
  #
9
9
  def method_alias(klass, method)
10
- if klass.method_defined?(method.to_sym)
10
+ if klass.method_defined?(method.to_sym) ||
11
+ klass.private_method_defined?(method.to_sym)
11
12
 
12
13
  with = "#{method}_with_instana"
13
14
  without = "#{method}_without_instana"
@@ -1,4 +1,4 @@
1
1
  module Instana
2
- VERSION = "1.0.3"
2
+ VERSION = "1.1.0"
3
3
  VERSION_FULL = "instana-#{VERSION}"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: instana
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Giacomo Lombardo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-13 00:00:00.000000000 Z
11
+ date: 2017-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -145,6 +145,7 @@ files:
145
145
  - lib/instana/frameworks/sinatra.rb
146
146
  - lib/instana/helpers.rb
147
147
  - lib/instana/instrumentation.rb
148
+ - lib/instana/instrumentation/dalli.rb
148
149
  - lib/instana/instrumentation/excon.rb
149
150
  - lib/instana/instrumentation/net-http.rb
150
151
  - lib/instana/instrumentation/rack.rb