instana 1.204.0 → 1.208.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 16c9cdd17a56509785d25d08fad5de5785f558408cba098c42eab712a4fffd5b
4
- data.tar.gz: d1a482064a6df6988fccb5ae72c39bf575ec5e2e50c5c2c2b652c18aa26b2f6c
3
+ metadata.gz: 2cec589ba39a110c9378497376585d47d2f968bd27c31cd1ccae259912a0d2b0
4
+ data.tar.gz: f9df2c3f6e1543e6e4bb3efaa44026e295f7ca03ef59add49c291a3218b04e4d
5
5
  SHA512:
6
- metadata.gz: a797522fc38b6eed1b5b7f6a38ca7f25659fade4a16528e69ab2ebc96128e15e67c1bedcf5dec6dfff5b5e33a20862f933ad65cdf95ea5481d2dd92f0958944d
7
- data.tar.gz: 68531c76fe1ef1a79cf58f69f9f0a4cca17c69fc00926d9efd584d161f5b19d5647958666fe79885f20f218c04cdf9aa663212b792c8c77f61369b9c37e683ba
6
+ metadata.gz: b9907bdca2a8c40e46667e4b557765d83ce2c8846bb3b2e508fd59374890e54f8dc172bbff496d9f90f031a787db240d2cad3b84e4722efb4c33d9f1013f1c37
7
+ data.tar.gz: 889963622d3fc6d24b6e4a3ca402d401b66c4608e9ff4a48e61998d99d4e59fb7a933f97963013a97d8bb1012c6405ab7a8ee32bfc80fcdad0301b3cb5c2cc5a
data/.circleci/config.yml CHANGED
@@ -15,6 +15,7 @@ executors:
15
15
  command: ["server", "/data"]
16
16
  - image: s12v/sns
17
17
  - image: softwaremill/elasticmq-native
18
+ - image: circleci/mongo:5-focal-ram
18
19
  ruby_26:
19
20
  docker:
20
21
  - image: circleci/ruby:2.6-node
@@ -29,6 +30,7 @@ executors:
29
30
  command: ["server", "/data"]
30
31
  - image: s12v/sns
31
32
  - image: softwaremill/elasticmq-native
33
+ - image: circleci/mongo:5-focal-ram
32
34
  ruby_27:
33
35
  docker:
34
36
  - image: circleci/ruby:2.7-node
@@ -43,6 +45,7 @@ executors:
43
45
  command: ["server", "/data"]
44
46
  - image: s12v/sns
45
47
  - image: softwaremill/elasticmq-native
48
+ - image: circleci/mongo:5-focal-ram
46
49
  ruby_25_mysql2:
47
50
  docker:
48
51
  - image: circleci/ruby:2.5-node
@@ -113,6 +116,11 @@ executors:
113
116
  commands:
114
117
  setup:
115
118
  steps:
119
+ - run:
120
+ name: Install iproute2
121
+ command: |
122
+ sudo apt-get update
123
+ sudo apt-get install iproute2
116
124
  - run:
117
125
  name: Install Java
118
126
  command: |
@@ -137,17 +145,25 @@ commands:
137
145
  - run:
138
146
  name: Install Java
139
147
  command: |
148
+ sudo apt-get update
140
149
  sudo apt-get install openjdk-11-jdk
141
150
  - run:
142
151
  name: Run SonarQube to capture coverage
143
152
  command: |
144
- wget -O /tmp/sonar-scanner-cli.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.5.0.2216.zip
153
+ wget -O /tmp/sonar-scanner-cli.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.6.2.2472.zip
145
154
  unzip -d /tmp /tmp/sonar-scanner-cli.zip
146
- /tmp/sonar-scanner-4.5.0.2216/bin/sonar-scanner \
147
- -Dsonar.projectKey=ruby-sensor \
148
- -Dsonar.sources=. \
149
- -Dsonar.host.url="${SONARQUBE_URL}" \
150
- -Dsonar.login="${SONARQUBE_LOGIN}"
155
+ if [[ -n "${CIRCLE_PR_NUMBER}" ]]; then
156
+ /tmp/sonar-scanner-4.6.2.2472/bin/sonar-scanner \
157
+ -Dsonar.host.url="${SONARQUBE_URL}" \
158
+ -Dsonar.login="${SONARQUBE_LOGIN}" \
159
+ -Dsonar.pullrequest.key="${CIRCLE_PR_NUMBER}" \
160
+ -Dsonar.pullrequest.branch="${CIRCLE_BRANCH}"
161
+ else
162
+ /tmp/sonar-scanner-4.6.2.2472/bin/sonar-scanner \
163
+ -Dsonar.host.url="${SONARQUBE_URL}" \
164
+ -Dsonar.login="${SONARQUBE_LOGIN}" \
165
+ -Dsonar.branch.name="${CIRCLE_BRANCH}"
166
+ fi
151
167
  run_tests:
