instana 1.215.1 → 1.217.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +102 -4
  3. data/.tekton/.currency/docs/report.md +15 -14
  4. data/.tekton/.currency/resources/requirements.txt +0 -1
  5. data/.tekton/.currency/resources/table.json +6 -0
  6. data/.tekton/.currency/scripts/generate_report.py +38 -130
  7. data/.tekton/README.md +278 -0
  8. data/.tekton/github-pr-eventlistener.yaml +1 -1
  9. data/.tekton/pipeline.yaml +154 -6
  10. data/.tekton/pipelinerun.yaml +2 -2
  11. data/.tekton/ruby-tracer-prepuller.yaml +4 -0
  12. data/.tekton/run_unittests.sh +27 -6
  13. data/.tekton/scheduled-eventlistener.yaml +2 -4
  14. data/.tekton/task.yaml +156 -0
  15. data/Rakefile +1 -1
  16. data/gemfiles/excon_0100.gemfile +14 -0
  17. data/gemfiles/excon_021.gemfile +1 -1
  18. data/gemfiles/excon_079.gemfile +1 -1
  19. data/gemfiles/excon_100.gemfile +2 -2
  20. data/gemfiles/rails_61.gemfile +1 -0
  21. data/gemfiles/rails_70.gemfile +1 -0
  22. data/gemfiles/rails_71.gemfile +2 -1
  23. data/gemfiles/rails_80.gemfile +17 -0
  24. data/gemfiles/{excon_02.gemfile → sequel_56.gemfile} +4 -5
  25. data/gemfiles/sequel_57.gemfile +16 -0
  26. data/gemfiles/sequel_58.gemfile +16 -0
  27. data/lib/instana/activators/sequel.rb +20 -0
  28. data/lib/instana/backend/host_agent.rb +12 -3
  29. data/lib/instana/config.rb +1 -0
  30. data/lib/instana/instrumentation/active_record.rb +1 -1
  31. data/lib/instana/instrumentation/instrumented_request.rb +2 -2
  32. data/lib/instana/instrumentation/sequel.rb +42 -0
  33. data/lib/instana/tracing/span.rb +2 -2
  34. data/lib/instana/version.rb +1 -1
  35. data/lib/instana.rb +4 -2
  36. data/test/activator_test.rb +1 -1
  37. data/test/instrumentation/rails_active_record_test.rb +1 -1
  38. data/test/instrumentation/sequel_test.rb +105 -0
  39. metadata +13 -9
  40. data/.tekton/.currency/currency-pipeline.yaml +0 -36
  41. data/.tekton/.currency/currency-pipelinerun.yaml +0 -20
  42. data/.tekton/.currency/currency-rbac.yaml +0 -29
  43. data/.tekton/.currency/currency-scheduled-eventlistener.yaml +0 -56
  44. data/.tekton/.currency/currency-tasks.yaml +0 -94
data/.tekton/task.yaml CHANGED
@@ -57,6 +57,10 @@ spec:
57
57
  - name: mariadb
58
58
  # mariadb:11.3.2
59
59
  image: mariadb@sha256:851f05fe1e4cb290442c1b12b7108436a33fd8f6a733d4989950322d06d45c65
60
+ startupProbe:
61
+ initialDelaySeconds: 10
62
+ tcpSocket:
63
+ port: 3306
60
64
  env:
61
65
  - name: MYSQL_ROOT_PASSWORD # or MARIADB_ROOT_PASSWORD
62
66
  value: passw0rd
@@ -93,6 +97,10 @@ spec:
93
97
  - name: postgres
94
98
  # postgres:16.2-bookworm
95
99
  image: postgres@sha256:6b841c8f6a819884207402f1209a8116844365df15fca8cf556fc54a24c70800
100
+ startupProbe:
101
+ initialDelaySeconds: 10
102
+ tcpSocket:
103
+ port: 5432
96
104
  env:
97
105
  - name: POSTGRES_DB
98
106
  value: 'ci_test'
@@ -182,6 +190,10 @@ spec:
182
190
  - name: redis
183
191
  # redis:7.2.4-bookworm
184
192
  image: redis@sha256:fe98b2d39d462d06a7360e2860dd6ceff930745e3731eccb3c1406dd0dd7f744
