helios-opentelemetry-sdk 0.1.12 → 0.1.15

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: ce889a94723b9b8f7b2c8da0a10608f5ae627841543649b3716cc01c5d915c2c
4
- data.tar.gz: ef7bc57d8507c1bb613a603197414700a9e428a58f9d271d5b3c19d975a97f68
3
+ metadata.gz: 11a4d057dafe06241ebe7042f68f2675fa052e653cb325df1ed7df27e609d603
4
+ data.tar.gz: 8b4b103be5da44eb1944a2211c58af5a85397c2acc1f3c20c554663979bde68b
5
5
  SHA512:
6
- metadata.gz: 1199e9514864e6497bd3cff0f9f2c311bd6711298ac4d6e7f94834bcb02c84d90ce08b0404ca76b2b6425736d027c3e91e67eb5e846ddfb5c01a4a8af36eae70
7
- data.tar.gz: a9d5cf728fda4d6745386218ffc55e7df3bbf0a1ac6119c404c94379106f7f570c51905c3f484046636b51604765dad633e7b1d82ca6f193ac159191a90ab3a7
6
+ metadata.gz: 39f09188ae59c71fe5779d7af3d84221cf3fa439372fbc71128e2668a4cb21e3b285846004965601d21d9b273edef9a7c4c7106e70eaed6091decabf617b868f
7
+ data.tar.gz: 4001559c175453f4a13742233b698aa96fa03948f29f5aa0b1530e28e85e6c4056cb808f5c6199bfef7232a09d0e0f22006589aa1688908bfd7ae960b1463bb8
data/.rubocop.yml CHANGED
@@ -21,3 +21,6 @@ Style/HashSyntax:
21
21
 
22
22
  Metrics/BlockLength:
23
23
  Enabled: false
24
+
25
+ Metrics/CyclomaticComplexity:
26
+ Enabled: false
data/Gemfile CHANGED
@@ -8,3 +8,5 @@ gem 'opentelemetry-instrumentation-all', '~> 0.25.0'
8
8
  gem 'opentelemetry-instrumentation-rspec', '~> 0.2.0'
9
9
  gem 'rubocop', '~> 1.30.1', group: [:development, :test]
10
10
  gem 'bundler', '~> 2.3.16', group: [:development, :test]
11
+ gem 'faraday', '~> 2.3.0', group: [:development, :test]
12
+ gem 'rack', '~> 2.2.4', group: [:development, :test]
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- helios-opentelemetry-sdk (0.1.12)
4
+ helios-opentelemetry-sdk (0.1.15)
5
5
  opentelemetry-exporter-otlp (~> 0.22.0)
6
6
  opentelemetry-instrumentation-all (~> 0.25.0)
7
7
  opentelemetry-instrumentation-rspec (~> 0.2.0)
@@ -12,6 +12,10 @@ GEM
12
12
  specs:
13
13
  ast (2.4.2)
14
14
  diff-lcs (1.5.0)
15
+ faraday (2.3.0)
16
+ faraday-net_http (~> 2.0)
17
+ ruby2_keywords (>= 0.0.4)
18
+ faraday-net_http (2.0.3)
15
19
  google-protobuf (3.21.1)
16
20
  googleapis-common-protos-types (1.3.1)
17
21
  google-protobuf (~> 3.14)
@@ -201,6 +205,7 @@ GEM
201
205
  parallel (1.22.1)
202
206
  parser (3.1.2.0)
203
207
  ast (~> 2.4.1)
208
+ rack (2.2.4)
204
209
  rainbow (3.1.1)
205
210
  rake (13.0.6)
206
211
  regexp_parser (2.5.0)
@@ -238,11 +243,13 @@ PLATFORMS
238
243
 
239
244
  DEPENDENCIES
240
245
  bundler (~> 2.3.16)
246
+ faraday (~> 2.3.0)
241
247
  helios-opentelemetry-sdk!
242
248
  opentelemetry-exporter-otlp (~> 0.22.0)
243
249
  opentelemetry-instrumentation-all (~> 0.25.0)
244
250
  opentelemetry-instrumentation-rspec (~> 0.2.0)
245
251
  opentelemetry-sdk (~> 1.1.0)
252
+ rack (~> 2.2.4)
246
253
  rake (~> 13.0)
247
254
  rspec (~> 3.0)
248
255
  rubocop (~> 1.30.1)
