helios-opentelemetry-sdk 0.1.17 → 0.1.20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +10 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +5 -1
- data/lib/helios/opentelemetry/sdk/instrumentations.rb +22 -0
- data/lib/helios/opentelemetry/sdk/patches/faraday_patch.rb +2 -2
- data/lib/helios/opentelemetry/sdk/patches/mongo_patch.rb +36 -0
- data/lib/helios/opentelemetry/sdk/patches/net_http_patch.rb +18 -14
- data/lib/helios/opentelemetry/sdk/patches/rack_patch.rb +4 -4
- data/lib/helios/opentelemetry/sdk/version.rb +1 -1
- data/lib/helios/opentelemetry/semantic_attributes.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a91efee8919de8c1d6ba5535e9bd3e347f3402545739261b272e33e1a64e036e
|
4
|
+
data.tar.gz: 1d0c7e40082bcb8153aacd08b36ed919589d32836a17cd65ba16ef68db13391c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62f535badbe0f1c481f15dd17e110209233c99025b8d544988e264e78ff23d5b70e12bc10579748f33a0cc23fcf0716b8b4bcade9e2ab3509a1150b1795ef88d
|
7
|
+
data.tar.gz: a935beb8953928cbd407dc71ddad09a6f1134f8d39c5d385e40eafdbf273f1976657f72a5fc114c64595a6ad53b52a2899f8878c8117c699458be3f8867e2568
|
data/.github/workflows/test.yml
CHANGED
@@ -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/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.
|
4
|
+
helios-opentelemetry-sdk (0.1.20)
|
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,8 +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
|
21
|
-
|
20
|
+
rescue StandardError => e
|
21
|
+
::OpenTelemetry.logger.debug("Error extracting faraday attributes: #{e}")
|
22
22
|
end
|
23
23
|
end
|
24
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,17 +7,10 @@ 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
|
10
|
-
collect_headers(req))
|
11
|
-
unless body.nil?
|
12
|
-
current_span.set_attribute(Helios::OpenTelemetry::SemanticAttributes::HTTP_REQUEST_BODY,
|
13
|
-
body.is_a?(String) ? body : body.to_s)
|
14
|
-
end
|
10
|
+
extract_request_attributes(current_span, req, body)
|
15
11
|
|
16
12
|
super(req, body, &block).tap do |response|
|
17
|
-
current_span
|
18
|
-
collect_headers(response))
|
19
|
-
current_span.set_attribute(Helios::OpenTelemetry::SemanticAttributes::HTTP_RESPONSE_BODY, response.body)
|
13
|
+
extract_response_attributes(current_span, response)
|
20
14
|
end
|
21
15
|
end
|
22
16
|
|
@@ -30,21 +24,31 @@ module NetHttpPatch
|
|
30
24
|
end
|
31
25
|
|
32
26
|
def extract_request_attributes(span, req, body)
|
33
|
-
::OpenTelemetry.logger.warn('aaaaaaa')
|
34
27
|
span.set_attribute(Helios::OpenTelemetry::SemanticAttributes::HTTP_REQUEST_HEADERS, collect_headers(req))
|
35
28
|
unless body.nil?
|
36
29
|
span.set_attribute(Helios::OpenTelemetry::SemanticAttributes::HTTP_REQUEST_BODY,
|
37
30
|
body.is_a?(String) ? body : body.to_s)
|
38
31
|
end
|
39
|
-
|
40
|
-
|
32
|
+
|
33
|
+
url = req.uri&.to_s
|
34
|
+
sem_conv = OpenTelemetry::SemanticConventions::Trace
|
35
|
+
if url.nil?
|
36
|
+
scheme = span.attributes[sem_conv::HTTP_SCHEME]
|
37
|
+
hostname = span.attributes[sem_conv::HTTP_HOST] || span.attributes[sem_conv::NET_PEER_NAME]
|
38
|
+
target = span.attributes[sem_conv::HTTP_TARGET]
|
39
|
+
url = "#{scheme}://#{hostname}#{target}" if scheme && hostname && target
|
40
|
+
end
|
41
|
+
|
42
|
+
span.set_attribute(sem_conv::HTTP_URL, url) unless url.nil?
|
43
|
+
rescue StandardError => e
|
44
|
+
::OpenTelemetry.logger.debug("Error extracting net http request attributes: #{e}")
|
41
45
|
end
|
42
46
|
|
43
47
|
def extract_response_attributes(span, response)
|
44
48
|
span.set_attribute(Helios::OpenTelemetry::SemanticAttributes::HTTP_RESPONSE_HEADERS, collect_headers(response))
|
45
49
|
span.set_attribute(Helios::OpenTelemetry::SemanticAttributes::HTTP_RESPONSE_BODY, response.body)
|
46
|
-
rescue StandardError
|
47
|
-
|
50
|
+
rescue StandardError => e
|
51
|
+
::OpenTelemetry.logger.debug("Error extracting net http response attributes: #{e}")
|
48
52
|
end
|
49
53
|
end
|
50
54
|
end
|
@@ -23,8 +23,8 @@ module RackPatch
|
|
23
23
|
request_body = env['rack.input']&.read
|
24
24
|
env['rack.input']&.rewind
|
25
25
|
res[semantic_attributes::HTTP_REQUEST_BODY] = request_body if request_body&.length&.positive?
|
26
|
-
rescue StandardError
|
27
|
-
|
26
|
+
rescue StandardError => e
|
27
|
+
::OpenTelemetry.logger.debug("Error extracting rack request attributes: #{e}")
|
28
28
|
end
|
29
29
|
|
30
30
|
def extract_response_attributes(span, headers, response)
|
@@ -33,8 +33,8 @@ module RackPatch
|
|
33
33
|
if response.respond_to?(:first) && response.first&.length&.positive?
|
34
34
|
span.set_attribute(semantic_attributes::HTTP_RESPONSE_BODY, response.first)
|
35
35
|
end
|
36
|
-
rescue StandardError
|
37
|
-
|
36
|
+
rescue StandardError => e
|
37
|
+
::OpenTelemetry.logger.debug("Error extracting rack response attributes: #{e}")
|
38
38
|
end
|
39
39
|
end
|
40
40
|
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.
|
4
|
+
version: 0.1.20
|
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-
|
11
|
+
date: 2022-09-06 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
|