appsignal 3.0.20 → 3.0.21.alpha.1

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: 18e505270b1fc0966691e2d270ae08fbe7157ee4fde1708dd3252e7da69c7c9e
4
- data.tar.gz: 37340595960a772bd6e094a6fc04d4f8940ac0ef96ecb3e848d7ce58f3f5019e
3
+ metadata.gz: 4d00b4618b222cc7be43c7bcd79445b41b356714b682bf0aa3737c131ef9893b
4
+ data.tar.gz: 38099b1d602f9aed9b67d38e24cee1fa7b63cf069ad806e218b8d360f4655806
5
5
  SHA512:
6
- metadata.gz: e4caeabfd901dfaae05d3aece53d2f346a80cb7e7134a98e59cc9c52788d0536ec3866dbb0371e5da8f3514a2b1e6301686670604c7b43c2a30c0ea24dd78ae2
7
- data.tar.gz: a3c490e7d04be8896d9513041d3d37e58dd5179664c8725d6939b432f6b516f70d27b3e27f2afde407cf145775a174619745976ab31c50747acbbbc7af29eb55
6
+ metadata.gz: 1514603d5cd1ae152f5b9e1bbe9297c20172e6d30f223c57a2ba7f0e9ab50e6937a207ceb32d12441a735286f0fa25cd47cc51fbc8f2fb66339d64bc2da13dbf
7
+ data.tar.gz: 85e43d5094ac8247abe40cade7fe61665a8fc1f0d655db63277db1a9875fa61ab675f35ef48f04f17a77882d80003b1c0d0dac4aff10f2ef6a25957b5f70796f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # AppSignal for Ruby gem Changelog
2
2
 
