appsignal 3.9.1-java → 3.9.3-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +3135 -0
  3. data/.rubocop.yml +28 -20
  4. data/.rubocop_todo.yml +7 -33
  5. data/CHANGELOG.md +58 -0
  6. data/Rakefile +79 -64
  7. data/appsignal.gemspec +1 -1
  8. data/build_matrix.yml +109 -179
  9. data/ext/base.rb +1 -1
  10. data/gemfiles/hanami-2.1.gemfile +7 -0
  11. data/lib/appsignal/cli/diagnose.rb +1 -1
  12. data/lib/appsignal/config.rb +1 -1
  13. data/lib/appsignal/demo.rb +0 -1
  14. data/lib/appsignal/environment.rb +5 -1
  15. data/lib/appsignal/extension/jruby.rb +1 -1
  16. data/lib/appsignal/helpers/instrumentation.rb +3 -3
  17. data/lib/appsignal/hooks/active_job.rb +2 -1
  18. data/lib/appsignal/integrations/action_cable.rb +1 -1
  19. data/lib/appsignal/integrations/grape.rb +19 -47
  20. data/lib/appsignal/integrations/hanami.rb +27 -41
  21. data/lib/appsignal/integrations/padrino.rb +46 -43
  22. data/lib/appsignal/integrations/railtie.rb +1 -4
  23. data/lib/appsignal/integrations/resque.rb +1 -1
  24. data/lib/appsignal/integrations/sidekiq.rb +2 -4
  25. data/lib/appsignal/integrations/sinatra.rb +7 -2
  26. data/lib/appsignal/probes/gvl.rb +24 -2
  27. data/lib/appsignal/probes/sidekiq.rb +1 -1
  28. data/lib/appsignal/probes.rb +1 -1
  29. data/lib/appsignal/rack/abstract_middleware.rb +62 -28
  30. data/lib/appsignal/rack/event_handler.rb +37 -26
  31. data/lib/appsignal/rack/grape_middleware.rb +40 -0
  32. data/lib/appsignal/rack/hanami_middleware.rb +20 -0
  33. data/lib/appsignal/rack/rails_instrumentation.rb +14 -56
  34. data/lib/appsignal/utils/integration_memory_logger.rb +78 -0
  35. data/lib/appsignal/utils.rb +1 -0
  36. data/lib/appsignal/version.rb +1 -1
  37. data/lib/appsignal.rb +34 -33
  38. data/spec/.rubocop.yml +1 -1
  39. data/spec/lib/appsignal/cli/diagnose_spec.rb +1 -1
  40. data/spec/lib/appsignal/cli/install_spec.rb +3 -3
  41. data/spec/lib/appsignal/config_spec.rb +7 -5
  42. data/spec/lib/appsignal/demo_spec.rb +38 -41
  43. data/spec/lib/appsignal/hooks/action_cable_spec.rb +86 -167
  44. data/spec/lib/appsignal/hooks/active_support_notifications/finish_with_state_shared_examples.rb +8 -20
  45. data/spec/lib/appsignal/hooks/active_support_notifications/instrument_shared_examples.rb +38 -84
  46. data/spec/lib/appsignal/hooks/active_support_notifications/start_finish_shared_examples.rb +16 -37
  47. data/spec/lib/appsignal/hooks/active_support_notifications_spec.rb +4 -4
  48. data/spec/lib/appsignal/hooks/activejob_spec.rb +111 -200
  49. data/spec/lib/appsignal/hooks/delayed_job_spec.rb +54 -91
  50. data/spec/lib/appsignal/hooks/dry_monitor_spec.rb +14 -32
  51. data/spec/lib/appsignal/hooks/excon_spec.rb +8 -12
  52. data/spec/lib/appsignal/hooks/net_http_spec.rb +7 -42
  53. data/spec/lib/appsignal/hooks/rake_spec.rb +9 -19
  54. data/spec/lib/appsignal/hooks/redis_client_spec.rb +18 -30
  55. data/spec/lib/appsignal/hooks/redis_spec.rb +10 -16
  56. data/spec/lib/appsignal/hooks/resque_spec.rb +42 -62
  57. data/spec/lib/appsignal/hooks/shoryuken_spec.rb +33 -74
  58. data/spec/lib/appsignal/integrations/hanami_spec.rb +126 -64
  59. data/spec/lib/appsignal/integrations/http_spec.rb +12 -20
  60. data/spec/lib/appsignal/integrations/net_http_spec.rb +33 -0
  61. data/spec/lib/appsignal/integrations/object_spec.rb +29 -36
  62. data/spec/lib/appsignal/integrations/padrino_spec.rb +47 -70
  63. data/spec/lib/appsignal/integrations/que_spec.rb +43 -70
  64. data/spec/lib/appsignal/integrations/railtie_spec.rb +26 -67
  65. data/spec/lib/appsignal/integrations/sidekiq_spec.rb +86 -160
  66. data/spec/lib/appsignal/integrations/sinatra_spec.rb +8 -3
  67. data/spec/lib/appsignal/integrations/webmachine_spec.rb +28 -39
  68. data/spec/lib/appsignal/probes/gvl_spec.rb +80 -3
  69. data/spec/lib/appsignal/probes_spec.rb +7 -4
  70. data/spec/lib/appsignal/rack/abstract_middleware_spec.rb +215 -106
  71. data/spec/lib/appsignal/rack/event_handler_spec.rb +151 -69
  72. data/spec/lib/appsignal/rack/generic_instrumentation_spec.rb +2 -12
  73. data/spec/lib/appsignal/rack/grape_middleware_spec.rb +234 -0
  74. data/spec/lib/appsignal/rack/hanami_middleware_spec.rb +36 -0
  75. data/spec/lib/appsignal/rack/rails_instrumentation_spec.rb +67 -131
  76. data/spec/lib/appsignal/rack/sinatra_instrumentation_spec.rb +36 -44
  77. data/spec/lib/appsignal/rack/streaming_listener_spec.rb +68 -86
  78. data/spec/lib/appsignal/transaction_spec.rb +79 -93
  79. data/spec/lib/appsignal/utils/integration_memory_logger_spec.rb +163 -0
  80. data/spec/lib/appsignal_spec.rb +363 -342
  81. data/spec/support/hanami/hanami_app.rb +1 -3
  82. data/spec/support/helpers/dependency_helper.rb +6 -1
  83. data/spec/support/helpers/std_streams_helper.rb +1 -1
  84. data/spec/support/helpers/transaction_helpers.rb +8 -0
  85. data/spec/support/matchers/transaction.rb +185 -0
  86. data/spec/support/mocks/dummy_app.rb +20 -0
  87. data/spec/support/shared_examples/instrument.rb +17 -12
  88. data/spec/support/testing.rb +18 -9
  89. metadata +17 -10
  90. data/.semaphore/semaphore.yml +0 -2347
  91. data/script/lint_git +0 -22
  92. data/spec/lib/appsignal/integrations/grape_spec.rb +0 -239
  93. data/spec/support/matchers/be_completed.rb +0 -5
  94. /data/gemfiles/{hanami.gemfile → hanami-2.0.gemfile} +0 -0
