instana 1.11.4 → 1.12.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.
@@ -7,14 +7,15 @@ module Instana
7
7
  def setup_environment
8
8
  # Set defaults if not set
9
9
  ENV['MEMCACHED_HOST'] ||= '127.0.0.1:11211'
10
- ENV['TRAVIS_PSQL_HOST'] ||= "127.0.0.1"
11
- ENV['TRAVIS_PSQL_USER'] ||= "postgres"
10
+ ENV['POSTGRES_HOST'] ||= "127.0.0.1"
11
+ ENV['POSTGRES_USER'] ||= "stan"
12
+ ENV['POSTGRES_PASSWORD'] ||= "stanlikesdata"
12
13
  ENV['TRAVIS_MYSQL_HOST'] ||= "127.0.0.1"
13
14
  ENV['TRAVIS_MYSQL_USER'] ||= "root"
14
15
 
15
16
  if !ENV.key?('DATABASE_URL')
16
17
  if ENV['DB_FLAVOR'] == 'postgresql'
17
- ENV['DATABASE_URL'] = "postgresql://#{ENV['TRAVIS_PSQL_USER']}:#{ENV['TRAVIS_PSQL_PASS']}@#{ENV['TRAVIS_PSQL_HOST']}:5432/travis_ci_test"
18
+ ENV['DATABASE_URL'] = "postgresql://#{ENV['POSTGRES_USER']}:#{ENV['POSTGRES_PASSWORD']}@#{ENV['POSTGRES_HOST']}:5432/#{ENV['POSTGRES_USER']}"
18
19
  elsif ENV['DB_FLAVOR'] == 'mysql'
19
20
  ENV['DATABASE_URL'] = "mysql://#{ENV['TRAVIS_MYSQL_USER']}:#{ENV['TRAVIS_MYSQL_PASS']}@#{ENV['TRAVIS_MYSQL_HOST']}:3306/travis_ci_test"
20
21
  else
@@ -26,7 +26,7 @@ module Instana
26
26
  # Will start a new trace or continue an on-going one (such as
27
27
  # from incoming remote requests with context headers).
28
28
  #
29
- # @param name [String] the name of the span to start
29
+ # @param name [String, Symbol] the name of the span to start
30
30
  # @param kvs [Hash] list of key values to be reported in the span
31
31
  # @param incoming_context [Hash] specifies the incoming context. At a
32
32
  # minimum, it should specify :trace_id and :span_id from the following:
@@ -52,7 +52,7 @@ module Instana
52
52
  # @db.select(1)
53
53
  # end
54
54
  #
55
- # @param name [String] the name of the span to start
55
+ # @param name [String, Symbol] the name of the span to start
56
56
  # @param kvs [Hash] list of key values to be reported in this new span
57
57
  #
58
58
  def trace(name, kvs = {}, &block)
@@ -72,7 +72,7 @@ module Instana
72
72
  # Will start a new trace or continue an on-going one (such as
73
73
  # from incoming remote requests with context headers).
74
74
  #
75
- # @param name [String] the name of the span to start
75
+ # @param name [String, Symbol] the name of the span to start
76
76
  # @param kvs [Hash] list of key values to be reported in the span
77
77
  # @param incoming_context [SpanContext or Hash] specifies the incoming context. At a
78
78
  # minimum, it should specify :trace_id and :span_id from the following:
@@ -107,7 +107,7 @@ module Instana
107
107
  # Will establish a new span as a child of the current span
108
108
  # in an existing trace
109
109
  #
110
- # @param name [String] the name of the span to create
110
+ # @param name [String, Symbol] the name of the span to create
111
111
  # @param kvs [Hash] list of key values to be reported in the span
112
112
  #
113
113
  def log_entry(name, kvs = nil, start_time = ::Instana::Util.now_in_ms, child_of = nil)
@@ -145,7 +145,7 @@ module Instana
145
145
  # @note `name` isn't really required but helps keep sanity that
146
146
  # we're closing out the span that we really want to close out.
147
147
  #
148
- # @param name [String] the name of the span to exit (close out)
148
+ # @param name [String, Symbol] the name of the span to exit (close out)
149
149
  # @param kvs [Hash] list of key values to be reported in the span
150
150
  #
151
151
  def log_exit(name, kvs = {})
@@ -263,6 +263,27 @@ module Instana
263
263
  new_span
264
264
  end
265
265
 
