appsignal 3.10.0 → 3.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/CHANGELOG.md +197 -0
  4. data/Gemfile +1 -0
  5. data/Rakefile +1 -1
  6. data/benchmark.rake +99 -42
  7. data/lib/appsignal/cli/demo.rb +0 -1
  8. data/lib/appsignal/cli/diagnose.rb +1 -1
  9. data/lib/appsignal/config.rb +204 -130
  10. data/lib/appsignal/demo.rb +16 -26
  11. data/lib/appsignal/event_formatter/rom/sql_formatter.rb +1 -0
  12. data/lib/appsignal/event_formatter.rb +3 -2
  13. data/lib/appsignal/helpers/instrumentation.rb +331 -19
  14. data/lib/appsignal/hooks/action_cable.rb +21 -16
  15. data/lib/appsignal/hooks/active_job.rb +14 -8
  16. data/lib/appsignal/hooks/delayed_job.rb +1 -1
  17. data/lib/appsignal/hooks/shoryuken.rb +3 -63
  18. data/lib/appsignal/integrations/action_cable.rb +5 -7
  19. data/lib/appsignal/integrations/active_support_notifications.rb +1 -0
  20. data/lib/appsignal/integrations/capistrano/capistrano_2_tasks.rb +36 -35
  21. data/lib/appsignal/integrations/data_mapper.rb +1 -0
  22. data/lib/appsignal/integrations/delayed_job_plugin.rb +27 -33
  23. data/lib/appsignal/integrations/dry_monitor.rb +1 -0
  24. data/lib/appsignal/integrations/excon.rb +1 -0
  25. data/lib/appsignal/integrations/grape.rb +7 -0
  26. data/lib/appsignal/integrations/hanami.rb +8 -43
  27. data/lib/appsignal/integrations/http.rb +1 -0
  28. data/lib/appsignal/integrations/net_http.rb +1 -0
  29. data/lib/appsignal/integrations/object.rb +6 -0
  30. data/lib/appsignal/integrations/padrino.rb +8 -73
  31. data/lib/appsignal/integrations/que.rb +13 -20
  32. data/lib/appsignal/integrations/railtie.rb +36 -14
  33. data/lib/appsignal/integrations/rake.rb +1 -5
  34. data/lib/appsignal/integrations/redis.rb +1 -0
  35. data/lib/appsignal/integrations/redis_client.rb +1 -0
  36. data/lib/appsignal/integrations/resque.rb +2 -5
  37. data/lib/appsignal/integrations/shoryuken.rb +75 -0
  38. data/lib/appsignal/integrations/sidekiq.rb +7 -15
  39. data/lib/appsignal/integrations/sinatra.rb +8 -19
  40. data/lib/appsignal/integrations/unicorn.rb +1 -0
  41. data/lib/appsignal/integrations/webmachine.rb +2 -5
  42. data/lib/appsignal/loaders/grape.rb +13 -0
  43. data/lib/appsignal/loaders/hanami.rb +40 -0
  44. data/lib/appsignal/loaders/padrino.rb +68 -0
  45. data/lib/appsignal/loaders/sinatra.rb +24 -0
  46. data/lib/appsignal/loaders.rb +92 -0
  47. data/lib/appsignal/logger.rb +7 -3
  48. data/lib/appsignal/probes/helpers.rb +1 -0
  49. data/lib/appsignal/probes/mri.rb +1 -0
  50. data/lib/appsignal/probes/sidekiq.rb +1 -0
  51. data/lib/appsignal/probes.rb +3 -0
  52. data/lib/appsignal/rack/abstract_middleware.rb +20 -13
  53. data/lib/appsignal/rack/event_handler.rb +44 -13
  54. data/lib/appsignal/rack/generic_instrumentation.rb +1 -0
  55. data/lib/appsignal/rack/grape_middleware.rb +2 -1
  56. data/lib/appsignal/rack/streaming_listener.rb +1 -0
  57. data/lib/appsignal/rack.rb +35 -0
  58. data/lib/appsignal/span.rb +1 -0
  59. data/lib/appsignal/transaction.rb +308 -101
  60. data/lib/appsignal/utils/data.rb +0 -1
  61. data/lib/appsignal/utils/hash_sanitizer.rb +0 -1
  62. data/lib/appsignal/utils/integration_logger.rb +0 -13
  63. data/lib/appsignal/utils/integration_memory_logger.rb +0 -13
  64. data/lib/appsignal/utils/json.rb +0 -1
  65. data/lib/appsignal/utils/query_params_sanitizer.rb +0 -1
  66. data/lib/appsignal/utils/stdout_and_logger_message.rb +0 -1
  67. data/lib/appsignal/utils.rb +6 -0
  68. data/lib/appsignal/version.rb +1 -1
  69. data/lib/appsignal.rb +169 -14
  70. data/spec/lib/appsignal/capistrano2_spec.rb +1 -1
  71. data/spec/lib/appsignal/cli/demo_spec.rb +0 -1
  72. data/spec/lib/appsignal/cli/diagnose/paths_spec.rb +1 -1
  73. data/spec/lib/appsignal/cli/diagnose_spec.rb +0 -1
  74. data/spec/lib/appsignal/config_spec.rb +291 -44
  75. data/spec/lib/appsignal/demo_spec.rb +1 -2
  76. data/spec/lib/appsignal/environment_spec.rb +4 -2
  77. data/spec/lib/appsignal/hooks/action_cable_spec.rb +43 -74
  78. data/spec/lib/appsignal/hooks/active_support_notifications_spec.rb +3 -6
  79. data/spec/lib/appsignal/hooks/activejob_spec.rb +12 -3
  80. data/spec/lib/appsignal/hooks/delayed_job_spec.rb +2 -443
  81. data/spec/lib/appsignal/hooks/dry_monitor_spec.rb +4 -7
  82. data/spec/lib/appsignal/hooks/excon_spec.rb +3 -6
  83. data/spec/lib/appsignal/hooks/gvl_spec.rb +2 -2
  84. data/spec/lib/appsignal/hooks/http_spec.rb +1 -3
  85. data/spec/lib/appsignal/hooks/net_http_spec.rb +1 -1
  86. data/spec/lib/appsignal/hooks/redis_client_spec.rb +5 -8
  87. data/spec/lib/appsignal/hooks/redis_spec.rb +3 -6
  88. data/spec/lib/appsignal/hooks/resque_spec.rb +1 -1
  89. data/spec/lib/appsignal/hooks/sequel_spec.rb +3 -5
  90. data/spec/lib/appsignal/hooks/shoryuken_spec.rb +0 -171
  91. data/spec/lib/appsignal/hooks/sidekiq_spec.rb +1 -1
  92. data/spec/lib/appsignal/hooks/webmachine_spec.rb +1 -1
  93. data/spec/lib/appsignal/integrations/delayed_job_plugin_spec.rb +459 -0
  94. data/spec/lib/appsignal/integrations/grape_spec.rb +36 -0
  95. data/spec/lib/appsignal/integrations/hanami_spec.rb +9 -178
  96. data/spec/lib/appsignal/integrations/http_spec.rb +1 -5
  97. data/spec/lib/appsignal/integrations/mongo_ruby_driver_spec.rb +4 -2
  98. data/spec/lib/appsignal/integrations/net_http_spec.rb +1 -1
  99. data/spec/lib/appsignal/integrations/object_spec.rb +1 -3
  100. data/spec/lib/appsignal/integrations/padrino_spec.rb +8 -330
  101. data/spec/lib/appsignal/integrations/que_spec.rb +3 -4
  102. data/spec/lib/appsignal/integrations/railtie_spec.rb +275 -191
  103. data/spec/lib/appsignal/integrations/shoryuken_spec.rb +167 -0
  104. data/spec/lib/appsignal/integrations/sidekiq_spec.rb +15 -13
  105. data/spec/lib/appsignal/integrations/sinatra_spec.rb +9 -104
  106. data/spec/lib/appsignal/integrations/webmachine_spec.rb +13 -1
  107. data/spec/lib/appsignal/loaders/grape_spec.rb +12 -0
  108. data/spec/lib/appsignal/loaders/hanami_spec.rb +95 -0
  109. data/spec/lib/appsignal/loaders/padrino_spec.rb +277 -0
  110. data/spec/lib/appsignal/loaders/sinatra_spec.rb +47 -0
  111. data/spec/lib/appsignal/loaders_spec.rb +137 -0
  112. data/spec/lib/appsignal/probes/sidekiq_spec.rb +1 -1
  113. data/spec/lib/appsignal/probes_spec.rb +6 -5
  114. data/spec/lib/appsignal/rack/abstract_middleware_spec.rb +51 -5
  115. data/spec/lib/appsignal/rack/event_handler_spec.rb +114 -10
  116. data/spec/lib/appsignal/rack/generic_instrumentation_spec.rb +1 -1
  117. data/spec/lib/appsignal/rack/grape_middleware_spec.rb +2 -35
  118. data/spec/lib/appsignal/rack/hanami_middleware_spec.rb +1 -1
  119. data/spec/lib/appsignal/rack/rails_instrumentation_spec.rb +4 -2
  120. data/spec/lib/appsignal/rack/sinatra_instrumentation_spec.rb +3 -3
  121. data/spec/lib/appsignal/rack_spec.rb +63 -0
  122. data/spec/lib/appsignal/span_spec.rb +1 -3
  123. data/spec/lib/appsignal/transaction_spec.rb +1640 -1075
  124. data/spec/lib/appsignal/utils/integration_logger_spec.rb +12 -16
  125. data/spec/lib/appsignal/utils/integration_memory_logger_spec.rb +0 -10
  126. data/spec/lib/appsignal_spec.rb +601 -36
  127. data/spec/lib/puma/appsignal_spec.rb +0 -3
  128. data/spec/spec_helper.rb +5 -4
  129. data/spec/support/helpers/config_helpers.rb +2 -1
  130. data/spec/support/helpers/loader_helper.rb +21 -0
  131. data/spec/support/helpers/transaction_helpers.rb +44 -20
  132. data/spec/support/matchers/transaction.rb +15 -1
  133. data/spec/support/stubs/appsignal/loaders/loader_stub.rb +7 -0
  134. data/spec/support/testing.rb +47 -1
  135. metadata +19 -2
