opentelemetry-instrumentation-action_pack 0.7.1 → 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 +10 -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/version.rb +1 -1
- metadata +24 -9
- 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,15 @@
|
|
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
|
+
|
3
13
|
### v0.7.1 / 2023-10-16
|
4
14
|
|
5
15
|
* FIXED: Add Rails 7.1 compatibility
|
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
|
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
|
@@ -128,14 +128,14 @@ dependencies:
|
|
128
128
|
requirements:
|
129
129
|
- - ">="
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: '6'
|
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: '6'
|
138
|
+
version: '6.1'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: rake
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -156,14 +156,28 @@ 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
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: rubocop-performance
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - "~>"
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: 1.19.1
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - "~>"
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: 1.19.1
|
167
181
|
- !ruby/object:Gem::Dependency
|
168
182
|
name: simplecov
|
169
183
|
requirement: !ruby/object:Gem::Requirement
|
@@ -220,18 +234,19 @@ files:
|
|
220
234
|
- lib/opentelemetry-instrumentation-action_pack.rb
|
221
235
|
- lib/opentelemetry/instrumentation.rb
|
222
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
|
223
239
|
- lib/opentelemetry/instrumentation/action_pack/instrumentation.rb
|
224
|
-
- lib/opentelemetry/instrumentation/action_pack/patches/action_controller/metal.rb
|
225
240
|
- lib/opentelemetry/instrumentation/action_pack/railtie.rb
|
226
241
|
- lib/opentelemetry/instrumentation/action_pack/version.rb
|
227
242
|
homepage: https://github.com/open-telemetry/opentelemetry-ruby-contrib
|
228
243
|
licenses:
|
229
244
|
- Apache-2.0
|
230
245
|
metadata:
|
231
|
-
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
|
232
247
|
source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/tree/main/instrumentation/action_pack
|
233
248
|
bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/issues
|
234
|
-
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
|
235
250
|
post_install_message:
|
236
251
|
rdoc_options: []
|
237
252
|
require_paths:
|
@@ -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
|