193
+ startupProbe:
194
+ initialDelaySeconds: 10
195
+ tcpSocket:
196
+ port: 6379
185
197
  params:
186
198
  - name: imageDigest
187
199
  type: string
@@ -245,6 +257,10 @@ spec:
245
257
  - name: mongo
246
258
  # mongo:5.0.25-focal
247
259
  image: mongo@sha256:d1b8a7b77424347397653ab8ff500c66b1e9979b4cebf826951d37b0d3966721
260
+ startupProbe:
261
+ initialDelaySeconds: 10
262
+ tcpSocket:
263
+ port: 27017
248
264
  params:
249
265
  - name: imageDigest
250
266
  type: string
@@ -291,3 +307,143 @@ spec:
291
307
  workingDir: /workspace/ruby-sensor/
292
308
  command:
293
309
  - /workspace/ruby-sensor/.tekton/run_unittests.sh
310
+ ---
311
+ apiVersion: tekton.dev/v1
312
+ kind: Task
313
+ metadata:
314
+ name: ruby-tracer-unittest-sequel-sqlite3-task
315
+ spec:
316
+ params:
317
+ - name: imageDigest
318
+ type: string
319
+ - name: gemfile
320
+ type: string
321
+ workspaces:
322
+ - name: task-pvc
323
+ mountPath: /workspace
324
+ steps:
325
+ - name: unittest
326
+ image: ruby@$(params.imageDigest)
327
+ env:
328
+ - name: TEST_CONFIGURATION
329
+ value: libraries
330
+ - name: BUNDLE_GEMFILE
331
+ value: $(params.gemfile)
332
+ - name: DATABASE_URL
333
+ value: "sqlite3::memory:"
334
+ workingDir: /workspace/ruby-sensor/
335
+ command:
336
+ - /workspace/ruby-sensor/.tekton/run_unittests.sh
337
+ ---
338
+ apiVersion: tekton.dev/v1
339
+ kind: Task
340
+ metadata:
341
+ name: ruby-tracer-unittest-sequel-mysql2-task
342
+ spec:
343
+ sidecars:
344
+ # MySQL (compatible Mariadb)
345
+ - name: mariadb
346
+ # mariadb:11.3.2
347
+ image: mariadb@sha256:851f05fe1e4cb290442c1b12b7108436a33fd8f6a733d4989950322d06d45c65
348
+ startupProbe:
349
+ initialDelaySeconds: 10
350
+ tcpSocket:
351
+ port: 3306
352
+ env:
353
+ - name: MYSQL_ROOT_PASSWORD # or MARIADB_ROOT_PASSWORD
354
+ value: passw0rd
355
+ - name: MYSQL_DATABASE # or MARIADB_DATABASE
356
+ value: ci_test
357
+ params:
358
+ - name: imageDigest
359
+ type: string
360
+ - name: gemfile
361
+ type: string
362
+ workspaces:
363
+ - name: task-pvc
364
+ mountPath: /workspace
365
+ steps:
366
+ - name: unittest
367
+ image: ruby@$(params.imageDigest)
368
+ env:
369
+ - name: TEST_CONFIGURATION
370
+ value: libraries
371
+ - name: BUNDLE_GEMFILE
372
+ value: $(params.gemfile)
373
+ - name: DATABASE_URL
374
+ value: "mysql2://root:passw0rd@127.0.0.1:3306/ci_test"
375
+ workingDir: /workspace/ruby-sensor/
376
+ command:
377
+ - /workspace/ruby-sensor/.tekton/run_unittests.sh
378
+ ---
379
+ apiVersion: tekton.dev/v1
380
+ kind: Task
381
+ metadata:
382
+ name: ruby-generate-currency-report-task
383
+ spec:
384
+ workspaces:
385
+ - name: task-pvc
386
+ mountPath: /workspace
387
+ steps:
388
+ - name: generate-currency-report
389
+ # 3.10.13-bookworm
390
+ image: python@sha256:c970ff53939772f47b0672e380328afb50d8fd1c0568ed4f82c22effc54244fc
391
+ script: |
392
+ #!/usr/bin/env bash
393
+
394
+ cd /workspace/ruby-sensor/.tekton/.currency
395
+
396
+ python -m venv /tmp/venv
397
+ source /tmp/venv/bin/activate
398
+ pip install -r resources/requirements.txt
399
+
400
+ python scripts/generate_report.py
401
+ if [ $? -ne 0 ]; then
402
+ echo "Error occured while generating the ruby tracer currency report." >&2
403
+ exit 1
404
+ fi
405
+ cat docs/report.md
406
+ ---
407
+ apiVersion: tekton.dev/v1
408
+ kind: Task
409
+ metadata:
410
+ name: ruby-upload-currency-report-task
411
+ spec:
412
+ params:
413
+ - name: github-token-secret
414
+ default: instanacd-github-api-token
415
+ workspaces:
416
+ - name: task-pvc
417
+ mountPath: /workspace
418
+ steps:
419
+ - name: upload-currency-report
420
+ # alpine/git:2.43.0
421
+ image: alpine/git@sha256:6ff4de047dcc8f0c7d75d2efff63fbc189e87d2f458305f2cc8f165ff83309cf
422
+ env:
423
+ - name: GH_ENTERPRISE_TOKEN
424
+ valueFrom:
425
+ secretKeyRef:
426
+ name: $(params.github-token-secret)
427
+ key: "GH_ENTERPRISE_TOKEN"
428
+ script: |
429
+ #!/bin/sh
430
+
431
+ cd /workspace
432
+ git clone https://oauth2:$GH_ENTERPRISE_TOKEN@github.ibm.com/instana/tracer-reports.git
433
+
434
+ if [ $? -ne 0 ]; then
435
+ echo "The attempt to clone the tracer-reports repository failed, preventing the upload of ruby tracer currency report." >&2
436
+ exit 1
437
+ fi
438
+
439
+ cd tracer-reports
440
+
441
+ cp ../ruby-sensor/.tekton/.currency/docs/report.md ./automated/currency/ruby/report.md
442
+
443
+ git config user.name "Instanacd PAT for GitHub Enterprise"
444
+ git config user.email instana.ibm.github.enterprise@ibm.com
445
+
446
+ git add .
447
+
448
+ git commit -m "chore: Updated ruby currency report"
449
+ git push origin main
data/Rakefile CHANGED
@@ -9,7 +9,7 @@ require 'json'
9
9
  Rake::TestTask.new(:test) do |t|