data/build_matrix.yml CHANGED
@@ -1,158 +1,81 @@
1
- semaphore: # Default `.semaphore/semaphore.yml` contents
2
- version: v1.0
3
- name: AppSignal Ruby Build and Tests
1
+ github:
2
+ name: Ruby gem CI
3
+ "on":
4
+ push:
5
+ branches:
6
+ - "main"
7
+ - "develop"
8
+ pull_request:
9
+ types:
10
+ - opened
11
+ - reopened
12
+ - synchronize
4
13
 
5
- agent:
6
- machine:
7
- type: e1-standard-2
8
- os_image: ubuntu2004
14
+ concurrency:
15
+ group: ${{ github.workflow }}-${{ github.ref }}
16
+ cancel-in-progress: ${{ !contains(github.ref, 'main')}}
9
17
 
10
- # Cancel all running and queued workflows before this one
11
- auto_cancel:
12
- running:
13
- # Ignore main AND develop branch as we want it to build all workflows
14
- when: "branch != 'main' AND branch != 'develop'"
18
+ jobs:
19
+ lint-git:
20
+ name: "Git linter (Lintje)"
21
+ runs-on: ubuntu-latest
22
+ steps:
23
+ - uses: actions/checkout@v4
24
+ with:
25
+ fetch-depth: 0 # Fetch depth is required
26
+ - name: "Run Git linter"
27
+ uses: lintje/action@v0.11
15
28
 
