helios-opentelemetry-sdk 0.1.16 → 0.1.19

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: 76cb4b1d14f9d68ab3bf329963f3a61b1df0962266bf20440fc882b3bc03dfc7
4
- data.tar.gz: 9eac30d4d73bade94970786bd8eedd9c1e530b1c026f96d37a30f61d2dea26d6
3
+ metadata.gz: e1333d4f45a6affbdc086bb2e8e98f8871e7a295a50e4dd87f624b60ca4be78e
4
+ data.tar.gz: b50075cf28a40a5ccc36dd39c46d6c1323b8a6514e027f558f3fc1cb4439e0e6
5
5
  SHA512:
6
- metadata.gz: 5c15ad22b47fb73056fbb5445bb9bd578b5f67afd3472c97bbcbf3ce44b923d25460ecb1e8e9bd738fc113d7aaece1273322eecaaea8daed9dc2b07d0908c671
7
- data.tar.gz: fa2d528cc8f882cb5ec06595e5ee7c46227cf7ff554c8d0c5613d0de78c682ad19e3d56382a6e8e450a0410dd6c7ef33ca286cd37b892bc5cb9d17a16bc38067
6
+ metadata.gz: d6467ee1a6eabce6fb8a743e536c8e83ba3bbdb9705b62fd9793552ef163b9d69a43649e13d948f686d4d4a6cbb4da02ad3f90e5a65b59d66d497a7757d89a91
7
+ data.tar.gz: 9b96c5e12e92befd75f0d5f650b2119e79279efe19e4b2aa4e1b69cceb7939a4f90f8eddc5ee495fa0bbfa72c435ae86ae4012634f6c514f93233aa00bf3337d
@@ -21,6 +21,16 @@ jobs:
21
21
  fail-fast: false
22
22
  matrix:
23
23
  ruby-version: ['2.6', '2.7', '3.1']
24
+ services:
25
+ mongodb:
26
+ image: mongo@sha256:845fd775d7a58f564fae7c17a4eec7ff038e1c4004ebe05cc1cb5fc3767cf6cc
27
+ ports:
28
+ - 27017:27017
29
+ options: >-
30
+ --health-cmd="echo 'db.runCommand(\"ping\").ok' | mongo localhost:27017/test --quiet"
31
+ --health-interval=10s
32
+ --health-timeout=5s
33
+ --health-retries=3
24
34
  steps:
25
35
  - uses: actions/checkout@v2
26
36
  - uses: actions/setup-ruby@v1
data/.rubocop.yml CHANGED
@@ -24,3 +24,6 @@ Metrics/BlockLength:
24
24
 
25
25
  Metrics/CyclomaticComplexity:
26
26
  Enabled: false
27
+
28
+ Metrics/PerceivedComplexity:
29
+ Enabled: false
data/Gemfile CHANGED
@@ -10,3 +10,4 @@ gem 'rubocop', '~> 1.30.1', group: [:development, :test]
10
10
  gem 'bundler', '~> 2.3.16', group: [:development, :test]
11
11
  gem 'faraday', '~> 2.3.0', group: [:development, :test]
12
12
  gem 'rack', '~> 2.2.4', group: [:development, :test]
13
+ gem 'mongo', '~> 2.5', 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.16)
4
+ helios-opentelemetry-sdk (0.1.19)
5
5
  opentelemetry-exporter-otlp (~> 0.22.0)
6
6
  opentelemetry-instrumentation-all (~> 0.25.0)
7
7
  opentelemetry-instrumentation-rspec (~> 0.2.0)
@@ -11,6 +11,7 @@ GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
13
  ast (2.4.2)
14
+ bson (4.15.0)
14
15
  diff-lcs (1.5.0)
15
16
  faraday (2.3.0)
16
17
  faraday-net_http (~> 2.0)
@@ -19,6 +20,8 @@ GEM
19
20
  google-protobuf (3.21.1)
20
21
  googleapis-common-protos-types (1.3.1)
21
22
  google-protobuf (~> 3.14)
23
+ mongo (2.18.1)
24
+ bson (>= 4.14.1, < 5.0.0)
22
25
  opentelemetry-api (1.0.2)
23
26
  opentelemetry-common (0.19.6)
24
27
  opentelemetry-api (~> 1.0)
@@ -245,6 +248,7 @@ DEPENDENCIES
245
248
  bundler (~> 2.3.16)
246
249
  faraday (~> 2.3.0)
247
250
  helios-opentelemetry-sdk!
251
+ mongo (~> 2.5)
248
252
  opentelemetry-exporter-otlp (~> 0.22.0)
249
253
  opentelemetry-instrumentation-all (~> 0.25.0)
250
254
  opentelemetry-instrumentation-rspec (~> 0.2.0)
@@ -55,6 +55,8 @@ end
55
55
  def patch_net_http
56
56
  require_relative 'patches/net_http_patch'