@@ -32,7 +32,7 @@ SUPPORTED_INSTRUMENTATIONS = {
32
32
  'OpenTelemetry::Instrumentation::Que' => { propagation_style: :child },
33
33
  'OpenTelemetry::Instrumentation::Rack' => {},
34
34
  'OpenTelemetry::Instrumentation::Rdkafka' => {},
35
- 'OpenTelemetry::Instrumentation::Redis' => {},
35
+ 'OpenTelemetry::Instrumentation::Redis' => { db_statement: :include },
36
36
  'OpenTelemetry::Instrumentation::Resque' => { propagation_style: :child },
37
37
  'OpenTelemetry::Instrumentation::RestClient' => {},
38
38
  'OpenTelemetry::Instrumentation::RSpec' => nil, # Disabled for now
@@ -52,7 +52,33 @@ def apply_instrumentations(otel_config)
52
52
  additional_patches
53
53
  end
54
54
 
55
- def additional_patches
56
- require_relative 'net_http_patch'
55
+ def patch_net_http
56
+ require_relative 'patches/net_http_patch'
57
57
  ::Net::HTTP.prepend(NetHttpPatch::Instrumentation)
58
58
  end
59
+
60
+ def patch_faraday
61
+ return unless defined?(::Faraday)
62
+
63
+ require 'opentelemetry/instrumentation/faraday/middlewares/tracer_middleware'
64
+ require_relative 'patches/faraday_patch'
65
+ ::OpenTelemetry::Instrumentation::Faraday::Middlewares::TracerMiddleware.prepend(
66
+ FaradayPatch::HeliosFaradayMiddleware
67
+ )
68
+ end
69
+
70
+ def patch_rack
71
+ return unless defined?(::Rack)
72
+
73
+ require 'opentelemetry/instrumentation/rack/middlewares/tracer_middleware'
74
+ require_relative 'patches/rack_patch'
75
+ ::OpenTelemetry::Instrumentation::Rack::Middlewares::TracerMiddleware.prepend(
76
+ RackPatch::HeliosRackMiddleware
77
+ )
78
+ end
79
+
80
+ def additional_patches
81
+ patch_net_http
82
+ patch_faraday
83
+ patch_rack
84
+ end
@@ -0,0 +1,22 @@
1
+ require 'faraday'
2
+ require 'json'
3
+ require_relative '../../semantic_attributes'
4
+
5
+ module FaradayPatch
6
+ module HeliosFaradayMiddleware
7
+ def trace_response(span, env)
8
+ extract_additional_attributes(span, env)
9
+ super(span, env)
10
+ end
11
+
12
+ def extract_additional_attributes(span, env)
13
+ request_headers = env.request_headers
14
+ semantic_attributes = Helios::OpenTelemetry::SemanticAttributes
15
+ span.set_attribute(semantic_attributes::HTTP_REQUEST_HEADERS, request_headers.to_json)
16
+ span.set_attribute(semantic_attributes::HTTP_REQUEST_BODY, env.body) unless env.body.nil?
17
+ response_headers = env.response_headers
18
+ span.set_attribute(semantic_attributes::HTTP_RESPONSE_HEADERS, response_headers.to_json)
19
+ span.set_attribute(semantic_attributes::HTTP_RESPONSE_BODY, env.response_body) unless env.response_body.nil?
20
+ end
21
+ end
22
+ end
@@ -1,5 +1,5 @@
1
1
  require 'json'
2
- require_relative '../semantic_attributes'
2
+ require_relative '../../semantic_attributes'
3
3
 
4
4
  module NetHttpPatch
5
5
  # Module to prepend to Net::HTTP for instrumentation
@@ -7,7 +7,7 @@ module NetHttpPatch
7
7
  def request(req, body = nil, &block)
8
8
  current_span = OpenTelemetry::Trace.current_span
9
9
  current_span.set_attribute(Helios::OpenTelemetry::SemanticAttributes::HTTP_REQUEST_HEADERS, collect_headers(req))
10
- unless req.body.nil?
10
+ unless body.nil?
11
11
  current_span.set_attribute(Helios::OpenTelemetry::SemanticAttributes::HTTP_REQUEST_BODY,
12
12
  body.is_a?(String) ? body : body.to_s)
13
13
  end
@@ -0,0 +1,26 @@
1
+ require 'rack'
2
+ require 'json'
3
+ require_relative '../../semantic_attributes'
4
+
5
+ module RackPatch
6
+ module HeliosRackMiddleware
7
+ def request_span_attributes(env:)
8
+ res = super(env: env)
9
+ # Request headers are attributes in the env hash that start with HTTP_
10
+ request_headers = env.select { |k, _v| k.start_with? 'HTTP_' }.transform_keys { |k| k.sub(/^HTTP_/, '').downcase }
11
+ semantic_attributes = Helios::OpenTelemetry::SemanticAttributes
12
+ res[semantic_attributes::HTTP_REQUEST_HEADERS] = request_headers.to_json
13
+ request_body = env['rack.input']&.read
14
+ env['rack.input']&.rewind
15
+ res[semantic_attributes::HTTP_REQUEST_BODY] = request_body if request_body&.length&.positive?
16
+ res
17
+ end
18
+
19
+ def set_attributes_after_request(span, status, headers, response)
20
+ semantic_attributes = Helios::OpenTelemetry::SemanticAttributes
21
+ span.set_attribute(semantic_attributes::HTTP_RESPONSE_HEADERS, headers.to_json)
22
+ span.set_attribute(semantic_attributes::HTTP_RESPONSE_BODY, response[0]) if response&.first&.length&.positive?
23
+ super(span, status, headers, response)
24
+ end
25
+ end
26
+ end
@@ -1,7 +1,7 @@
1
1
  module Helios
2
2
  module OpenTelemetry
3
3
  module SDK
4
- VERSION = '0.1.12'
4
+ VERSION = '0.1.15'
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: helios-opentelemetry-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12
4
+ version: 0.1.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Team Helios
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-15 00:00:00.000000000 Z
11
+ date: 2022-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -130,7 +130,9 @@ files:
130
130
  - helios-opentelemetry-sdk.gemspec
131
131
  - lib/helios/opentelemetry/sdk.rb
132
132
  - lib/helios/opentelemetry/sdk/instrumentations.rb
133
- - lib/helios/opentelemetry/sdk/net_http_patch.rb
133
+ - lib/helios/opentelemetry/sdk/patches/faraday_patch.rb
134
+ - lib/helios/opentelemetry/sdk/patches/net_http_patch.rb
135
+ - lib/helios/opentelemetry/sdk/patches/rack_patch.rb
134
136
  - lib/helios/opentelemetry/sdk/version.rb
135
137
  - lib/helios/opentelemetry/semantic_attributes.rb
136
138
  homepage: https://gethelios.dev