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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3cc81f964b6c014c38abbdfcf4250fa467ba0c8ef2dfd8077967d851bdd9f567
4
- data.tar.gz: 5fb6975a0916e18d1603aa03ec78d7639b4e6a37de079e2ed72326a7db8c6ee0
3
+ metadata.gz: 525b8e2ad45dd955af7095839bfdf024e29b11309e8a0103b36bddb7980f3c41
4
+ data.tar.gz: 0766a2822dad2acb536aeccba788ac898ce7474ae4d74de355577de544772a4b
5
5
  SHA512:
6
- metadata.gz: ba5ef3bc321a50fd4203a033a023bbfc491071d29a05edb9c9a93cd6a2c53a8a59ec6af2e97cc919d57695193993ecedbf42914b53cbda72a6ab80d9085b763c
7
- data.tar.gz: e5a44d04828a788321193d00a6c7196fa38c92ce7aaa274636448f50609c3759410d11444360cd42f7d1ee066af020660e706732b2209686dc224da707d6ec33
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'
@@ -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
- # @yieldparam config [Uptrace::Config]
10
- # @return [void]
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
- @cfg.dsno
13
+ @dsn = DSN.new(dsn)
20
14
  rescue ArgumentError => e
21
15
  Uptrace.logger.error("Uptrace is disabled: #{e.message}")
22
- @cfg.disabled = true
16
+ @disabled = true
23
17
 
24
- @cfg.dsn = 'https://TOKEN@api.uptrace.dev/PROJECT_ID'
18
+ @dsn = DSN.new('https://TOKEN@api.uptrace.dev/PROJECT_ID')
25
19
  end
26
20
  end
27
21
 
28
- # @param [optional Numeric] timeout An optional timeout in seconds.
29
- def close(timeout: nil)
30
- return if @cfg.disabled
31
-
32
- OpenTelemetry.tracer_provider.shutdown(timeout: timeout)
22
+ def disabled?
23
+ @disabled
33
24
  end
34
25
 
35
- # @return [OpenTelemetry::Trace::Span]
26
+ # @param [OpenTelemetry::Trace::Span] span
27
+ # @return [String]
36
28
  def trace_url(span)
37
- dsn = @cfg.dsno
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(@cfg)
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(cfg)
24
- @cfg = cfg
23
+ def initialize(dsn)
24
+ @dsn = dsn
25
+ @endpoint = "/api/v1/tracing/#{@dsn.project_id}/spans"
25
26
 
26
- dsn = @cfg.dsno
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 #{@cfg.dsno.token}")
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')
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uptrace
4
- VERSION = '0.2.3'
4
+ VERSION = '0.2.4'
5
5
  end
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.3
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
@@ -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