opentelemetry-instrumentation-rack 0.31.1 → 0.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +4 -7
- data/lib/opentelemetry/instrumentation/rack/middlewares/dup/event_handler.rb +26 -8
- data/lib/opentelemetry/instrumentation/rack/middlewares/dup/tracer_middleware.rb +2 -0
- data/lib/opentelemetry/instrumentation/rack/middlewares/old/event_handler.rb +24 -8
- data/lib/opentelemetry/instrumentation/rack/middlewares/stable/event_handler.rb +26 -8
- data/lib/opentelemetry/instrumentation/rack/middlewares/stable/tracer_middleware.rb +2 -0
- data/lib/opentelemetry/instrumentation/rack/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a797be7b734f8623eeb3855bb6de2643dbc225d146c67fa090e908a877b11e8d
|
|
4
|
+
data.tar.gz: 448a358aa336e27a3c5aa15b8eacf7f74c3dce2f307b717b8ccb72909720f3c1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6d6c07cd7615ee3d27e988cffe0adc1ce2d3fbeb93ae23ac3638fba7839747ee4d197bd4d991f51fc3c49f616b315f549208e538721b65f2b9ccc08275bd9a4f
|
|
7
|
+
data.tar.gz: e6ae2d36b2849ae7315ae3dc17535a89722ae9d140a0f12d0bae7db0de74b9ce7fca894530469d250f2cd9dfa39476bcc60a616279029c2ac3f7ad08957840d3
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Release History: opentelemetry-instrumentation-rack
|
|
2
2
|
|
|
3
|
+
## v0.32.0 / 2026-11-17
|
|
4
|
+
|
|
5
|
+
- ADDED: Set client.address from Rack::Request#ip (#2667)
|
|
6
|
+
|
|
7
|
+
## v0.31.2 / 2026-09-29
|
|
8
|
+
|
|
9
|
+
- FIXED: Fiber-safe context detachment in `EventHandler` (#2130)
|
|
10
|
+
|
|
3
11
|
## v0.31.1 / 2026-05-21
|
|
4
12
|
|
|
5
13
|
- FIXED: Handle missing config in middleware when OTEL_SDK_DISABLED=true (#2231)
|
data/README.md
CHANGED
|
@@ -85,9 +85,9 @@ Example usage can be seen in the [`./example/trace_demonstration.rb` file](https
|
|
|
85
85
|
|
|
86
86
|
## How can I get involved?
|
|
87
87
|
|
|
88
|
-
The `opentelemetry-instrumentation-rack` gem source is [on github][repo-github], along with related gems
|
|
88
|
+
The `opentelemetry-instrumentation-rack` gem source is [on github][repo-github], along with related gems.
|
|
89
89
|
|
|
90
|
-
The OpenTelemetry Ruby gems are maintained by the OpenTelemetry Ruby
|
|
90
|
+
The OpenTelemetry Ruby gems are maintained by the OpenTelemetry Ruby Special Interest Group (SIG). You can find details on our weekly meeting times, GitHub Discussions, and CNCF Slack channels on the [Ruby SDK SIG page][ruby-sig].
|
|
91
91
|
|
|
92
92
|
## License
|
|
93
93
|
|
|
@@ -95,12 +95,9 @@ The `opentelemetry-instrumentation-rack` gem is distributed under the Apache 2.0
|
|
|
95
95
|
|
|
96
96
|
[rack-home]: https://github.com/rack/rack
|
|
97
97
|
[bundler-home]: https://bundler.io
|
|
98
|
-
[repo-github]: https://github.com/open-telemetry/opentelemetry-ruby
|
|
98
|
+
[repo-github]: https://github.com/open-telemetry/opentelemetry-ruby-contrib
|
|
99
99
|
[license-github]: https://github.com/open-telemetry/opentelemetry-ruby-contrib/blob/main/LICENSE
|
|
100
|
-
[ruby-sig]: https://github.com/open-telemetry/community#ruby-
|
|
101
|
-
[community-meetings]: https://github.com/open-telemetry/community#community-meetings
|
|
102
|
-
[slack-channel]: https://cloud-native.slack.com/archives/C01NWKKMKMY
|
|
103
|
-
[discussions-url]: https://github.com/open-telemetry/opentelemetry-ruby/discussions
|
|
100
|
+
[ruby-sig]: https://github.com/open-telemetry/community/blob/main/sigs.md#ruby-sdk
|
|
104
101
|
|
|
105
102
|
## HTTP semantic convention stability
|
|
106
103
|
|
|
@@ -43,7 +43,7 @@ module OpenTelemetry
|
|
|
43
43
|
class EventHandler
|
|
44
44
|
include ::Rack::Events::Abstract
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
OTEL_CONTEXT_INFO = 'otel.rack.context_info'
|
|
47
47
|
EMPTY_HASH = {}.freeze
|
|
48
48
|
|
|
49
49
|
# Creates a server span for this current request using the incoming parent context
|
|
@@ -62,7 +62,8 @@ module OpenTelemetry
|
|
|
62
62
|
span = create_span(parent_context, request)
|
|
63
63
|
span_ctx = OpenTelemetry::Trace.context_with_span(span, parent_context: parent_context)
|
|
64
64
|
rack_ctx = OpenTelemetry::Instrumentation::Rack.context_with_span(span, parent_context: span_ctx)
|
|
65
|
-
|
|
65
|
+
token = OpenTelemetry::Context.attach(rack_ctx)
|
|
66
|
+
(request.env[OTEL_CONTEXT_INFO] ||= {})[request] = [Fiber.current, token, span]
|
|
66
67
|
rescue StandardError => e
|
|
67
68
|
OpenTelemetry.handle_error(exception: e)
|
|
68
69
|
end
|
|
@@ -107,14 +108,17 @@ module OpenTelemetry
|
|
|
107
108
|
# @param [Rack::Request] The current HTTP request
|
|
108
109
|
# @param [Rack::Response] The current HTTP response
|
|
109
110
|
def on_finish(request, response)
|
|
110
|
-
|
|
111
|
+
request_context = context_for_request(request)
|
|
112
|
+
return unless request_context
|
|
113
|
+
|
|
114
|
+
_, _, span = request_context
|
|
111
115
|
return unless span.recording?
|
|
112
116
|
|
|
113
117
|
add_response_attributes(span, response) if response
|
|
114
118
|
rescue StandardError => e
|
|
115
119
|
OpenTelemetry.handle_error(exception: e)
|
|
116
120
|
ensure
|
|
117
|
-
detach_context(
|
|
121
|
+
detach_context(request_context)
|
|
118
122
|
end
|
|
119
123
|
|
|
120
124
|
private
|
|
@@ -200,6 +204,8 @@ module OpenTelemetry
|
|
|
200
204
|
}
|
|
201
205
|
|
|
202
206
|
attributes['url.query'] = env['QUERY_STRING'] unless env['QUERY_STRING'].empty?
|
|
207
|
+
client_address = ::Rack::Request.new(env).ip
|
|
208
|
+
attributes['client.address'] = client_address if client_address
|
|
203
209
|
if env['HTTP_USER_AGENT']
|
|
204
210
|
attributes['http.user_agent'] = env['HTTP_USER_AGENT']
|
|
205
211
|
attributes['user_agent.original'] = env['HTTP_USER_AGENT']
|
|
@@ -208,12 +214,24 @@ module OpenTelemetry
|
|
|
208
214
|
attributes
|
|
209
215
|
end
|
|
210
216
|
|
|
211
|
-
def
|
|
212
|
-
|
|
217
|
+
def context_for_request(request)
|
|
218
|
+
contexts = request.env[OTEL_CONTEXT_INFO]
|
|
219
|
+
return unless contexts
|
|
220
|
+
|
|
221
|
+
contexts.delete(request)
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
def detach_context(request_context)
|
|
225
|
+
return unless request_context
|
|
213
226
|
|
|
214
|
-
token, span =
|
|
227
|
+
original_fiber, token, span = request_context
|
|
215
228
|
span.finish
|
|
216
|
-
|
|
229
|
+
|
|
230
|
+
if Fiber.current.equal?(original_fiber)
|
|
231
|
+
OpenTelemetry::Context.detach(token)
|
|
232
|
+
else
|
|
233
|
+
OpenTelemetry.logger.debug { '[OpenTelemetry::Instrumentation::Rack] Skipping context detach: response processed in different fiber than request.' }
|
|
234
|
+
end
|
|
217
235
|
rescue StandardError => e
|
|
218
236
|
OpenTelemetry.handle_error(exception: e)
|
|
219
237
|
end
|
|
@@ -136,6 +136,8 @@ module OpenTelemetry
|
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
attributes['url.query'] = env['QUERY_STRING'] unless env['QUERY_STRING'].empty?
|
|
139
|
+
client_address = ::Rack::Request.new(env).ip
|
|
140
|
+
attributes['client.address'] = client_address if client_address
|
|
139
141
|
if env['HTTP_USER_AGENT']
|
|
140
142
|
attributes['http.user_agent'] = env['HTTP_USER_AGENT']
|
|
141
143
|
attributes['user_agent.original'] = env['HTTP_USER_AGENT']
|
|
@@ -43,7 +43,7 @@ module OpenTelemetry
|
|
|
43
43
|
class EventHandler
|
|
44
44
|
include ::Rack::Events::Abstract
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
OTEL_CONTEXT_INFO = 'otel.rack.context_info'
|
|
47
47
|
EMPTY_HASH = {}.freeze
|
|
48
48
|
|
|
49
49
|
# Creates a server span for this current request using the incoming parent context
|
|
@@ -62,7 +62,8 @@ module OpenTelemetry
|
|
|
62
62
|
span = create_span(parent_context, request)
|
|
63
63
|
span_ctx = OpenTelemetry::Trace.context_with_span(span, parent_context: parent_context)
|
|
64
64
|
rack_ctx = OpenTelemetry::Instrumentation::Rack.context_with_span(span, parent_context: span_ctx)
|
|
65
|
-
|
|
65
|
+
token = OpenTelemetry::Context.attach(rack_ctx)
|
|
66
|
+
(request.env[OTEL_CONTEXT_INFO] ||= {})[request] = [Fiber.current, token, span]
|
|
66
67
|
rescue StandardError => e
|
|
67
68
|
OpenTelemetry.handle_error(exception: e)
|
|
68
69
|
end
|
|
@@ -107,14 +108,17 @@ module OpenTelemetry
|
|
|
107
108
|
# @param [Rack::Request] The current HTTP request
|
|
108
109
|
# @param [Rack::Response] The current HTTP response
|
|
109
110
|
def on_finish(request, response)
|
|
110
|
-
|
|
111
|
+
request_context = context_for_request(request)
|
|
112
|
+
return unless request_context
|
|
113
|
+
|
|
114
|
+
_, _, span = request_context
|
|
111
115
|
return unless span.recording?
|
|
112
116
|
|
|
113
117
|
add_response_attributes(span, response) if response
|
|
114
118
|
rescue StandardError => e
|
|
115
119
|
OpenTelemetry.handle_error(exception: e)
|
|
116
120
|
ensure
|
|
117
|
-
detach_context(
|
|
121
|
+
detach_context(request_context)
|
|
118
122
|
end
|
|
119
123
|
|
|
120
124
|
private
|
|
@@ -197,12 +201,24 @@ module OpenTelemetry
|
|
|
197
201
|
attributes
|
|
198
202
|
end
|
|
199
203
|
|
|
200
|
-
def
|
|
201
|
-
|
|
204
|
+
def context_for_request(request)
|
|
205
|
+
contexts = request.env[OTEL_CONTEXT_INFO]
|
|
206
|
+
return unless contexts
|
|
207
|
+
|
|
208
|
+
contexts.delete(request)
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
def detach_context(request_context)
|
|
212
|
+
return unless request_context
|
|
202
213
|
|
|
203
|
-
token, span =
|
|
214
|
+
original_fiber, token, span = request_context
|
|
204
215
|
span.finish
|
|
205
|
-
|
|
216
|
+
|
|
217
|
+
if Fiber.current.equal?(original_fiber)
|
|
218
|
+
OpenTelemetry::Context.detach(token)
|
|
219
|
+
else
|
|
220
|
+
OpenTelemetry.logger.debug { '[OpenTelemetry::Instrumentation::Rack] Skipping context detach: response processed in different fiber than request.' }
|
|
221
|
+
end
|
|
206
222
|
rescue StandardError => e
|
|
207
223
|
OpenTelemetry.handle_error(exception: e)
|
|
208
224
|
end
|
|
@@ -43,7 +43,7 @@ module OpenTelemetry
|
|
|
43
43
|
class EventHandler
|
|
44
44
|
include ::Rack::Events::Abstract
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
OTEL_CONTEXT_INFO = 'otel.rack.context_info'
|
|
47
47
|
EMPTY_HASH = {}.freeze
|
|
48
48
|
|
|
49
49
|
# Creates a server span for this current request using the incoming parent context
|
|
@@ -62,7 +62,8 @@ module OpenTelemetry
|
|
|
62
62
|
span = create_span(parent_context, request)
|
|
63
63
|
span_ctx = OpenTelemetry::Trace.context_with_span(span, parent_context: parent_context)
|
|
64
64
|
rack_ctx = OpenTelemetry::Instrumentation::Rack.context_with_span(span, parent_context: span_ctx)
|
|
65
|
-
|
|
65
|
+
token = OpenTelemetry::Context.attach(rack_ctx)
|
|
66
|
+
(request.env[OTEL_CONTEXT_INFO] ||= {})[request] = [Fiber.current, token, span]
|
|
66
67
|
rescue StandardError => e
|
|
67
68
|
OpenTelemetry.handle_error(exception: e)
|
|
68
69
|
end
|
|
@@ -107,14 +108,17 @@ module OpenTelemetry
|
|
|
107
108
|
# @param [Rack::Request] The current HTTP request
|
|
108
109
|
# @param [Rack::Response] The current HTTP response
|
|
109
110
|
def on_finish(request, response)
|
|
110
|
-
|
|
111
|
+
request_context = context_for_request(request)
|
|
112
|
+
return unless request_context
|
|
113
|
+
|
|
114
|
+
_, _, span = request_context
|
|
111
115
|
return unless span.recording?
|
|
112
116
|
|
|
113
117
|
add_response_attributes(span, response) if response
|
|
114
118
|
rescue StandardError => e
|
|
115
119
|
OpenTelemetry.handle_error(exception: e)
|
|
116
120
|
ensure
|
|
117
|
-
detach_context(
|
|
121
|
+
detach_context(request_context)
|
|
118
122
|
end
|
|
119
123
|
|
|
120
124
|
private
|
|
@@ -191,17 +195,31 @@ module OpenTelemetry
|
|
|
191
195
|
}
|
|
192
196
|
|
|
193
197
|
attributes['url.query'] = env['QUERY_STRING'] unless env['QUERY_STRING'].empty?
|
|
198
|
+
client_address = ::Rack::Request.new(env).ip
|
|
199
|
+
attributes['client.address'] = client_address if client_address
|
|
194
200
|
attributes['user_agent.original'] = env['HTTP_USER_AGENT'] if env['HTTP_USER_AGENT']
|
|
195
201
|
attributes.merge!(extract_request_headers(env))
|
|
196
202
|
attributes
|
|
197
203
|
end
|
|
198
204
|
|
|
199
|
-
def
|
|
200
|
-
|
|
205
|
+
def context_for_request(request)
|
|
206
|
+
contexts = request.env[OTEL_CONTEXT_INFO]
|
|
207
|
+
return unless contexts
|
|
208
|
+
|
|
209
|
+
contexts.delete(request)
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
def detach_context(request_context)
|
|
213
|
+
return unless request_context
|
|
201
214
|
|
|
202
|
-
token, span =
|
|
215
|
+
original_fiber, token, span = request_context
|
|
203
216
|
span.finish
|
|
204
|
-
|
|
217
|
+
|
|
218
|
+
if Fiber.current.equal?(original_fiber)
|
|
219
|
+
OpenTelemetry::Context.detach(token)
|
|
220
|
+
else
|
|
221
|
+
OpenTelemetry.logger.debug { '[OpenTelemetry::Instrumentation::Rack] Skipping context detach: response processed in different fiber than request.' }
|
|
222
|
+
end
|
|
205
223
|
rescue StandardError => e
|
|
206
224
|
OpenTelemetry.handle_error(exception: e)
|
|
207
225
|
end
|
|
@@ -132,6 +132,8 @@ module OpenTelemetry
|
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
attributes['url.query'] = env['QUERY_STRING'] unless env['QUERY_STRING'].empty?
|
|
135
|
+
client_address = ::Rack::Request.new(env).ip
|
|
136
|
+
attributes['client.address'] = client_address if client_address
|
|
135
137
|
attributes['user_agent.original'] = env['HTTP_USER_AGENT'] if env['HTTP_USER_AGENT']
|
|
136
138
|
attributes.merge!(allowed_request_headers(env))
|
|
137
139
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: opentelemetry-instrumentation-rack
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.32.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- OpenTelemetry Authors
|
|
@@ -51,10 +51,10 @@ homepage: https://github.com/open-telemetry/opentelemetry-ruby-contrib
|
|
|
51
51
|
licenses:
|
|
52
52
|
- Apache-2.0
|
|
53
53
|
metadata:
|
|
54
|
-
changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-rack/0.
|
|
55
|
-
source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/tree/opentelemetry-instrumentation-rack/v0.
|
|
54
|
+
changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-rack/0.32.0/file/CHANGELOG.md
|
|
55
|
+
source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/tree/opentelemetry-instrumentation-rack/v0.32.0/instrumentation/rack
|
|
56
56
|
bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/issues
|
|
57
|
-
documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-rack/0.
|
|
57
|
+
documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-rack/0.32.0
|
|
58
58
|
rdoc_options: []
|
|
59
59
|
require_paths:
|
|
60
60
|
- lib
|
|
@@ -69,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
69
69
|
- !ruby/object:Gem::Version
|
|
70
70
|
version: '0'
|
|
71
71
|
requirements: []
|
|
72
|
-
rubygems_version: 4.0.
|
|
72
|
+
rubygems_version: 4.0.20
|
|
73
73
|
specification_version: 4
|
|
74
74
|
summary: Rack instrumentation for the OpenTelemetry framework
|
|
75
75
|
test_files: []
|