152
168
  steps:
153
169
  - run:
@@ -156,7 +172,7 @@ commands:
156
172
  mkdir _junit
157
173
  bundle exec rake
158
174
  - store_test_results:
159
- path: ~/_junit
175
+ path: ~/project/_junit
160
176
  run_rubocop:
161
177
  steps:
162
178
  - run:
@@ -171,11 +187,11 @@ commands:
171
187
  mkdir -p ~/.gem
172
188
  echo -e "---\r\n:rubygems_api_key: $RUBYGEMS_API_KEY" > ~/.gem/credentials
173
189
  chmod 0600 /home/circleci/.gem/credentials
174
- - run:
190
+ - run:
175
191
  name: Publish Gem
176
192
  command: |
177
193
  bundle exec rake release[origin]
178
-
194
+
179
195
  jobs:
180
196
  test_core:
181
197
  parameters:
@@ -267,6 +283,7 @@ workflows:
267
283
  - "./gemfiles/sidekiq_50.gemfile"
268
284
  - "./gemfiles/sinatra_14.gemfile"
269
285
  - "./gemfiles/shoryuken_50.gemfile"
286
+ - "./gemfiles/mongo_216.gemfile"
270
287
  rails:
271
288
  jobs:
272
289
  - test_apprisal:
data/Appraisals CHANGED
@@ -13,7 +13,7 @@ appraise 'cuba-30' do
13
13
  gem 'cuba', '>= 3.0', '< 4.0'
14
14
  end
15
15
 
16
- appraise 'dalli-20' do
16
+ appraise 'dalli-20' do
17
17
  gem 'dalli', '>= 2.0', '< 3.0'
18
18
  end
19
19
 
@@ -69,7 +69,7 @@ appraise 'rails-60' do
69
69
  gem 'sqlite3', '~> 1.4'
70
70
  end
71
71
 
72
- appraise 'redis-40' do
72
+ appraise 'redis-40' do
73
73
  gem 'redis', '>= 4.0.0', '< 5.0'
74
74
  end
75
75
 
@@ -87,7 +87,7 @@ appraise 'resque-122' do
87
87
  end
88
88
 
89
89
  appraise 'resque-20' do
90
- gem 'resque', '>= 2.0', '< 3.0'
90
+ gem 'resque', '>= 2.0', '< 3.0'
91
91
  end
92
92
 
93
93
  appraise 'roda-20' do
@@ -118,3 +118,7 @@ end
118
118
  appraise 'sidekiq-50' do
119
119
  gem 'sidekiq', '>= 5.0', '< 6.0'
120
120
  end
121
+
122
+ appraise 'mongo-216' do
123
+ gem 'mongo', '>= 2.16', '< 3'
124
+ end
data/README.md CHANGED
@@ -6,11 +6,8 @@
6
6
 