10
10
  t.verbose = false
11
11
  t.warning = false
12
- t.ruby_opts = []
12
+ t.ruby_opts = ["--parser=parse.y"] if Gem::Version.new(RUBY_VERSION) > Gem::Version.new('3.3')
13
13
 
14
14
  t.libs << "test"
15
15
  t.libs << "lib"
@@ -0,0 +1,14 @@
1
+ # (c) Copyright IBM Corp. 2023
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rack"
6
+ gem "rackup"
7
+ gem "minitest-reporters"
8
+ gem "webmock"
9
+ gem "puma"
10
+ gem "rack-test"
11
+ gem "simplecov", "~> 0.21.2"
12
+ gem "excon", ">= 0.100.0", "< 1.0"
13
+
14
+ gemspec path: "../"
@@ -12,6 +12,6 @@ gem "webmock"
12
12
  gem "puma"
13
13
  gem "rack-test"
14
14
  gem "simplecov", "~> 0.21.2"
15
- gem "excon", ">= 0.21.0", "< 1.0"
15
+ gem "excon", "0.21.0"
16
16
 
17
17
  gemspec path: "../"
@@ -12,6 +12,6 @@ gem "webmock"
12
12
  gem "puma"
13
13
  gem "rack-test"
14
14
  gem "simplecov", "~> 0.21.2"
15
- gem "excon", ">= 0.79.0", "< 1.0"
15
+ gem "excon", "0.79.0"
16
16
 
17
17
  gemspec path: "../"
@@ -1,4 +1,4 @@
1
- # (c) Copyright IBM Corp. 2023
1
+ # (c) Copyright IBM Corp. 2024
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
@@ -9,6 +9,6 @@ gem "webmock"
9
9
  gem "puma"
10
10
  gem "rack-test"
11
11
  gem "simplecov", "~> 0.21.2"
12
- gem "excon", ">= 0.100.0", "< 1.0"
12
+ gem "excon", ">= 1.0.0", "< 2.0"
13
13
 
14
14
  gemspec path: "../"
