opentelemetry-instrumentation-action_pack 0.5.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +25 -0
- data/README.md +19 -0
- data/lib/opentelemetry/instrumentation/action_pack/handlers/action_controller.rb +59 -0
- data/lib/opentelemetry/instrumentation/action_pack/handlers.rb +38 -0
- data/lib/opentelemetry/instrumentation/action_pack/instrumentation.rb +3 -3
- data/lib/opentelemetry/instrumentation/action_pack/railtie.rb +1 -1
- data/lib/opentelemetry/instrumentation/action_pack/version.rb +1 -1
- data/lib/opentelemetry/instrumentation/action_pack.rb +2 -2
- data/lib/opentelemetry/instrumentation.rb +1 -1
- data/lib/opentelemetry-instrumentation-action_pack.rb +1 -1
- metadata +32 -31
- data/lib/opentelemetry/instrumentation/action_pack/patches/action_controller/metal.rb +0 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e06ad2752b2424da0f9118ec0cf639d7a71f8eeb125dc09c7b6382a71fa1adee
|
4
|
+
data.tar.gz: 4df567444bc1fff28bcc26f28229aa5023d2eacaf240f3ee1bbb9869b96bd8f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3524725aa834c10dea18cdde35cc860e4d5b5b3fe5c4f2e4b3e7235af15f9c6d53111a3b59699631c4f76eb67c323ff6d0c8a3a37645ca885ee14f52d686b8e
|
7
|
+
data.tar.gz: 516886964fa80632bc3b237ada0b85ff60d4b9193d685414aa7dc069ced6f04acd42f06b2586a00db5cbb57645902c7309af38f786932b8a88a7d77c335c167c
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,30 @@
|
|
1
1
|
# Release History: opentelemetry-instrumentation-action_pack
|
2
2
|
|
3
|
+
### v0.9.0 / 2024-01-09
|
4
|
+
|
5
|
+
* BREAKING CHANGE: Use ActiveSupport instead of patches #703
|
6
|
+
|
7
|
+
### v0.8.0 / 2023-11-22
|
8
|
+
|
9
|
+
* BREAKING CHANGE: Drop Rails 6.0 EOL
|
10
|
+
|
11
|
+
* ADDED: Drop Rails 6.0 EOL
|
12
|
+
|
13
|
+
### v0.7.1 / 2023-10-16
|
14
|
+
|
15
|
+
* FIXED: Add Rails 7.1 compatibility
|
16
|
+
|
17
|
+
### v0.7.0 / 2023-06-05
|
18
|
+
|
19
|
+
* ADDED: Use Rack Middleware Helper
|
20
|
+
* FIXED: Base config options
|
21
|
+
|
22
|
+
### v0.6.0 / 2023-04-17
|
23
|
+
|
24
|
+
* BREAKING CHANGE: Drop support for EoL Ruby 2.7
|
25
|
+
|
26
|
+
* ADDED: Drop support for EoL Ruby 2.7
|
27
|
+
|
3
28
|
### v0.5.0 / 2023-02-01
|
4
29
|
|
5
30
|
* BREAKING CHANGE: Drop Rails 5 Support
|
data/README.md
CHANGED
@@ -30,6 +30,25 @@ OpenTelemetry::SDK.configure do |c|
|
|
30
30
|
end
|
31
31
|
```
|
32
32
|
|
33
|
+
## Active Support Instrumentation
|
34
|
+
|
35
|
+
Earlier versions of this instrumentation relied on patching custom `dispatch` hooks from Rails's [Action Controller](https://github.com/rails/rails/blob/main/actionpack/lib/action_controller/metal.rb#L224) to extract request information.
|
36
|
+
|
37
|
+
This instrumentation now relies on `ActiveSupport::Notifications` and registers a custom Subscriber that listens to relevant events to modify the Rack span.
|
38
|
+
|
39
|
+
See the table below for details of what [Rails Framework Hook Events](https://guides.rubyonrails.org/active_support_instrumentation.html#action-controller) are recorded by this instrumentation:
|
40
|
+
|
41
|
+
| Event Name | Subscribe? | Creates Span? | Notes |
|
42
|
+
| - | - | - | - |
|
43
|
+
| `process_action.action_controller` | :white_check_mark: | :x: | It modifies the existing Rack span |
|
44
|
+
|
45
|
+
|
46
|
+
### Error Handling for Action Controller
|
47
|
+
|
48
|
+
If an error is triggered by Action Controller (such as a 500 internal server error), Action Pack will typically employ the default `ActionDispatch::PublicExceptions.new(Rails.public_path)` as the `exceptions_app`, as detailed in the [documentation](https://guides.rubyonrails.org/configuring.html#config-exceptions-app).
|
49
|
+
|
50
|
+
The error object will be retained within `payload[:exception_object]`. Additionally, its storage in `request.env['action_dispatch.exception']` is contingent upon the configuration of `action_dispatch.show_exceptions` in Rails.
|
51
|
+
|
33
52
|
## Examples
|
34
53
|
|
35
54
|
Example usage can be seen in the `./example/trace_demonstration.rb` file [here](https://github.com/open-telemetry/opentelemetry-ruby-contrib/blob/main/instrumentation/action_pack/example/trace_demonstration.ru)
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright The OpenTelemetry Authors
|
4
|
+
#
|
5
|
+
# SPDX-License-Identifier: Apache-2.0
|
6
|
+
|
7
|
+
module OpenTelemetry
|
8
|
+
module Instrumentation
|
9
|
+
module ActionPack
|
10
|
+
module Handlers
|
11
|
+
# Action Controller handler to handle the notification from Active Support
|
12
|
+
class ActionController
|
13
|
+
# @param config [Hash] of instrumentation options
|
14
|
+
def initialize(config)
|
15
|
+
@config = config
|
16
|
+
end
|
17
|
+
|
18
|
+
# Invoked by ActiveSupport::Notifications at the start of the instrumentation block
|
19
|
+
#
|
20
|
+
# @param _name [String] of the event (unused)
|
21
|
+
# @param _id [String] of the event (unused)
|
22
|
+
# @param payload [Hash] the payload passed as a method argument
|
23
|
+
# @return [Hash] the payload passed as a method argument
|
24
|
+
def start(_name, _id, payload)
|
25
|
+
rack_span = OpenTelemetry::Instrumentation::Rack.current_span
|
26
|
+
|
27
|
+
request = payload[:request]
|
28
|
+
|
29
|
+
rack_span.name = "#{payload[:controller]}##{payload[:action]}" unless request.env['action_dispatch.exception']
|
30
|
+
|
31
|
+
attributes_to_append = {
|
32
|
+
OpenTelemetry::SemanticConventions::Trace::CODE_NAMESPACE => String(payload[:controller]),
|
33
|
+
OpenTelemetry::SemanticConventions::Trace::CODE_FUNCTION => String(payload[:action])
|
34
|
+
}
|
35
|
+
|
36
|
+
attributes_to_append[OpenTelemetry::SemanticConventions::Trace::HTTP_TARGET] = request.filtered_path if request.filtered_path != request.fullpath
|
37
|
+
|
38
|
+
rack_span.add_attributes(attributes_to_append)
|
39
|
+
rescue StandardError => e
|
40
|
+
OpenTelemetry.handle_error(exception: e)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Invoked by ActiveSupport::Notifications at the end of the instrumentation block
|
44
|
+
#
|
45
|
+
# @param _name [String] of the event (unused)
|
46
|
+
# @param _id [String] of the event (unused)
|
47
|
+
# @param payload [Hash] the payload passed as a method argument
|
48
|
+
# @return [Hash] the payload passed as a method argument
|
49
|
+
def finish(_name, _id, payload)
|
50
|
+
rack_span = OpenTelemetry::Instrumentation::Rack.current_span
|
51
|
+
rack_span.record_exception(payload[:exception_object]) if payload[:exception_object]
|
52
|
+
rescue StandardError => e
|
53
|
+
OpenTelemetry.handle_error(exception: e)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright The OpenTelemetry Authors
|
4
|
+
#
|
5
|
+
# SPDX-License-Identifier: Apache-2.0
|
6
|
+
|
7
|
+
require_relative 'handlers/action_controller'
|
8
|
+
|
9
|
+
module OpenTelemetry
|
10
|
+
module Instrumentation
|
11
|
+
module ActionPack
|
12
|
+
# Module that contains custom event handlers, which are used to generate spans per event
|
13
|
+
module Handlers
|
14
|
+
module_function
|
15
|
+
|
16
|
+
def subscribe
|
17
|
+
return unless Array(@subscriptions).empty?
|
18
|
+
|
19
|
+
config = ActionPack::Instrumentation.instance.config
|
20
|
+
handlers_by_pattern = {
|
21
|
+
'process_action.action_controller' => Handlers::ActionController.new(config)
|
22
|
+
}
|
23
|
+
|
24
|
+
@subscriptions = handlers_by_pattern.map do |key, handler|
|
25
|
+
::ActiveSupport::Notifications.subscribe(key, handler)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Removes Event Handler Subscriptions for Action Controller notifications
|
30
|
+
# @note this method is not thread-safe and should not be used in a multi-threaded context
|
31
|
+
def unsubscribe
|
32
|
+
@subscriptions&.each { |subscriber| ::ActiveSupport::Notifications.unsubscribe(subscriber) }
|
33
|
+
@subscriptions = nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -9,7 +9,7 @@ module OpenTelemetry
|
|
9
9
|
module ActionPack
|
10
10
|
# The Instrumentation class contains logic to detect and install the ActionPack instrumentation
|
11
11
|
class Instrumentation < OpenTelemetry::Instrumentation::Base
|
12
|
-
MINIMUM_VERSION = Gem::Version.new('6.
|
12
|
+
MINIMUM_VERSION = Gem::Version.new('6.1.0')
|
13
13
|
|
14
14
|
install do |_config|
|
15
15
|
require_railtie
|
@@ -32,11 +32,11 @@ module OpenTelemetry
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def patch
|
35
|
-
|
35
|
+
Handlers.subscribe
|
36
36
|
end
|
37
37
|
|
38
38
|
def require_dependencies
|
39
|
-
require_relative '
|
39
|
+
require_relative 'handlers'
|
40
40
|
end
|
41
41
|
|
42
42
|
def require_railtie
|
@@ -16,5 +16,5 @@ module OpenTelemetry
|
|
16
16
|
end
|
17
17
|
|
18
18
|
require 'opentelemetry-instrumentation-rack'
|
19
|
-
require_relative '
|
20
|
-
require_relative '
|
19
|
+
require_relative 'action_pack/instrumentation'
|
20
|
+
require_relative 'action_pack/version'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opentelemetry-instrumentation-action_pack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- OpenTelemetry Authors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opentelemetry-api
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
33
|
+
version: 0.22.1
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.
|
40
|
+
version: 0.22.1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: opentelemetry-instrumentation-rack
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 2.
|
61
|
+
version: '2.5'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 2.
|
68
|
+
version: '2.5'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: bundler
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -112,30 +112,30 @@ dependencies:
|
|
112
112
|
name: opentelemetry-test-helpers
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- - "
|
115
|
+
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
117
|
+
version: '0.3'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- - "
|
122
|
+
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: '0'
|
124
|
+
version: '0.3'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: rails
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
129
|
- - ">="
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: '
|
131
|
+
version: '6.1'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
136
|
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: '
|
138
|
+
version: '6.1'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: rake
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -156,70 +156,70 @@ dependencies:
|
|
156
156
|
requirements:
|
157
157
|
- - "~>"
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version: 1.
|
159
|
+
version: 1.59.0
|
160
160
|
type: :development
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
164
|
- - "~>"
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version: 1.
|
166
|
+
version: 1.59.0
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
|
-
name:
|
168
|
+
name: rubocop-performance
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
170
170
|
requirements:
|
171
171
|
- - "~>"
|
172
172
|
- !ruby/object:Gem::Version
|
173
|
-
version:
|
173
|
+
version: 1.19.1
|
174
174
|
type: :development
|
175
175
|
prerelease: false
|
176
176
|
version_requirements: !ruby/object:Gem::Requirement
|
177
177
|
requirements:
|
178
178
|
- - "~>"
|
179
179
|
- !ruby/object:Gem::Version
|
180
|
-
version:
|
180
|
+
version: 1.19.1
|
181
181
|
- !ruby/object:Gem::Dependency
|
182
|
-
name:
|
182
|
+
name: simplecov
|
183
183
|
requirement: !ruby/object:Gem::Requirement
|
184
184
|
requirements:
|
185
185
|
- - "~>"
|
186
186
|
- !ruby/object:Gem::Version
|
187
|
-
version:
|
187
|
+
version: 0.17.1
|
188
188
|
type: :development
|
189
189
|
prerelease: false
|
190
190
|
version_requirements: !ruby/object:Gem::Requirement
|
191
191
|
requirements:
|
192
192
|
- - "~>"
|
193
193
|
- !ruby/object:Gem::Version
|
194
|
-
version:
|
194
|
+
version: 0.17.1
|
195
195
|
- !ruby/object:Gem::Dependency
|
196
|
-
name:
|
196
|
+
name: webmock
|
197
197
|
requirement: !ruby/object:Gem::Requirement
|
198
198
|
requirements:
|
199
199
|
- - "~>"
|
200
200
|
- !ruby/object:Gem::Version
|
201
|
-
version: '
|
201
|
+
version: '3.19'
|
202
202
|
type: :development
|
203
203
|
prerelease: false
|
204
204
|
version_requirements: !ruby/object:Gem::Requirement
|
205
205
|
requirements:
|
206
206
|
- - "~>"
|
207
207
|
- !ruby/object:Gem::Version
|
208
|
-
version: '
|
208
|
+
version: '3.19'
|
209
209
|
- !ruby/object:Gem::Dependency
|
210
|
-
name: yard
|
210
|
+
name: yard
|
211
211
|
requirement: !ruby/object:Gem::Requirement
|
212
212
|
requirements:
|
213
213
|
- - "~>"
|
214
214
|
- !ruby/object:Gem::Version
|
215
|
-
version: 0.
|
215
|
+
version: '0.9'
|
216
216
|
type: :development
|
217
217
|
prerelease: false
|
218
218
|
version_requirements: !ruby/object:Gem::Requirement
|
219
219
|
requirements:
|
220
220
|
- - "~>"
|
221
221
|
- !ruby/object:Gem::Version
|
222
|
-
version: 0.
|
222
|
+
version: '0.9'
|
223
223
|
description: ActionPack instrumentation for the OpenTelemetry framework
|
224
224
|
email:
|
225
225
|
- cncf-opentelemetry-contributors@lists.cncf.io
|
@@ -234,18 +234,19 @@ files:
|
|
234
234
|
- lib/opentelemetry-instrumentation-action_pack.rb
|
235
235
|
- lib/opentelemetry/instrumentation.rb
|
236
236
|
- lib/opentelemetry/instrumentation/action_pack.rb
|
237
|
+
- lib/opentelemetry/instrumentation/action_pack/handlers.rb
|
238
|
+
- lib/opentelemetry/instrumentation/action_pack/handlers/action_controller.rb
|
237
239
|
- lib/opentelemetry/instrumentation/action_pack/instrumentation.rb
|
238
|
-
- lib/opentelemetry/instrumentation/action_pack/patches/action_controller/metal.rb
|
239
240
|
- lib/opentelemetry/instrumentation/action_pack/railtie.rb
|
240
241
|
- lib/opentelemetry/instrumentation/action_pack/version.rb
|
241
242
|
homepage: https://github.com/open-telemetry/opentelemetry-ruby-contrib
|
242
243
|
licenses:
|
243
244
|
- Apache-2.0
|
244
245
|
metadata:
|
245
|
-
changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-action_pack/0.
|
246
|
+
changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-action_pack/0.9.0/file/CHANGELOG.md
|
246
247
|
source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/tree/main/instrumentation/action_pack
|
247
248
|
bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/issues
|
248
|
-
documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-action_pack/0.
|
249
|
+
documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-action_pack/0.9.0
|
249
250
|
post_install_message:
|
250
251
|
rdoc_options: []
|
251
252
|
require_paths:
|
@@ -254,14 +255,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
254
255
|
requirements:
|
255
256
|
- - ">="
|
256
257
|
- !ruby/object:Gem::Version
|
257
|
-
version:
|
258
|
+
version: '3.0'
|
258
259
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
259
260
|
requirements:
|
260
261
|
- - ">="
|
261
262
|
- !ruby/object:Gem::Version
|
262
263
|
version: '0'
|
263
264
|
requirements: []
|
264
|
-
rubygems_version: 3.
|
265
|
+
rubygems_version: 3.2.33
|
265
266
|
signing_key:
|
266
267
|
specification_version: 4
|
267
268
|
summary: ActionPack instrumentation for the OpenTelemetry framework
|
@@ -1,40 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright The OpenTelemetry Authors
|
4
|
-
#
|
5
|
-
# SPDX-License-Identifier: Apache-2.0
|
6
|
-
|
7
|
-
module OpenTelemetry
|
8
|
-
module Instrumentation
|
9
|
-
module ActionPack
|
10
|
-
module Patches
|
11
|
-
module ActionController
|
12
|
-
# Module to prepend to ActionController::Metal for instrumentation
|
13
|
-
module Metal
|
14
|
-
def dispatch(name, request, response)
|
15
|
-
rack_span = OpenTelemetry::Instrumentation::Rack.current_span
|
16
|
-
if rack_span.recording?
|
17
|
-
rack_span.name = "#{self.class.name}##{name}" unless request.env['action_dispatch.exception']
|
18
|
-
|
19
|
-
attributes_to_append = {
|
20
|
-
OpenTelemetry::SemanticConventions::Trace::CODE_NAMESPACE => self.class.name,
|
21
|
-
OpenTelemetry::SemanticConventions::Trace::CODE_FUNCTION => String(name)
|
22
|
-
}
|
23
|
-
attributes_to_append[OpenTelemetry::SemanticConventions::Trace::HTTP_TARGET] = request.filtered_path if request.filtered_path != request.fullpath
|
24
|
-
rack_span.add_attributes(attributes_to_append)
|
25
|
-
end
|
26
|
-
|
27
|
-
super(name, request, response)
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
def instrumentation_config
|
33
|
-
ActionPack::Instrumentation.instance.config
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|