uptrace 0.2.1 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/RELEASE.md +7 -0
- data/lib/uptrace.rb +16 -0
- data/lib/uptrace/client.rb +22 -39
- 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 +3 -3
- 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: 7eaccd23f9b8a866577eb6ef2c81589306a4930280bedbed67340b8d908339c4
|
4
|
+
data.tar.gz: fe2bce7cfb97c14318f2cf63d65aa102d6e74ac6f01f12a600d2822856abf15c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6f15e1110e43582d2aba18a19ef16aa6844a85584d101c9c4c72de0f072941d31c9a42deae5b42802f03b7da3050b7279e3a5b07b9ba9a3d4e76251d9293d24
|
7
|
+
data.tar.gz: 72fbe0da3afe6979150c16f5944fe140439ea552009aef1c84164d9cebed73d40a5639ed346e4e57029ba8c39087f78af7358f121d36084ed1715d7a96e3fb4d
|
data/RELEASE.md
ADDED
data/lib/uptrace.rb
CHANGED
@@ -7,8 +7,24 @@ 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_opentelemetry(c, dsn: '')
|
24
|
+
@client = Client.new(dsn: dsn) unless dsn.empty?
|
25
|
+
|
26
|
+
c.add_span_processor(client.span_processor) unless client.disabled?
|
27
|
+
end
|
12
28
|
end
|
13
29
|
|
14
30
|
require 'uptrace/version'
|
data/lib/uptrace/client.rb
CHANGED
@@ -5,58 +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
|
-
max_export_batch_size: 1000,
|
53
|
-
schedule_delay: 5_000
|
54
|
-
)
|
55
|
-
c.add_span_processor(bsp)
|
56
|
-
|
57
|
-
c.service_name = @cfg.service_name
|
58
|
-
c.service_version = @cfg.service_version
|
59
|
-
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
|
+
)
|
60
43
|
end
|
61
44
|
end
|
62
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.6
|
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-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: msgpack
|
@@ -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
|