@@ -11,6 +11,7 @@ gem "puma"
11
11
  gem "rack-test"
12
12
  gem "simplecov", "~> 0.21.2"
13
13
  gem "mail", ">= 2.8.1"
14
+ gem "mutex_m" # mutex_m is not part of the default gems since Ruby 3.4.0
14
15
  gem "rails", ">= 6.1", "< 7.0"
15
16
  gem "mysql2", "0.5.5"
16
17
  gem "pg"
@@ -8,6 +8,7 @@ gem "puma"
8
8
  gem "rack-test"
9
9
  gem "simplecov", "~> 0.21.2"
10
10
  gem "mail", ">= 2.8.1"
11
+ gem "mutex_m" # mutex_m is not part of the default gems since Ruby 3.4.0
11
12
  gem "rails", "7.0.3"
12
13
  gem "mysql2", "0.5.5"
13
14
  gem "pg"
@@ -8,7 +8,8 @@ gem "puma"
8
8
  gem "rack-test"
9
9
  gem "simplecov", "~> 0.21.2"
10
10
  gem "mail", ">= 2.8.1"
11
- gem "rails", ">= 7.1"
11
+ gem "mutex_m" # mutex_m is not part of the default gems since Ruby 3.4.0
12
+ gem "rails", "~> 7.1"
12
13
  gem "mysql2", "0.5.5"
13
14
  gem "pg"
14
15
  gem "sqlite3", "~> 1.4"
@@ -0,0 +1,17 @@
1
+ # (c) Copyright IBM Corp. 2024
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "minitest-reporters"
6
+ gem "webmock"
7
+ gem "puma"
8
+ gem "rack-test"
9
+ gem "simplecov", "~> 0.21.2"
10
+ gem "mail", ">= 2.8.1"
11
+ gem "mutex_m" # mutex_m is not part of the default gems since Ruby 3.4.0
12
+ gem "rails", ">= 8.0"
13
+ gem "mysql2", "0.5.5"
14
+ gem "pg"
15
+ gem "sqlite3", ">= 2.1"
16
+
17
+ gemspec path: "../"
@@ -1,17 +1,16 @@
1
1
  # This file was generated by Appraisal
2
2
 
3
- # (c) Copyright IBM Corp. 2021
4
- # (c) Copyright Instana Inc. 2021
3
+ # (c) Copyright IBM Corp. 2024
5
4
 
6
5
  source "https://rubygems.org"
7
6
 
8
- gem "rack"
9
- gem "rackup"
10
7
  gem "minitest-reporters"
11
8
  gem "webmock"
12
9
  gem "puma"
13
10
  gem "rack-test"
14
11
  gem "simplecov", "~> 0.21.2"
15
- gem "excon", ">= 0.21.0", "< 1.0"
12
+ gem "sequel", "~> 5.60.0"
13
+ gem "sqlite3", "~> 1.4"
14
+ gem "mysql2", "0.5.5"
16
15
 
17
16
  gemspec path: "../"
@@ -0,0 +1,16 @@
1
+ # This file was generated by Appraisal
2
+
3
+ # (c) Copyright IBM Corp. 2024
4
+
5
+ source "https://rubygems.org"
6
+
7
+ gem "minitest-reporters"
8
+ gem "webmock"
9
+ gem "puma"
10
+ gem "rack-test"
11
+ gem "simplecov", "~> 0.21.2"
12
+ gem "sequel", "~> 5.70.0"
13
+ gem "sqlite3", "~> 1.4"
14
+ gem "mysql2", "0.5.5"
15
+
16
+ gemspec path: "../"
@@ -0,0 +1,16 @@
1
+ # This file was generated by Appraisal
2
+
3
+ # (c) Copyright IBM Corp. 2024
4
+
5
+ source "https://rubygems.org"
6
+
7
+ gem "minitest-reporters"
8
+ gem "webmock"
9
+ gem "puma"
10
+ gem "rack-test"
11
+ gem "simplecov", "~> 0.21.2"
12
+ gem "sequel", ">= 5.80"
13
+ gem "sqlite3", "~> 1.4"
14
+ gem "mysql2", "0.5.5"
15
+
16
+ gemspec path: "../"
@@ -0,0 +1,20 @@
1
+ # (c) Copyright IBM Corp. 2024
2
+
3
+ module Instana
4
+ module Activators
5
+ class Sequel < Activator
6
+ def can_instrument?
7
+ defined?(::Sequel::Database)
8
+ end
9
+
10
+ def instrument
11
+ require 'instana/instrumentation/sequel'
12
+
13
+ ::Sequel::Database
14
+ .prepend(Instana::Instrumentation::Sequel)
15
+
16
+ true
17
+ end
18
+ end
19
+ end
20
+ end
@@ -12,6 +12,8 @@ module Instana
12
12
  @logger = logger
