uptrace 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/uptrace.rb +20 -0
- data/lib/uptrace/client.rb +14 -22
- data/lib/uptrace/trace/exporter.rb +5 -7
- data/lib/uptrace/version.rb +1 -1
- metadata +1 -2
- data/lib/uptrace/trace/config.rb +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 525b8e2ad45dd955af7095839bfdf024e29b11309e8a0103b36bddb7980f3c41
|
4
|
+
data.tar.gz: 0766a2822dad2acb536aeccba788ac898ce7474ae4d74de355577de544772a4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36c69755595e07ffee78a62f3f1633fdd62def2d910b50876e8ffc4e2791800869d98f61b338bb2e30a01280610cc5fbeabe58a0f17214b5f2377031c2801f07
|
7
|
+
data.tar.gz: f33956036979a79d2f39e05f8a30f3008ffd967a828a048d88b187867e562bd013cecf9b0958584dc885142341633848739c3fc05dded624c8c16dc7ee8d7848
|
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,43 +5,35 @@ 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?
|
15
|
-
|
16
|
-
@cfg.dsn = ENV.fetch('UPTRACE_DSN', '') if @cfg.dsn.nil? || @cfg.dsn.empty?
|
8
|
+
# @param [string] dsn
|
9
|
+
def initialize(dsn: '')
|
10
|
+
dsn = ENV.fetch('UPTRACE_DSN', '') if dsn.empty?
|
17
11
|
|
18
12
|
begin
|
19
|
-
@
|
13
|
+
@dsn = DSN.new(dsn)
|
20
14
|
rescue ArgumentError => e
|
21
15
|
Uptrace.logger.error("Uptrace is disabled: #{e.message}")
|
22
|
-
@
|
16
|
+
@disabled = true
|
23
17
|
|
24
|
-
@
|
18
|
+
@dsn = DSN.new('https://TOKEN@api.uptrace.dev/PROJECT_ID')
|
25
19
|
end
|
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}/search/#{dsn.project_id}?q=#{trace_id}"
|
31
|
+
"#{@dsn.scheme}://#{host}/search/#{@dsn.project_id}?q=#{trace_id}"
|
41
32
|
end
|
42
33
|
|
34
|
+
# @return [OpenTelemetry::SDK::Trace::Export::BatchSpanProcessor]
|
43
35
|
def span_processor
|
44
|
-
exp = Uptrace::Trace::Exporter.new(@
|
36
|
+
exp = Uptrace::Trace::Exporter.new(@dsn)
|
45
37
|
OpenTelemetry::SDK::Trace::Export::BatchSpanProcessor.new(
|
46
38
|
exp,
|
47
39
|
max_queue_size: 1000,
|
@@ -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
|
@@ -133,7 +131,7 @@ module Uptrace
|
|
133
131
|
data = Zstd.compress(data, 3)
|
134
132
|
|
135
133
|
req = Net::HTTP::Post.new(@endpoint)
|
136
|
-
req.add_field('Authorization', "Bearer #{@
|
134
|
+
req.add_field('Authorization', "Bearer #{@dsn.token}")
|
137
135
|
req.add_field('Content-Type', 'application/msgpack')
|
138
136
|
req.add_field('Content-Encoding', 'zstd')
|
139
137
|
req.add_field('Connection', 'keep-alive')
|
data/lib/uptrace/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Uptrace Authors
|
@@ -180,7 +180,6 @@ files:
|
|
180
180
|
- lib/uptrace/dsn.rb
|
181
181
|
- lib/uptrace/metric.rb
|
182
182
|
- lib/uptrace/trace.rb
|
183
|
-
- lib/uptrace/trace/config.rb
|
184
183
|
- lib/uptrace/trace/exporter.rb
|
185
184
|
- lib/uptrace/version.rb
|
186
185
|
homepage: https://github.com/uptrace/uptrace-ruby
|
data/lib/uptrace/trace/config.rb
DELETED
@@ -1,26 +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 dsno
|
22
|
-
@dsno ||= DSN.new(@dsn)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|