16
- global_job_config:
17
- env_vars:
18
- - name: RUNNING_IN_CI
19
- value: "true"
20
- - name: _BUNDLER_CACHE
21
- value: "v3"
22
- - name: _GEMS_CACHE
23
- value: "v3"
24
- prologue:
25
- commands:
26
- - checkout
27
- - rm -f $HOME/.rbenv/plugins/rbenv-gem-rehash/etc/rbenv.d/exec/~gem-rehash.bash
28
- - |
29
- if [ -n "$RUBY_VERSION" ]; then
30
- if ! (sem-version ruby "$RUBY_VERSION"); then
31
- ruby_key="rbenv-ruby-$RUBY_VERSION"
32
- echo "Attempting to build Ruby $RUBY_VERSION from source"
33
- git -C "$HOME/.rbenv/plugins/ruby-build" pull
34
- cache restore "$ruby_key"
35
- sem-version ruby "$RUBY_VERSION"
36
- if ! cache has_key "$ruby_key"; then
37
- cache store "$ruby_key" "$HOME/.rbenv/versions/$RUBY_VERSION"
38
- fi
39
- fi
40
- ./support/check_versions
41
- else
42
- echo Skipping Ruby install
43
- fi
29
+ lint-style:
30
+ name: "Ruby style linter (RuboCop)"
31
+ runs-on: ubuntu-latest
32
+ steps:
33
+ - uses: actions/checkout@v4
34
+ - uses: ruby/setup-ruby@v1
35
+ with:
36
+ ruby-version: "3.3"
37
+ bundler-cache: true
38
+ - name: "Run RuboCop"
39
+ run: bundle exec rubocop
44
40
 