266
+ # Start a new span which is the child of the current span
267
+ #
268
+ # @param operation_name [String] The name of the operation represented by the span
269
+ # @param child_of [Span] A span to be used as the ChildOf reference
270
+ # @param start_time [Time] the start time of the span
271
+ # @param tags [Hash] Starting tags for the span
272
+ #
273
+ # @return [Span]
274
+ #
275
+ def start_active_span(operation_name, child_of: self.current_span, start_time: ::Instana::Util.now_in_ms, tags: nil)
276
+ self.current_span = start_span(operation_name, child_of: child_of, start_time: start_time, tags: tags)
277
+ end
278
+
279
+ # Returns the currently active span
280
+ #
281
+ # @return [Span]
282
+ #
283
+ def active_span
284
+ self.current_span
285
+ end
286
+
266
287
  # Inject a span into the given carrier
267
288
  #
268
289
  # @param span_context [SpanContext]
@@ -303,6 +303,15 @@ module Instana
303
303
  # a String, Numeric, or Boolean it will be encoded with to_s
304
304
  #
305
305
  def set_tag(key, value)
306
+ if ![Symbol, String].include?(key.class)
307
+ key = key.to_s
308
+ end
309
+
310
+ # If <value> is not a Symbol, String, Array, Hash or Numeric - convert to string
311
+ if ![Symbol, String, Array, TrueClass, FalseClass, Hash].include?(value.class) && !value.is_a?(Numeric)
312
+ value = value.to_s
313
+ end
314
+
306
315
  if custom?
307
316
  @data[:data][:sdk][:custom] ||= {}
308
317
  @data[:data][:sdk][:custom][:tags] ||= {}
@@ -1,4 +1,4 @@
1
1
  module Instana
2
- VERSION = "1.11.4"
2
+ VERSION = "1.12.0"
3
3
  VERSION_FULL = "instana-#{VERSION}"
4
4
  end
@@ -7,6 +7,10 @@ Cuba.define do
7
7
  on "hello" do
8
8
  res.write "Hello Instana!"
9
9
  end
10
+
11
+ on "greet/:name" do |name|
12
+ res.write "Hello, #{name}"
13
+ end
10
14
 
11
15
  on root do
12
16
  res.redirect '/hello'
@@ -6,5 +6,8 @@ class InstanaRodaApp < Roda
6
6
  r.get "hello" do
7
7
  "Hello Roda + Instana"
8
8
  end
9
+ r.get "greet", String do |name|
10
+ "Hello, #{name}!"
11
+ end
9
12
  end
10
13
  end
@@ -2,4 +2,8 @@ class InstanaSinatraApp < ::Sinatra::Base
2
2
  get '/' do
3
3
  "Hello Sinatra!"
4
4
  end
5
+
6
+ get '/greet/:name' do
7
+ "Hello, #{params[:name]}!"
8
+ end
5
9
  end
@@ -1,4 +1,3 @@
1
-
2
1
  if defined?(::Cuba)
3
2
  require 'test_helper'
4
3
  require File.expand_path(File.dirname(__FILE__) + '/../apps/cuba')
@@ -40,5 +39,19 @@ if defined?(::Cuba)
40
39
  assert first_span[:data][:http].key?(:host)
41
40
  assert_equal "example.org", first_span[:data][:http][:host]
42
41
  end
42
+
43
+ def test_path_template
44
+ clear_all!
45
+
46
+ r = get '/greet/instana'
47
+ assert last_response.ok?
48
+
49
+ spans = ::Instana.processor.queued_spans
50
+ assert_equal 1, spans.count
51
+
52
+ first_span = spans.first
53
+ assert_equal :rack, first_span[:n]
54
+ assert_equal '/greet/{name}', first_span[:data][:http][:path_tpl]
55
+ end
43
56
  end
44
57
  end
@@ -5,16 +5,22 @@ require "instana/rack"
5
5
 
6
6
  class RackTest < Minitest::Test
7
7
  include Rack::Test::Methods
8
+
9
+ class PathTemplateApp
10
+ def call(env)
11
+ env['INSTANA_HTTP_PATH_TEMPLATE'] = 'sample_template'
12
+ [200, {}, ['Ok']]
13
+ end
14
+ end
8
15
 
9
16
  def app
10
- @app = Rack::Builder.new {
17
+ @app = Rack::Builder.new do
11
18
  use Rack::CommonLogger
12
19
  use Rack::ShowExceptions
13
20
  use Instana::Rack
14
- map "/mrlobster" do
15
- run Rack::Lobster.new
16
- end
17
- }
21
+ map("/mrlobster") { run Rack::Lobster.new }
22
+ map("/path_tpl") { run PathTemplateApp.new }
23
+ end
18
24
  end
19
25
 
20
26
  def test_basic_get