7
7
  The Instana gem provides Ruby metrics and traces (request, queue & cross-host) for [Instana](https://www.instana.com/).
8
8
 
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)
9
+ [![CircleCI](https://circleci.com/gh/instana/ruby-sensor.svg?style=svg)](https://circleci.com/gh/instana/ruby-sensor)
12
10
  [![Gem Version](https://badge.fury.io/rb/instana.svg)](https://badge.fury.io/rb/instana)
13
- [![OpenTracing Badge](https://img.shields.io/badge/OpenTracing-enabled-blue.svg)](http://opentracing.io)
14
11
 
15
12
  ## Note
16
13
 
@@ -78,4 +75,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/instan
78
75
  ## More
79
76
 
80
77
  Want to instrument other languages? See our [Node.js](https://github.com/instana/nodejs), [Go](https://github.com/instana/golang-sensor), [Python](https://github.com/instana/python-sensor) repositories or [many other supported technologies](https://www.instana.com/supported-technologies/).
81
-
@@ -0,0 +1,18 @@
1
+ # This file was generated by Appraisal
2
+
3
+ # (c) Copyright IBM Corp. 2021
4
+ # (c) Copyright Instana Inc. 2021
5
+
6
+ source "https://rubygems.org"
7
+
8
+ gem "rake"
9
+ gem "minitest", "5.9.1"
10
+ gem "minitest-reporters"
11
+ gem "webmock"
12
+ gem "puma"
13
+ gem "rubocop", "~> 1.9"
14
+ gem "rack-test"
15
+ gem "simplecov", "~> 0.21.2"
16
+ gem "mongo", ">= 2.16", "< 3"
17
+
18
+ gemspec path: "../"
@@ -0,0 +1,23 @@
1
+ # (c) Copyright IBM Corp. 2021
2
+ # (c) Copyright Instana Inc. 2021
3
+
4
+ module Instana
5
+ module Activators
6
+ class Mongo < Activator
7
+ def can_instrument?
8
+ defined?(::Mongo::Client) && defined?(::Mongo::Monitoring::Global)
9
+ end
10
+
11
+ def instrument
12
+ require 'instana/instrumentation/mongo'
13
+
14
+ ::Mongo::Monitoring::Global.subscribe(
15
+ ::Mongo::Monitoring::COMMAND,
16
+ ::Instana::Mongo.new
17
+ )
18
+
19
+ true
20
+ end
21
+ end
22
+ end
23
+ end
@@ -9,6 +9,7 @@ module Instana
9
9
  ENTITY_DATA_URL = '/com.instana.plugin.ruby.%i'.freeze
10
10
  RESPONSE_DATA_URL = '/com.instana.plugin.ruby/response.%i?messageId=%s'.freeze
11
11
  TRACES_DATA_URL = "/com.instana.plugin.ruby/traces.%i".freeze
12
+ TRACE_METRICS_URL = "/tracermetrics".freeze
12
13
 
13
14
  attr_reader :report_timer
14
15
 
@@ -35,10 +36,24 @@ module Instana
35
36
  def report_to_backend
36
37
  report_metrics if ::Instana.config[:metrics][:enabled]
37
38
  report_traces if ::Instana.config[:tracing][:enabled]
39
+ report_trace_stats if ::Instana.config[:tracing][:enabled]
38
40
  rescue StandardError => e
39
41
  @logger.error(%(#{e}\n#{e.backtrace.join("\n")}))
40
42
  end
41
43
 
44
+ def report_trace_stats
45
+ discovery = @discovery.value
46
+ return unless discovery
47
+
48
+ payload = {
49
+ tracer: 'ruby',
50
+ pid: discovery['pid'],
51
+ metrics: @processor.span_metrics
52
+ }
53
+
54
+ @client.send_request('POST', TRACE_METRICS_URL, payload)
55
+ end
56
+
42
57
  def report_traces
43
58
  discovery = @discovery.value
44
59
  return unless discovery
@@ -87,17 +102,27 @@ module Instana
87
102
  end
88
103
 
89
104
  def metrics_payload(discovery)
90
- proc_table = Sys::ProcTable.ps(pid: Process.pid)
91
- process = ProcessInfo.new(proc_table)
92
-
93
- {
105
+ payload = {
94
106
  pid: discovery['pid'],
95
- name: Util.get_app_name,
96
- exec_args: process.arguments,
97
- gc: GCSnapshot.instance.report,
98
- thread: {count: ::Thread.list.count},
99
- memory: {rss_size: proc_table.rss / 1024} # Bytes to Kilobytes
107
+ name: Util.get_app_name
100
108
  }
109
+
110
+ if ::Instana.config[:metrics][:memory][:enabled]
111
+ proc_table = Sys::ProcTable.ps(pid: Process.pid)
112
+ process = ProcessInfo.new(proc_table)
113
+ payload[:exec_args] = process.arguments
114
+ payload[:memory] = {rss_size: process.memory_used}
115
+ end
116
+
117
+ if ::Instana.config[:metrics][:gc][:enabled]
118
+ payload[:gc] = GCSnapshot.instance.report
119
+ end
120
+
121
+ if ::Instana.config[:metrics][:thread][:enabled]
122
+ payload[:thread] = {count: ::Thread.list.count}
123
+ end
124
+
125
+ payload
101
126
  end
102
127
  end
103
128
  end
@@ -47,6 +47,14 @@ module Instana
47
47
  File.read(path).match(/\d+/).to_s.to_i
48
48
  end
49
49
 
50
+ def memory_used
51
+ if RbConfig::CONFIG['host_os'].include?('darwin')
52
+ rss / 1024
53
+ else
54
+ rss * 4096
55
+ end
56
+ end
57
+
50
58
  private
51
59
 
52
60
  def clean_arguments(arguments)
@@ -19,7 +19,7 @@ module Instana
19
19
  }
20
20
  }
21
21
 
22
- if binds.all? { |b| b.respond_to?(:value_before_type_cast) }
22
+ if binds.all? { |b| b.respond_to?(:value_before_type_cast) } && !::Instana.config[:sanitize_sql]
23
23
  mapped = binds.map(&:value_before_type_cast)
24
24
  call_payload[:activerecord][:binds] = mapped
25
25
  end
@@ -130,6 +130,7 @@ module Instana
130
130
  return {} unless @env.has_key?('HTTP_TRACEPARENT')
131
131
  matches = @env['HTTP_TRACEPARENT'].match(W3_TRACE_PARENT_FORMAT)
132
132
  return {} unless matches
133
+ return {} if matches_is_invalid(matches)
133
134
 
134
135
  trace_id = ::Instana::Util.header_to_id(matches['trace'][16..-1]) # rubocop:disable Style/SlicingWithRange, Lint/RedundantCopDisableDirective
135
136
  span_id = ::Instana::Util.header_to_id(matches['parent'])
@@ -143,6 +144,10 @@ module Instana
143
144
  }
144
145
  end
145
146
 
147
+ def matches_is_invalid(matches)
148
+ matches['trace'].match(/\A0+\z/) || matches['parent'].match(/\A0+\z/)
149
+ end
150
+
146
151
  def context_from_trace_state
147
152
  state = parse_trace_state
148
153
 
@@ -0,0 +1,46 @@
1
+ # (c) Copyright IBM Corp. 2021
2
+ # (c) Copyright Instana Inc. 2021
3
+
4
+ module Instana
5
+ class Mongo
6
+ REMOVED_COMMAND_ELEMENTS = %w[lsid $db documents].freeze
7
+
8
+ def initialize
9
+ @requests = {}
10
+ end
11
+
12
+ def started(event)
13
+ tags = {
14
+ namespace: event.database_name,
15
+ command: event.command_name,
16
+ peer: {
17
+ hostname: event.address.host,
18
+ port: event.address.port
19
+ },
20
+ json: filter_statement(event.command)
21
+ }
22
+
23
+ @requests[event.request_id] = ::Instana.tracer.log_async_entry(:mongo, {mongo: tags})
24
+ end
25
+
26
+ def failed(event)
27
+ span = @requests.delete(event.request_id)
28
+ span.add_error(Exception.new(event.message))
29
+
30
+ ::Instana.tracer.log_async_exit(:mongo, {}, span)
31
+ end
32
+
33
+ def succeeded(event)
34
+ span = @requests.delete(event.request_id)
35
+ ::Instana.tracer.log_async_exit(:mongo, {}, span)
36
+ end
37
+
38
+ private
39
+
40
+ def filter_statement(command)
41
+ command.delete_if { |k, _| REMOVED_COMMAND_ELEMENTS.include?(k) }
42
+
43
+ JSON.dump(command)
44
+ end
45
+ end
46
+ end
@@ -20,6 +20,9 @@ module Instana
20
20
  @batch_size = 3000
21
21
  @logger = logger
22
22
  @pid = Process.pid
23
+
24
+ @spans_opened = Concurrent::AtomicFixnum.new(0)
25
+ @spans_closed = Concurrent::AtomicFixnum.new(0)
23
26
  end
24
27
 
25
28
  # Adds a span to the span queue
@@ -34,9 +37,31 @@ module Instana
34
37
  end
35
38
  # :nocov:
36
39
 
40
+ @spans_closed.increment
37
41
  @queue.push(span)
38
42
  end
39
43
 
44
+ # Note that we've started a new span. Used to
45
+ # generate monitoring metrics.
46
+ def start_span(_)
47
+ @spans_opened.increment
48
+ end
49
+
50
+ # Clears and retrieves metrics associated with span creation and submission
51
+ def span_metrics
52
+ response = {
53
+ opened: @spans_opened.value,
54
+ closed: @spans_closed.value,
55
+ filtered: 0,
56
+ dropped: 0
57
+ }
58
+
59
+ @spans_opened.value = 0
60
+ @spans_closed.value = 0
61
+
62
+ response
63
+ end
64
+
40
65
  ##
41
66
  # send
42
67
  #
@@ -82,6 +107,9 @@ module Instana
82
107
  # test suite to reset state.
83
108
  #
84
109
  def clear!
110
+ @spans_opened.value = 0
111
+ @spans_closed.value = 0
112
+
85
113
  until @queue.empty? do
86
114
  # Non-blocking pop; ignore exception
87
115
  @queue.pop(true) rescue nil
@@ -7,12 +7,12 @@ module Instana
7
7
  :memcache, :'net-http', :rack, :render, :'rpc-client',
8
8
  :'rpc-server', :'sidekiq-client', :'sidekiq-worker',
9
9
  :redis, :'resque-client', :'resque-worker', :'graphql.server', :dynamodb, :s3, :sns, :sqs, :'aws.lambda.entry', :activejob, :log, :"mail.actionmailer",
10
- :"aws.lambda.invoke" ].freeze
10
+ :"aws.lambda.invoke", :mongo ].freeze
11
11
  ENTRY_SPANS = [ :rack, :'resque-worker', :'rpc-server', :'sidekiq-worker', :'graphql.server', :sqs,
12
12
  :'aws.lambda.entry' ].freeze
13
13
  EXIT_SPANS = [ :activerecord, :excon, :'net-http', :'resque-client',
14
14
  :'rpc-client', :'sidekiq-client', :redis, :dynamodb, :s3, :sns, :sqs, :log, :"mail.actionmailer",
15
- :"aws.lambda.invoke" ].freeze
15
+ :"aws.lambda.invoke", :mongo ].freeze
16
16
  HTTP_SPANS = [ :rack, :excon, :'net-http' ].freeze
17
17
 
18
18
  attr_accessor :parent
@@ -71,6 +71,8 @@ module Instana
71
71
  configure_custom(name)
72
72
  end
73
73
 
74
+ ::Instana.processor.start_span(self)
75
+
74
76
  # Attach a backtrace to all exit spans
75
77
  add_stack if ::Instana.config[:collect_backtraces] && exit_span?
76
78
  end
@@ -118,7 +120,7 @@ module Instana
118
120
  elsif @data[:n] == :activerecord
119
121
  @data[:data][:activerecord][:error] = e.message
120
122
  else
121
- log(:error, Time.now, { :message => e.message, :parameters => e.class.to_s })
123
+ log(:error, Time.now, message: e.message, parameters: e.class.to_s)
122
124
  end
123
125
  e.instance_variable_set(:@instana_logged, true)
124
126
  end
@@ -47,7 +47,7 @@ module Instana
47
47
  state.unshift("in=#{trace_id_header};#{span_id_header}")
48
48
  end
49
49
 
50
- state.reject { |v| v.nil? }.join(',')
50
+ state.take(32).reject { |v| v.nil? }.join(',')
51
51
  end
52
52
 
53
53
  def to_hash
@@ -2,6 +2,6 @@
2
2
  # (c) Copyright Instana Inc. 2016
3
3
 
4
4
  module Instana
5
- VERSION = "1.204.0"
5
+ VERSION = "1.208.0"
6
6
  VERSION_FULL = "instana-#{VERSION}"
7
7
  end
@@ -0,0 +1,9 @@
1
+ sonar.projectKey=ruby-sensor
2
+ sonar.sources=lib
3
+ sonar.tests=test
4
+ sonar.exclusions=_junit/*
5
+ sonar.ruby.coverage.reportPaths=coverage/coverage.json
6
+ sonar.links.homepage=https://github.com/instana/ruby-sensor/
7
+ sonar.links.ci=https://circleci.com/gh/instana/ruby-sensor
8
+ sonar.links.issue=https://github.com/instana/ruby-sensor/issues
9
+ sonar.links.scm=https://github.com/instana/ruby-sensor/
@@ -23,6 +23,8 @@ class HostAgentReportingObserverTest < Minitest::Test
23
23
  end
24
24
 
25
25
  def test_report
26
+ stub_request(:post, "http://10.10.10.10:9292/tracermetrics")
27
+ .to_return(status: 200)
26
28
  stub_request(:post, "http://10.10.10.10:9292/com.instana.plugin.ruby.0")
27
29
  .to_return(status: 200)
28
30
 
@@ -35,6 +37,8 @@ class HostAgentReportingObserverTest < Minitest::Test
35
37
  end
36
38
 
37
39
  def test_report_fail
40
+ stub_request(:post, "http://10.10.10.10:9292/tracermetrics")
41
+ .to_return(status: 200)
38
42
  stub_request(:post, "http://10.10.10.10:9292/com.instana.plugin.ruby.0")
39
43
  .to_return(status: 500)
40
44
 
@@ -54,6 +58,9 @@ class HostAgentReportingObserverTest < Minitest::Test
54
58
  args: {file: 'test_helper.rb'}
55
59
  )
56
60
 
61
+ stub_request(:post, "http://10.10.10.10:9292/tracermetrics")
62
+ .to_return(status: 200)
63
+
57
64
  stub_request(:post, "http://10.10.10.10:9292/com.instana.plugin.ruby.0")
58
65
  .to_return(status: 200, body: action)
59
66
 
@@ -75,6 +82,9 @@ class HostAgentReportingObserverTest < Minitest::Test
75
82
  args: {file: 'test_helper.rb'}
76
83
  ])
77
84
 
85
+ stub_request(:post, "http://10.10.10.10:9292/tracermetrics")
86
+ .to_return(status: 200)
87
+
78
88
  stub_request(:post, "http://10.10.10.10:9292/com.instana.plugin.ruby.0")
79
89
  .to_return(status: 200, body: action)
80
90
 
@@ -90,6 +100,9 @@ class HostAgentReportingObserverTest < Minitest::Test
90
100
  end
91
101
 
92
102
  def test_agent_action_error
103
+ stub_request(:post, "http://10.10.10.10:9292/tracermetrics")
104
+ .to_return(status: 200)
105
+
93
106
  stub_request(:post, "http://10.10.10.10:9292/com.instana.plugin.ruby.0")
94
107
  .to_return(status: 200, body: 'INVALID')
95
108
 
@@ -114,6 +127,75 @@ class HostAgentReportingObserverTest < Minitest::Test
114
127
  ::Instana.config[:metrics][:enabled] = true
115
128
  end
116
129
 
130
+ def test_disable_metrics_memory
131
+ ::Instana.config[:metrics][:memory][:enabled] = false
132
+
133
+ stub_request(:post, "http://10.10.10.10:9292/tracermetrics")
134
+ .to_return(status: 200)
135
+
136
+ stub_request(:post, "http://10.10.10.10:9292/com.instana.plugin.ruby.0")
137
+ .with(body: ->(data) { (JSON.parse(data).keys & ['exec_args', 'memory']).length.eql?(0) })
138
+ .to_return(status: 200)
139
+
140
+ stub_request(:post, "http://10.10.10.10:9292/com.instana.plugin.ruby/traces.0")
141
+ .to_return(status: 200)
142
+
143
+ client = Instana::Backend::RequestClient.new('10.10.10.10', 9292)
144
+ discovery = Concurrent::Atom.new({'pid' => 0})
145
+
146
+ subject = Instana::Backend::HostAgentReportingObserver.new(client, discovery, timer_class: MockTimer)
147
+
148
+ subject.report_timer.block.call
149
+ ensure
150
+ ::Instana.config[:metrics][:memory][:enabled] = true
151
+ end
152
+
153
+ def test_disable_gc
154
+ ::Instana.config[:metrics][:gc][:enabled] = false
155
+
156
+ stub_request(:post, "http://10.10.10.10:9292/tracermetrics")
157
+ .to_return(status: 200)
158
+
159
+ stub_request(:post, "http://10.10.10.10:9292/com.instana.plugin.ruby.0")
160
+ .with(body: ->(data) { (JSON.parse(data).keys & ['gc']).length.eql?(0) })
161
+ .to_return(status: 200)
162
+
163
+ stub_request(:post, "http://10.10.10.10:9292/com.instana.plugin.ruby/traces.0")
164
+ .to_return(status: 200)
165
+
166
+ client = Instana::Backend::RequestClient.new('10.10.10.10', 9292)
167
+ discovery = Concurrent::Atom.new({'pid' => 0})
168
+
169
+ subject = Instana::Backend::HostAgentReportingObserver.new(client, discovery, timer_class: MockTimer)
170
+
171
+ subject.report_timer.block.call
172
+ ensure
173
+ ::Instana.config[:metrics][:gc][:enabled] = true
174
+ end
175
+
176
+ def test_disable_thread
177
+ ::Instana.config[:metrics][:thread][:enabled] = false
178
+
179
+ stub_request(:post, "http://10.10.10.10:9292/tracermetrics")
180
+ .to_return(status: 200)
181
+
182
+ stub_request(:post, "http://10.10.10.10:9292/com.instana.plugin.ruby.0")
183
+ .with(body: ->(data) { (JSON.parse(data).keys & ['thread']).length.eql?(0) })
184
+ .to_return(status: 200)
185
+
186
+ stub_request(:post, "http://10.10.10.10:9292/com.instana.plugin.ruby/traces.0")
187
+ .to_return(status: 200)
188
+
189
+ client = Instana::Backend::RequestClient.new('10.10.10.10', 9292)
190
+ discovery = Concurrent::Atom.new({'pid' => 0})
191
+
192
+ subject = Instana::Backend::HostAgentReportingObserver.new(client, discovery, timer_class: MockTimer)
193
+
194
+ subject.report_timer.block.call
195
+ ensure
196
+ ::Instana.config[:metrics][:thread][:enabled] = true
197
+ end
198
+
117
199
  def test_disable_tracing
118
200
  ::Instana.config[:tracing][:enabled] = false
119
201
 
@@ -60,4 +60,24 @@ class ProcessInfoTest < Minitest::Test
60
60
  assert_equal subject.sched_pid, subject.parent_pid
61
61
  end
62
62
  end
63
+
64
+ def test_osx_memory_used
65
+ host_os = RbConfig::CONFIG['host_os']
66
+ RbConfig::CONFIG['host_os'] = 'darwin'
67
+
68
+ subject = Instana::Backend::ProcessInfo.new(OpenStruct.new(rss: 1024))
69
+ assert_equal 1, subject.memory_used
70
+ ensure
71
+ RbConfig::CONFIG['host_os'] = host_os
72
+ end
73
+
74
+ def test_linux_memory_used
75
+ host_os = RbConfig::CONFIG['host_os']
76
+ RbConfig::CONFIG['host_os'] = 'linux'
77
+
78
+ subject = Instana::Backend::ProcessInfo.new(OpenStruct.new(rss: 1))
79
+ assert_equal 4096, subject.memory_used
80
+ ensure
81
+ RbConfig::CONFIG['host_os'] = host_os
82
+ end
63
83
  end
@@ -0,0 +1,37 @@
1
+ # (c) Copyright IBM Corp. 2021
2
+ # (c) Copyright Instana Inc. 2021
3
+
4
+ require 'test_helper'
5
+
6
+ class MongoTest < Minitest::Test
7
+ def setup
8
+ clear_all!
9
+ end
10
+
11
+ def test_mongo
12
+ Instana.tracer.start_or_continue_trace(:'mongo-test') do
13
+ client = Mongo::Client.new('mongodb://127.0.0.1:27017/instana')
14
+ client[:people].delete_many({ name: /$S*/ })
15
+ client[:people].insert_many([{ _id: 1, name: "Stan" }])
16
+ end
17
+
18
+ spans = ::Instana.processor.queued_spans
19
+ delete_span, insert_span, = spans
20
+
21
+ delete_data = delete_span[:data][:mongo]
22
+ insert_data = insert_span[:data][:mongo]
23
+
24
+ assert_equal delete_span[:n], :mongo
25
+ assert_equal insert_span[:n], :mongo
26
+
27
+ assert_equal delete_data[:namespace], "instana"
28
+ assert_equal delete_data[:command], "delete"
29
+ assert_equal delete_data[:peer], {hostname: "127.0.0.1", port: 27017}
30
+ assert delete_data[:json].include?("delete")
31
+
32
+ assert_equal insert_data[:namespace], "instana"
33
+ assert_equal insert_data[:command], "insert"
34
+ assert_equal insert_data[:peer], {hostname: "127.0.0.1", port: 27017}
35
+ assert insert_data[:json].include?("insert")
36
+ end
37
+ end
@@ -56,6 +56,20 @@ class RackInstrumentedRequestTest < Minitest::Test
56
56
  assert req.continuing_from_trace_parent?
57
57
  end
58
58
 
59
+ def test_incoming_w3_content_invalid_id
60
+ req = Instana::InstrumentedRequest.new(
61
+ 'HTTP_X_INSTANA_L' => '1',
62
+ 'HTTP_TRACEPARENT' => '00-00000000000000000000000000000000-0000000000000000-01'
63
+ )
64
+
65
+ expected = {
66
+ level: '1'
67
+ }
68
+
69
+ assert_equal expected, req.incoming_context
70
+ refute req.continuing_from_trace_parent?
71
+ end
72
+
59
73
  def test_incoming_invalid_w3_content
60
74
  req = Instana::InstrumentedRequest.new(
61
75
  'HTTP_X_INSTANA_L' => '1',
@@ -38,8 +38,6 @@ class RailsActiveRecordTest < Minitest::Test
38
38
  data = span[:data][:activerecord]
39
39
 
40
40
  assert data[:sql].start_with?('INSERT INTO')
41
- assert 'core', data[:binds][0]
42
- assert 'blue', data[:binds][1]
43
41
  end
44
42
 
45
43
  def test_read
@@ -54,8 +52,6 @@ class RailsActiveRecordTest < Minitest::Test
54
52
  data = span[:data][:activerecord]
55
53
 
56
54
  assert data[:sql].start_with?('SELECT')
57
- assert 'core', data[:binds][0]
58
- assert 1, data[:binds][1]
59
55
  end
60
56
 
61
57
  def test_update
@@ -73,8 +69,6 @@ class RailsActiveRecordTest < Minitest::Test
73
69
  data = span[:data][:activerecord]
74
70
 
75
71
  assert data[:sql].start_with?('UPDATE')
76
- assert 'red', data[:binds][0]
77
- assert 1, data[:binds][2]
78
72
  end
79
73
 
80
74
  def test_delete
@@ -90,7 +84,6 @@ class RailsActiveRecordTest < Minitest::Test
90
84
  data = span[:data][:activerecord]
91
85
 
92
86
  assert data[:sql].start_with?('DELETE')
93
- assert 1, data[:binds][0]
94
87
  end
95
88
 
96
89
  def test_raw
@@ -10,8 +10,6 @@ class ErrorJob
10
10
  def self.perform
11
11
  if ENV.key?('REDIS_URL')
12
12
  redis = Redis.new(:url => ENV['REDIS_URL'])
13
- elsif ENV.key?('REDIS_URL')
14
- redis = Redis.new(:url => ENV['REDIS_URL'])
15
13
  else
16
14
  redis = Redis.new(:url => 'localhost:6379')
17
15
  end
@@ -20,6 +18,5 @@ class ErrorJob
20
18
  redis.set('ts', dt)
21
19
 
22
20
  raise Exception.new("Silly Rabbit, Trix are for kids.")
23
- redis.set(:nb_id, 2)
24
21
  end
25
22
  end
@@ -12,8 +12,6 @@ class FastJob
12
12
 
13
13
  if ENV.key?('REDIS_URL')
14
14
  redis = Redis.new(:url => ENV['REDIS_URL'])
15
- elsif ENV.key?('REDIS_URL')
16
- redis = Redis.new(:url => ENV['REDIS_URL'])
17
15
  else
18
16
  redis = Redis.new(:url => 'redis://localhost:6379')
19
17
  end
@@ -111,7 +111,6 @@ class CustomTracingTest < Minitest::Test
111
111
 
112
112
  ::Instana.tracer.log_entry(:custom_span, kvs)
113
113
  raise "custom tracing error. This is only a test"
114
- ::Instana.tracer.log_info({:on_info_kv => 1})
115
114
  rescue => e
116
115
  ::Instana.tracer.log_error(e)
117
116
  ensure
@@ -133,4 +133,21 @@ class SpanTest < Minitest::Test
133
133
  assert_equal({}, span.tags)
134
134
  time.verify
135
135
  end
136
+
137
+ def test_inc_processed_counts
138
+ clear_all!
139
+
140
+ span = Instana::Span.new(:excon)
141
+ span.close
142
+
143
+ metrics = Instana.processor.span_metrics
144
+
145
+ assert_equal 1, metrics[:opened]
146
+ assert_equal 1, metrics[:closed]
147
+
148
+ metrics = Instana.processor.span_metrics
149
+
150
+ assert_equal 0, metrics[:opened]
151
+ assert_equal 0, metrics[:closed]
152
+ end
136
153
  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.204.0
4
+ version: 1.208.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: 2021-07-12 00:00:00.000000000 Z
11
+ date: 2021-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -160,6 +160,7 @@ files:
160
160
  - gemfiles/excon_079.gemfile
161
161
  - gemfiles/graphql_10.gemfile
162
162
  - gemfiles/grpc_10.gemfile
163
+ - gemfiles/mongo_216.gemfile
163
164
  - gemfiles/net_http_01.gemfile
164
165
  - gemfiles/rack_16.gemfile
165
166
  - gemfiles/rack_20.gemfile
@@ -199,6 +200,7 @@ files:
199
200
  - lib/instana/activators/graphql.rb
200
201
  - lib/instana/activators/grpc_client.rb
201
202
  - lib/instana/activators/grpc_server.rb
203
+ - lib/instana/activators/mongo.rb
202
204
  - lib/instana/activators/net_http.rb
203
205
  - lib/instana/activators/rack.rb
204
206
  - lib/instana/activators/rails.rb
@@ -242,6 +244,7 @@ files:
242
244
  - lib/instana/instrumentation/graphql.rb
243
245
  - lib/instana/instrumentation/grpc.rb
244
246
  - lib/instana/instrumentation/instrumented_request.rb
247
+ - lib/instana/instrumentation/mongo.rb
245
248
  - lib/instana/instrumentation/net-http.rb
246
249
  - lib/instana/instrumentation/rack.rb
247
250
  - lib/instana/instrumentation/redis.rb
@@ -275,6 +278,7 @@ files:
275
278
  - lib/instana/version.rb
276
279
  - lib/opentracing.rb
277
280
  - log/.keep
281
+ - sonar-project.properties
278
282
  - test/activator_test.rb
279
283
  - test/backend/agent_test.rb
280
284
  - test/backend/gc_snapshot_test.rb
@@ -297,6 +301,7 @@ files:
297
301
  - test/instrumentation/excon_test.rb
298
302
  - test/instrumentation/graphql_test.rb
299
303
  - test/instrumentation/grpc_test.rb
304
+ - test/instrumentation/mongo_test.rb
300
305
  - test/instrumentation/net_http_test.rb
301
306
  - test/instrumentation/rack_instrumented_request_test.rb
302
307
  - test/instrumentation/rack_test.rb
@@ -401,6 +406,7 @@ test_files:
401
406
  - test/instrumentation/excon_test.rb
402
407
  - test/instrumentation/graphql_test.rb
403
408
  - test/instrumentation/grpc_test.rb
409
+ - test/instrumentation/mongo_test.rb
404
410
  - test/instrumentation/net_http_test.rb
405
411
  - test/instrumentation/rack_instrumented_request_test.rb
406
412
  - test/instrumentation/rack_test.rb