13
13
  @future = nil
14
14
  @client = nil
15
+ # Timer task to poll for agent liveliness
16
+ @agent_connection_task = Concurrent::TimerTask.new(execution_interval: 75) { announce }
15
17
  end
16
18
 
17
19
  def setup; end
@@ -27,7 +29,12 @@ module Instana
27
29
  alias start spawn_background_thread
28
30
 
29
31
  def announce
30
- @client = until_not_nil { HostAgentLookup.new.call }
32
+ @client = with_timeout { HostAgentLookup.new.call }
33
+ # Shuts down the connection task based on agent connection client.
34
+ @client ? @agent_connection_task.shutdown : @agent_connection_task.execute
35
+ # Do not continue further if the agent is down/connection to the agent is unsuccessfull
36
+ return nil unless @client
37
+
31
38
  begin
32
39
  @discovery.send(:observers)&.send(:notify_and_delete_observers, Time.now, nil, nil)
33
40
  ensure
@@ -74,14 +81,16 @@ module Instana
74
81
 
75
82
  private
76
83
 
77
- def until_not_nil
78
- loop do
84
+ def with_timeout
85
+ 15.times do
79
86
  result = yield
80
87
  return result unless result.nil?
81
88
 
82
89
  @logger.debug("Waiting on a connection to the agent.")
83
90
  sleep(1)
84
91
  end
92
+ @logger.info("Agent connection timed out retrying after 60 seconds")
93
+ nil
85
94
  end
86
95
 
87
96
  def discovery_value
@@ -73,6 +73,7 @@ module Instana
73
73
  @config[:'resque-client'] = { :enabled => true, :propagate => true }
74
74
  @config[:'resque-worker'] = { :enabled => true, :'setup-fork' => true }
75
75
  @config[:'rest-client'] = { :enabled => true }
76
+ @config[:sequel] = { :enabled => true }
76
77
  @config[:'sidekiq-client'] = { :enabled => true }
77
78
  @config[:'sidekiq-worker'] = { :enabled => true }
78
79
  end
@@ -6,7 +6,7 @@ module Instana
6
6
  module ActiveRecord
7
7
  IGNORED_NAMES = %w[SCHEMA EXPLAIN CACHE].freeze
8
8
  IGNORED_SQL = %w[BEGIN COMMIT SET].freeze
9
- SANITIZE_REGEXP = /('[\s\S][^']*'|\d*\.\d+|\d+|NULL)/i.freeze
9
+ SANITIZE_REGEXP = /('[\s\S][^']*'|\d*\.\d+|\d+|NULL)/i
10
10
 
11
11
  def log(sql, name = 'SQL', binds = [], *args, **kwargs, &block)