@@ -1,19 +1,4 @@
1
1
  describe Appsignal::Config do
2
- describe "config keys" do
3
- it "all config keys have an environment variable version registered" do
4
- config = Appsignal::Config
5
- mapped_env_keys = config::ENV_TO_KEY_MAPPING.keys.sort
6
- configured_env_keys = (
7
- config::ENV_STRING_KEYS +
8
- config::ENV_BOOLEAN_KEYS +
9
- config::ENV_ARRAY_KEYS +
10
- config::ENV_FLOAT_KEYS
11
- ).sort
12
-
13
- expect(mapped_env_keys).to eql(configured_env_keys)
14
- end
15
- end
16
-
17
2
  describe "#initialize" do
18
3
  describe "environment" do
19
4
  context "when environment is nil" do
@@ -26,7 +11,7 @@ describe Appsignal::Config do
26
11
 
27
12
  context "when environment is given" do
28
13
  let(:env) { "my_env" }
29
- let(:config) { described_class.new("", "my_env") }
14
+ let(:config) { described_class.new("/root/path", "my_env") }
30
15
 
31
16
  it "sets the environment" do
32
17
  expect(config.env).to eq(env)
@@ -35,6 +20,7 @@ describe Appsignal::Config do
35
20
  it "sets the environment as loaded through the initial_config" do
