codecov_opentelem 0.1.4 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/codecov_opentelem/coverage_exporter.rb +24 -15
- data/lib/codecov_opentelem/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83e1f51507354acfa43c050b11374b65b2a32be4175b93c9d0a525eb1bdc4779
|
4
|
+
data.tar.gz: 536e666085bc3519781dc1de6bdecffcc1dbb85e7e39d5aecfc6ac429a24030e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9878e50adfe01c11cf13d17db8c9b878a9e34f157703f63cb088e0e3b769a3993a64efced82c71e38b8f2845a21a2766f6cd4aae76c3f005cba6183f667110f9
|
7
|
+
data.tar.gz: a0385f0c0681f3667f6b995af11d20380da211b15e78056f912ea674b2dcec5f502d70a302fec0e15fef6e17867ca309b9e0efce5b215ba8fa6b750a16f4b220
|
data/Gemfile.lock
CHANGED
@@ -1,42 +1,44 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'base64'
|
3
4
|
require 'json'
|
4
|
-
require 'uri'
|
5
5
|
require 'net/http'
|
6
|
+
require 'uri'
|
6
7
|
|
7
|
-
require 'opentelemetry/sdk'
|
8
8
|
require 'coverage'
|
9
|
+
require 'opentelemetry/sdk'
|
9
10
|
|
10
11
|
module CoverageSpanFilter
|
12
|
+
FILE_IGNORE_NAME = 'file_ignore_regex'
|
11
13
|
REGEX_NAME = 'name_regex'
|
12
14
|
SPAN_KIND = 'span_kind'
|
13
15
|
end
|
14
16
|
|
15
17
|
class CodecovCoverageStorageManager
|
16
18
|
def initialize(filters)
|
17
|
-
Coverage.start
|
18
19
|
@filters = filters
|
19
20
|
@inner = {}
|
20
21
|
end
|
21
22
|
|
22
23
|
def start_coverage_for_span(span)
|
23
24
|
if !@filters[CoverageSpanFilter::REGEX_NAME].nil? && @filters[CoverageSpanFilter::REGEX_NAME].match(span.name)
|
25
|
+
puts 'returned false'
|
24
26
|
return false
|
25
27
|
end
|
26
28
|
|
27
|
-
Coverage.
|
29
|
+
Coverage.start unless Coverage.running?
|
28
30
|
true
|
29
31
|
end
|
30
32
|
|
31
33
|
def stop_coverage_for_span(span)
|
32
|
-
span_id = span.span_id
|
33
|
-
Coverage.suspend
|
34
|
+
span_id = span.context.span_id
|
34
35
|
@inner[span_id] = Coverage.result(stop: false, clear: true)
|
35
36
|
end
|
36
37
|
|
37
38
|
def pop_coverage_for_span(span)
|
38
39
|
span_id = span.span_id
|
39
|
-
@inner.delete(span_id)
|
40
|
+
cov = @inner.delete(span_id)
|
41
|
+
cov.select { |key, value| !@filters[CoverageSpanFilter::FILE_IGNORE_NAME].match(key) } unless @filters[CoverageSpanFilter::FILE_IGNORE_NAME].nil?
|
40
42
|
end
|
41
43
|
end
|
42
44
|
|
@@ -48,10 +50,10 @@ class CodecovCoverageGenerator < OpenTelemetry::SDK::Trace::SpanProcessor
|
|
48
50
|
end
|
49
51
|
|
50
52
|
def on_start(span, _parent_context = nil)
|
51
|
-
@cov_storage.start_coverage_for_span(span) if rand < @sample_rate
|
53
|
+
@cov_storage.start_coverage_for_span(span) if rand() < @sample_rate
|
52
54
|
end
|
53
55
|
|
54
|
-
def
|
56
|
+
def on_finish(span)
|
55
57
|
@cov_storage.stop_coverage_for_span(span)
|
56
58
|
end
|
57
59
|
end
|
@@ -69,6 +71,7 @@ class CoverageExporter < OpenTelemetry::SDK::Trace::Export::SpanExporter
|
|
69
71
|
def export(spans, timeout)
|
70
72
|
tracked_spans = []
|
71
73
|
untracked_spans = []
|
74
|
+
|
72
75
|
spans.each do |span|
|
73
76
|
cov = @cov_storage.pop_coverage_for_span(span)
|
74
77
|
|
@@ -77,15 +80,21 @@ class CoverageExporter < OpenTelemetry::SDK::Trace::Export::SpanExporter
|
|
77
80
|
v = v.dup.force_encoding("ISO-8859-1").encode("UTF-8") if v.is_a? String
|
78
81
|
span_hash[k] = v
|
79
82
|
end
|
80
|
-
|
83
|
+
|
84
|
+
cov_string = cov.map{ |k, v| "\"#{k}\":[#{v.map{ |i| i.nil? ? "null" : i}.join(',')}]"}.join(',')
|
85
|
+
cov_string = "{\"coverage\":{#{cov_string}}}"
|
81
86
|
|
82
87
|
if !cov.nil?
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
88
|
+
span_hash['codecov'] = {
|
89
|
+
'coverage': Base64.strict_encode64(cov_string),
|
90
|
+
'type': 'bytes',
|
91
|
+
}
|
92
|
+
tracked_spans.append(span_hash)
|
93
|
+
elsif rand() < @untracked_export_rate
|
94
|
+
untracked_spans.append(span_hash)
|
87
95
|
end
|
88
96
|
end
|
97
|
+
|
89
98
|
return OpenTelemetry::SDK::Trace::Export::SUCCESS if !tracked_spans && !untracked_spans
|
90
99
|
|
91
100
|
body = { 'profiling' => @code }.to_json
|
@@ -110,7 +119,7 @@ class CoverageExporter < OpenTelemetry::SDK::Trace::Export::SpanExporter
|
|
110
119
|
req.body = {
|
111
120
|
'spans' => tracked_spans,
|
112
121
|
'untracked' => untracked_spans
|
113
|
-
}.to_json
|
122
|
+
}.to_json
|
114
123
|
https.request(req)
|
115
124
|
OpenTelemetry::SDK::Trace::Export::SUCCESS
|
116
125
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codecov_opentelem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ahmed-Elghrbawy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-06-
|
11
|
+
date: 2022-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|