opentelemetry-instrumentation-rack 0.6.0 → 0.10.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 554df8fdcc4832dfe5c7af3bedcb7c96003e9cbc0f1ed57f1c8dac2277af64e9
4
- data.tar.gz: bb4dea5f452eeed9f0ade6a18c058c99097e9b28094982200f3dfba9f3a3c581
3
+ metadata.gz: 0c079f65d4e53d8d3089785f6c6e6cfdb71ddc0236d3b82f2b6f344b762b283f
4
+ data.tar.gz: c83a43d564760aeaba8e7f0870941a94cc6afcd387ca5e2bd1caec1e3496b77f
5
5
  SHA512:
6
- metadata.gz: 07d6f7edf293523eced6ad8faa0bc8df171869dc37fc8c12dfec8aa1880664f94f007ed1f4413e6e862e293c49a84efb2b74427d8573b03c8823a0a19c7724a9
7
- data.tar.gz: 2a4198e6881b35a0cba43a676bc87099d40d95b36ff54a094fd1cd1450176c86ec889e2736b100b0d10998d306cf50e666f842bc824b57779f5cdfcbd7daad6f
6
+ metadata.gz: 01fe4134ce9315800e6e448398d1bd4c27c75b32032d64a01d3423201b6939ebdc99f284ccdfddc98aa711d17689dd616be30e81978caa53ca1177ef3c924b4d
7
+ data.tar.gz: efbd8de523f9ad3406c4fc8871c440181e782f616fb6ca924ef216f55b0ca046ea61639f662377b950931cd204ed25b6a13220210db227d9bfb845e6e9d1331e
@@ -0,0 +1,9 @@
1
+ --no-private
2
+ --title=OpenTelemetry Rack Instrumentation
3
+ --markup=markdown
4
+ --main=README.md
5
+ ./lib/opentelemetry/instrumentation/**/*.rb
6
+ ./lib/opentelemetry/instrumentation.rb
7
+ -
8
+ README.md
9
+ CHANGELOG.md
@@ -1,5 +1,34 @@
1
1
  # Release History: opentelemetry-instrumentation-rack
2
2
 
3
+ ### v0.10.1 / 2020-12-09
4
+
5
+ * FIXED: Rack current_span
6
+
7
+ ### v0.10.0 / 2020-12-03
8
+
9
+ * (No significant changes)
10
+
11
+ ### v0.9.0 / 2020-11-27
12
+
13
+ * BREAKING CHANGE: Add timeout for force_flush and shutdown
14
+
15
+ * ADDED: Instrument rails
16
+ * ADDED: Add timeout for force_flush and shutdown
17
+
18
+ ### v0.8.0 / 2020-10-27
19
+
20
+ * BREAKING CHANGE: Move context/span methods to Trace module
21
+ * BREAKING CHANGE: Remove 'canonical' from status codes
22
+
23
+ * FIXED: Move context/span methods to Trace module
24
+ * FIXED: Remove 'canonical' from status codes
25
+
26
+ ### v0.7.0 / 2020-10-07
27
+
28
+ * FIXED: Remove superfluous file from Rack gem
29
+ * DOCS: Added README for Rack Instrumentation
30
+ * DOCS: Standardize toplevel docs structure and readme
31
+
3
32
  ### v0.6.0 / 2020-09-10
4
33
 
5
34
  * (No significant changes)
