appsignal 3.6.5 → 3.7.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: 7e49b3ec10a26021ffd8c443f281cbf4d74618ba2aa9c20b8690c7ab96b1b976
4
- data.tar.gz: a3ce7b25084fc17e7c17c7fb54ecc9f954a1a3849594bf21b5777a37f559620d
3
+ metadata.gz: dec1a369e0bac47e7f5a95ca739da65c860c881491c8597a308f5f46d2ae9a74
4
+ data.tar.gz: 9d0fe210cc0366f1b2efb4378c12eef17b57106f272c3d50b142894dae61ffb0
5
5
  SHA512:
6
- metadata.gz: 61347869e731de4bc86818535ddb295e977d1774f04cd27cf8255f506c9516b9b8a9ecb68e8e7df0c1b2bc57cd7f6b1cd9a1eab1fa6852b95b11c9c3750c4bfc
7
- data.tar.gz: c88ddfc0c2127f750ceaa82961a287893668462265326a52bf81a66e012c3ec89f3fd82a9b61ed0b3c9000170d04e907a9e0a42079eac48b2dda9f3c7f91d85b
6
+ metadata.gz: b4906cde89b1d23ae7d35c09e722e1557301e93103678fc221bf40da9b389bbf55a239c827237a9335ecbfebcbdcf73075318a89d6b7d9161f7314feaacf8241
7
+ data.tar.gz: f35b795cc7ac0d5f831f05f52721cb21d22fa0ed1326c5b2b209d9bd746225f8e8b8344aaa66a523972c9946cf93d93cf8f3bc5612221105c58d4da8996f5485
data/CHANGELOG.md CHANGED
@@ -1,5 +1,43 @@
1
1
  # AppSignal for Ruby gem Changelog
2
2
 