36
21
  expect(config.initial_config).to eq(:env => env)
37
22
  expect(config.config_hash).to_not have_key(:env)
23
+ expect(config.config_hash).to_not have_key(:root_path)
38
24
  end
39
25
 
40
26
  context "with APPSIGNAL_APP_ENV environment variable" do
@@ -49,6 +35,7 @@ describe Appsignal::Config do
49
35
  expect(config.initial_config).to eq(:env => env)
50
36
  expect(config.env_config).to eq(:env => env_env)
51
37
  expect(config.config_hash).to_not have_key(:env)
38
+ expect(config.config_hash).to_not have_key(:root_path)
52
39
  end
53
40
  end
54
41
  end
@@ -136,6 +123,76 @@ describe Appsignal::Config do
136
123
  end
137
124
  end
138
125
 
126
+ describe "loader default config" do
127
+ let(:config) do
128
+ described_class.new("some-path", "production")
129
+ end
130
+ before do
131
+ class TestLoader < Appsignal::Loaders::Loader
132
+ register :test
133
+ def on_load
134
+ register_config_defaults(
135
+ :env => "new_env",
136
+ :root_path => "/some/path",
137
+ :my_option => "my_value",
138
+ :nil_option => nil
139
+ )
140
+ end
141
+ end
142
+ load_loader(:test)
143
+ end
144
+ after do
145
+ Object.send(:remove_const, :TestLoader)
146
+ unregister_loader(:first)
147
+ end
148
+
149
+ it "merges with the loader defaults" do
150
+ expect(config.config_hash).to include(:my_option => "my_value")
151
+ end
152
+
153
+ it "does not set any nil values" do
154
+ expect(config.config_hash).to_not have_key(:nil_option)
155
+ end
156
+
157
+ it "overwrites the env" do
158
+ expect(config.env).to eq("new_env")
159
+ end
160
+
161
+ it "overwrites the path" do
162
+ expect(config.root_path).to eq("/some/path")
163
+ end
164
+
165
+ context "with multiple loaders" do
166
+ before do
167
+ class SecondLoader < Appsignal::Loaders::Loader
168
+ register :second
169
+ def on_load
170
+ register_config_defaults(
171
+ :env => "second_env",
172
+ :root_path => "/second/path",
173
+ :my_option => "second_value",
174
+ :second_option => "second_value"
175
+ )
176
+ end
177
+ end
178
+ load_loader(:second)
179
+ end
180
+ after do
181
+ Object.send(:remove_const, :SecondLoader)
182
+ unregister_loader(:second)
183
+ end
184
+
185
+ it "makes the first loader's config leading" do
186
+ expect(config.config_hash).to include(
187
+ :my_option => "my_value",
188
+ :second_option => "second_value"
189
+ )
190
+ expect(config.env).to eq("new_env")
191
+ expect(config.root_path).to eq("/some/path")
192
+ end
193
+ end
194
+ end
195
+
139
196
  describe "initial config" do