45
- blocks:
46
- - name: Validation
47
- dependencies: []
48
- task:
49
- prologue:
50
- commands:
51
- - cache restore $_BUNDLER_CACHE-bundler-$RUBY_VERSION-$GEMSET-$(checksum $BUNDLE_GEMFILE)-$(checksum appsignal.gemspec)
52
- - cache restore $_GEMS_CACHE-gems-$RUBY_VERSION-$GEMSET-$(checksum $BUNDLE_GEMFILE)-$(checksum appsignal.gemspec)
53
- - ./support/bundler_wrapper install --jobs=3 --retry=3
54
- jobs:
55
- - name: Validate CI setup
56
- env_vars:
57
- - name: RUBY_VERSION
58
- value: 3.2.2
59
- - name: GEMSET
60
- value: no_dependencies
61
- - name: BUNDLE_GEMFILE
62
- value: Gemfile
63
- commands:
64
- - ./support/bundler_wrapper exec rake build_matrix:semaphore:validate
65
- epilogue:
66
- on_pass:
67
- commands:
68
- - cache store $_BUNDLER_CACHE-bundler-$RUBY_VERSION-$GEMSET-$(checksum $BUNDLE_GEMFILE)-$(checksum appsignal.gemspec) .bundle
69
- - cache store $_GEMS_CACHE-gems-$RUBY_VERSION-$GEMSET-$(checksum $BUNDLE_GEMFILE)-$(checksum appsignal.gemspec) $HOME/.gem
70
- - name: Ruby linters
71
- dependencies: []
72
- task:
73
- prologue:
74
- commands:
75
- - cache restore $_BUNDLER_CACHE-bundler-$RUBY_VERSION-$GEMSET-$(checksum $BUNDLE_GEMFILE)-$(checksum appsignal.gemspec)
76
- - cache restore $_GEMS_CACHE-gems-$RUBY_VERSION-$GEMSET-$(checksum $BUNDLE_GEMFILE)-$(checksum appsignal.gemspec)
77
- - ./support/bundler_wrapper install --jobs=3 --retry=3
78
- jobs:
79
- - name: RuboCop
80
- env_vars:
81
- - name: RUBY_VERSION
82
- value: 3.2.2
83
- - name: GEMSET
84
- value: no_dependencies
85
- - name: BUNDLE_GEMFILE
86
- value: Gemfile
87
- commands:
88
- - ./support/bundler_wrapper exec rubocop
89
- epilogue:
90
- on_pass:
91
- commands:
92
- - cache store $_BUNDLER_CACHE-bundler-$RUBY_VERSION-$GEMSET-$(checksum $BUNDLE_GEMFILE)-$(checksum appsignal.gemspec) .bundle
93
- - cache store $_GEMS_CACHE-gems-$RUBY_VERSION-$GEMSET-$(checksum $BUNDLE_GEMFILE)-$(checksum appsignal.gemspec) $HOME/.gem
94
- - name: Other linters
95
- dependencies: []
96
- task:
97
- jobs:
98
- - name: Git Lint (Lintje)
99
- commands:
100
- - script/lint_git
101
- - name: Integration tests
102
- dependencies:
103
- - Validation
104
- task:
105
- prologue:
106
- commands:
107
- - cache restore $_BUNDLER_CACHE-bundler-$RUBY_VERSION-diagnose-$(checksum Gemfile)
108
- - cache restore $_GEMS_CACHE-gems-$RUBY_VERSION-diagnose-$(checksum Gemfile)
109
- - ./support/bundler_wrapper install --jobs=3 --retry=3
110
- - ./support/bundler_wrapper exec rake extension:install
111
- - "[ -e ext/install.report ] && cat ext/install.report || echo 'No ext/install.report file found'"
112
- - "[ -f ext/mkmf.log ] && cat ext/mkmf.log || echo 'No ext/mkmf.log file found'"
113
- - git submodule init
114
- - git submodule update
115
- jobs:
116
- - name: Diagnose
117
- env_vars:
118
- - name: RUBY_VERSION
119
- value: 3.0.2
120
- - name: LANGUAGE
121
- value: ruby
122
- commands:
123
- - spec/integration/diagnose/bin/test
124
- epilogue:
125
- on_pass:
126
- commands:
127
- - cache store $_BUNDLER_CACHE-bundler-$RUBY_VERSION-diagnose-$(checksum Gemfile) .bundle
128
- - cache store $_GEMS_CACHE-gems-$RUBY_VERSION-diagnose-$(checksum Gemfile) $HOME/.gem
41
+ validation:
42
+ name: "Validation of CI"
43
+ runs-on: ubuntu-latest
44
+ steps:
45
+ - uses: actions/checkout@v4
46
+ - uses: ruby/setup-ruby@v1
47
+ with:
48
+ ruby-version: "3.3"
49
+ bundler-cache: true
50
+ - run: rake build_matrix:github:validate
129
51
 
130
- matrix:
131
- env_vars: # Shared for all jobs in the build matrix
132
- - name: BUNDLE_PATH
133
- value: "../.bundle/"
134
- - name: RAILS_ENV
135
- value: "test"
136
- - name: JRUBY_OPTS
137
- value: ""
138
- - name: COV
139
- value: "1"
140
- prologue: # Shared for all jobs in the build matrix
141
- commands:
142
- - cache restore $_BUNDLER_CACHE-bundler-$RUBY_VERSION-$GEMSET-$(checksum $BUNDLE_GEMFILE)-$(checksum appsignal.gemspec)
143
- - cache restore $_GEMS_CACHE-gems-$RUBY_VERSION-$(checksum $BUNDLE_GEMFILE)-$(checksum appsignal.gemspec)
144
- - ./support/install_deps
145
- - bundle config set clean 'true'
146
- - ./support/bundler_wrapper install --jobs=3 --retry=3
147
- epilogue: # Shared for all jobs in the build matrix
148
- on_pass:
149
- commands:
150
- - cache store $_BUNDLER_CACHE-bundler-$RUBY_VERSION-$GEMSET-$(checksum $BUNDLE_GEMFILE)-$(checksum appsignal.gemspec) .bundle
151
- - cache store $_GEMS_CACHE-gems-$RUBY_VERSION-$(checksum $BUNDLE_GEMFILE)-$(checksum appsignal.gemspec) $HOME/.gem
52
+ integration_tests:
53
+ name: "Diagnose integration tests"
54
+ runs-on: ubuntu-latest
55
+ steps:
56
+ - uses: actions/checkout@v4
57
+ with:
58
+ submodules: true
59
+ - uses: ruby/setup-ruby@v1
60
+ with:
61
+ ruby-version: "3.3"
62
+ bundler-cache: true
63
+ - name: "Install gem extension"
64
+ run: rake extension:install
65
+ - name: "Bundle install"
66
+ run: bundle install
67
+ working-directory: "spec/integration/diagnose"
68
+ - name: "Run diagnose integration tests"
69
+ run: bundle exec rspec
70
+ working-directory: "spec/integration/diagnose"
71
+ env:
72
+ LANGUAGE: ruby
152
73
 