3
+ ## 3.7.0
4
+
5
+ _Published on 2024-04-22._
6
+
7
+ ### Added
8
+
9
+ - [5b0eb9b2](https://github.com/appsignal/appsignal-ruby/commit/5b0eb9b25ee3f5a738962acee9052dfce74acb29) minor - _Heartbeats are currently only available to beta testers. If you are interested in trying it out, [send an email to support@appsignal.com](mailto:support@appsignal.com?subject=Heartbeat%20beta)!_
10
+
11
+ ---
12
+
13
+ Add heartbeats support. You can send heartbeats directly from your code, to track the execution of certain processes:
14
+
15
+ ```ruby
16
+ def send_invoices()
17
+ # ... your code here ...
18
+ Appsignal.heartbeat("send_invoices")
19
+ end
20
+ ```
21
+
22
+ You can pass a block to `Appsignal.heartbeat`, to report to AppSignal both when the process starts, and when it finishes, allowing you to see the duration of the process:
23
+
24
+ ```ruby
25
+ def send_invoices()
26
+ Appsignal.heartbeat("send_invoices") do
27
+ # ... your code here ...
28
+ end
29
+ end
30
+ ```
31
+
32
+ If an exception is raised within the block, the finish event will not be reported to AppSignal, triggering a notification about the missing heartbeat. The exception will bubble outside of the heartbeat block.
33
+ - [5fc83cc1](https://github.com/appsignal/appsignal-ruby/commit/5fc83cc186b1574d759731c5191edf13cf8339b7) patch - Implement the `ignore_logs` configuration option, which can also be configured as the `APPSIGNAL_IGNORE_LOGS` environment variable.
34
+
35
+ The value of `ignore_logs` is a list (comma-separated, when using the environment variable) of log line messages that should be ignored. For example, the value `"start"` will cause any message containing the word "start" to be ignored. Any log line message containing a value in `ignore_logs` will not be reported to AppSignal.
36
+
37
+ The values can use a small subset of regular expression syntax (specifically, `^`, `$` and `.*`) to narrow or expand the scope of lines that should be matched.
38
+
39
+ For example, the value `"^start$"` can be used to ignore any message that is _exactly_ the word "start", but not messages that merely contain it, like "Process failed to start". The value `"Task .* succeeded"` can be used to ignore messages about task success regardless of the specific task name.
40
+
3
41
  ## 3.6.5
4
42
 
5
43
  _Published on 2024-04-17._
data/ext/agent.rb CHANGED
@@ -6,7 +6,7 @@
6
6
  # Modifications to this file will be overwritten with the next agent release.
7
7
 
8
8
  APPSIGNAL_AGENT_CONFIG = {
9
- "version" => "0.34.2",
9
+ "version" => "0.35.2",
10
10
  "mirrors" => [
11
11
  "https://appsignal-agent-releases.global.ssl.fastly.net",
12
12
  "https://d135dj0rjqvssy.cloudfront.net"
@@ -14,131 +14,131 @@ APPSIGNAL_AGENT_CONFIG = {
14
14
  "triples" => {
15
15
  "x86_64-darwin" => {
16
16
  "static" => {
17
- "checksum" => "5bf07d396b22fd414eac70c545c710ab60114b1a2fa28aa92f8a5379483fe8fc",
17
+ "checksum" => "4a01803fae744971e2da08a325acb88a5f79bf44cbde03456652affb91fa0817",
18
18
  "filename" => "appsignal-x86_64-darwin-all-static.tar.gz"
19
19
  },
20
20
  "dynamic" => {
21
- "checksum" => "d58133f8fd7e47906392e8b587e2ad29e8a31404ac7a6dc78650699b9ef84bd1",
21
+ "checksum" => "843f6bfd798b7ae829c4a169f249a5576f01eb102755e1851f2901d4ddfff1b0",
22
22
  "filename" => "appsignal-x86_64-darwin-all-dynamic.tar.gz"
23
23
  }
24
24
  },
25
25
  "universal-darwin" => {
26
26
  "static" => {
27
- "checksum" => "5bf07d396b22fd414eac70c545c710ab60114b1a2fa28aa92f8a5379483fe8fc",
27
+ "checksum" => "4a01803fae744971e2da08a325acb88a5f79bf44cbde03456652affb91fa0817",
28
28
  "filename" => "appsignal-x86_64-darwin-all-static.tar.gz"
29
29
  },
30
30
  "dynamic" => {
31
- "checksum" => "d58133f8fd7e47906392e8b587e2ad29e8a31404ac7a6dc78650699b9ef84bd1",
31
+ "checksum" => "843f6bfd798b7ae829c4a169f249a5576f01eb102755e1851f2901d4ddfff1b0",
32
32
  "filename" => "appsignal-x86_64-darwin-all-dynamic.tar.gz"
33
33
  }
34
34
  },
35
35
  "aarch64-darwin" => {
36
36
  "static" => {
37
- "checksum" => "6099dfa72394de9e19e8524c19e5292cacd2359a5ceac634c878c113b6f5e875",
37
+ "checksum" => "c80fa534a0f34d0056102ed5ec21cb558b714b17dc2a91f62fabdb992acc8a54",
38
38
  "filename" => "appsignal-aarch64-darwin-all-static.tar.gz"
39
39
  },
40
40
  "dynamic" => {
41
- "checksum" => "be6bef642febaae556086b7a26e8676c3f1496277150e6a9330ce1afe6a4a7c2",
41
+ "checksum" => "53139766b4a6459f6db2ef0e9175ab7828652594f32a885fe0d650bdd1748719",
42
42
  "filename" => "appsignal-aarch64-darwin-all-dynamic.tar.gz"
43
43
  }
44
44
  },
45
45
  "arm64-darwin" => {
46
46
  "static" => {
47
- "checksum" => "6099dfa72394de9e19e8524c19e5292cacd2359a5ceac634c878c113b6f5e875",
47
+ "checksum" => "c80fa534a0f34d0056102ed5ec21cb558b714b17dc2a91f62fabdb992acc8a54",
48
48
  "filename" => "appsignal-aarch64-darwin-all-static.tar.gz"
49
49
  },
50
50
  "dynamic" => {
51
- "checksum" => "be6bef642febaae556086b7a26e8676c3f1496277150e6a9330ce1afe6a4a7c2",
51
+ "checksum" => "53139766b4a6459f6db2ef0e9175ab7828652594f32a885fe0d650bdd1748719",
52
52
  "filename" => "appsignal-aarch64-darwin-all-dynamic.tar.gz"
53
53
  }
54
54
  },
55
55
  "arm-darwin" => {
56
56
  "static" => {
57
- "checksum" => "6099dfa72394de9e19e8524c19e5292cacd2359a5ceac634c878c113b6f5e875",
57
+ "checksum" => "c80fa534a0f34d0056102ed5ec21cb558b714b17dc2a91f62fabdb992acc8a54",
58
58
  "filename" => "appsignal-aarch64-darwin-all-static.tar.gz"
59
59
  },
60
60
  "dynamic" => {
61
- "checksum" => "be6bef642febaae556086b7a26e8676c3f1496277150e6a9330ce1afe6a4a7c2",
61
+ "checksum" => "53139766b4a6459f6db2ef0e9175ab7828652594f32a885fe0d650bdd1748719",
62
62
  "filename" => "appsignal-aarch64-darwin-all-dynamic.tar.gz"
63
63
  }
64
64
  },
65
65
  "aarch64-linux" => {
66
66
  "static" => {
67
- "checksum" => "34061220065890545627b8988062950a20ab873f297c1e3ba1c1709038c23c96",
67
+ "checksum" => "71236975f40316d67c2b0e797814d52a49df8c5941375c0aed81c6870d82f299",
68
68
  "filename" => "appsignal-aarch64-linux-all-static.tar.gz"
69
69
  },
70
70
  "dynamic" => {
71
- "checksum" => "6d6da3fb88012143081d07a1adefb60cbc9868acb9ad5a260df68b12aec0ab4d",
71
+ "checksum" => "b9dffb56bbf0f1fe5538e914c9a0124c10390ce88077351b1e47cb93efbce1e5",
72
72
  "filename" => "appsignal-aarch64-linux-all-dynamic.tar.gz"
73
73
  }
74
74
  },
75
75
  "i686-linux" => {
76
76
  "static" => {
77
- "checksum" => "f8285d87fa72717889e89059a64bba7e98c45ecc720e533c2b4fc92c60a30a04",
77
+ "checksum" => "00ab0d029ede31225b2d134cdfab1e2c75e15e96229ef9e89ac14f51b8329988",
78
78
  "filename" => "appsignal-i686-linux-all-static.tar.gz"
79
79
  },
80
80
  "dynamic" => {
81
- "checksum" => "5f59ea1875a86124cdd215a75fb964c2dcef8c0689b3ae116a693a451c7cdb0c",
81
+ "checksum" => "8a6aba576fc1c9ba419758e49d6d5fc9ffd636f983e160a7595871f09f382e9b",
82
82
  "filename" => "appsignal-i686-linux-all-dynamic.tar.gz"
83
83
  }
84
84
  },
85
85
  "x86-linux" => {
86
86
  "static" => {
87
- "checksum" => "f8285d87fa72717889e89059a64bba7e98c45ecc720e533c2b4fc92c60a30a04",
87
+ "checksum" => "00ab0d029ede31225b2d134cdfab1e2c75e15e96229ef9e89ac14f51b8329988",
88
88
  "filename" => "appsignal-i686-linux-all-static.tar.gz"
89
89
  },
90
90
  "dynamic" => {
91
- "checksum" => "5f59ea1875a86124cdd215a75fb964c2dcef8c0689b3ae116a693a451c7cdb0c",
91
+ "checksum" => "8a6aba576fc1c9ba419758e49d6d5fc9ffd636f983e160a7595871f09f382e9b",
92
92
  "filename" => "appsignal-i686-linux-all-dynamic.tar.gz"
93
93
  }
94
94
  },
95
95
  "x86_64-linux" => {
96
96
  "static" => {
97
- "checksum" => "fd6718fee5638986b77ebd777649f013b52f69f4b1886c41c85626c6f901bcb9",
97
+ "checksum" => "2e96245f692f47ee8fd12cca92b620baf79845ec920fb19b38612dd1cb051961",
98
98
  "filename" => "appsignal-x86_64-linux-all-static.tar.gz"
99
99
  },
100
100
  "dynamic" => {
101
- "checksum" => "13f09cc708cb75a6fcc43cc52166992f0fd56d40927cd8b25fd32e7a53de11d3",
101
+ "checksum" => "c64e9903bddf0478ab9bbc316ce8ab46c0998173c922312fee527045e91554ad",
102
102
  "filename" => "appsignal-x86_64-linux-all-dynamic.tar.gz"
103
103
  }
104
104
  },
105
105
  "x86_64-linux-musl" => {
106
106
  "static" => {
107
- "checksum" => "561626ac2bf31c6a5af9d21994fe7ca55cc89619b0db0d1f575d311259e99bae",
107
+ "checksum" => "a99ebcdf993cd740dc556de9fba6e7ce1c802704c290c4d8b842cb4dc971473a",
108
108
  "filename" => "appsignal-x86_64-linux-musl-all-static.tar.gz"
109
109
  },
110
110
  "dynamic" => {
111
- "checksum" => "905f9ec4138ed9c66e460ceb03e521b8aa1ade15a8fdf20c7a3b5352d1595c02",
111
+ "checksum" => "bfb583eebc82c2ae22f904a423df5af3cbf899225ffd8a3f96d0158985aa6e7c",
112
112
  "filename" => "appsignal-x86_64-linux-musl-all-dynamic.tar.gz"
113
113
  }
114
114
  },
115
115
  "aarch64-linux-musl" => {
116
116
  "static" => {
117
- "checksum" => "03d8464040796f2d242ce66f12297f238d686794a0c2fe4090e0cde1b7bee272",
117
+ "checksum" => "874542de2899dc7ef6d286f1cb719614877651c6cafc9f5ae73d37d1aa0e61da",
118
118
  "filename" => "appsignal-aarch64-linux-musl-all-static.tar.gz"
119
119
  },
120
120
  "dynamic" => {
121
- "checksum" => "805b27b9ced058f79627700ac0e04cb458e888c6df753104b778cf5c18793f98",
121
+ "checksum" => "02f895487486732bce4cbbed251275a3fc4830a4e890c592f2e95559a5ca11d5",
122
122
  "filename" => "appsignal-aarch64-linux-musl-all-dynamic.tar.gz"
123
123
  }
124
124
  },
125
125
  "x86_64-freebsd" => {
126
126
  "static" => {
127
- "checksum" => "422cbc821ac99087ca132aa1ac4290cdf08d6f5b8c24fed18e7d321b1ea8e460",
127
+ "checksum" => "f30c529ed4fffe4f0668bcb59881061b22050813d9d10acf5a4bf03f4547a51b",
128
128
  "filename" => "appsignal-x86_64-freebsd-all-static.tar.gz"
129
129
  },
130
130
  "dynamic" => {
131
- "checksum" => "9167daf766e3d1c4a7cdcd49e21f6c22e553d24760ecb78652c5601ae8df513c",
131
+ "checksum" => "da6f4e31097ab2315b5bbffa8752284e40b535f4900057dc273a7bc7a23ac1ac",
132
132
  "filename" => "appsignal-x86_64-freebsd-all-dynamic.tar.gz"
133
133
  }
134
134
  },
135
135
  "amd64-freebsd" => {
136
136
  "static" => {
137
- "checksum" => "422cbc821ac99087ca132aa1ac4290cdf08d6f5b8c24fed18e7d321b1ea8e460",
137
+ "checksum" => "f30c529ed4fffe4f0668bcb59881061b22050813d9d10acf5a4bf03f4547a51b",
138
138
  "filename" => "appsignal-x86_64-freebsd-all-static.tar.gz"
139
139
  },
140
140
  "dynamic" => {
141
- "checksum" => "9167daf766e3d1c4a7cdcd49e21f6c22e553d24760ecb78652c5601ae8df513c",
141
+ "checksum" => "da6f4e31097ab2315b5bbffa8752284e40b535f4900057dc273a7bc7a23ac1ac",
142
142
  "filename" => "appsignal-x86_64-freebsd-all-dynamic.tar.gz"
143
143
  }
144
144
  }
@@ -30,6 +30,7 @@ module Appsignal
30
30
  :filter_session_data => [],
31
31
  :ignore_actions => [],
32
32
  :ignore_errors => [],
33
+ :ignore_logs => [],
33
34
  :ignore_namespaces => [],
34
35
  :instrument_http_rb => true,
35
36
  :instrument_net_http => true,
@@ -90,6 +91,7 @@ module Appsignal
90
91
  "APPSIGNAL_HTTP_PROXY" => :http_proxy,
91
92
  "APPSIGNAL_IGNORE_ACTIONS" => :ignore_actions,
92
93
  "APPSIGNAL_IGNORE_ERRORS" => :ignore_errors,
94
+ "APPSIGNAL_IGNORE_LOGS" => :ignore_logs,
93
95
  "APPSIGNAL_IGNORE_NAMESPACES" => :ignore_namespaces,
94
96
  "APPSIGNAL_INSTRUMENT_HTTP_RB" => :instrument_http_rb,
95
97
  "APPSIGNAL_INSTRUMENT_NET_HTTP" => :instrument_net_http,
@@ -165,6 +167,7 @@ module Appsignal
165
167
  APPSIGNAL_FILTER_SESSION_DATA
166
168
  APPSIGNAL_IGNORE_ACTIONS
167
169
  APPSIGNAL_IGNORE_ERRORS
170
+ APPSIGNAL_IGNORE_LOGS
168
171
  APPSIGNAL_IGNORE_NAMESPACES
169
172
  APPSIGNAL_REQUEST_HEADERS
170
173
  ].freeze
@@ -363,6 +366,7 @@ module Appsignal
363
366
  ENV["_APPSIGNAL_HTTP_PROXY"] = config_hash[:http_proxy]
364
367
  ENV["_APPSIGNAL_IGNORE_ACTIONS"] = config_hash[:ignore_actions].join(",")
365
368
  ENV["_APPSIGNAL_IGNORE_ERRORS"] = config_hash[:ignore_errors].join(",")
369
+ ENV["_APPSIGNAL_IGNORE_LOGS"] = config_hash[:ignore_logs].join(",")
366
370
  ENV["_APPSIGNAL_IGNORE_NAMESPACES"] = config_hash[:ignore_namespaces].join(",")
367
371
  ENV["_APPSIGNAL_LANGUAGE_INTEGRATION_VERSION"] = "ruby-#{Appsignal::VERSION}"
368
372
  ENV["_APPSIGNAL_LOG"] = config_hash[:log]
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Appsignal
4
+ class Heartbeat
5
+ class << self
6
+ def transmitter
7
+ @transmitter ||= Appsignal::Transmitter.new(
8
+ "#{Appsignal.config[:logging_endpoint]}/heartbeats/json"
9
+ )
10
+ end
11
+ end
12
+
13
+ attr_reader :name, :id
14
+
15
+ def initialize(name:)
16
+ @name = name
17
+ @id = SecureRandom.hex(8)
18
+ end
19
+
20
+ def start
21
+ transmit_event("start")
22
+ end
23
+
24
+ def finish
25
+ transmit_event("finish")
26
+ end
27
+
28
+ private
29
+
30
+ def event(kind)
31
+ {
32
+ :name => name,
33
+ :id => @id,
34
+ :kind => kind,
35
+ :timestamp => Time.now.utc.to_i
36
+ }
37
+ end
38
+
39
+ def transmit_event(kind)
40
+ unless Appsignal.active?
41
+ Appsignal.internal_logger.debug("AppSignal not active, not transmitting heartbeat event")
42
+ return
43
+ end
44
+
45
+ response = self.class.transmitter.transmit(event(kind))
46
+
47
+ if response.code.to_i >= 200 && response.code.to_i < 300
48
+ Appsignal.internal_logger.trace("Transmitted heartbeat `#{name}` (#{id}) #{kind} event")
49
+ else
50
+ Appsignal.internal_logger.error(
51
+ "Failed to transmit heartbeat event: status code was #{response.code}"
52
+ )
53
+ end
54
+ rescue => e
55
+ Appsignal.internal_logger.error("Failed to transmit heartbeat event: #{e}")
56
+ end
57
+ end
58
+
59
+ def self.heartbeat(name)
60
+ heartbeat = Appsignal::Heartbeat.new(:name => name)
61
+ output = nil
62
+
63
+ if block_given?
64
+ heartbeat.start
65
+ output = yield
66
+ end
67
+
68
+ heartbeat.finish
69
+ output
70
+ end
71
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Appsignal
4
- VERSION = "3.6.5"
4
+ VERSION = "3.7.0"
5
5
  end
data/lib/appsignal.rb CHANGED
@@ -307,3 +307,4 @@ require "appsignal/transaction"
307
307
  require "appsignal/version"
308
308
  require "appsignal/rack/generic_instrumentation"
309
309
  require "appsignal/transmitter"
310
+ require "appsignal/heartbeat"
@@ -172,6 +172,7 @@ describe Appsignal::Config do
172
172
  :filter_session_data => [],
173
173
  :ignore_actions => [],
174
174
  :ignore_errors => [],
175
+ :ignore_logs => [],
175
176
  :ignore_namespaces => [],
176
177
  :instrument_http_rb => true,
177
178
  :instrument_net_http => true,
@@ -421,6 +422,7 @@ describe Appsignal::Config do
421
422
  :dns_servers => ["8.8.8.8", "8.8.4.4"],
422
423
  :ignore_actions => %w[action1 action2],
423
424
  :ignore_errors => %w[ExampleStandardError AnotherError],
425
+ :ignore_logs => ["^start$", "^Completed 2.* in .*ms (.*)"],
424
426
  :ignore_namespaces => %w[admin private_namespace],
425
427
  :instrument_net_http => false,
426
428
  :instrument_redis => false,
@@ -443,6 +445,7 @@ describe Appsignal::Config do
443
445
  ENV["APPSIGNAL_DNS_SERVERS"] = "8.8.8.8,8.8.4.4"
444
446
  ENV["APPSIGNAL_IGNORE_ACTIONS"] = "action1,action2"
445
447
  ENV["APPSIGNAL_IGNORE_ERRORS"] = "ExampleStandardError,AnotherError"
448
+ ENV["APPSIGNAL_IGNORE_LOGS"] = "^start$,^Completed 2.* in .*ms (.*)"
446
449
  ENV["APPSIGNAL_IGNORE_NAMESPACES"] = "admin,private_namespace"
447
450
  ENV["APPSIGNAL_INSTRUMENT_NET_HTTP"] = "false"
448
451
  ENV["APPSIGNAL_INSTRUMENT_REDIS"] = "false"
@@ -639,6 +642,7 @@ describe Appsignal::Config do
639
642
  config[:http_proxy] = "http://localhost"
640
643
  config[:ignore_actions] = %w[action1 action2]
641
644
  config[:ignore_errors] = %w[ExampleStandardError AnotherError]
645
+ config[:ignore_logs] = ["^start$", "^Completed 2.* in .*ms (.*)"]
642
646
  config[:ignore_namespaces] = %w[admin private_namespace]
643
647
  config[:log] = "stdout"
644
648
  config[:log_path] = "/tmp"
@@ -672,6 +676,7 @@ describe Appsignal::Config do
672
676
  expect(ENV.fetch("_APPSIGNAL_HTTP_PROXY", nil)).to eq "http://localhost"
673
677
  expect(ENV.fetch("_APPSIGNAL_IGNORE_ACTIONS", nil)).to eq "action1,action2"
674
678
  expect(ENV.fetch("_APPSIGNAL_IGNORE_ERRORS", nil)).to eq "ExampleStandardError,AnotherError"
679
+ expect(ENV.fetch("_APPSIGNAL_IGNORE_LOGS", nil)).to eq "^start$,^Completed 2.* in .*ms (.*)"
675
680
  expect(ENV.fetch("_APPSIGNAL_IGNORE_NAMESPACES", nil)).to eq "admin,private_namespace"
676
681
  expect(ENV.fetch("_APPSIGNAL_RUNNING_IN_CONTAINER", nil)).to eq "false"
677
682
  expect(ENV.fetch("_APPSIGNAL_ENABLE_HOST_METRICS", nil)).to eq "true"
@@ -0,0 +1,89 @@
1
+ describe Appsignal::Heartbeat do
2
+ let(:config) { project_fixture_config }
3
+ let(:heartbeat) { described_class.new(:name => "heartbeat-name") }
4
+ let(:transmitter) { Appsignal::Transmitter.new("http://heartbeats/", config) }
5
+
6
+ before(:each) do
7
+ allow(Appsignal).to receive(:active?).and_return(true)
8
+ config.logger = Logger.new(StringIO.new)
9
+ allow(Appsignal::Heartbeat).to receive(:transmitter).and_return(transmitter)
10
+ end
11
+
12
+ describe "when Appsignal is not active" do
13
+ it "should not transmit any events" do
14
+ allow(Appsignal).to receive(:active?).and_return(false)
15
+ expect(transmitter).not_to receive(:transmit)
16
+
17
+ heartbeat.start
18
+ heartbeat.finish
19
+ end
20
+ end
21
+
22
+ describe "#start" do
23
+ it "should send a heartbeat start" do
24
+ expect(transmitter).to receive(:transmit).with(hash_including(
25
+ :name => "heartbeat-name",
26
+ :kind => "start"
27
+ )).and_return(nil)
28
+
29
+ heartbeat.start
30
+ end
31
+ end
32
+
33
+ describe "#finish" do
34
+ it "should send a heartbeat finish" do
35
+ expect(transmitter).to receive(:transmit).with(hash_including(
36
+ :name => "heartbeat-name",
37
+ :kind => "finish"
38
+ )).and_return(nil)
39
+
40
+ heartbeat.finish
41
+ end
42
+ end
43
+
44
+ describe ".heartbeat" do
45
+ describe "when a block is given" do
46
+ it "should send a heartbeat start and finish and return the block output" do
47
+ expect(transmitter).to receive(:transmit).with(hash_including(
48
+ :kind => "start",
49
+ :name => "heartbeat-with-block"
50
+ )).and_return(nil)
51
+
52
+ expect(transmitter).to receive(:transmit).with(hash_including(
53
+ :kind => "finish",
54
+ :name => "heartbeat-with-block"
55
+ )).and_return(nil)
56
+
57
+ output = Appsignal.heartbeat("heartbeat-with-block") { "output" }
58
+ expect(output).to eq("output")
59
+ end
60
+
61
+ it "should not send a heartbeat finish event when an error is raised" do
62
+ expect(transmitter).to receive(:transmit).with(hash_including(
63
+ :kind => "start",
64
+ :name => "heartbeat-with-block"
65
+ )).and_return(nil)
66
+
67
+ expect(transmitter).not_to receive(:transmit).with(hash_including(
68
+ :kind => "finish",
69
+ :name => "heartbeat-with-block"
70
+ ))
71
+
72
+ expect do
73
+ Appsignal.heartbeat("heartbeat-with-block") { raise "error" }
74
+ end.to raise_error(RuntimeError, "error")
75
+ end
76
+ end
77
+
78
+ describe "when no block is given" do
79
+ it "should only send a heartbeat finish event" do
80
+ expect(transmitter).to receive(:transmit).with(hash_including(
81
+ :kind => "finish",
82
+ :name => "heartbeat-without-block"
83
+ )).and_return(nil)
84
+
85
+ Appsignal.heartbeat("heartbeat-without-block")
86
+ end
87
+ end
88
+ end
89
+ end
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.6.5
4
+ version: 3.7.0
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: 2024-04-17 00:00:00.000000000 Z
13
+ date: 2024-04-22 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rack
@@ -206,6 +206,7 @@ files:
206
206
  - lib/appsignal/extension.rb
207
207
  - lib/appsignal/extension/jruby.rb
208
208
  - lib/appsignal/garbage_collection.rb
209
+ - lib/appsignal/heartbeat.rb
209
210
  - lib/appsignal/helpers/instrumentation.rb
210
211
  - lib/appsignal/helpers/metrics.rb
211
212
  - lib/appsignal/hooks.rb
@@ -318,6 +319,7 @@ files:
318
319
  - spec/lib/appsignal/extension_install_failure_spec.rb
319
320
  - spec/lib/appsignal/extension_spec.rb
320
321
  - spec/lib/appsignal/garbage_collection_spec.rb
322
+ - spec/lib/appsignal/heartbeat_spec.rb
321
323
  - spec/lib/appsignal/hooks/action_cable_spec.rb
322
324
  - spec/lib/appsignal/hooks/action_mailer_spec.rb
323
325
  - spec/lib/appsignal/hooks/active_support_notifications/finish_with_state_shared_examples.rb