57
57
  ::Net::HTTP.prepend(NetHttpPatch::Instrumentation)
58
+ rescue StandardError => e
59
+ ::OpenTelemetry.logger.debug("Error patching net http: #{e}")
58
60
  end
59
61
 
60
62
  def patch_faraday
@@ -65,6 +67,8 @@ def patch_faraday
65
67
  ::OpenTelemetry::Instrumentation::Faraday::Middlewares::TracerMiddleware.prepend(
66
68
  FaradayPatch::HeliosFaradayMiddleware
67
69
  )
70
+ rescue StandardError => e
71
+ ::OpenTelemetry.logger.debug("Error patching faraday: #{e}")
68
72
  end
69
73
 
70
74
  def patch_rack
@@ -75,10 +79,28 @@ def patch_rack
75
79
  ::OpenTelemetry::Instrumentation::Rack::Middlewares::TracerMiddleware.prepend(
76
80
  RackPatch::HeliosRackMiddleware
77
81
  )
82
+ rescue StandardError => e
83
+ ::OpenTelemetry.logger.debug("Error patching rack: #{e}")
84
+ end
85
+
86
+ def patch_mongo
87
+ return unless defined?(::Mongo::Monitoring::Global)
88
+
89
+ require 'opentelemetry/instrumentation/mongo/subscriber'
90
+ min_version = ::OpenTelemetry::Instrumentation::Mongo::Instrumentation::MINIMUM_VERSION
91
+ mongo_version = Gem::Version.new(::Mongo::VERSION)
92
+ return unless mongo_version >= min_version
93
+
94
+ require_relative 'patches/mongo_patch'
95
+ ::OpenTelemetry::Instrumentation::Mongo::Subscriber.prepend(MongoPatch::Subscriber)
96
+ ::OpenTelemetry::Instrumentation::Mongo::CommandSerializer.prepend(MongoPatch::CommandSerializer)
97
+ rescue StandardError => e
98
+ ::OpenTelemetry.logger.debug("Error patching mongo: #{e}")
78
99
  end
79
100
 
80
101
  def additional_patches
81
102
  patch_net_http
82
103
  patch_faraday
83
104
  patch_rack
105
+ patch_mongo
84
106
  end
@@ -17,6 +17,8 @@ module FaradayPatch
17
17
  response_headers = env.response_headers
18
18
  span.set_attribute(semantic_attributes::HTTP_RESPONSE_HEADERS, response_headers.to_json)
19
19
  span.set_attribute(semantic_attributes::HTTP_RESPONSE_BODY, env.response_body) unless env.response_body.nil?
20
+ rescue StandardError => e
21
+ ::OpenTelemetry.logger.debug("Error extracting faraday attributes: #{e}")
20
22
  end
21
23
  end
22
24
  end
@@ -0,0 +1,36 @@
1
+ require 'json'
2
+ require_relative '../../semantic_attributes'
3
+
4
+ module MongoPatch
5
+ module Subscriber
6
+ def succeeded(event)
7
+ extract_query_result(event)
8
+ super(event)
9
+ end
10
+
11
+ def extract_query_result(event)
12
+ span = get_span(event)
13
+ return unless span
14
+
15
+ span.set_attribute(Helios::OpenTelemetry::SemanticAttributes::DB_QUERY_RESULT, event.reply.to_json)
16
+ rescue StandardError => e
17
+ ::OpenTelemetry.logger.debug("Error extracting mongo query result: #{e}")
18
+ end
19
+ end
20
+
21
+ module CommandSerializer
22
+ # Temp patch until the upstream fix is released
23
+ def mask(hash)
24
+ hash.each_with_object({}) do |(k, v), h|
25
+ value = if v.is_a?(Hash)
26
+ mask(v)
27
+ elsif @obfuscate
28
+ MASK_VALUE
29
+ else
30
+ v
31
+ end
32
+ h[k] = value
33
+ end
34
+ end
35
+ end
36
+ end
@@ -1,4 +1,5 @@
1
1
  require 'json'
2
+ require 'opentelemetry/semantic_conventions'
2
3
  require_relative '../../semantic_attributes'
3
4
 
4
5
  module NetHttpPatch
@@ -6,7 +7,9 @@ module NetHttpPatch
6
7
  module Instrumentation
7
8
  def request(req, body = nil, &block)
8
9
  current_span = OpenTelemetry::Trace.current_span
9
- current_span.set_attribute(Helios::OpenTelemetry::SemanticAttributes::HTTP_REQUEST_HEADERS, collect_headers(req))
10
+ current_span.set_attribute(Helios::OpenTelemetry::SemanticAttributes::HTTP_REQUEST_HEADERS,
11
+ collect_headers(req))
12
+ current_span.set_attribute(OpenTelemetry::SemanticConventions::Trace::HTTP_URL, req.uri&.to_s)
10
13
  unless body.nil?