12
12
  call_payload = {
@@ -9,8 +9,8 @@ require 'rack/request'
9
9
 
10
10
  module Instana
11
11
  class InstrumentedRequest < Rack::Request
12
- W3C_TRACE_PARENT_FORMAT = /[0-9a-f][0-9a-e]-(?<trace>[0-9a-f]{32})-(?<parent>[0-9a-f]{16})-(?<flags>[0-9a-f]{2})/.freeze
13
- INSTANA_TRACE_STATE = /in=(?<trace>[0-9a-f]+);(?<span>[0-9a-f]+)/.freeze
12
+ W3C_TRACE_PARENT_FORMAT = /[0-9a-f][0-9a-e]-(?<trace>[0-9a-f]{32})-(?<parent>[0-9a-f]{16})-(?<flags>[0-9a-f]{2})/
13
+ INSTANA_TRACE_STATE = /in=(?<trace>[0-9a-f]+);(?<span>[0-9a-f]+)/
14
14
 
15
15
  def skip_trace?
16
16
  # Honor X-Instana-L
@@ -0,0 +1,42 @@
1
+ # (c) Copyright IBM Corp. 2024
2
+
3
+ module Instana
4
+ module Instrumentation
5
+ module Sequel
6
+ IGNORED_SQL = %w[BEGIN COMMIT SET].freeze
7
+ VERSION_SELECT_STATEMENT = "SELECT VERSION()".freeze
8
+ SANITIZE_REGEXP = /('[\s\S][^']*'|\d*\.\d+|\d+|NULL)/i
9
+
10
+ def log_connection_yield(sql, conn, *args)
11
+ call_payload = {
12
+ sequel: {
13
+ adapter: opts[:adapter],
14
+ host: opts[:host],
15
+ username: opts[:user],
16
+ db: opts[:database],
17
+ sql: maybe_sanitize(sql)
18
+ }
19
+ }
20
+ maybe_trace(call_payload) { super(sql, conn, *args) }
21
+ end
22
+
23
+ private
24
+
25
+ def maybe_sanitize(sql)
26
+ ::Instana.config[:sanitize_sql] ? sql.gsub(SANITIZE_REGEXP, '?') : sql
27
+ end
28
+
29
+ def maybe_trace(call_payload, &blk)
30
+ if ::Instana.tracer.tracing? && !ignored?(call_payload)
31
+ ::Instana.tracer.trace(:sequel, call_payload, &blk)
32
+ else
33
+ yield
34
+ end
35
+ end
36
+
37
+ def ignored?(call_payload)
38
+ IGNORED_SQL.any? { |s| call_payload[:sequel][:sql].upcase.start_with?(s) } || call_payload[:sequel][:sql].upcase == VERSION_SELECT_STATEMENT
39
+ end
40
+ end
41
+ end
42
+ 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", :mongo ].freeze
10
+ :"aws.lambda.invoke", :mongo, :sequel ].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", :mongo ].freeze
15
+ :"aws.lambda.invoke", :mongo, :sequel ].freeze
16
16
  HTTP_SPANS = [ :rack, :excon, :'net-http' ].freeze
17
17
 
18
18
  attr_accessor :parent
@@ -2,6 +2,6 @@
2
2
  # (c) Copyright Instana Inc. 2016
3
3
 
4
4
  module Instana
5
- VERSION = "1.215.1"
5
+ VERSION = "1.217.0"
6
6
  VERSION_FULL = "instana-#{VERSION}"
7
7
  end
data/lib/instana.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  # (c) Copyright IBM Corp. 2021
2
2
  # (c) Copyright Instana Inc. 2016
3
-
4
- require 'instana/setup'
3
+ if ENV.fetch('INSTANA_DISABLE', false) && defined?(::Instana)
4
+ Object.send(:remove_const, :Instana)
5
+ end
5
6
 
6
7
  # Boot the instana agent background thread. If you wish to have greater
7
8
  # control on the where and which thread this is run in, instead use
@@ -14,6 +15,7 @@ require 'instana/setup'
14
15
 
15
16
  # :nocov:
16
17
  unless ENV.fetch('INSTANA_DISABLE', false)
18
+ require 'instana/setup'
17
19
  ::Instana::Activator.start
18
20
  ::Instana.agent.spawn_background_thread
19
21
 
@@ -43,7 +43,7 @@ class ActivatorTest < Minitest::Test
43
43
  ENV.delete('INSTANA_ACTIVATE_SET')
44
44
  subject = activated_set
45
45
  assert_instance_of Set, subject
46
- assert_equal 31, subject.length
46
+ assert_equal 32, subject.length
47
47
  ensure
48
48
  ENV.delete('INSTANA_ACTIVATE_SET')
49
49
  end
@@ -17,7 +17,7 @@ class RailsActiveRecordTest < Minitest::Test
17
17
  ActiveRecord::Migration.suppress_messages do
18
18
  ActiveRecord::Migration.run(CreateBlocks, direction: :down)
19
19
  end
20
- ActiveRecord::Base.remove_connection(@connection)
20
+ ActiveRecord::Base.remove_connection
21
21
  end
22
22
 
23
23
  def test_config_defaults
