instana 1.207.0 → 1.209.0.pre2

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: 01f078ad2a63d8cd71303a9bf7b413209eda0b2f464ce72f88c84ae05bf797da
4
- data.tar.gz: d547946bdbb52ea3c3c3a7fc317f7bcd2dd8ccf37d52507788bff1b85fc4434c
3
+ metadata.gz: 579fd0682a5f684184c9a916d2bbb03cd080ff4cdedf566518ae62b4485f9dc5
4
+ data.tar.gz: 6530042c84f14c495ad31b2bc55d6840935b58bcafb211e4fde30b6bc72c241e
5
5
  SHA512:
6
- metadata.gz: df3a3926477ab6842628f7fe1062655e63760c0fc1e5100912c8191f5894b8b4dabb1e030441b0b924d379bd6be56a9b69e877c22220153acba3393af59e4b51
7
- data.tar.gz: 05fd9a76497614afca946d9538577bdfda21bd3a901759b285d7033425610206fd5a88405f86e86d52928da8f9324798cbf579bb516d845a8749f7c000d98fdf
6
+ metadata.gz: 7a4e3cf400528959af43933f0a3c0c6f19d8e856bf01b77c0031640bd552b4e00165b6a3c49628fe1bf1877d633b7abcde42bc010032ee1e32e4eb42b31cf29e
7
+ data.tar.gz: 98b0616dcb9e649d6563120e640e6ece098d4d8a918c5df97abeda3ac58122b50559bf57fed13b42d9e5e3e7ba79ebf4be225ef7b996fec4516adb865d7363d0
data/.circleci/config.yml CHANGED
@@ -1,20 +1,6 @@
1
1
  version: 2.1
2
2
 
3
3
  executors:
4
- ruby_25:
5
- docker:
6
- - image: circleci/ruby:2.5-node
7
- environment:
8
- MEMCACHED_HOST: '127.0.0.1:11211'
9
- REDIS_URL: 'redis://127.0.0.1:6379'
10
- DATABASE_URL: 'sqlite3::memory:'
11
- - image: memcached
12
- - image: redis
13
- - image: circleci/dynamodb
14
- - image: minio/minio:latest
15
- command: ["server", "/data"]
16
- - image: s12v/sns
17
- - image: softwaremill/elasticmq-native
18
4
  ruby_26:
19
5
  docker:
20
6
  - image: circleci/ruby:2.6-node
@@ -29,6 +15,7 @@ executors:
29
15
  command: ["server", "/data"]
30
16
  - image: s12v/sns
31
17
  - image: softwaremill/elasticmq-native
18
+ - image: circleci/mongo:5-focal-ram
32
19
  ruby_27:
33
20
  docker:
34
21
  - image: circleci/ruby:2.7-node
@@ -43,19 +30,7 @@ executors:
43
30
  command: ["server", "/data"]
44
31
  - image: s12v/sns
45
32
  - image: softwaremill/elasticmq-native
46
- ruby_25_mysql2:
47
- docker:
48
- - image: circleci/ruby:2.5-node
49
- environment:
50
- DATABASE_URL: "mysql2://root@127.0.0.1:3306/ci_test"
51
- - image: mariadb
52
- environment:
53
- MYSQL_DATABASE: 'ci_test'
54
- MYSQL_USER: 'root'
55
- MYSQL_PASSWORD: ''
56
- MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
57
- MYSQL_ROOT_PASSWORD: ''
58
- MYSQL_ROOT_HOST: '%'
33
+ - image: circleci/mongo:5-focal-ram
59
34
  ruby_26_mysql2:
60
35
  docker:
61
36
  - image: circleci/ruby:2.6-node
@@ -82,15 +57,6 @@ executors:
82
57
  MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
83
58
  MYSQL_ROOT_PASSWORD: ''
84
59
  MYSQL_ROOT_HOST: '%'
85
- ruby_25_postgres:
86
- docker:
87
- - image: circleci/ruby:2.6-node
88
- environment:
89
- DATABASE_URL: "postgres://postgres:test@127.0.0.1:5432/ci_test"
90
- - image: postgres
91
- environment:
92
- POSTGRES_PASSWORD: 'test'
93
- POSTGRES_DB: 'ci_test'
94
60
  ruby_26_postgres:
95
61
  docker:
96
62
  - image: circleci/ruby:2.6-node
@@ -116,6 +82,7 @@ commands:
116
82
  - run:
117
83
  name: Install iproute2
118
84
  command: |
85
+ sudo apt-get update
119
86
  sudo apt-get install iproute2
120
87
  - run:
121
88
  name: Install Java
@@ -141,6 +108,7 @@ commands:
141
108
  - run:
142
109
  name: Install Java
143
110
  command: |
111
+ sudo apt-get update
144
112
  sudo apt-get install openjdk-11-jdk
145
113
  - run:
146
114
  name: Run SonarQube to capture coverage
@@ -246,7 +214,6 @@ workflows:
246
214
  stack:
247
215
  - ruby_27
248
216
  - ruby_26
249
- - ruby_25
250
217
  libraries:
251
218
  jobs:
252
219
  - test_apprisal:
@@ -255,7 +222,6 @@ workflows:
255
222
  stack:
256
223
  - ruby_27
257
224
  - ruby_26