153
- defaults:
154
- rubygems: "latest"
155
- bundler: "latest"
74
+ matrix:
75
+ env: # Shared for all jobs in the build matrix
76
+ RAILS_ENV: "test"
77
+ JRUBY_OPTS: ""
78
+ COV: "1"
156
79
 
157
80
  gemsets: # By default all gems are tested
158
81
  none:
@@ -165,11 +88,11 @@ matrix:
165
88
  - "rails-7.1"
166
89
 
167
90
  ruby:
168
- - ruby: "2.7.8"
169
- - ruby: "3.0.5"
170
- - ruby: "3.1.3"
171
- - ruby: "3.2.1"
172
91
  - ruby: "3.3.1"
92
+ - ruby: "3.2.1"
93
+ - ruby: "3.1.3"
94
+ - ruby: "3.0.5"
95
+ - ruby: "2.7.8"
173
96
  - ruby: "jruby-9.4.1.0"
174
97
  gems: "minimal"
175
98
  gems:
@@ -179,69 +102,76 @@ matrix:
179
102
  - gem: "dry-monitor"
180
103
  only:
181
104
  ruby:
182
- - "3.0.5"
183
- - "3.1.3"
184
- - "3.2.1"
185
105
  - "3.3.1"
106
+ - "3.2.1"
107
+ - "3.1.3"
108
+ - "3.0.5"
186
109
  - gem: "grape"
187
- - gem: "hanami"
110
+ - gem: "hanami-2.0"
188
111
  only:
189
112
  ruby:
190
- - "3.0.5"
191
- - "3.1.3"
113
+ - "3.3.1"
192
114
  - "3.2.1"
115
+ - "3.1.3"
116
+ - "3.0.5"
117
+ - gem: "hanami-2.1"
118
+ only:
119
+ ruby:
193
120
  - "3.3.1"
121
+ - "3.2.1"
122
+ - "3.1.3"
123
+ - "3.0.5"
194
124
  - gem: "http5"
195
125
  - gem: "padrino"
196
126
  - gem: "psych-3"
197
127
  only:
198
128
  ruby:
199
- - "2.7.8"
200
- - "3.0.5"
201
- - "3.1.3"
202
- - "3.2.1"
203
129
  - "3.3.1"
130
+ - "3.2.1"
131
+ - "3.1.3"
132
+ - "3.0.5"
133
+ - "2.7.8"
204
134
  - gem: "psych-4"
205
135
  only:
206
136
  ruby:
207
- - "2.7.8"
208
- - "3.0.5"
209
- - "3.1.3"
210
- - "3.2.1"
211
137
  - "3.3.1"
138
+ - "3.2.1"
139
+ - "3.1.3"
140
+ - "3.0.5"
141
+ - "2.7.8"
212
142
  - gem: "que"
213
143
  - gem: "que_beta"
214
144
  - gem: "rails-6.0"
215
145
  only:
216
146
  ruby:
217
- - "2.7.8"
218
147
  - "3.0.5"
148
+ - "2.7.8"
219
149
  - "jruby-9.4.1.0"
220
150
  - gem: "rails-6.1"
221
151
  only:
222
152
  ruby:
223
- - "2.7.8"
224
- - "3.0.5"
225
- - "3.1.3"
226
- - "3.2.1"
227
153
  - "3.3.1"
154
+ - "3.2.1"
155
+ - "3.1.3"
156
+ - "3.0.5"
157
+ - "2.7.8"
228
158
  - "jruby-9.4.1.0"
229
159
  - gem: "rails-7.0"
230
160
  only:
231
161
  ruby:
232
- - "2.7.8"
233
- - "3.0.5"
234
- - "3.1.3"
235
- - "3.2.1"
236
162
  - "3.3.1"
163
+ - "3.2.1"
164
+ - "3.1.3"
165
+ - "3.0.5"
166
+ - "2.7.8"
237
167
  - "jruby-9.4.1.0"
238
168
  - gem: "rails-7.1"
239
169
  only:
240
170
  ruby:
241
- - "3.0.5"
242
- - "3.1.3"
243
- - "3.2.1"
244
171
  - "3.3.1"
172
+ - "3.2.1"
173
+ - "3.1.3"
174
+ - "3.0.5"
245
175
  - "jruby-9.4.1.0"
246
176
  - gem: "sequel"
247
177
  - gem: "sinatra"
data/ext/base.rb CHANGED
@@ -8,7 +8,7 @@ require "json"
8
8
  require "rubygems/package"
9
9
  require File.expand_path("../lib/appsignal/version.rb", __dir__)
10
10
  require File.expand_path("../lib/appsignal/system.rb", __dir__)
11
- require_relative "./agent"
11
+ require_relative "agent"
12
12
 
13
13
  EXT_PATH = File.expand_path(__dir__).freeze
14
14
 
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "hanami", "~> 2.1.0"
4
+ gem "hanami-router", "~> 2.1.0"
5
+ gem "hanami-controller", "~> 2.1.0"
6
+
7
+ gemspec :path => '../'
@@ -200,7 +200,7 @@ module Appsignal
200
200
  initial_config
201
201
  )
202
202
  Appsignal.config.write_to_environment
203
- Appsignal.start_logger
203
+ Appsignal._start_logger
204
204
  Appsignal.internal_logger.info("Starting AppSignal diagnose")
205
205
  end
206
206
 
@@ -233,7 +233,7 @@ module Appsignal
233
233
  # variables config.
234
234
  # @param logger [Logger] The logger to use for the AppSignal gem. This is
235
235
  # used by the configuration class only. Default:
236
- # {Appsignal.internal_logger}. See also {Appsignal.start_logger}.
236
+ # {Appsignal.internal_logger}. See also {Appsignal.start}.
237
237
  # @param config_file [String] Custom config file location. Default
238
238
  # `config/appsignal.yml`.
239
239
  #
@@ -29,7 +29,6 @@ module Appsignal
29
29
  # - returns `false` if Appsignal is not active.
30
30
  def transmit
31
31
  Appsignal.start
32
- Appsignal.start_logger
33
32
  return false unless Appsignal.active?
34
33
 
35
34
  create_example_error_request
@@ -3,6 +3,8 @@
3
3
  module Appsignal
4
4
  # @api private
5
5
  class Environment
6
+ ERROR_ON_YIELD = :APPSIGNAL_ERROR_ON_YIELD
7
+
6
8
  # Add environment metadata.
7
9
  #
8
10
  # The key and value of the environment metadata must be a String, even if
@@ -46,9 +48,11 @@ module Appsignal
46
48
  Appsignal.internal_logger.error \
47
49
  "Unable to report on environment metadata #{key.inspect}:\n" \
48
50
  "#{e.class}: #{e}"
49
- return
51
+ ERROR_ON_YIELD
50
52
  end
51
53
 
54
+ return if yielded_value == ERROR_ON_YIELD
55
+
52
56
  value =
53
57
  case yielded_value
54
58
  when TrueClass, FalseClass
@@ -9,7 +9,7 @@ module Appsignal
9
9
  # Only loaded if the system is detected as JRuby.
10
10
  #
11
11
  # @api private
12
- module Jruby # rubocop:disable Metrics/ModuleLength
12
+ module Jruby
13
13
  extend FFI::Library
