opentelemetry-instrumentation-action_pack 0.9.0 → 0.10.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 +4 -0
- data/README.md +22 -2
- data/lib/opentelemetry/instrumentation/action_pack/handlers/action_controller.rb +33 -15
- data/lib/opentelemetry/instrumentation/action_pack/instrumentation.rb +27 -1
- data/lib/opentelemetry/instrumentation/action_pack/version.rb +1 -1
- metadata +10 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5af8d8cb9038f564234140ffaa6d87f1b07ecb7021e4fe579ec5efc938b2898e
|
4
|
+
data.tar.gz: '091d78c0c499b98b31a31ea31aa6f0990f8cabe53dab62dd532036985def42ef'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e7782f0b1b04ab4a019677bd81a68c01954af5ece9a7f3b0073a764490241fed82b8173cc435fcbbcd7ec46786e1237a7b5e4406982de61674ad8285aafe60c
|
7
|
+
data.tar.gz: 97404fce81bd10262a19e129f6397aeaabe39ae54850a0f3d085952e6264e1392617727bab6a1fd22837338d48b2e603444a2392499168a0872abd0b62a71f06
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -6,7 +6,7 @@ The Action Pack instrumentation is a community-maintained instrumentation for th
|
|
6
6
|
|
7
7
|
Install the gem using:
|
8
8
|
|
9
|
-
```
|
9
|
+
```console
|
10
10
|
gem install opentelemetry-instrumentation-action_pack
|
11
11
|
```
|
12
12
|
|
@@ -42,6 +42,24 @@ See the table below for details of what [Rails Framework Hook Events](https://gu
|
|
42
42
|
| - | - | - | - |
|
43
43
|
| `process_action.action_controller` | :white_check_mark: | :x: | It modifies the existing Rack span |
|
44
44
|
|
45
|
+
## Semantic Conventions
|
46
|
+
|
47
|
+
This instrumentation generally uses [HTTP server semantic conventions](https://opentelemetry.io/docs/specs/semconv/http/http-spans/) to update the existing Rack span.
|
48
|
+
|
49
|
+
For Rails 7.1+, the span name is updated to match the HTTP method and route that was matched for the request using [`ActionDispatch::Request#route_uri_pattern`](https://api.rubyonrails.org/classes/ActionDispatch/Request.html#method-i-route_uri_pattern), e.g.: `GET /users/:id`
|
50
|
+
|
51
|
+
For older versions of Rails the span name is updated to match the HTTP method, controller, and action name that was the target of the request, e.g.: `GET /example/index`
|
52
|
+
|
53
|
+
> ![NOTE]: Users may override the `span_naming` option to default to Legacy Span Naming Behavior that uses the controller's class name and action in Ruby documentation syntax, e.g. `ExampleController#index`.
|
54
|
+
|
55
|
+
This instrumentation does not emit any custom attributes.
|
56
|
+
|
57
|
+
| Attribute Name | Type | Notes |
|
58
|
+
| - | - | - |
|
59
|
+
| `code.namespace` | String | `ActionController` class name |
|
60
|
+
| `code.function` | String | `ActionController` action name e.g. `index`, `show`, `edit`, etc... |
|
61
|
+
| `http.route` | String | (Rails 7.1+) the route that was matched for the request |
|
62
|
+
| `http.target` | String | The `request.filtered_path` |
|
45
63
|
|
46
64
|
### Error Handling for Action Controller
|
47
65
|
|
@@ -57,7 +75,7 @@ Example usage can be seen in the `./example/trace_demonstration.rb` file [here](
|
|
57
75
|
|
58
76
|
The `opentelemetry-instrumentation-action_pack` gem source is [on github][repo-github], along with related gems including `opentelemetry-api` and `opentelemetry-sdk`.
|
59
77
|
|
60
|
-
The OpenTelemetry Ruby gems are maintained by the OpenTelemetry
|
78
|
+
The OpenTelemetry Ruby gems are maintained by the OpenTelemetry Ruby special interest group (SIG). You can get involved by joining us on our [GitHub Discussions][discussions-url], [Slack Channel][slack-channel] or attending our weekly meeting. See the [meeting calendar][community-meetings] for dates and times. For more information on this and other language SIGs, see the OpenTelemetry [community page][ruby-sig].
|
61
79
|
|
62
80
|
## License
|
63
81
|
|
@@ -68,4 +86,6 @@ The `opentelemetry-instrumentation-action_pack` gem is distributed under the Apa
|
|
68
86
|
[license-github]: https://github.com/open-telemetry/opentelemetry-ruby-contrib/blob/main/LICENSE
|
69
87
|
[ruby-sig]: https://github.com/open-telemetry/community#ruby-sig
|
70
88
|
[community-meetings]: https://github.com/open-telemetry/community#community-meetings
|
89
|
+
[slack-channel]: https://cloud-native.slack.com/archives/C01NWKKMKMY
|
71
90
|
[discussions-url]: https://github.com/open-telemetry/opentelemetry-ruby/discussions
|
91
|
+
[rails-home]: https://rubyonrails.org/
|
@@ -13,6 +13,7 @@ module OpenTelemetry
|
|
13
13
|
# @param config [Hash] of instrumentation options
|
14
14
|
def initialize(config)
|
15
15
|
@config = config
|
16
|
+
@span_naming = config.fetch(:span_naming)
|
16
17
|
end
|
17
18
|
|
18
19
|
# Invoked by ActiveSupport::Notifications at the start of the instrumentation block
|
@@ -22,20 +23,11 @@ module OpenTelemetry
|
|
22
23
|
# @param payload [Hash] the payload passed as a method argument
|
23
24
|
# @return [Hash] the payload passed as a method argument
|
24
25
|
def start(_name, _id, payload)
|
25
|
-
|
26
|
+
span_name, attributes = to_span_name_and_attributes(payload)
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
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)
|
28
|
+
span = OpenTelemetry::Instrumentation::Rack.current_span
|
29
|
+
span.name = span_name
|
30
|
+
span.add_attributes(attributes)
|
39
31
|
rescue StandardError => e
|
40
32
|
OpenTelemetry.handle_error(exception: e)
|
41
33
|
end
|
@@ -47,11 +39,37 @@ module OpenTelemetry
|
|
47
39
|
# @param payload [Hash] the payload passed as a method argument
|
48
40
|
# @return [Hash] the payload passed as a method argument
|
49
41
|
def finish(_name, _id, payload)
|
50
|
-
|
51
|
-
|
42
|
+
span = OpenTelemetry::Instrumentation::Rack.current_span
|
43
|
+
span.record_exception(payload[:exception_object]) if payload[:exception_object]
|
52
44
|
rescue StandardError => e
|
53
45
|
OpenTelemetry.handle_error(exception: e)
|
54
46
|
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
# Extracts the span name and attributes from the payload
|
51
|
+
#
|
52
|
+
# @param payload [Hash] the payload passed from ActiveSupport::Notifications
|
53
|
+
# @return [Array<String, Hash>] the span name and attributes
|
54
|
+
def to_span_name_and_attributes(payload)
|
55
|
+
request = payload[:request]
|
56
|
+
http_route = request.route_uri_pattern if request.respond_to?(:route_uri_pattern)
|
57
|
+
|
58
|
+
attributes = {
|
59
|
+
OpenTelemetry::SemanticConventions::Trace::CODE_NAMESPACE => String(payload[:controller]),
|
60
|
+
OpenTelemetry::SemanticConventions::Trace::CODE_FUNCTION => String(payload[:action])
|
61
|
+
}
|
62
|
+
attributes[OpenTelemetry::SemanticConventions::Trace::HTTP_ROUTE] = http_route if http_route
|
63
|
+
attributes[OpenTelemetry::SemanticConventions::Trace::HTTP_TARGET] = request.filtered_path if request.filtered_path != request.fullpath
|
64
|
+
|
65
|
+
if @span_naming == :semconv
|
66
|
+
return ["#{request.method} #{http_route.gsub('(.:format)', '')}", attributes] if http_route
|
67
|
+
|
68
|
+
return ["#{request.method} /#{payload.dig(:params, :controller)}/#{payload.dig(:params, :action)}", attributes]
|
69
|
+
end
|
70
|
+
|
71
|
+
["#{payload[:controller]}##{payload[:action]}", attributes]
|
72
|
+
end
|
55
73
|
end
|
56
74
|
end
|
57
75
|
end
|
@@ -7,7 +7,31 @@
|
|
7
7
|
module OpenTelemetry
|
8
8
|
module Instrumentation
|
9
9
|
module ActionPack
|
10
|
-
# The Instrumentation class contains logic to detect and install the ActionPack instrumentation
|
10
|
+
# The {OpenTelemetry::Instrumentation::ActionPack::Instrumentation} class contains logic to detect and install the ActionPack instrumentation
|
11
|
+
#
|
12
|
+
# Installation and configuration of this instrumentation is done within the
|
13
|
+
# {https://www.rubydoc.info/gems/opentelemetry-sdk/OpenTelemetry/SDK#configure-instance_method OpenTelemetry::SDK#configure}
|
14
|
+
# block, calling {https://www.rubydoc.info/gems/opentelemetry-sdk/OpenTelemetry%2FSDK%2FConfigurator:use use()}
|
15
|
+
# or {https://www.rubydoc.info/gems/opentelemetry-sdk/OpenTelemetry%2FSDK%2FConfigurator:use_all use_all()}.
|
16
|
+
#
|
17
|
+
# ## Configuration keys and options
|
18
|
+
#
|
19
|
+
# ### `:span_naming`
|
20
|
+
#
|
21
|
+
# Specifies how the span names are set. Can be one of:
|
22
|
+
#
|
23
|
+
# - `:semconv` **(default)** - The span name will use HTTP semantic conventions '{method http.route}', for example `GET /users/:id`
|
24
|
+
# - `:class` - The span name will appear as '<ActionController class name>#<action>',
|
25
|
+
# for example `UsersController#show`.
|
26
|
+
#
|
27
|
+
# @example An explicit default configuration
|
28
|
+
# OpenTelemetry::SDK.configure do |c|
|
29
|
+
# c.use_all({
|
30
|
+
# 'OpenTelemetry::Instrumentation::ActionPack' => {
|
31
|
+
# span_naming: :class
|
32
|
+
# },
|
33
|
+
# })
|
34
|
+
# end
|
11
35
|
class Instrumentation < OpenTelemetry::Instrumentation::Base
|
12
36
|
MINIMUM_VERSION = Gem::Version.new('6.1.0')
|
13
37
|
|
@@ -17,6 +41,8 @@ module OpenTelemetry
|
|
17
41
|
patch
|
18
42
|
end
|
19
43
|
|
44
|
+
option :span_naming, default: :semconv, validate: %i[semconv class]
|
45
|
+
|
20
46
|
present do
|
21
47
|
defined?(::ActionController)
|
22
48
|
end
|
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.10.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: 2024-
|
11
|
+
date: 2024-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opentelemetry-api
|
@@ -122,20 +122,6 @@ dependencies:
|
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0.3'
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: rails
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - ">="
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: '6.1'
|
132
|
-
type: :development
|
133
|
-
prerelease: false
|
134
|
-
version_requirements: !ruby/object:Gem::Requirement
|
135
|
-
requirements:
|
136
|
-
- - ">="
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
version: '6.1'
|
139
125
|
- !ruby/object:Gem::Dependency
|
140
126
|
name: rake
|
141
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -156,28 +142,28 @@ dependencies:
|
|
156
142
|
requirements:
|
157
143
|
- - "~>"
|
158
144
|
- !ruby/object:Gem::Version
|
159
|
-
version: 1.
|
145
|
+
version: 1.68.0
|
160
146
|
type: :development
|
161
147
|
prerelease: false
|
162
148
|
version_requirements: !ruby/object:Gem::Requirement
|
163
149
|
requirements:
|
164
150
|
- - "~>"
|
165
151
|
- !ruby/object:Gem::Version
|
166
|
-
version: 1.
|
152
|
+
version: 1.68.0
|
167
153
|
- !ruby/object:Gem::Dependency
|
168
154
|
name: rubocop-performance
|
169
155
|
requirement: !ruby/object:Gem::Requirement
|
170
156
|
requirements:
|
171
157
|
- - "~>"
|
172
158
|
- !ruby/object:Gem::Version
|
173
|
-
version: 1.
|
159
|
+
version: 1.22.0
|
174
160
|
type: :development
|
175
161
|
prerelease: false
|
176
162
|
version_requirements: !ruby/object:Gem::Requirement
|
177
163
|
requirements:
|
178
164
|
- - "~>"
|
179
165
|
- !ruby/object:Gem::Version
|
180
|
-
version: 1.
|
166
|
+
version: 1.22.0
|
181
167
|
- !ruby/object:Gem::Dependency
|
182
168
|
name: simplecov
|
183
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -198,14 +184,14 @@ dependencies:
|
|
198
184
|
requirements:
|
199
185
|
- - "~>"
|
200
186
|
- !ruby/object:Gem::Version
|
201
|
-
version:
|
187
|
+
version: 3.24.0
|
202
188
|
type: :development
|
203
189
|
prerelease: false
|
204
190
|
version_requirements: !ruby/object:Gem::Requirement
|
205
191
|
requirements:
|
206
192
|
- - "~>"
|
207
193
|
- !ruby/object:Gem::Version
|
208
|
-
version:
|
194
|
+
version: 3.24.0
|
209
195
|
- !ruby/object:Gem::Dependency
|
210
196
|
name: yard
|
211
197
|
requirement: !ruby/object:Gem::Requirement
|
@@ -243,10 +229,10 @@ homepage: https://github.com/open-telemetry/opentelemetry-ruby-contrib
|
|
243
229
|
licenses:
|
244
230
|
- Apache-2.0
|
245
231
|
metadata:
|
246
|
-
changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-action_pack/0.
|
232
|
+
changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-action_pack/0.10.0/file/CHANGELOG.md
|
247
233
|
source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/tree/main/instrumentation/action_pack
|
248
234
|
bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/issues
|
249
|
-
documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-action_pack/0.
|
235
|
+
documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-action_pack/0.10.0
|
250
236
|
post_install_message:
|
251
237
|
rdoc_options: []
|
252
238
|
require_paths:
|