@@ -29,23 +35,33 @@ class RackTest < Minitest::Test
29
35
  # Span validation
30
36
  assert_equal 1, spans.count
31
37
 
32
- first_span = spans.first
33
- assert_equal :rack, first_span[:n]
34
- assert first_span.key?(:data)
35
- assert first_span[:data].key?(:http)
36
- assert_equal "GET", first_span[:data][:http][:method]
37
- assert_equal "/mrlobster", first_span[:data][:http][:url]
38
- assert_equal 200, first_span[:data][:http][:status]
39
- assert_equal 'example.org', first_span[:data][:http][:host]
40
- assert first_span.key?(:f)
41
- assert first_span[:f].key?(:e)
42
- assert first_span[:f].key?(:h)
43
- assert_equal ::Instana.agent.agent_uuid, first_span[:f][:h]
38
+ rack_span = spans.first
39
+ assert_equal :rack, rack_span[:n]
40
+
41
+ assert last_response.headers.key?("X-Instana-T")
42
+ assert last_response.headers["X-Instana-T"] == ::Instana::Util.id_to_header(rack_span[:t])
43
+ assert last_response.headers.key?("X-Instana-S")
44
+ assert last_response.headers["X-Instana-S"] == ::Instana::Util.id_to_header(rack_span[:s])
45
+ assert last_response.headers.key?("X-Instana-L")
46
+ assert last_response.headers["X-Instana-L"] == '1'
47
+ assert last_response.headers.key?("Server-Timing")
48
+ assert last_response.headers["Server-Timing"] == "intid;desc=#{::Instana::Util.id_to_header(rack_span[:t])}"
49
+
50
+ assert rack_span.key?(:data)
51
+ assert rack_span[:data].key?(:http)
52
+ assert_equal "GET", rack_span[:data][:http][:method]
53
+ assert_equal "/mrlobster", rack_span[:data][:http][:url]
54
+ assert_equal 200, rack_span[:data][:http][:status]
55
+ assert_equal 'example.org', rack_span[:data][:http][:host]
56
+ assert rack_span.key?(:f)
57
+ assert rack_span[:f].key?(:e)
58
+ assert rack_span[:f].key?(:h)
59
+ assert_equal ::Instana.agent.agent_uuid, rack_span[:f][:h]
44
60
 
45
61
  # Backtrace fingerprint validation
46
- assert first_span.key?(:stack)
47
- assert_equal 2, first_span[:stack].count
48
- refute_nil first_span[:stack].first[:c].match(/instana\/instrumentation\/rack.rb/)
62
+ assert rack_span.key?(:stack)
63
+ assert_equal 2, rack_span[:stack].count
64
+ refute_nil rack_span[:stack].first[:c].match(/instana\/instrumentation\/rack.rb/)
49
65
 
50
66
  # Restore to default
51
67
  ::Instana.config[:collect_backtraces] = false
@@ -63,8 +79,8 @@ class RackTest < Minitest::Test
63
79
  # Span validation
64
80
  assert_equal 1, spans.count
65
81
 
66
- first_span = spans.first
67
- assert_equal 'WalterBishop', first_span[:data][:service]
82
+ rack_span = spans.first
83
+ assert_equal 'WalterBishop', rack_span[:data][:service]
68
84
 
69
85
  ENV.delete('INSTANA_SERVICE_NAME')
70
86
  end
@@ -78,17 +94,27 @@ class RackTest < Minitest::Test
78
94
 
79
95
  # Span validation
80
96
  assert_equal 1, spans.count
81
- first_span = spans.first
82
- assert_equal :rack, first_span[:n]
83
- assert first_span.key?(:data)
84
- assert first_span[:data].key?(:http)
85
- assert_equal "POST", first_span[:data][:http][:method]
86
- assert_equal "/mrlobster", first_span[:data][:http][:url]
87
- assert_equal 200, first_span[:data][:http][:status]
88
- assert first_span.key?(:f)
89
- assert first_span[:f].key?(:e)
90
- assert first_span[:f].key?(:h)
91
- assert_equal ::Instana.agent.agent_uuid, first_span[:f][:h]
97
+ rack_span = spans.first
98
+ assert_equal :rack, rack_span[:n]
99
+
100
+ assert last_response.headers.key?("X-Instana-T")
101
+ assert last_response.headers["X-Instana-T"] == ::Instana::Util.id_to_header(rack_span[:t])
102
+ assert last_response.headers.key?("X-Instana-S")
103
+ assert last_response.headers["X-Instana-S"] == ::Instana::Util.id_to_header(rack_span[:s])
104
+ assert last_response.headers.key?("X-Instana-L")
105
+ assert last_response.headers["X-Instana-L"] == '1'
106
+ assert last_response.headers.key?("Server-Timing")
107
+ assert last_response.headers["Server-Timing"] == "intid;desc=#{::Instana::Util.id_to_header(rack_span[:t])}"
108
+
109
+ assert rack_span.key?(:data)
110
+ assert rack_span[:data].key?(:http)
111
+ assert_equal "POST", rack_span[:data][:http][:method]
112
+ assert_equal "/mrlobster", rack_span[:data][:http][:url]
113
+ assert_equal 200, rack_span[:data][:http][:status]
114
+ assert rack_span.key?(:f)
115
+ assert rack_span[:f].key?(:e)
116
+ assert rack_span[:f].key?(:h)
117
+ assert_equal ::Instana.agent.agent_uuid, rack_span[:f][:h]
92
118
  end