14
14
 
15
15
  # JRuby extension String helpers.
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Appsignal
4
4
  module Helpers
5
- module Instrumentation # rubocop:disable Metrics/ModuleLength
5
+ module Instrumentation
6
6
  include Appsignal::Utils::StdoutAndLoggerMessage
7
7
 
8
8
  # Creates an AppSignal transaction for the given block.
@@ -176,7 +176,7 @@ module Appsignal
176
176
  #
177
177
  # @example Add more metadata to transaction
178
178
  # Appsignal.send_error(e) do |transaction|
179
- # transaction.params = { :search_query => params[:search_query] }
179
+ # transaction.set_params(:search_query => params[:search_query])
180
180
  # transaction.set_action("my_action_name")
181
181
  # transaction.set_tags(:key => "value")
182
182
  # transaction.set_namespace("my_namespace")
@@ -273,7 +273,7 @@ module Appsignal
273
273
  #
274
274
  # @example Add more metadata to transaction
275
275
  # Appsignal.set_error(e) do |transaction|
276
- # transaction.params = { :search_query => params[:search_query] }
276
+ # transaction.set_params(:search_query => params[:search_query])
277
277
  # transaction.set_action("my_action_name")
278
278
  # transaction.set_tags(:key => "value")
279
279
  # transaction.set_namespace("my_namespace")
@@ -62,11 +62,12 @@ module Appsignal
62
62
  end
63
63
 
64
64
  if transaction
65
- transaction.params =
65
+ transaction.set_params_if_nil(
66
66
  Appsignal::Utils::HashSanitizer.sanitize(
67
67
  job["arguments"],
68
68
  Appsignal.config[:filter_parameters]
69
69
  )
70
+ )
70
71
 
71
72
  transaction_tags = ActiveJobHelpers.transaction_tags_for(job)
72
73
  transaction_tags["active_job_id"] = job["job_id"]
@@ -22,7 +22,7 @@ module Appsignal
22
22
  transaction.set_error(exception)
23
23
  raise exception
24
24
  ensure
25
- transaction.params = args.first
25
+ transaction.set_params_if_nil(args.first)
26
26
  transaction.set_action_if_nil("#{self.class}##{args.first["action"]}")
27
27
  transaction.set_metadata("path", request.path)
28
28
  transaction.set_metadata("method", "websocket")
@@ -1,55 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "appsignal"
4
+ require "appsignal/rack/grape_middleware"
5
+
6
+ Appsignal.internal_logger.debug("Loading Grape integration")
7
+
3
8
  module Appsignal
4
- # @todo Move to sub-namespace
5
9
  # @api private
6
10
  module Grape
7
- class Middleware < ::Grape::Middleware::Base
8
- def call(env)
9
- if Appsignal.active?
10
- call_with_appsignal_monitoring(env)
11
- else
12
- app.call(env)
13
- end
14
- end
15
-
16
- def call_with_appsignal_monitoring(env)
17
- request = ::Rack::Request.new(env)
18
- transaction = Appsignal::Transaction.create(
19
- SecureRandom.uuid,
20
- Appsignal::Transaction::HTTP_REQUEST,
21
- request
22
- )
23
- begin
24
- app.call(env)
25
- rescue Exception => error # rubocop:disable Lint/RescueException
26
- # Do not set error if "grape.skip_appsignal_error" is set to `true`.
27
- transaction.set_error(error) unless env["grape.skip_appsignal_error"]
28
- raise error
29
- ensure
30
- request_method = request.request_method.to_s.upcase
31
- path = request.path # Path without namespaces
32
- endpoint = env["api.endpoint"]
33
-
34
- if endpoint&.options
35
- options = endpoint.options
36
- request_method = options[:method].first.to_s.upcase
37
- klass = options[:for]
38
- namespace = endpoint.namespace
39
- namespace = "" if namespace == "/"
40
-
41
- path = options[:path].first.to_s
42
- path = "/#{path}" if path[0] != "/"
43
- path = "#{namespace}#{path}"
44
-
45
- transaction.set_action_if_nil("#{request_method}::#{klass}##{path}")
46
- end
47
-
48
- transaction.set_http_or_background_queue_start
49
- transaction.set_metadata("path", path)
50
- transaction.set_metadata("method", request_method)
51
- Appsignal::Transaction.complete_current!
52
- end
11
+ # Alias constants that have moved with a warning message that points to the
12
+ # place to update the reference.
13
+ def self.const_missing(name)
14
+ case name
15
+ when :Middleware
16
+ callers = caller
17
+ Appsignal::Utils::StdoutAndLoggerMessage.warning \
18
+ "The constant Appsignal::Grape::Middleware has been deprecated. " \
19
+ "Please update the constant name to " \
20
+ "Appsignal::Rack::GrapeMiddleware in the following file to " \
21
+ "remove this message.\n#{callers.first}"
22
+ Appsignal::Rack::GrapeMiddleware
23
+ else
24
+ super
53
25
  end