@@ -0,0 +1,53 @@
1
+ # OpenTelemetry Rack Instrumentation
2
+
3
+ The Rack instrumentation is a community-maintained instrumentation for the [Rack][rack-home] web server interface.
4
+
5
+ ## How do I get started?
6
+
7
+ Install the gem using:
8
+
9
+ ```
10
+ gem install opentelemetry-instrumentation-rack
11
+ ```
12
+
13
+ Or, if you use [bundler][bundler-home], include `opentelemetry-instrumentation-rack` in your `Gemfile`.
14
+
15
+ ## Usage
16
+
17
+ To use the instrumentation, call `use` with the name of the instrumentation:
18
+
19
+ ```ruby
20
+ OpenTelemetry::SDK.configure do |c|
21
+ c.use 'OpenTelemetry::Instrumentation::Rack'
22
+ end
23
+ ```
24
+
25
+ Alternatively, you can also call `use_all` to install all the available instrumentation.
26
+
27
+ ```ruby
28
+ OpenTelemetry::SDK.configure do |c|
29
+ c.use_all
30
+ end
31
+ ```
32
+
33
+ ## Examples
34
+
35
+ Example usage can be seen in the `./example/trace_demonstration.rb` file [here](https://github.com/open-telemetry/opentelemetry-ruby/blob/master/instrumentation/rack/example/trace_demonstration.rb)
36
+
37
+ ## How can I get involved?
38
+
39
+ The `opentelemetry-instrumentation-rack` gem source is [on github][repo-github], along with related gems including `opentelemetry-api` and `opentelemetry-sdk`.
40
+
41
+ The OpenTelemetry Ruby gems are maintained by the OpenTelemetry-Ruby special interest group (SIG). You can get involved by joining us on our [gitter channel][ruby-gitter] 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].
42
+
43
+ ## License
44
+
45
+ The `opentelemetry-instrumentation-rack` gem is distributed under the Apache 2.0 license. See [LICENSE][license-github] for more information.
46
+
47
+ [rack-home]: https://github.com/rack/rack
48
+ [bundler-home]: https://bundler.io
49
+ [repo-github]: https://github.com/open-telemetry/opentelemetry-ruby
50
+ [license-github]: https://github.com/open-telemetry/opentelemetry-ruby/blob/master/LICENSE
51
+ [ruby-sig]: https://github.com/open-telemetry/community#ruby-sig
52
+ [community-meetings]: https://github.com/open-telemetry/community#community-meetings
53
+ [ruby-gitter]: https://gitter.im/open-telemetry/opentelemetry-ruby
@@ -4,6 +4,12 @@
4
4
  #
5
5
  # SPDX-License-Identifier: Apache-2.0
6
6
 
7
+ # OpenTelemetry is an open source observability framework, providing a
8
+ # general-purpose API, SDK, and related tools required for the instrumentation
9
+ # of cloud-native software, frameworks, and libraries.
10
+ #
11
+ # The OpenTelemetry module provides global accessors for telemetry objects.
12
+ # See the documentation for the `opentelemetry-api` gem for details.
7
13
  module OpenTelemetry
8
14
  # Instrumentation should be able to handle the case when the library is not installed on a user's system.
9
15
  module Instrumentation
@@ -10,6 +10,40 @@ module OpenTelemetry
10
10
  module Instrumentation
11
11
  # Contains the OpenTelemetry instrumentation for the Rack gem
12
12
  module Rack
13
+ extend self
14
+
15
+ CURRENT_SPAN_KEY = Context.create_key('current-span')
16
+
17
+ private_constant :CURRENT_SPAN_KEY
18
+
19
+ # Returns the current span from the current or provided context
20
+ #
21
+ # @param [optional Context] context The context to lookup the current
22
+ # {Span} from. Defaults to Context.current
23
+ def current_span(context = nil)
24
+ context ||= Context.current
25
+ context.value(CURRENT_SPAN_KEY) || OpenTelemetry::Trace::Span::INVALID
26
+ end
27
+
28
+ # Returns a context containing the span, derived from the optional parent
29
+ # context, or the current context if one was not provided.
30
+ #
31
+ # @param [optional Context] context The context to use as the parent for
32
+ # the returned context
33
+ def context_with_span(span, parent_context: Context.current)
34
+ parent_context.set_value(CURRENT_SPAN_KEY, span)
35
+ end
36
+
37
+ # Activates/deactivates the Span within the current Context, which makes the "current span"
38
+ # available implicitly.
39
+ #
40
+ # On exit, the Span that was active before calling this method will be reactivated.
41
+ #
42
+ # @param [Span] span the span to activate
43
+ # @yield [span, context] yields span and a context containing the span to the block.
44
+ def with_span(span)
45
+ Context.with_value(CURRENT_SPAN_KEY, span) { |c, s| yield s, c }
46
+ end
13
47
  end
14
48
  end
15
49
  end
@@ -51,7 +51,7 @@ module OpenTelemetry
51
51
  @app = app
52
52
  end
53
53
 
54
- def call(env)
54
+ def call(env) # rubocop:disable Metrics/AbcSize
55
55
  original_env = env.dup
56
56
  extracted_context = OpenTelemetry.propagation.http.extract(env)
57
57
  frontend_context = create_frontend_span(env, extracted_context)
@@ -63,8 +63,10 @@ module OpenTelemetry
63
63
  tracer.in_span(request_span_name,
64
64
  attributes: request_span_attributes(env: env),
65
65
  kind: request_span_kind) do |request_span|