93
119
 
94
120
  def test_basic_put
@@ -100,17 +126,27 @@ class RackTest < Minitest::Test
100
126
 
101
127
  # Span validation
102
128
  assert_equal 1, spans.count
103
- first_span = spans.first
104
- assert_equal :rack, first_span[:n]
105
- assert first_span.key?(:data)
106
- assert first_span[:data].key?(:http)
107
- assert_equal "PUT", first_span[:data][:http][:method]
108
- assert_equal "/mrlobster", first_span[:data][:http][:url]
109
- assert_equal 200, first_span[:data][:http][:status]
110
- assert first_span.key?(:f)
111
- assert first_span[:f].key?(:e)
112
- assert first_span[:f].key?(:h)
113
- assert_equal ::Instana.agent.agent_uuid, first_span[:f][:h]
129
+ rack_span = spans.first
130
+ assert_equal :rack, rack_span[:n]
131
+
132
+ assert last_response.headers.key?("X-Instana-T")
133
+ assert last_response.headers["X-Instana-T"] == ::Instana::Util.id_to_header(rack_span[:t])
134
+ assert last_response.headers.key?("X-Instana-S")
135
+ assert last_response.headers["X-Instana-S"] == ::Instana::Util.id_to_header(rack_span[:s])
136
+ assert last_response.headers.key?("X-Instana-L")
137
+ assert last_response.headers["X-Instana-L"] == '1'
138
+ assert last_response.headers.key?("Server-Timing")
139
+ assert last_response.headers["Server-Timing"] == "intid;desc=#{::Instana::Util.id_to_header(rack_span[:t])}"
140
+
141
+ assert rack_span.key?(:data)
142
+ assert rack_span[:data].key?(:http)
143
+ assert_equal "PUT", rack_span[:data][:http][:method]
144
+ assert_equal "/mrlobster", rack_span[:data][:http][:url]
145
+ assert_equal 200, rack_span[:data][:http][:status]
146
+ assert rack_span.key?(:f)
147
+ assert rack_span[:f].key?(:e)
148
+ assert rack_span[:f].key?(:h)
149
+ assert_equal ::Instana.agent.agent_uuid, rack_span[:f][:h]
114
150
  end
115
151
 
116
152
  def test_context_continuation
@@ -125,23 +161,33 @@ class RackTest < Minitest::Test
125
161
 
126
162
  # Span validation
127
163
  assert_equal 1, spans.count
128
- first_span = spans.first
129
- assert_equal :rack, first_span[:n]
130
- assert first_span.key?(:data)
131
- assert first_span[:data].key?(:http)
132
- assert_equal "GET", first_span[:data][:http][:method]
133
- assert_equal "/mrlobster", first_span[:data][:http][:url]
134
- assert_equal 200, first_span[:data][:http][:status]
135
- assert first_span.key?(:f)
136
- assert first_span[:f].key?(:e)
137
- assert first_span[:f].key?(:h)
138
- assert_equal ::Instana.agent.agent_uuid, first_span[:f][:h]
164
+ rack_span = spans.first
165
+ assert_equal :rack, rack_span[:n]
166
+
167
+ assert last_response.headers.key?("X-Instana-T")
168
+ assert last_response.headers["X-Instana-T"] == ::Instana::Util.id_to_header(rack_span[:t])
169
+ assert last_response.headers.key?("X-Instana-S")
170
+ assert last_response.headers["X-Instana-S"] == ::Instana::Util.id_to_header(rack_span[:s])
171
+ assert last_response.headers.key?("X-Instana-L")
172
+ assert last_response.headers["X-Instana-L"] == '1'
173
+ assert last_response.headers.key?("Server-Timing")
174
+ assert last_response.headers["Server-Timing"] == "intid;desc=#{::Instana::Util.id_to_header(rack_span[:t])}"
175
+
176
+ assert rack_span.key?(:data)
177
+ assert rack_span[:data].key?(:http)
178
+ assert_equal "GET", rack_span[:data][:http][:method]
179
+ assert_equal "/mrlobster", rack_span[:data][:http][:url]
180
+ assert_equal 200, rack_span[:data][:http][:status]
181
+ assert rack_span.key?(:f)
182
+ assert rack_span[:f].key?(:e)
183
+ assert rack_span[:f].key?(:h)
184
+ assert_equal ::Instana.agent.agent_uuid, rack_span[:f][:h]
139
185
 
