opentelemetry-instrumentation-http 0.22.0 → 0.23.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4b26732c1377859a8826f9ab1dfd0979bf15b7b19a2eefd13814713e4fdb0da4
4
- data.tar.gz: 50b5a3d8cc28a8b6b15ef0a034188151682fba452955dd6a9250d935f6d4002f
3
+ metadata.gz: 7520e68ea064b0f26bd7b375c3570cc3bce18d049afc55fa3ceb01595bda8393
4
+ data.tar.gz: 7d7a46cdbeb076c0aace30742d8800754c2badfb379b36602f83a6d3a262b145
5
5
  SHA512:
6
- metadata.gz: c5640a46cd6533b483f7a57250266d713dd56e65b7d013f2ebbff75ad7ecb1d7d7ed35d3dbeda4378b29c6d706603a51f5e087c09c1c8cd9f74f588667f2bd69
7
- data.tar.gz: e2009128b0b3429fb866ee14ae7aa7fc23e9feca29f1f65f77d54dbe769bdb5f14b8be125a9388bdf97373aea8838a83f3f26ed48e289732ac5f60fc8107ec31
6
+ metadata.gz: 15b98fc0bb58a37e67d04bc8d8984c4a39ec1fb71f3df5d8a74d572bf5fa41ccffafdbd291b2362a1273c7358a5fa1cfa5da29cfb8c074a19d39b48b5a13f565
7
+ data.tar.gz: 4b8f049396a292cb47cdd276a7d1dfae09ea90c6031029d4aebbadcc0d697662b25fa7045af9994f2babd3d8b32c52602a2a284520ccc0979f74a47a4454e93b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Release History: opentelemetry-instrumentation-http
2
2
 
3
+ ### v0.23.0 / 2023-05-15
4
+
5
+ * ADDED: Add span_preprocessor hook
6
+
3
7
  ### v0.22.0 / 2023-04-17
4
8
 
5
9
  * BREAKING CHANGE: Drop support for EoL Ruby 2.7
data/README.md CHANGED
@@ -30,6 +30,18 @@ OpenTelemetry::SDK.configure do |c|
30
30
  end
31
31
  ```
32
32
 
33
+ ## Enriching http span names
34
+
35
+ We surface a hook to easily rename your span.
36
+
37
+ The lambda accepts as arguments (request_method, request_path) and returns a string that is set as the span name.
38
+
39
+ ```ruby
40
+ OpenTelemetry::SDK.configure do |c|
41
+ c.use 'OpenTelemetry::Instrumentation::Rack', { span_name_formatter: ->(request_method, request_path) { "HTTP #{request_method} #{request_path}" }
42
+ end
43
+ ```
44
+
33
45
  ## Examples
34
46
 
35
47
  Example usage can be seen in the `./example/trace_demonstration.rb` file [here](https://github.com/open-telemetry/opentelemetry-ruby-contrib/blob/main/instrumentation/http/example/trace_demonstration.rb)
@@ -18,6 +18,8 @@ module OpenTelemetry
18
18
  !(defined?(::HTTP::Client).nil? || defined?(::HTTP::Connection).nil?)
19
19
  end
20
20
 
21
+ option :span_name_formatter, default: nil, validate: :callable
22
+
21
23
  def patch
22
24
  ::HTTP::Client.prepend(Patches::Client)
23
25
  ::HTTP::Connection.prepend(Patches::Connection)
@@ -13,6 +13,7 @@ module OpenTelemetry
13
13
  def perform(req, options)
14
14
  uri = req.uri
15
15
  request_method = req.verb.to_s.upcase
16
+ span_name = create_request_span_name(request_method, uri.path)
16
17
 
17
18
  attributes = {
18
19
  'http.method' => request_method,
@@ -23,7 +24,7 @@ module OpenTelemetry
23
24
  'net.peer.port' => uri.port
24
25
  }.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes)
25
26
 
26
- tracer.in_span("HTTP #{request_method}", attributes: attributes, kind: :client) do |span|
27
+ tracer.in_span(span_name, attributes: attributes, kind: :client) do |span|
27
28
  OpenTelemetry.propagation.inject(req.headers)
28
29
  super.tap do |response|
29
30
  annotate_span_with_response!(span, response)
@@ -33,6 +34,10 @@ module OpenTelemetry
33
34
 
34
35
  private
35
36
 
37
+ def config
38
+ OpenTelemetry::Instrumentation::HTTP::Instrumentation.instance.config
39
+ end
40
+
36
41
  def annotate_span_with_response!(span, response)
37
42
  return unless response&.status
38
43
 
@@ -41,6 +46,17 @@ module OpenTelemetry
41
46
  span.status = OpenTelemetry::Trace::Status.error unless (100..399).include?(status_code.to_i)
42
47
  end
43
48
 
49
+ def create_request_span_name(request_method, request_path)
50
+ if (implementation = config[:span_name_formatter])
51
+ updated_span_name = implementation.call(request_method, request_path)
52
+ updated_span_name.is_a?(String) ? updated_span_name : "HTTP #{request_method}"
53
+ else
54
+ "HTTP #{request_method}"
55
+ end
56
+ rescue StandardError
57
+ "HTTP #{request_method}"
58
+ end
59
+
44
60
  def tracer
45
61
  HTTP::Instrumentation.instance.tracer
46
62
  end
@@ -7,7 +7,7 @@
7
7
  module OpenTelemetry
8
8
  module Instrumentation
9
9
  module HTTP
10
- VERSION = '0.22.0'
10
+ VERSION = '0.23.0'
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-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.22.0
4
+ version: 0.23.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: 2023-04-17 00:00:00.000000000 Z
11
+ date: 2023-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opentelemetry-api
@@ -156,14 +156,14 @@ dependencies:
156
156
  requirements:
157
157
  - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: 1.48.1
159
+ version: 1.50.2
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.48.1
166
+ version: 1.50.2
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: simplecov
169
169
  requirement: !ruby/object:Gem::Requirement
@@ -242,10 +242,10 @@ homepage: https://github.com/open-telemetry/opentelemetry-ruby-contrib
242
242
  licenses:
243
243
  - Apache-2.0
244
244
  metadata:
245
- changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-http/0.22.0/file/CHANGELOG.md
245
+ changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-http/0.23.0/file/CHANGELOG.md
246
246
  source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/tree/main/instrumentation/http
247
247
  bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/issues
248
- documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-http/0.22.0
248
+ documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-http/0.23.0
249
249
  post_install_message:
250
250
  rdoc_options: []
251
251
  require_paths: