instana 0.12.0 → 0.12.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -7,6 +7,8 @@
7
7
  The Instana gem provides Ruby metrics and traces (request, queue & cross-host) for [Instana](https://www.instana.com/).
8
8
 
9
9
  [![Build Status](https://travis-ci.org/instana/ruby-sensor.svg?branch=master)](https://travis-ci.org/instana/ruby-sensor)
10
+ [![Code
11
+ Climate](https://codeclimate.com/github/instana/ruby-sensor/badges/gpa.svg)](https://codeclimate.com/github/instana/ruby-sensor)
10
12
  [![Gem Version](https://badge.fury.io/rb/instana.svg)](https://badge.fury.io/rb/instana)
11
13
 
12
14
  ## Note
@@ -15,6 +17,13 @@ This gem supports Ruby versions 2.0 or greater.
15
17
 
16
18
  Any and all feedback is welcome. Happy Ruby visibility.
17
19
 
20
+ ![rails](https://s3.amazonaws.com/instana/rails-logo.jpg?1)
21
+ ![roda](https://s3.amazonaws.com/instana/roda-logo.png?1)
22
+ ![cuba](https://s3.amazonaws.com/instana/cuba-logo.png?1)
23
+ ![sinatra](https://s3.amazonaws.com/instana/sinatra-logo.png?1)
24
+ ![padrino](https://s3.amazonaws.com/instana/padrino-logo.png?1)
25
+ ![rack](https://s3.amazonaws.com/instana/rack-logo.png?1)
26
+
18
27
  ## Installation
19
28
 
20
29
  The gem is available on [Rubygems](https://rubygems.org/gems/instana). To install, add this line to _the end_ of your application's Gemfile:
data/lib/instana/agent.rb CHANGED
@@ -397,9 +397,9 @@ module Instana
397
397
  Net::HTTP.start(req.uri.hostname, req.uri.port, :open_timeout => 1, :read_timeout => 1) do |http|
398
398
  response = http.request(req)
399
399
  end
400
- ::Instana.logger.agent_comm "#{req.method} Req -> -body-: #{req.uri} -> -#{req.body}- Resp -> body:#{response} -> -#{response.body}-"
400
+ ::Instana.logger.agent_comm "#{req.method}->#{req.uri} body:(#{req.body}) Response:#{response} body:(#{response.body})"
401
401
  response
402
- rescue Errno::ECONNREFUSED => e
402
+ rescue Errno::ECONNREFUSED
403
403
  return nil
404
404
  rescue => e
405
405
  Instana.logger.error "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
@@ -1,6 +1,6 @@
1
1
  require "instana/rack"
2
2
 
3
3
  if defined?(::Cuba)
4
- ::Instana.logger.warn "Instana: Instrumenting Cuba"
4
+ ::Instana.logger.warn "Instrumenting Cuba"
5
5
  Cuba.use ::Instana::Rack
6
6
  end
@@ -6,14 +6,14 @@ if defined?(::Rails)
6
6
 
7
7
  if ::Rails::VERSION::MAJOR < 3
8
8
  ::Rails.configuration.after_initialization do
9
- ::Instana.logger.warn "Instana: Instrumenting Rack"
9
+ ::Instana.logger.warn "Instrumenting Rack"
10
10
  ::Rails.configuration.middleware.insert 0, ::Instana::Rack
11
11
  end
12
12
  else
13
13
  module ::Instana
14
14
  class Railtie < ::Rails::Railtie
15
15
  initializer 'instana.rack' do |app|
16
- ::Instana.logger.warn "Instana: Instrumenting Rack"
16
+ ::Instana.logger.warn "Instrumenting Rack"
17
17
  app.config.middleware.insert 0, ::Instana::Rack
18
18
  end
19
19
  end
@@ -1,6 +1,6 @@
1
1
  require "instana/rack"
2
2
 
3
3
  if defined?(::Roda)
4
- ::Instana.logger.warn "Instana: Instrumenting Roda"
4
+ ::Instana.logger.warn "Instrumenting Roda"
5
5
  Roda.use ::Instana::Rack
6
6
  end
@@ -4,6 +4,6 @@ require "instana/rack"
4
4
  # the latter is based on Sinatra
5
5
 
6
6
  if defined?(::Sinatra)
7
- ::Instana.logger.warn "Instana: Instrumenting Sinatra"
7
+ ::Instana.logger.warn "Instrumenting Sinatra"
8
8
  ::Sinatra::Base.use ::Instana::Rack
9
9
  end
@@ -1,25 +1,18 @@
1
- #
2
- # Load all of the files in the instrumentation subdirectory
3
- #
4
- pattern = File.join(File.dirname(__FILE__), 'instrumentation', '*.rb')
5
- Dir.glob(pattern) do |f|
6
- begin
7
- require f
8
- rescue => e
9
- Instana.logger.error "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
10
- Instana.logger.debug e.backtrace.join("\r\n")
11
- end
1
+ module Instana
2
+ AUTOLOAD_DIRECTORIES = [:instrumentation, :frameworks].freeze
12
3
  end
13
4
 
14
5
  #
15
- # Load all of the files in the frameworks subdirectory
6
+ # Load all of the files in the specified subdirectories
16
7
  #
17
- pattern = File.join(File.dirname(__FILE__), 'frameworks', '*.rb')
18
- Dir.glob(pattern) do |f|
19
- begin
20
- require f
21
- rescue => e
22
- Instana.logger.error "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
23
- Instana.logger.debug e.backtrace.join("\r\n")
8
+ ::Instana::AUTOLOAD_DIRECTORIES.each do |d|
9
+ pattern = File.join(File.dirname(__FILE__), d.to_s, '*.rb')
10
+ Dir.glob(pattern) do |f|
11
+ begin
12
+ require f
13
+ rescue => e
14
+ Instana.logger.error "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
15
+ Instana.logger.debug e.backtrace.join("\r\n")
16
+ end
24
17
  end
25
18
  end
@@ -43,7 +43,7 @@ Net::HTTP.class_eval {
43
43
  ::Instana.tracer.log_exit(:'net-http')
44
44
  end
45
45
 
46
- Instana.logger.info "Instana: Instrumenting net/http"
46
+ Instana.logger.info "Instrumenting net/http"
47
47
 
48
48
  alias request_without_instana request
49
49
  alias request request_with_instana
@@ -33,5 +33,9 @@ module Instana
33
33
  def raw
34
34
  @data
35
35
  end
36
+
37
+ def custom?
38
+ @data[:n] == :sdk
39
+ end
36
40
  end
37
41
  end
@@ -1,5 +1,7 @@
1
1
  module Instana
2
2
  class Trace
3
+ REGISTERED_SPANS = [ :rack, :'net-http' ]
4
+
3
5
  # @return [Integer] the ID for this trace
4
6
  attr_reader :id
5
7
 
@@ -31,14 +33,20 @@ module Instana
31
33
  # This is a new trace so open the first span with the proper
32
34
  # root span IDs.
33
35
  @current_span = Span.new({
34
- :s => @id, # Span ID
35
- :n => name, # Span name
36
- :ts => ts_now, # Timestamp
37
- :ta => :ruby, # Agent
38
- :data => kvs, # Data
36
+ :s => @id, # Span ID
37
+ :ts => ts_now, # Timestamp
38
+ :ta => :ruby, # Agent
39
39
  :f => { :e => ::Instana.agent.report_pid, :h => ::Instana.agent.agent_uuid } # Entity Source
40
40
  })
41
41
 
42
+ # Check for custom tracing
43
+ if !REGISTERED_SPANS.include?(name.to_sym)
44
+ configure_custom_span(name, kvs)
45
+ else
46
+ @current_span[:n] = name.to_sym
47
+ @current_span[:data] = kvs
48
+ end
49
+
42
50
  # Handle potential incoming context
43
51
  if incoming_context.empty?
44
52
  # No incoming context. Set trace ID the same
@@ -65,15 +73,22 @@ module Instana
65
73
  :s => generate_id, # Span ID
66
74
  :t => @id, # Trace ID (same as :s for root span)
67
75
  :p => @current_span[:s], # Parent ID
68
- :n => name, # Span name
69
76
  :ts => ts_now, # Timestamp
70
77
  :ta => :ruby, # Agent
71
- :data => kvs, # Data
72
78
  :f => { :e => Process.pid, :h => :agent_id } # Entity Source
73
79
  })
80
+
74
81
  new_span.parent = @current_span
75
82
  @spans.add(new_span)
76
83
  @current_span = new_span
84
+
85
+ # Check for custom tracing
86
+ if !REGISTERED_SPANS.include?(name.to_sym)
87
+ configure_custom_span(name, kvs)
88
+ else
89
+ @current_span[:n] = name.to_sym
90
+ @current_span[:data] = kvs
91
+ end
77
92
  end
78
93
 
79
94
  # Add KVs to the current span
@@ -81,7 +96,15 @@ module Instana
81
96
  # @param kvs [Hash] list of key values to be reported in the span
82
97
  #
83
98
  def add_info(kvs)
84
- @current_span[:data].merge!(kvs)
99
+ if @current_span.custom?
100
+ if @current_span[:data][:sdk].key?(:custom)
101
+ @current_span[:data][:sdk][:custom].merge!(kvs)
102
+ else
103
+ @current_span[:data][:sdk][:custom] = kvs
104
+ end
105
+ else
106
+ @current_span[:data].merge!(kvs)
107
+ end
85
108
  end
86
109
 
87
110
  # Log an error into the current span
@@ -90,6 +113,24 @@ module Instana
90
113
  #
91
114
  def add_error(e)
92
115
  @current_span[:error] = true
116
+
117
+ if @current_span.key?(:ec)
118
+ @current_span[:ec] = @current_span[:ec] + 1
119
+ else
120
+ @current_span[:ec] = 1
121
+ end
122
+
123
+ #if e.backtrace && e.backtrace.is_a?(Array)
124
+ # @current_span[:stack] = []
125
+ # e.backtrace.each do |x|
126
+ # file, line, method = x.split(':')
127
+ # @current_span[:stack] << {
128
+ # :f => file,
129
+ # :n => line
130
+ # #:m => method
131
+ # }
132
+ # end
133
+ #end
93
134
  end
94
135
 
95
136
  # Close out the current span and set the parent as
@@ -133,7 +174,9 @@ module Instana
133
174
  def has_error?
134
175
  @spans.each do |s|
135
176
  if s.key?(:error)
136
- return s[:error]
177
+ if s[:error] == true
178
+ return true
179
+ end
137
180
  end
138
181
  end
139
182
  false
@@ -150,6 +193,26 @@ module Instana
150
193
 
151
194
  private
152
195
 
196
+ # Configure @current_span to be a custom span per the
197
+ # SDK generic span type.
198
+ #
199
+ def configure_custom_span(name, kvs = {})
200
+ @current_span[:n] = :sdk
201
+ @current_span[:data] = { :sdk => { :name => name.to_sym } }
202
+ @current_span[:data][:sdk][:type] = kvs.key?(:type) ? kvs[:type] : :local
203
+
204
+ if kvs.key?(:arguments)
205
+ @current_span[:data][:sdk][:arguments] = kvs[:arguments]
206
+ end
207
+
208
+ if kvs.key?(:return)
209
+ @current_span[:data][:sdk][:return] = kvs[:return]
210
+ end
211
+ @current_span[:data][:sdk][:custom] = kvs unless kvs.empty?
212
+ #@current_span[:data][:sdk][:custom][:tags] = {}
213
+ #@current_span[:data][:sdk][:custom][:logs] = {}
214
+ end
215
+
153
216
  # Get the current time in milliseconds
154
217
  #
155
218
  # @return [Integer] the current time in milliseconds
@@ -1,3 +1,3 @@
1
1
  module Instana
2
- VERSION = "0.12.0"
2
+ VERSION = "0.12.1"
3
3
  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: 0.12.0
4
+ version: 0.12.1
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: 2016-12-01 00:00:00.000000000 Z
11
+ date: 2016-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -115,7 +115,9 @@ executables: []
115
115
  extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
+ - ".codeclimate.yml"
118
119
  - ".gitignore"
120
+ - ".rubocop.yml"
119
121
  - ".travis.yml"
120
122
  - Configuration.md
121
123
  - Gemfile