258
- - ruby_25
259
225
  gemfile:
260
226
  - "./gemfiles/aws_30.gemfile"
261
227
  - "./gemfiles/cuba_30.gemfile"
@@ -278,6 +244,7 @@ workflows:
278
244
  - "./gemfiles/sidekiq_50.gemfile"
279
245
  - "./gemfiles/sinatra_14.gemfile"
280
246
  - "./gemfiles/shoryuken_50.gemfile"
247
+ - "./gemfiles/mongo_216.gemfile"
281
248
  rails:
282
249
  jobs:
283
250
  - test_apprisal:
@@ -286,13 +253,10 @@ workflows:
286
253
  stack:
287
254
  - ruby_27
288
255
  - ruby_26
289
- - ruby_25
290
256
  - ruby_27_postgres
291
257
  - ruby_26_postgres
292
- - ruby_25_postgres
293
258
  - ruby_27_mysql2
294
259
  - ruby_26_mysql2
295
- - ruby_25_mysql2
296
260
  gemfile:
297
261
  - "./gemfiles/rails_60.gemfile"
298
262
  - "./gemfiles/rails_52.gemfile"
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
@@ -34,6 +34,8 @@ module Instana
34
34
  raise DiscoveryError, "Discovery response was #{discovery_response.code} with `#{payload}`." unless discovery_response.ok?
35
35
 
36
36
  discovery = discovery_response.json
37
+ raise DiscoveryError, "Expected discovery to be a Hash, not a `#{discovery.class}`." unless discovery.is_a?(Hash)
38
+
37
39
  @logger.debug("Discovery complete (`#{discovery}`). Waiting for agent.")
38
40
  wait_for_backend(discovery['pid'])
39
41
  @logger.debug("Agent ready.")
data/lib/instana/base.rb CHANGED
@@ -38,5 +38,3 @@ module Instana
38
38
  end
39
39
  end
40
40
  end
41
-
42
- ::Instana.logger.info "Stan is on the scene. Starting Instana instrumentation version #{::Instana::VERSION}"
@@ -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
@@ -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
@@ -120,7 +120,7 @@ module Instana
120
120
  elsif @data[:n] == :activerecord
121
121
  @data[:data][:activerecord][:error] = e.message
122
122
  else
123
- 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)
124
124
  end
125
125
  e.instance_variable_set(:@instana_logged, true)
126
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.207.0"
5
+ VERSION = "1.209.0.pre2"
6
6
  VERSION_FULL = "instana-#{VERSION}"
7
7
  end
data/lib/instana.rb CHANGED
@@ -12,5 +12,11 @@ require 'instana/setup'
12
12
  # the thread of your choice.
13
13
  #
14
14
 
15
- ::Instana::Activator.start
16
- ::Instana.agent.spawn_background_thread
15
+ # :nocov:
16
+ unless ENV.fetch('INSTANA_DISABLE', false)
17
+ ::Instana::Activator.start
18
+ ::Instana.agent.spawn_background_thread
19
+
20
+ ::Instana.logger.info "Stan is on the scene. Starting Instana instrumentation version #{::Instana::VERSION}"
21
+ end
22
+ # :nocov:
@@ -12,6 +12,7 @@ class HostAgentActivationObserverTest < Minitest::Test
12
12
  stub_request(:put, "http://10.10.10.10:9292/com.instana.plugin.ruby.discovery")
13
13
  .and_timeout
14
14
  .and_return(status: 500, body: '{"ok": false}')
15
+ .and_return(status: 200, body: '[{"pid": 1234}]')
15
16
  .and_return(status: 200, body: '{"pid": 1234}')
16
17
 
17
18
  stub_request(:head, "http://10.10.10.10:9292/com.instana.plugin.ruby.1234")
@@ -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',
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.207.0
4
+ version: 1.209.0.pre2
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-08-30 00:00:00.000000000 Z
11
+ date: 2022-03-28 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
@@ -298,6 +301,7 @@ files:
298
301
  - test/instrumentation/excon_test.rb
299
302
  - test/instrumentation/graphql_test.rb
300
303
  - test/instrumentation/grpc_test.rb
304
+ - test/instrumentation/mongo_test.rb
301
305
  - test/instrumentation/net_http_test.rb
302
306
  - test/instrumentation/rack_instrumented_request_test.rb
303
307
  - test/instrumentation/rack_test.rb
@@ -371,9 +375,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
371
375
  version: '2.1'
372
376
  required_rubygems_version: !ruby/object:Gem::Requirement
373
377
  requirements:
374
- - - ">="
378
+ - - ">"
375
379
  - !ruby/object:Gem::Version
376
- version: '0'
380
+ version: 1.3.1
377
381
  requirements: []
378
382
  rubygems_version: 3.1.6
379
383
  signing_key:
@@ -402,6 +406,7 @@ test_files:
402
406
  - test/instrumentation/excon_test.rb
403
407
  - test/instrumentation/graphql_test.rb
404
408
  - test/instrumentation/grpc_test.rb
409
+ - test/instrumentation/mongo_test.rb
405
410
  - test/instrumentation/net_http_test.rb
406
411
  - test/instrumentation/rack_instrumented_request_test.rb
407
412
  - test/instrumentation/rack_test.rb