11
14
  current_span.set_attribute(Helios::OpenTelemetry::SemanticAttributes::HTTP_REQUEST_BODY,
12
15
  body.is_a?(String) ? body : body.to_s)
@@ -27,5 +30,22 @@ module NetHttpPatch
27
30
 
28
31
  headers.to_json
29
32
  end
33
+
34
+ def extract_request_attributes(span, req, body)
35
+ span.set_attribute(Helios::OpenTelemetry::SemanticAttributes::HTTP_REQUEST_HEADERS, collect_headers(req))
36
+ unless body.nil?
37
+ span.set_attribute(Helios::OpenTelemetry::SemanticAttributes::HTTP_REQUEST_BODY,
38
+ body.is_a?(String) ? body : body.to_s)
39
+ end
40
+ rescue StandardError => e
41
+ ::OpenTelemetry.logger.debug("Error extracting net http request attributes: #{e}")
42
+ end
43
+
44
+ def extract_response_attributes(span, response)
45
+ span.set_attribute(Helios::OpenTelemetry::SemanticAttributes::HTTP_RESPONSE_HEADERS, collect_headers(response))
46
+ span.set_attribute(Helios::OpenTelemetry::SemanticAttributes::HTTP_RESPONSE_BODY, response.body)
47
+ rescue StandardError => e
48
+ ::OpenTelemetry.logger.debug("Error extracting net http response attributes: #{e}")
49
+ end
30
50
  end
31
51
  end
@@ -6,6 +6,16 @@ module RackPatch
6
6
  module HeliosRackMiddleware
7
7
  def request_span_attributes(env:)
8
8
  res = super(env: env)
9
+ extract_request_attributes(env, res)
10
+ res
11
+ end
12
+
13
+ def set_attributes_after_request(span, status, headers, response)
14
+ extract_response_attributes(span, headers, response)
15
+ super(span, status, headers, response)
16
+ end
17
+
18
+ def extract_request_attributes(env, res)
9
19
  # Request headers are attributes in the env hash that start with HTTP_
10
20
  request_headers = env.select { |k, _v| k.start_with? 'HTTP_' }.transform_keys { |k| k.sub(/^HTTP_/, '').downcase }
11
21
  semantic_attributes = Helios::OpenTelemetry::SemanticAttributes
@@ -13,17 +23,18 @@ module RackPatch
13
23
  request_body = env['rack.input']&.read
14
24
  env['rack.input']&.rewind
15
25
  res[semantic_attributes::HTTP_REQUEST_BODY] = request_body if request_body&.length&.positive?
16
- res
26
+ rescue StandardError => e
27
+ ::OpenTelemetry.logger.debug("Error extracting rack request attributes: #{e}")
17
28
  end
18
29
 
19
- def set_attributes_after_request(span, status, headers, response)
30
+ def extract_response_attributes(span, headers, response)
20
31
  semantic_attributes = Helios::OpenTelemetry::SemanticAttributes
21
32
  span.set_attribute(semantic_attributes::HTTP_RESPONSE_HEADERS, headers.to_json)
22
33
  if response.respond_to?(:first) && response.first&.length&.positive?
23
34
  span.set_attribute(semantic_attributes::HTTP_RESPONSE_BODY, response.first)
24
35
  end
25
-
26
- super(span, status, headers, response)
36
+ rescue StandardError => e
37
+ ::OpenTelemetry.logger.debug("Error extracting rack response attributes: #{e}")
27
38
  end
28
39
  end
29
40
  end
@@ -1,7 +1,7 @@
1
1
  module Helios
2
2
  module OpenTelemetry
3
3
  module SDK
4
- VERSION = '0.1.16'
4
+ VERSION = '0.1.19'
5
5
  end
6
6
  end
7
7
  end
@@ -5,6 +5,7 @@ module Helios
5
5
  HTTP_REQUEST_HEADERS = 'http.request.headers'
6
6
  HTTP_RESPONSE_BODY = 'http.response.body'
7
7
  HTTP_RESPONSE_HEADERS = 'http.response.headers'
8
+ DB_QUERY_RESULT = 'db.query_result'
8
9
  end
9
10
  end
10
11
  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.16
4
+ version: 0.1.19
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-29 00:00:00.000000000 Z
11
+ date: 2022-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -131,6 +131,7 @@ files:
131
131
  - lib/helios/opentelemetry/sdk.rb
132
132
  - lib/helios/opentelemetry/sdk/instrumentations.rb
133
133
  - lib/helios/opentelemetry/sdk/patches/faraday_patch.rb
134
+ - lib/helios/opentelemetry/sdk/patches/mongo_patch.rb
134
135
  - lib/helios/opentelemetry/sdk/patches/net_http_patch.rb
135
136
  - lib/helios/opentelemetry/sdk/patches/rack_patch.rb
136
137
  - lib/helios/opentelemetry/sdk/version.rb