140
197
  let(:initial_config) do
141
198
  {
@@ -416,49 +473,159 @@ describe Appsignal::Config do
416
473
  let(:working_directory_path) { File.join(tmp_dir, "test_working_directory_path") }
417
474
  let(:env_config) do
418
475
  {
419
- :running_in_container => true,
420
- :push_api_key => "aaa-bbb-ccc",
421
476
  :active => true,
477
+ :activejob_report_errors => "all",
422
478
  :bind_address => "0.0.0.0",
479
+ :ca_file_path => "/some/path",
423
480
  :cpu_count => 1.5,
424
- :name => "App name",
425
481
  :debug => true,
426
482
  :dns_servers => ["8.8.8.8", "8.8.4.4"],
427
- :ignore_actions => %w[action1 action2],
428
- :ignore_errors => %w[ExampleStandardError AnotherError],
483
+ :enable_allocation_tracking => false,
484
+ :enable_gvl_global_timer => false,
485
+ :enable_gvl_waiting_threads => false,
486
+ :enable_host_metrics => false,
487
+ :enable_minutely_probes => false,
488
+ :enable_nginx_metrics => false,
489
+ :enable_rails_error_reporter => false,
490
+ :enable_rake_performance_instrumentation => false,
491
+ :enable_statsd => false,
492
+ :endpoint => "https://test.appsignal.com",
493
+ :files_world_accessible => false,
494
+ :filter_metadata => ["key1", "key2"],
495
+ :filter_parameters => ["param1", "param2"],
496
+ :filter_session_data => ["session1", "session2"],
497
+ :host_role => "my host role",
498
+ :hostname => "my hostname",
499
+ :http_proxy => "some proxy",
500
+ :ignore_actions => ["action1", "action2"],
501
+ :ignore_errors => ["ExampleStandardError", "AnotherError"],
429
502
  :ignore_logs => ["^start$", "^Completed 2.* in .*ms (.*)"],
430
- :ignore_namespaces => %w[admin private_namespace],
503
+ :ignore_namespaces => ["admin", "private_namespace"],
504
+ :instrument_http_rb => false,
431
505
  :instrument_net_http => false,
432
506
  :instrument_redis => false,
433
507
  :instrument_sequel => false,
434
- :files_world_accessible => false,
435
- :request_headers => %w[accept accept-charset],
508
+ :log => "file",
509
+ :log_level => "debug",
510
+ :log_path => "/tmp/something",
511
+ :logging_endpoint => "https://appsignal-endpoint.net/test",
512
+ :name => "App name",
513
+ :push_api_key => "aaa-bbb-ccc",
514
+ :request_headers => ["accept", "accept-charset"],
436
515
  :revision => "v2.5.1",
516
+ :running_in_container => true,
437
517
  :send_environment_metadata => false,
518
+ :send_params => false,
519
+ :send_session_data => false,
520
+ :sidekiq_report_errors => "all",
521
+ :skip_session_data => false,
522
+ :statsd_port => "7890",
523
+ :transaction_debug_mode => false,
524
+ :working_dir_path => "/some/path",
438
525
  :working_directory_path => working_directory_path
439
526
  }
440
527
  end
528
+ let(:env_vars) do
529
+ {
530
+ # Strings
531
+ "APPSIGNAL_ACTIVEJOB_REPORT_ERRORS" => "all",
532
+ "APPSIGNAL_APP_NAME" => "App name",
533
+ "APPSIGNAL_BIND_ADDRESS" => "0.0.0.0",
534
+ "APPSIGNAL_CA_FILE_PATH" => "/some/path",
535
+ "APPSIGNAL_HOSTNAME" => "my hostname",
536
+ "APPSIGNAL_HOST_ROLE" => "my host role",
537
+ "APPSIGNAL_HTTP_PROXY" => "some proxy",
538
+ "APPSIGNAL_LOG" => "file",
539
+ "APPSIGNAL_LOGGING_ENDPOINT" => "https://appsignal-endpoint.net/test",
540
+ "APPSIGNAL_LOG_LEVEL" => "debug",
541
+ "APPSIGNAL_LOG_PATH" => "/tmp/something",
542
+ "APPSIGNAL_PUSH_API_ENDPOINT" => "https://test.appsignal.com",
543
+ "APPSIGNAL_PUSH_API_KEY" => "aaa-bbb-ccc",
544
+ "APPSIGNAL_SIDEKIQ_REPORT_ERRORS" => "all",
545
+ "APPSIGNAL_STATSD_PORT" => "7890",
546
+ "APPSIGNAL_WORKING_DIRECTORY_PATH" => working_directory_path,
547
+ "APPSIGNAL_WORKING_DIR_PATH" => "/some/path",
548
+ "APP_REVISION" => "v2.5.1",
549
+
550
+ # Booleans
551
+ "APPSIGNAL_ACTIVE" => "true",
552
+ "APPSIGNAL_DEBUG" => "true",
553
+ "APPSIGNAL_ENABLE_ALLOCATION_TRACKING" => "false",
554
+ "APPSIGNAL_ENABLE_GVL_GLOBAL_TIMER" => "false",
555
+ "APPSIGNAL_ENABLE_GVL_WAITING_THREADS" => "false",
556
+ "APPSIGNAL_ENABLE_HOST_METRICS" => "false",
557
+ "APPSIGNAL_ENABLE_MINUTELY_PROBES" => "false",
558
+ "APPSIGNAL_ENABLE_NGINX_METRICS" => "false",
559
+ "APPSIGNAL_ENABLE_RAILS_ERROR_REPORTER" => "false",
560
+ "APPSIGNAL_ENABLE_RAKE_PERFORMANCE_INSTRUMENTATION" => "false",
561
+ "APPSIGNAL_ENABLE_STATSD" => "false",
562
+ "APPSIGNAL_FILES_WORLD_ACCESSIBLE" => "false",
563
+ "APPSIGNAL_INSTRUMENT_HTTP_RB" => "false",
564
+ "APPSIGNAL_INSTRUMENT_NET_HTTP" => "false",
565
+ "APPSIGNAL_INSTRUMENT_REDIS" => "false",
566
+ "APPSIGNAL_INSTRUMENT_SEQUEL" => "false",
567
+ "APPSIGNAL_RUNNING_IN_CONTAINER" => "true",
568
+ "APPSIGNAL_SEND_ENVIRONMENT_METADATA" => "false",
569
+ "APPSIGNAL_SEND_PARAMS" => "false",
570
+ "APPSIGNAL_SEND_SESSION_DATA" => "false",
571
+ "APPSIGNAL_SKIP_SESSION_DATA" => "false",
572
+ "APPSIGNAL_TRANSACTION_DEBUG_MODE" => "false",
573
+
574
+ # Arrays
575
+ "APPSIGNAL_DNS_SERVERS" => "8.8.8.8,8.8.4.4",
576
+ "APPSIGNAL_FILTER_METADATA" => "key1,key2",
577
+ "APPSIGNAL_FILTER_PARAMETERS" => "param1,param2",
578
+ "APPSIGNAL_FILTER_SESSION_DATA" => "session1,session2",
579
+ "APPSIGNAL_IGNORE_ACTIONS" => "action1,action2",
580
+ "APPSIGNAL_IGNORE_ERRORS" => "ExampleStandardError,AnotherError",
581
+ "APPSIGNAL_IGNORE_LOGS" => "^start$,^Completed 2.* in .*ms (.*)",
582
+ "APPSIGNAL_IGNORE_NAMESPACES" => "admin,private_namespace",
583
+ "APPSIGNAL_REQUEST_HEADERS" => "accept,accept-charset",
584
+
585
+ # Floats
586
+ "APPSIGNAL_CPU_COUNT" => "1.5"
587
+ }
588
+ end
441
589
  before do
442
- ENV["APPSIGNAL_RUNNING_IN_CONTAINER"] = "true"
443
- ENV["APPSIGNAL_PUSH_API_KEY"] = "aaa-bbb-ccc"
444
- ENV["APPSIGNAL_ACTIVE"] = "true"
445
- ENV["APPSIGNAL_APP_NAME"] = "App name"
446
- ENV["APPSIGNAL_BIND_ADDRESS"] = "0.0.0.0"
447
- ENV["APPSIGNAL_CPU_COUNT"] = "1.5"
448
- ENV["APPSIGNAL_DEBUG"] = "true"
449
- ENV["APPSIGNAL_DNS_SERVERS"] = "8.8.8.8,8.8.4.4"
450
- ENV["APPSIGNAL_IGNORE_ACTIONS"] = "action1,action2"
451
- ENV["APPSIGNAL_IGNORE_ERRORS"] = "ExampleStandardError,AnotherError"
452
- ENV["APPSIGNAL_IGNORE_LOGS"] = "^start$,^Completed 2.* in .*ms (.*)"
453
- ENV["APPSIGNAL_IGNORE_NAMESPACES"] = "admin,private_namespace"
454
- ENV["APPSIGNAL_INSTRUMENT_NET_HTTP"] = "false"
455
- ENV["APPSIGNAL_INSTRUMENT_REDIS"] = "false"
456
- ENV["APPSIGNAL_INSTRUMENT_SEQUEL"] = "false"
457
- ENV["APPSIGNAL_FILES_WORLD_ACCESSIBLE"] = "false"
458
- ENV["APPSIGNAL_REQUEST_HEADERS"] = "accept,accept-charset"
459
- ENV["APPSIGNAL_SEND_ENVIRONMENT_METADATA"] = "false"
460
- ENV["APPSIGNAL_WORKING_DIRECTORY_PATH"] = working_directory_path
461
- ENV["APP_REVISION"] = "v2.5.1"
590
+ env_vars.each do |key, value|
591
+ ENV[key] = value
592
+ end
593
+ end
594
+
595
+ it "reads all string env keys" do
596
+ config
597
+
598
+ Appsignal::Config::ENV_STRING_KEYS.each do |env_key, option|
599
+ ENV.fetch(env_key) { raise "Config env var '#{env_key}' is not set for this test" }
600
+ expect(config[option]).to eq(ENV.fetch(env_key, nil))
601
+ end
602
+ end
603
+
604
+ it "reads all boolean env keys" do
605
+ config
606
+
607
+ Appsignal::Config::ENV_BOOLEAN_KEYS.each do |env_key, option|
608
+ ENV.fetch(env_key) { raise "Config env var '#{env_key}' is not set for this test" }
609
+ expect(config[option]).to eq(ENV.fetch(env_key, nil) == "true")
610
+ end
611
+ end
612
+
613
+ it "reads all array env keys" do
614
+ config
615
+
616
+ Appsignal::Config::ENV_ARRAY_KEYS.each do |env_key, option|
617
+ ENV.fetch(env_key) { raise "Config env var '#{env_key}' is not set for this test" }
618
+ expect(config[option]).to eq(ENV.fetch(env_key, nil).split(","))
619
+ end
620
+ end
621
+
622
+ it "reads all float env keys" do
623
+ config
624
+
625
+ Appsignal::Config::ENV_FLOAT_KEYS.each do |env_key, option|
626
+ ENV.fetch(env_key) { raise "Config env var '#{env_key}' is not set for this test" }
627
+ expect(config[option]).to eq(ENV.fetch(env_key, nil).to_f)
628
+ end
462
629
  end
463
630
 
464
631
  it "overrides config with environment values" do
@@ -1164,4 +1331,84 @@ describe Appsignal::Config do
1164
1331
  end
1165
1332
  end
1166
1333
  end
1334
+
1335
+ describe Appsignal::Config::ConfigDSL do
1336
+ let(:env) { :production }
1337
+ let(:config) { project_fixture_config(env) }
1338
+ let(:dsl) { described_class.new(config) }
1339
+
1340
+ describe "default options" do
1341
+ let(:env) { :unknown_env }
1342
+
1343
+ it "returns default values for config options" do
1344
+ Appsignal::Config::DEFAULT_CONFIG.each do |option, value|
1345
+ expect(dsl.send(option)).to eq(value)
1346
+ end
1347
+ end
1348
+ end
1349
+
1350
+ it "returns already set values for config options" do
1351
+ ENV["APPSIGNAL_IGNORE_ERRORS"] = "my_error1,my_error2"
1352
+ config[:push_api_key] = "my push key"
1353
+ config[:ignore_actions] = ["My ignored action"]
1354
+
1355
+ expect(dsl.push_api_key).to eq("my push key")
1356
+ expect(dsl.ignore_actions).to eq(["My ignored action"])
1357
+ expect(dsl.ignore_errors).to eq(["my_error1", "my_error2"])
1358
+ end
1359
+
1360
+ it "returns the env" do
1361
+ expect(dsl.env).to eq("production")
1362
+ end
1363
+
1364
+ it "sets config options" do
1365
+ dsl.push_api_key = "my push key"
1366
+ dsl.ignore_actions = ["My ignored action"]
1367
+
1368
+ expect(dsl.push_api_key).to eq("my push key")
1369
+ expect(dsl.ignore_actions).to eq(["My ignored action"])
1370
+ end
1371
+
1372
+ it "doesn't update the config object" do
1373
+ dsl.push_api_key = "my push key"
1374
+
1375
+ expect(dsl.push_api_key).to eq("my push key")
1376
+ expect(config[:push_api_key]).to eq("abc") # Loaded from file
1377
+ end
1378
+
1379
+ it "casts strings to strings" do
1380
+ dsl.activejob_report_errors = :all
1381
+ dsl.sidekiq_report_errors = :all
1382
+
1383
+ expect(dsl.activejob_report_errors).to eq("all")
1384
+ expect(dsl.sidekiq_report_errors).to eq("all")
1385
+ end
1386
+
1387
+ it "casts booleans to booleans" do
1388
+ dsl.active = :yes
1389
+ dsl.enable_host_metrics = "An object representing a truthy value"
1390
+ dsl.send_params = true
1391
+ dsl.send_session_data = false
1392
+
1393
+ expect(dsl.active).to be(true)
1394
+ expect(dsl.enable_host_metrics).to be(true)
1395
+ expect(dsl.send_params).to be(true)
1396
+ expect(dsl.send_session_data).to be(false)
1397
+ end
1398
+
1399
+ it "casts arrays to arrays" do
1400
+ ignore_actions = Set.new
1401
+ ignore_actions << "my ignored action 1"
1402
+ ignore_actions << "my ignored action 2"
1403
+ dsl.ignore_actions = ignore_actions
1404
+
1405
+ expect(dsl.ignore_actions).to eq(["my ignored action 1", "my ignored action 2"])
1406
+ end
1407
+
1408
+ it "casts floats to floats" do
1409
+ dsl.cpu_count = 1
1410
+
1411
+ expect(dsl.cpu_count).to eq(1.0)
1412
+ end
1413
+ end
1167
1414
  end
@@ -16,8 +16,7 @@ describe Appsignal::Demo do
16
16
  end
17
17
 
18
18
  context "with config" do
19
- let(:config) { project_fixture_config("production") }
20
- before { Appsignal.config = config }
19
+ before { start_agent }
21
20
 
22
21
  it "returns true" do
23
22
  expect(subject).to eq(true)
@@ -1,8 +1,10 @@
1
1
  describe Appsignal::Environment do
2
2
  include EnvironmentMetadataHelper
3
3
 
4
- before(:context) { start_agent }
5
- before { capture_environment_metadata_report_calls }
4
+ before do
5
+ start_agent
6
+ capture_environment_metadata_report_calls
7
+ end
6
8
 
7
9
  def report(key, &value_block)
8
10
  described_class.report(key, &value_block)