@@ -0,0 +1,105 @@
1
+ # (c) Copyright IBM Corp. 2024
2
+
3
+ require 'test_helper'
4
+ require 'sequel'
5
+
6
+ class SequelTest < Minitest::Test
7
+ def setup
8
+ skip unless ENV['DATABASE_URL']
9
+ db_url = ENV['DATABASE_URL'].sub("sqlite3", "sqlite")
10
+ @db = Sequel.connect(db_url)
11
+ @db.create_table!(:blocks) do
12
+ String :name
13
+ String :color
14
+ end
15
+ @model = @db[:blocks]
16
+ end
17
+
18
+ def teardown
19
+ @db.drop_table(:blocks)
20
+ @db.disconnect
21
+ end
22
+
23
+ def test_config_defaults
24
+ assert ::Instana.config[:sanitize_sql] == true
25
+ assert ::Instana.config[:sequel].is_a?(Hash)
26
+ assert ::Instana.config[:sequel].key?(:enabled)
27
+ assert_equal true, ::Instana.config[:sequel][:enabled]
28
+ end
29
+
30
+ def test_create
31
+ Instana::Tracer.start_or_continue_trace(:sequel_test, {}) do
32
+ @model.insert(name: 'core', color: 'blue')
33
+ end
34
+ spans = ::Instana.processor.queued_spans
35
+ assert_equal 2, spans.length
36
+ span = find_first_span_by_name(spans, :sequel)
37
+ data = span[:data][:sequel]
38
+ assert data[:sql].start_with?('INSERT INTO')
39
+ end
40
+
41
+ def test_read
42
+ @model.insert(name: 'core', color: 'blue')
43
+ Instana::Tracer.start_or_continue_trace(:sequel_test, {}) do
44
+ @model.where(name: 'core').first
45
+ end
46
+ spans = ::Instana.processor.queued_spans
47
+ assert_equal 2, spans.length
48
+ span = find_first_span_by_name(spans, :sequel)
49
+ data = span[:data][:sequel]
50
+ assert data[:sql].start_with?('SELECT')
51
+ assert_nil span[:ec]
52
+ end
53
+
54
+ def test_update
55
+ @model.insert(name: 'core', color: 'blue')
56
+ Instana::Tracer.start_or_continue_trace(:sequel_test, {}) do
57
+ @model.where(name: 'core').update(color: 'red')
58
+ end
59
+ spans = ::Instana.processor.queued_spans
60
+ assert_equal 2, spans.length
61
+ span = find_first_span_by_name(spans, :sequel)
62
+ data = span[:data][:sequel]
63
+ assert data[:sql].start_with?('UPDATE')
64
+ assert_nil span[:ec]
65
+ assert_equal 'red', @model.where(name: 'core').first[:color]
66
+ end
67
+
68
+ def test_delete
69
+ @model.insert(name: 'core', color: 'blue')
70
+ Instana::Tracer.start_or_continue_trace(:sequel_test, {}) do
71
+ @model.where(name: 'core').delete
72
+ end
73
+ spans = ::Instana.processor.queued_spans
74
+ assert_equal 2, spans.length
75
+ span = find_first_span_by_name(spans, :sequel)
76
+ data = span[:data][:sequel]
77
+ assert data[:sql].start_with?('DELETE')
78
+ assert_nil span[:ec]
79
+ assert_nil @model.where(name: 'core').first
80
+ end
81
+
82
+ def test_raw
83
+ Instana::Tracer.start_or_continue_trace(:sequel_test, {}) do
84
+ @db.run('SELECT 1')
85
+ end
86
+ spans = ::Instana.processor.queued_spans
87
+ assert_equal 2, spans.length
88
+ span = find_first_span_by_name(spans, :sequel)
89
+ data = span[:data][:sequel]
90
+ assert 'SELECT 1', data[:sql]
91
+ assert_nil span[:ec]
92
+ end
93
+
94
+ def test_raw_error
95
+ assert_raises Sequel::DatabaseError do
96
+ Instana::Tracer.start_or_continue_trace(:sequel_test, {}) do
97
+ @db.run('INVALID')
98
+ end
99
+ end
100
+ spans = ::Instana.processor.queued_spans
101
+ assert_equal 2, spans.length
102
+ span = find_first_span_by_name(spans, :sequel)
103
+ assert_equal 1, span[:ec]
104
+ end
105
+ end