66
- @app.call(env).tap do |status, headers, response|
67
- set_attributes_after_request(request_span, status, headers, response)
66
+ OpenTelemetry::Instrumentation::Rack.with_span(request_span) do
67
+ @app.call(env).tap do |status, headers, response|
68
+ set_attributes_after_request(request_span, status, headers, response)
69
+ end
68
70
  end
69
71
  end
70
72
  end
@@ -81,21 +83,17 @@ module OpenTelemetry
81
83
  return unless config[:record_frontend_span] && !request_start_time.nil?
82
84
 
83
85
  span = tracer.start_span('http_server.proxy',
84
- with_parent_context: extracted_context,
86
+ with_parent: extracted_context,
85
87
  attributes: {
86
88
  'start_time' => request_start_time.to_f
87
89
  },
88
90
  kind: :server)
89
91
 
90
- extracted_context.set_value(current_span_key, span)
92
+ OpenTelemetry::Trace.context_with_span(span, parent_context: extracted_context)
91
93
  end
92
94
 
93
95
  def finish_span(context)
94
- context[current_span_key]&.finish if context
95
- end
96
-
97
- def current_span_key
98
- OpenTelemetry::Trace::Propagation::ContextKeys.current_span_key
96
+ OpenTelemetry::Trace.current_span(context).finish if context
99
97
  end
100
98
 
101
99
  def tracer
@@ -107,7 +105,8 @@ module OpenTelemetry
107
105
  'http.method' => env['REQUEST_METHOD'],
108
106
  'http.host' => env['HTTP_HOST'] || 'unknown',
109
107
  'http.scheme' => env['rack.url_scheme'],
110
- 'http.target' => fullpath(env)
108
+ 'http.target' => fullpath(env),
109
+ 'http.user_agent' => env['HTTP_USER_AGENT']
111
110
  }.merge(allowed_request_headers(env))
112
111
  end
113
112
 
@@ -7,7 +7,7 @@
7
7
  module OpenTelemetry
8
8
  module Instrumentation
9
9
  module Rack
10
- VERSION = '0.6.0'
10
+ VERSION = '0.10.1'
11
11
  end
12
12
  end
13
13
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opentelemetry-instrumentation-rack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - OpenTelemetry Authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-11 00:00:00.000000000 Z
11
+ date: 2020-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opentelemetry-api
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.6.0
19
+ version: 0.10.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.6.0
26
+ version: 0.10.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: appraisal
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -199,11 +199,12 @@ executables: []
199
199
  extensions: []
200
200
  extra_rdoc_files: []
201
201
  files:
202
+ - ".yardopts"
202
203
  - CHANGELOG.md
203
204
  - LICENSE
205
+ - README.md
204
206
  - lib/opentelemetry-instrumentation-rack.rb
205
207
  - lib/opentelemetry/instrumentation.rb
206
- - lib/opentelemetry/instrumentation/instrumentation.rb
207
208
  - lib/opentelemetry/instrumentation/rack.rb
208
209
  - lib/opentelemetry/instrumentation/rack/instrumentation.rb
209
210
  - lib/opentelemetry/instrumentation/rack/middlewares/tracer_middleware.rb
@@ -212,7 +213,11 @@ files:
212
213
  homepage: https://github.com/open-telemetry/opentelemetry-ruby
213
214
  licenses:
214
215
  - Apache-2.0
215
- metadata: {}
216
+ metadata:
217
+ changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-rack/v0.10.1/file.CHANGELOG.html
218
+ source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby/tree/master/instrumentation/rack
219
+ bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby/issues
220
+ documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-rack/v0.10.1
216
221
  post_install_message:
217
222
  rdoc_options: []
218
223
  require_paths:
@@ -228,7 +233,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
228
233
  - !ruby/object:Gem::Version
229
234
  version: '0'
230
235
  requirements: []
231
- rubygems_version: 3.1.2
236
+ rubygems_version: 3.1.4
232
237
  signing_key:
233
238
  specification_version: 4
234
239
  summary: Rack instrumentation for the OpenTelemetry framework
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright 2019 OpenTelemetry Authors
4
- #
5
- # SPDX-License-Identifier: Apache-2.0
6
-
7
- module OpenTelemetry
8
- # "Instrumentation" are specified by
9
- # https://github.com/open-telemetry/opentelemetry-specification/blob/784635d01d8690c8f5fcd1f55bdbc8a13cf2f4f2/specification/glossary.md#instrumentation-library
10
- #
11
- # Instrumentation should be able to handle the case when the library is not installed on a user's system.
12
- module Instrumentation
13
- end
14
- end
15
-
16
- require_relative './instrumentation/rack'