140
186
  # Context validation
141
187
  # The first span should have the passed in trace ID
142
188
  # and specify the passed in span ID as it's parent.
143
- assert_equal 1234, first_span[:t]
144
- assert_equal 4321, first_span[:p]
189
+ assert_equal 1234, rack_span[:t]
190
+ assert_equal 4321, rack_span[:p]
145
191
  end
146
192
 
147
193
  def test_instana_response_headers
@@ -181,20 +227,34 @@ class RackTest < Minitest::Test
181
227
 
182
228
  # Span validation
183
229
  assert_equal 1, spans.count
184
- first_span = spans.first
230
+ rack_span = spans.first
185
231
 
186
- assert first_span[:data][:http].key?(:header)
187
- assert first_span[:data][:http][:header].key?(:"X-Capture-This")
188
- assert !first_span[:data][:http][:header].key?(:"X-Capture-That")
189
- assert_equal "ThereYouGo", first_span[:data][:http][:header][:"X-Capture-This"]
232
+ assert rack_span[:data][:http].key?(:header)
233
+ assert rack_span[:data][:http][:header].key?(:"X-Capture-This")
234
+ assert !rack_span[:data][:http][:header].key?(:"X-Capture-That")
235
+ assert_equal "ThereYouGo", rack_span[:data][:http][:header][:"X-Capture-This"]
190
236
 
191
237
  # Backtrace fingerprint validation
192
- assert first_span.key?(:stack)
193
- assert_equal 2, first_span[:stack].count
194
- refute_nil first_span[:stack].first[:c].match(/instana\/instrumentation\/rack.rb/)
238
+ assert rack_span.key?(:stack)
239
+ assert_equal 2, rack_span[:stack].count
240
+ refute_nil rack_span[:stack].first[:c].match(/instana\/instrumentation\/rack.rb/)
195
241
 
196
242
  # Restore to default
197
243
  ::Instana.config[:collect_backtraces] = false
198
244
  ::Instana.agent.extra_headers = nil
199
245
  end
246
+
247
+ def test_capture_http_path_template
248
+ clear_all!
249
+
250
+ get '/path_tpl'
251
+ assert last_response.ok?
252
+
253
+ spans = ::Instana.processor.queued_spans
254
+ assert_equal 1, spans.length
255
+
256
+ rack_span = spans.first
257
+ assert_equal :rack, rack_span[:n]
258
+ assert_equal 'sample_template', rack_span[:data][:http][:path_tpl]
259
+ end
200
260
  end
@@ -153,4 +153,16 @@ class ActionControllerTest < Minitest::Test
153
153
  assert ac_span.key?(:stack)
154
154
  assert 1, ac_span[:ec]
155
155
  end
156
+
157
+ def test_path_template
158
+ clear_all!
159
+
160
+ Net::HTTP.get(URI.parse('http://localhost:3205/test/world'))
161
+
162
+ spans = ::Instana.processor.queued_spans
163
+ rack_span = find_first_span_by_name(spans, :rack)
164
+
165
+ assert_equal false, rack_span.key?(:error)
166
+ assert_equal '/test/world(.:format)', rack_span[:data][:http][:path_tpl]
167
+ end
156
168
  end
@@ -40,5 +40,19 @@ if defined?(::Roda)
40
40
  assert first_span[:data][:http].key?(:host)
41
41
  assert_equal "example.org", first_span[:data][:http][:host]
42
42
  end
43
+
44
+ def test_path_template
45
+ clear_all!
46
+
47
+ r = get '/greet/instana'
48
+ assert last_response.ok?
49
+
50
+ spans = ::Instana.processor.queued_spans
51
+ assert_equal 1, spans.count
52
+
53
+ first_span = spans.first
54
+ assert_equal :rack, first_span[:n]
55
+ assert_equal '/greet/{name}', first_span[:data][:http][:path_tpl]
56
+ end
43
57
  end
44
58
  end