3
+ ## 3.0.21.alpha.1
4
+
5
+ ### Changed
6
+
7
+ - [f19d9dcc](https://github.com/appsignal/appsignal-ruby/commit/f19d9dcc1c00103f5dc92951481becf4d4ade39e) patch - The MongoDB query sanitization now shows all the attributes in the query at all levels.
8
+ Only the actual values are filtered with a `?` character. Less MongoDB queries are now marked
9
+ as N+1 queries when they weren't the exact same query. This increases the number of unique events
10
+ AppSignal tracks for MongoDB queries.
11
+
3
12
  ## 3.0.20
4
13
 
5
14
  ### Added
data/appsignal.gemspec CHANGED
@@ -25,6 +25,7 @@ Gem::Specification.new do |gem| # rubocop:disable Metrics/BlockLength
25
25
  gem.extensions = %w[ext/extconf.rb]
26
26
 
27
27
  gem.metadata = {
28
+ "rubygems_mfa_required" => "true",
28
29
  "bug_tracker_uri" => "https://github.com/appsignal/appsignal-ruby/issues",
29
30
  "changelog_uri" =>
30
31
  "https://github.com/appsignal/appsignal-ruby/blob/main/CHANGELOG.md",
@@ -21,28 +21,28 @@ module Appsignal
21
21
  },
22
22
  "insert" => {
23
23
  "insert" => :allow,
24
- "documents" => :deny_array,
24
+ "documents" => :sanitize_document,
25
25
  "ordered" => :allow
26
26
  },
27
27
  "update" => {
28
28
  "update" => :allow,
29
- "updates" => :sanitize_bulk,
29
+ "updates" => :sanitize_document,
30
30
  "ordered" => :allow
31
31
  },
32
32
  "findandmodify" => {
33
33
  "findandmodify" => :allow,
34
34
  "query" => :sanitize_document,
35
- "update" => :deny_array,
35
+ "update" => :sanitize_document,
36
36
  "new" => :allow
37
37
  },
38
38
  "delete" => {
39
39
  "delete" => :allow,
40
- "deletes" => :sanitize_bulk,
40
+ "deletes" => :sanitize_document,
41
41
  "ordered" => :allow
42
42
  },
43
43
  "bulk" => {
44
44
  "q" => :sanitize_document,
45
- "u" => :deny_array,
45
+ "u" => :sanitize_document,
46
46
  "limit" => :allow,
47
47
  "multi" => :allow,
48
48
  "upsert" => :allow
@@ -68,20 +68,9 @@ module Appsignal
68
68
  # Applies strategy on hash values based on keys
69
69
  def self.apply_strategy(strategy, val)
70
70
  case strategy
71
- when :allow then val
72
- when :deny then "?"
73
- when :deny_array then "[?]"
71
+ when :allow then val
74
72
  when :sanitize_document
75
- Appsignal::Utils::QueryParamsSanitizer.sanitize(val, true, :mongodb)
76
- when :sanitize_bulk
77
- if val.length > 1
78
- [
79
- format(:bulk, val.first),
80
- "[...]"
81
- ]
82
- else
83
- val.map { |v| format(:bulk, v) }
84
- end
73
+ Appsignal::Utils::QueryParamsSanitizer.sanitize(val, false, :mongodb)
85
74
  else "?"
86
75
  end
87
76
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Appsignal
4
- VERSION = "3.0.20".freeze
4
+ VERSION = "3.0.21.alpha.1".freeze
5
5
  end
@@ -11,8 +11,12 @@ describe Appsignal::EventFormatter::MongoRubyDriver::QueryFormatter do
11
11
  end
12
12
 
13
13
  it "should apply a strategy for each key" do
14
+ # TODO: additional curly brackets required for issue
15
+ # https://github.com/rspec/rspec-mocks/issues/1460
16
+ # rubocop:disable Style/BracesAroundHashParameters
14
17
  expect(formatter).to receive(:apply_strategy)
15
- .with(:sanitize_document, "_id" => 1)
18
+ .with(:sanitize_document, { "_id" => 1 })
19
+ # rubocop:enable Style/BracesAroundHashParameters
16
20
 
17
21
  expect(formatter).to receive(:apply_strategy)
18
22
  .with(:allow, "users")
@@ -47,57 +51,27 @@ describe Appsignal::EventFormatter::MongoRubyDriver::QueryFormatter do
47
51
  end
48
52
  end
49
53
 
50
- context "when strategy is deny" do
51
- let(:strategy) { :deny }
52
- let(:value) { { "_id" => 1 } }
53
-
54
- it "should return a '?'" do
55
- expect(formatter.apply_strategy(strategy, value)).to eql("?")
56
- end
57
- end
58
-
59
- context "when strategy is deny_array" do
60
- let(:strategy) { :deny_array }
61
- let(:value) { { "_id" => 1 } }
62
-
63
- it "should return a sanitized array string" do
64
- expect(formatter.apply_strategy(strategy, value)).to eql("[?]")
65
- end
66
- end
67
-
68
54
  context "when strategy is sanitize_document" do
69
55
  let(:strategy) { :sanitize_document }
70
- let(:value) { { "_id" => 1 } }
71
-
72
- it "should return a sanitized document" do
73
- expect(formatter.apply_strategy(strategy, value)).to eql("_id" => "?")
74
- end
75
- end
76
-
77
- context "when strategy is sanitize_bulk" do
78
- let(:strategy) { :sanitize_bulk }
79
- let(:value) { [{ "q" => { "_id" => 1 }, "u" => [{ "foo" => "bar" }] }] }
80
-
81
- it "should return an array of sanitized bulk documents" do
82
- expect(formatter.apply_strategy(strategy, value)).to eql([
83
- { "q" => { "_id" => "?" }, "u" => "[?]" }
84
- ])
56
+ let(:value) do
57
+ {
58
+ "_id" => 1,
59
+ "authors" => [
60
+ { "name" => "BarBaz" },
61
+ { "name" => "FooBar" },
62
+ { "name" => "BarFoo", "surname" => "Baz" }
63
+ ]
64
+ }
85
65
  end
86
66
 
87
- context "when bulk has more than one update" do
88
- let(:value) do
89
- [
90
- { "q" => { "_id" => 1 }, "u" => [{ "foo" => "bar" }] },
91
- { "q" => { "_id" => 2 }, "u" => [{ "foo" => "baz" }] }
67
+ it "should return a sanitized document" do
68
+ expect(formatter.apply_strategy(strategy, value)).to eql(
69
+ "_id" => "?",
70
+ "authors" => [
71
+ { "name" => "?" },
72
+ { "name" => "?", "surname" => "?" }
92
73
  ]
93
- end
94
-
95
- it "should return only the first value of sanitized bulk documents" do
96
- expect(formatter.apply_strategy(strategy, value)).to eql([
97
- { "q" => { "_id" => "?" }, "u" => "[?]" },
98
- "[...]"
99
- ])
100
- end
74
+ )
101
75
  end
102
76
  end
103
77
 
@@ -17,8 +17,12 @@ describe Appsignal::Hooks::MongoMonitorSubscriber do
17
17
  end
18
18
 
19
19
  it "should sanitize command" do
20
+ # TODO: additional curly brackets required for issue
21
+ # https://github.com/rspec/rspec-mocks/issues/1460
22
+ # rubocop:disable Style/BracesAroundHashParameters
20
23
  expect(Appsignal::EventFormatter::MongoRubyDriver::QueryFormatter)
21
- .to receive(:format).with("find", "foo" => "bar")
24
+ .to receive(:format).with("find", { "foo" => "bar" })
25
+ # rubocop:enable Style/BracesAroundHashParameters
22
26
 
23
27
  subscriber.started(event)
24
28
  end
@@ -228,10 +228,14 @@ describe Appsignal::Integrations::SidekiqMiddleware, :with_yaml_parse_error => f
228
228
  let(:error) { ExampleException }
229
229
 
230
230
  it "creates a transaction and adds the error" do
231
+ # TODO: additional curly brackets required for issue
232
+ # https://github.com/rspec/rspec-mocks/issues/1460
233
+ # rubocop:disable Style/BracesAroundHashParameters
231
234
  expect(Appsignal).to receive(:increment_counter)
232
- .with("sidekiq_queue_job_count", 1, :queue => "default", :status => :failed)
235
+ .with("sidekiq_queue_job_count", 1, { :queue => "default", :status => :failed })
233
236
  expect(Appsignal).to receive(:increment_counter)
234
- .with("sidekiq_queue_job_count", 1, :queue => "default", :status => :processed)
237
+ .with("sidekiq_queue_job_count", 1, { :queue => "default", :status => :processed })
238
+ # rubocop:enable Style/BracesAroundHashParameters
235
239
 
236
240
  expect do
237
241
  perform_job { raise error, "uh oh" }
@@ -267,8 +271,12 @@ describe Appsignal::Integrations::SidekiqMiddleware, :with_yaml_parse_error => f
267
271
 
268
272
  context "without an error" do
269
273
  it "creates a transaction with events" do
274
+ # TODO: additional curly brackets required for issue
275
+ # https://github.com/rspec/rspec-mocks/issues/1460
276
+ # rubocop:disable Style/BracesAroundHashParameters
270
277
  expect(Appsignal).to receive(:increment_counter)
271
- .with("sidekiq_queue_job_count", 1, :queue => "default", :status => :processed)
278
+ .with("sidekiq_queue_job_count", 1, { :queue => "default", :status => :processed })
279
+ # rubocop:enable Style/BracesAroundHashParameters
272
280
 
273
281
  perform_job
274
282
 
@@ -117,7 +117,7 @@ describe Appsignal::Utils::QueryParamsSanitizer do
117
117
  context "when value is an array" do
118
118
  let(:value) { %w[foo bar] }
119
119
 
120
- it "should sanitize all hash values with a single questionmark" do
120
+ it "should sanitize all hash values with a single question mark" do
121
121
  expect(subject).to eq(["?"])
122
122
  end
123
123
  end
@@ -125,7 +125,7 @@ describe Appsignal::Utils::QueryParamsSanitizer do
125
125
  context "when value is a mixed array" do
126
126
  let(:value) { [nil, "foo", "bar"] }
127
127
 
128
- it "should sanitize all hash values with a single questionmark" do
128
+ it "should sanitize all hash values with a single question mark" do
129
129
  expect(subject).to eq(["?"])
130
130
  end
131
131
  end
@@ -427,49 +427,89 @@ describe Appsignal do
427
427
  end
428
428
 
429
429
  describe ".monitor_single_transaction" do
430
+ around { |example| keep_transactions { example.run } }
431
+
430
432
  context "with a successful call" do
431
- it "should call monitor_transaction and stop" do
432
- expect(Appsignal).to receive(:monitor_transaction).with(
433
- "perform_job.something",
434
- :key => :value
435
- ).and_yield
433
+ it "calls monitor_transaction and Appsignal.stop" do
436
434
  expect(Appsignal).to receive(:stop)
437
435
 
438
- Appsignal.monitor_single_transaction("perform_job.something", :key => :value) do
436
+ Appsignal.monitor_single_transaction(
437
+ "perform_job.something",
438
+ :controller => :my_controller,
439
+ :action => :my_action
440
+ ) do
439
441
  # nothing
440
442
  end
443
+
444
+ transaction = last_transaction
445
+ transaction_hash = transaction.to_h
446
+ expect(transaction_hash).to include(
447
+ "action" => "my_controller#my_action"
448
+ )
449
+ expect(transaction_hash["events"]).to match([
450
+ hash_including(
451
+ "name" => "perform_job.something",
452
+ "title" => "",
453
+ "body" => "",
454
+ "body_format" => Appsignal::EventFormatter::DEFAULT
455
+ )
456
+ ])
441
457
  end
442
458
  end
443
459
 
444
460
  context "with an erroring call" do
445
461
  let(:error) { ExampleException.new }
446
462
 
447
- it "should call monitor_transaction and stop and then raise the error" do
448
- expect(Appsignal).to receive(:monitor_transaction).with(
449
- "perform_job.something",
450
- :key => :value
451
- ).and_yield
463
+ it "calls monitor_transaction and stop and re-raises the error" do
452
464
  expect(Appsignal).to receive(:stop)
453
465
 
454
466
  expect do
455
- Appsignal.monitor_single_transaction("perform_job.something", :key => :value) do
467
+ Appsignal.monitor_single_transaction(
468
+ "perform_job.something",
469
+ :controller => :my_controller,
470
+ :action => :my_action
471
+ ) do
456
472
  raise error
457
473
  end
458
474
  end.to raise_error(error)
475
+
476
+ transaction = last_transaction
477
+ transaction_hash = transaction.to_h
478
+ expect(transaction_hash).to include(
479
+ "action" => "my_controller#my_action"
480
+ )
481
+ expect(transaction_hash["events"]).to match([
482
+ hash_including(
483
+ "name" => "perform_job.something",
484
+ "title" => "",
485
+ "body" => "",
486
+ "body_format" => Appsignal::EventFormatter::DEFAULT
487
+ )
488
+ ])
459
489
  end
460
490
  end
461
491
  end
462
492
 
463
493
  describe ".tag_request" do
464
- before { allow(Appsignal::Transaction).to receive(:current).and_return(transaction) }
494
+ let(:transaction) { http_request_transaction }
495
+ around do |example|
496
+ start_agent
497
+ with_current_transaction transaction do
498
+ keep_transactions { example.run }
499
+ end
500
+ end
465
501
 
466
502
  context "with transaction" do
467
- let(:transaction) { double }
468
- it "should call set_tags on transaction" do
469
- expect(transaction).to receive(:set_tags).with("a" => "b")
470
- end
503
+ it "calls set_tags on the current transaction" do
504
+ Appsignal.tag_request("a" => "b")
505
+ transaction.complete # Manually trigger transaction sampling
471
506
 
472
- after { Appsignal.tag_request("a" => "b") }
507
+ expect(transaction.to_h).to include(
508
+ "sample_data" => hash_including(
509
+ "tags" => { "a" => "b" }
510
+ )
511
+ )
512
+ end
473
513
  end
474
514
 
475
515
  context "without transaction" do
@@ -56,6 +56,16 @@ module TransactionHelpers
56
56
  Thread.current[:appsignal_transaction] = nil
57
57
  end
58
58
 
59
+ # Set the current for the duration of the given block.
60
+ #
61
+ # Helper for {set_current_transaction} and {clear_current_transaction!}
62
+ def with_current_transaction(transaction)
63
+ set_current_transaction transaction
64
+ yield
65
+ ensure
66
+ clear_current_transaction!
67
+ end
68
+
59
69
  # Track the AppSignal transaction JSON when a transaction gets completed
60
70
  # ({Appsignal::Transaction.complete}).
61
71
  #
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appsignal
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.20
4
+ version: 3.0.21.alpha.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Beekman
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-01-17 00:00:00.000000000 Z
13
+ date: 2022-02-14 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rack
@@ -405,6 +405,7 @@ homepage: https://github.com/appsignal/appsignal-ruby
405
405
  licenses:
406
406
  - MIT
407
407
  metadata:
408
+ rubygems_mfa_required: 'true'
408
409
  bug_tracker_uri: https://github.com/appsignal/appsignal-ruby/issues
409
410
  changelog_uri: https://github.com/appsignal/appsignal-ruby/blob/main/CHANGELOG.md
410
411
  documentation_uri: https://docs.appsignal.com/ruby/
@@ -422,11 +423,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
422
423
  version: '2.0'
423
424
  required_rubygems_version: !ruby/object:Gem::Requirement
424
425
  requirements:
425
- - - ">="
426
+ - - ">"
426
427
  - !ruby/object:Gem::Version
427
- version: '0'
428
+ version: 1.3.1
428
429
  requirements: []
429
- rubygems_version: 3.3.4
430
+ rubygems_version: 3.1.6
430
431
  signing_key:
431
432
  specification_version: 4
432
433
  summary: Logs performance and exception data from your app to appsignal.com