54
26
  end
55
27
  end
@@ -1,62 +1,48 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "appsignal"
4
+ require "appsignal/rack/hanami_middleware"
4
5
 
5
6
  module Appsignal
6
7
  module Integrations
8
+ # @api private
7
9
  module HanamiPlugin
8
10
  def self.init
9
11
  Appsignal.internal_logger.debug("Loading Hanami integration")
10
12
 
11
13
  hanami_app_config = ::Hanami.app.config
12
- Appsignal.config = Appsignal::Config.new(
13
- hanami_app_config.root || Dir.pwd,
14
- hanami_app_config.env
15
- )
16
14
 
17
- Appsignal.start_logger
18
- Appsignal.start
15
+ unless Appsignal.active?
16
+ Appsignal.config = Appsignal::Config.new(
17
+ hanami_app_config.root || Dir.pwd,
18
+ hanami_app_config.env
19
+ )
20
+ Appsignal.start
21
+ end
22
+
23
+ return unless Appsignal.active?
24
+
25
+ hanami_app_config.middleware.use(
26
+ ::Rack::Events,
27
+ [Appsignal::Rack::EventHandler.new]
28
+ )
29
+ hanami_app_config.middleware.use(Appsignal::Rack::HanamiMiddleware)
19
30
 
20
- ::Hanami::Action.prepend Appsignal::Integrations::HanamiIntegration if Appsignal.active?
31
+ ::Hanami::Action.prepend Appsignal::Integrations::HanamiIntegration
21
32
  end
22
33
  end
23
- end
24
- end
25
34
 
26
- module Appsignal::Integrations::HanamiIntegration
27
- def call(env)
28
- params = ::Hanami::Action::BaseParams.new(env)
29
- request = ::Hanami::Action::Request.new(
30
- :env => env,
31
- :params => params,
32
- :sessions_enabled => true
33
- )
34
-
35
- transaction = Appsignal::Transaction.create(
36
- SecureRandom.uuid,
37
- Appsignal::Transaction::HTTP_REQUEST,
38
- request
39
- )
40
-
41
- begin
42
- Appsignal.instrument("process_action.hanami") do
43
- super.tap do |response|
44
- transaction.set_metadata("status", response.status.to_s)
45
- end
35
+ # @api private
36
+ module HanamiIntegration
37
+ def call(env)
38
+ super
39
+ ensure
40
+ transaction = env[::Appsignal::Rack::APPSIGNAL_TRANSACTION]
41
+
42
+ transaction&.set_action_if_nil(self.class.name)
46
43
  end
47
- rescue Exception => error # rubocop:disable Lint/RescueException
48
- transaction.set_error(error)
49
- transaction.set_metadata("status", "500")
50
- raise error
51
- ensure
52
- transaction.params = request.params.to_h
53
- transaction.set_action_if_nil(self.class.name)
54
- transaction.set_metadata("path", request.path)
55
- transaction.set_metadata("method", request.request_method)
56
- transaction.set_http_or_background_queue_start
57
- Appsignal::Transaction.complete_current!
58
44
  end
59
45
  end
60
46
  end
61
47
 
62
- Appsignal::Integrations::HanamiPlugin.init
48
+ Appsignal::Integrations::HanamiPlugin.init unless Appsignal.testing?