uptrace 0.2.0 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/RELEASE.md +7 -0
- data/lib/uptrace.rb +20 -0
- data/lib/uptrace/client.rb +22 -34
- data/lib/uptrace/dsn.rb +3 -3
- data/lib/uptrace/trace.rb +0 -1
- data/lib/uptrace/trace/exporter.rb +16 -26
- data/lib/uptrace/version.rb +1 -1
- metadata +5 -5
- data/lib/uptrace/trace/config.rb +0 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43f0392ed577dc7bd8e63985d033e8d8d89ccaa53ef76bbe32b9c7c28a5d5882
|
4
|
+
data.tar.gz: 12becd6950ec2bfd5bd81aa350a00dfdee9a91ce3034a4506b907edbe2213dff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1447f636c276d492e6eeedabbe0d6f825b11c7bdb69312f8f9c45ea02436edd22318812f80aba2211d3d93f2f3ba0c3f637e9b616cfb9acdffc0288170501560
|
7
|
+
data.tar.gz: 685dc638c8506fbd17bb01aaf00fe2831cec1a7be8852ad9f484e1964df4f933fbb73c20e1a2bb266f0f7a3c52b55f40f5fceb28ccc9065877f1b9c19f2b1f21
|
data/RELEASE.md
ADDED
data/lib/uptrace.rb
CHANGED
@@ -7,8 +7,28 @@ module Uptrace
|
|
7
7
|
extend self
|
8
8
|
|
9
9
|
attr_accessor :logger
|
10
|
+
attr_writer :client
|
10
11
|
|
11
12
|
self.logger = Logger.new($stdout)
|
13
|
+
|
14
|
+
# @return [Object, Client] registered client or a default no-op implementation of the client.
|
15
|
+
def client
|
16
|
+
@client ||= Client.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def trace_url(span)
|
20
|
+
client.trace_url(span)
|
21
|
+
end
|
22
|
+
|
23
|
+
def configure_tracing(c, dsn: '')
|
24
|
+
upclient = if dsn.empty?
|
25
|
+
client
|
26
|
+
else
|
27
|
+
Client.new(dsn: dsn)
|
28
|
+
end
|
29
|
+
|
30
|
+
c.add_span_processor(upclient.span_processor) unless upclient.disabled?
|
31
|
+
end
|
12
32
|
end
|
13
33
|
|
14
34
|
require 'uptrace/version'
|
data/lib/uptrace/client.rb
CHANGED
@@ -5,53 +5,41 @@ require 'opentelemetry/sdk'
|
|
5
5
|
module Uptrace
|
6
6
|
# Uptrace client that configures OpenTelemetry SDK to use Uptrace exporter.
|
7
7
|
class Client
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
#
|
12
|
-
def initialize
|
13
|
-
@cfg = Uptrace::Trace::Config.new
|
14
|
-
yield @cfg if block_given?
|
8
|
+
# @param [string] dsn
|
9
|
+
def initialize(dsn: '')
|
10
|
+
dsn = ENV.fetch('UPTRACE_DSN', '') if dsn.empty?
|
15
11
|
|
16
12
|
begin
|
17
|
-
@
|
13
|
+
@dsn = DSN.new(dsn)
|
18
14
|
rescue ArgumentError => e
|
19
|
-
Uptrace.logger.error(e.message)
|
20
|
-
@
|
15
|
+
Uptrace.logger.error("Uptrace is disabled: #{e.message}")
|
16
|
+
@disabled = true
|
21
17
|
|
22
|
-
@
|
18
|
+
@dsn = DSN.new('https://TOKEN@api.uptrace.dev/PROJECT_ID')
|
23
19
|
end
|
24
|
-
|
25
|
-
setup_tracing unless @cfg.disabled
|
26
20
|
end
|
27
21
|
|
28
|
-
|
29
|
-
|
30
|
-
return if @cfg.disabled
|
31
|
-
|
32
|
-
OpenTelemetry.tracer_provider.shutdown(timeout: timeout)
|
22
|
+
def disabled?
|
23
|
+
@disabled
|
33
24
|
end
|
34
25
|
|
35
|
-
# @
|
26
|
+
# @param [OpenTelemetry::Trace::Span] span
|
27
|
+
# @return [String]
|
36
28
|
def trace_url(span)
|
37
|
-
|
38
|
-
host = dsn.host.delete_prefix('api.')
|
29
|
+
host = @dsn.host.delete_prefix('api.')
|
39
30
|
trace_id = span.context.hex_trace_id
|
40
|
-
"#{dsn.scheme}://#{host}/#{dsn.project_id}
|
31
|
+
"#{@dsn.scheme}://#{host}/search/#{@dsn.project_id}?q=#{trace_id}"
|
41
32
|
end
|
42
33
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
c.service_name = @cfg.service_name
|
53
|
-
c.service_version = @cfg.service_version
|
54
|
-
end
|
34
|
+
# @return [OpenTelemetry::SDK::Trace::Export::BatchSpanProcessor]
|
35
|
+
def span_processor
|
36
|
+
exp = Uptrace::Trace::Exporter.new(@dsn)
|
37
|
+
OpenTelemetry::SDK::Trace::Export::BatchSpanProcessor.new(
|
38
|
+
exp,
|
39
|
+
max_queue_size: 1000,
|
40
|
+
max_export_batch_size: 1000,
|
41
|
+
schedule_delay: 5_000
|
42
|
+
)
|
55
43
|
end
|
56
44
|
end
|
57
45
|
end
|
data/lib/uptrace/dsn.rb
CHANGED
@@ -8,12 +8,12 @@ module Uptrace
|
|
8
8
|
attr_reader :dsn, :port, *KEYS
|
9
9
|
|
10
10
|
def initialize(dsn)
|
11
|
-
raise ArgumentError, "
|
11
|
+
raise ArgumentError, "DSN can't be empty" if dsn.empty?
|
12
12
|
|
13
13
|
begin
|
14
14
|
uri = URI.parse(dsn)
|
15
15
|
rescue URI::InvalidURIError => e
|
16
|
-
raise ArgumentError, %(
|
16
|
+
raise ArgumentError, %(can't parse DSN=#{dsn.inspect}: #{e})
|
17
17
|
end
|
18
18
|
|
19
19
|
@dsn = dsn
|
@@ -25,7 +25,7 @@ module Uptrace
|
|
25
25
|
|
26
26
|
KEYS.each do |k|
|
27
27
|
v = public_send(k)
|
28
|
-
raise ArgumentError, %(
|
28
|
+
raise ArgumentError, %(DSN does not have #{k} (DSN=#{dsn.inspect})) if v.nil? || v.empty?
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
data/lib/uptrace/trace.rb
CHANGED
@@ -20,13 +20,11 @@ module Uptrace
|
|
20
20
|
##
|
21
21
|
# @param [Config] cfg
|
22
22
|
#
|
23
|
-
def initialize(
|
24
|
-
@
|
23
|
+
def initialize(dsn)
|
24
|
+
@dsn = dsn
|
25
|
+
@endpoint = "/api/v1/tracing/#{@dsn.project_id}/spans"
|
25
26
|
|
26
|
-
|
27
|
-
@endpoint = "/api/v1/tracing/#{dsn.project_id}/spans"
|
28
|
-
|
29
|
-
@http = Net::HTTP.new(dsn.host, 443)
|
27
|
+
@http = Net::HTTP.new(@dsn.host, 443)
|
30
28
|
@http.use_ssl = true
|
31
29
|
@http.open_timeout = 5
|
32
30
|
@http.read_timeout = 5
|
@@ -79,18 +77,21 @@ module Uptrace
|
|
79
77
|
endTime: as_unix_nano(span.end_timestamp),
|
80
78
|
|
81
79
|
resource: uptrace_resource(span.resource),
|
82
|
-
attrs: span.attributes
|
80
|
+
attrs: span.attributes
|
81
|
+
}
|
83
82
|
|
84
|
-
|
85
|
-
statusMessage: span.status.description,
|
83
|
+
out[:parentId] = span.parent_span_id.unpack1('Q') if span.parent_span_id
|
86
84
|
|
87
|
-
|
88
|
-
|
85
|
+
out[:events] = uptrace_events(span.events) unless span.events.nil?
|
86
|
+
out[:links] = uptrace_links(span.links) unless span.links.nil?
|
89
87
|
|
90
|
-
|
88
|
+
status = span.status
|
89
|
+
out[:statusCode] = status_code_as_str(status.code)
|
90
|
+
out[:statusMessage] = status.description unless status.description.empty?
|
91
91
|
|
92
|
-
|
93
|
-
out[
|
92
|
+
il = span.instrumentation_library
|
93
|
+
out[:tracerName] = il.name
|
94
|
+
out[:tracerVersion] = il.name unless il.version.empty?
|
94
95
|
|
95
96
|
out
|
96
97
|
end
|
@@ -130,7 +131,7 @@ module Uptrace
|
|
130
131
|
data = Zstd.compress(data, 3)
|
131
132
|
|
132
133
|
req = Net::HTTP::Post.new(@endpoint)
|
133
|
-
req.add_field('Authorization', "Bearer #{@
|
134
|
+
req.add_field('Authorization', "Bearer #{@dsn.token}")
|
134
135
|
req.add_field('Content-Type', 'application/msgpack')
|
135
136
|
req.add_field('Content-Encoding', 'zstd')
|
136
137
|
req.add_field('Connection', 'keep-alive')
|
@@ -216,17 +217,6 @@ module Uptrace
|
|
216
217
|
end
|
217
218
|
out
|
218
219
|
end
|
219
|
-
|
220
|
-
##
|
221
|
-
# @param [OpenTelemetry::SDK::InstrumentationLibrary] il
|
222
|
-
# @return [Hash]
|
223
|
-
#
|
224
|
-
def uptrace_tracer(il)
|
225
|
-
{
|
226
|
-
name: il.name,
|
227
|
-
version: il.version
|
228
|
-
}
|
229
|
-
end
|
230
220
|
end
|
231
221
|
end
|
232
222
|
end
|
data/lib/uptrace/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uptrace
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Uptrace Authors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: msgpack
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
33
|
+
version: 0.15.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.
|
40
|
+
version: 0.15.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: zstd-ruby
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -174,12 +174,12 @@ files:
|
|
174
174
|
- ".yardopts"
|
175
175
|
- LICENSE
|
176
176
|
- README.md
|
177
|
+
- RELEASE.md
|
177
178
|
- lib/uptrace.rb
|
178
179
|
- lib/uptrace/client.rb
|
179
180
|
- lib/uptrace/dsn.rb
|
180
181
|
- lib/uptrace/metric.rb
|
181
182
|
- lib/uptrace/trace.rb
|
182
|
-
- lib/uptrace/trace/config.rb
|
183
183
|
- lib/uptrace/trace/exporter.rb
|
184
184
|
- lib/uptrace/version.rb
|
185
185
|
homepage: https://github.com/uptrace/uptrace-ruby
|
data/lib/uptrace/trace/config.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'uptrace/dsn'
|
4
|
-
|
5
|
-
module Uptrace
|
6
|
-
module Trace
|
7
|
-
# Config is a configuration for Uptrace span exporter.
|
8
|
-
class Config
|
9
|
-
# @return [string] a data source name to connect to uptrace.dev.
|
10
|
-
attr_accessor :dsn
|
11
|
-
|
12
|
-
# @return [string] `service.name` resource attribute.
|
13
|
-
attr_accessor :service_name
|
14
|
-
|
15
|
-
# @return [string] `service.name` resource attribute.
|
16
|
-
attr_accessor :service_version
|
17
|
-
|
18
|
-
# @return [boolean] disables the exporter.
|
19
|
-
attr_accessor :disabled
|
20
|
-
|
21
|
-
def initialize
|
22
|
-
@dsn = ENV.fetch('UPTRACE_DSN', '')
|
23
|
-
end
|
24
|
-
|
25
|
-
def dsno
|
26
|
-
@dsno ||= DSN.new(@dsn)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|