uptrace 0.2.2 → 0.16.0
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/README.md +47 -6
- data/RELEASE.md +3 -1
- data/lib/uptrace.rb +18 -0
- data/lib/uptrace/client.rb +25 -40
- data/lib/uptrace/dsn.rb +3 -3
- data/lib/uptrace/trace.rb +0 -1
- data/lib/uptrace/trace/exporter.rb +22 -14
- data/lib/uptrace/version.rb +1 -1
- metadata +4 -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: d437c19b7fc3feb724d4fa895fb7ef5e9cfc8501931a16f53d598fb9ef5afddc
|
4
|
+
data.tar.gz: 6340b2ba9b3991f922777310e43d7e256384f621b18c6598e422332b1940efce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cdb698a1ee148f598fbf2ecf93ddc47867d797fd0f72a33bdc44547dfe5cec846984eaaba71e69c198ce3423c64bfe8ff830313b770980624a8cff164b0b431d
|
7
|
+
data.tar.gz: 95c417612dd655203b05d3323188536f453fa03ba4f412e84491dc23bdca90397f9ae3d99cdfd1899f06e23632282efa6f74251a9e93da8436d1255aa74431df
|
data/README.md
CHANGED
@@ -1,21 +1,62 @@
|
|
1
1
|
# Uptrace Ruby exporter for OpenTelemetry
|
2
2
|
|
3
|
-
|
3
|
+

|
4
4
|
[](https://docs.uptrace.dev/ruby/)
|
5
5
|
|
6
6
|
<a href="https://docs.uptrace.dev/ruby/">
|
7
7
|
<img src="https://docs.uptrace.dev/devicons/ruby-original.svg" height="200px" />
|
8
8
|
</a>
|
9
9
|
|
10
|
-
##
|
10
|
+
## Introduction
|
11
|
+
|
12
|
+
uptrace-ruby is an OpenTelemery distribution configured to export
|
13
|
+
[traces](https://docs.uptrace.dev/tracing/#spans) to Uptrace.
|
14
|
+
|
15
|
+
## Quickstart
|
16
|
+
|
17
|
+
Install uptrace-ruby:
|
11
18
|
|
12
19
|
```bash
|
13
20
|
gem install uptrace
|
14
21
|
```
|
15
22
|
|
16
|
-
|
23
|
+
Run the [basic example](example/basic) below using the DSN from the Uptrace project settings page.
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
#!/usr/bin/env ruby
|
27
|
+
# frozen_string_literal: true
|
28
|
+
|
29
|
+
require 'rubygems'
|
30
|
+
require 'bundler/setup'
|
31
|
+
require 'uptrace'
|
17
32
|
|
18
|
-
|
19
|
-
|
33
|
+
OpenTelemetry::SDK.configure do |c|
|
34
|
+
c.service_name = 'myservice'
|
35
|
+
c.service_version = '1.0.0'
|
36
|
+
|
37
|
+
# Configure OpenTelemetry to export data to Uptrace.
|
38
|
+
# Copy your project DSN here or use UPTRACE_DSN env var.
|
39
|
+
Uptrace.configure_opentelemetry(c, dsn: '')
|
40
|
+
end
|
41
|
+
|
42
|
+
tracer = OpenTelemetry.tracer_provider.tracer('my_app_or_gem', '0.1.0')
|
43
|
+
|
44
|
+
tracer.in_span('main') do |span|
|
45
|
+
tracer.in_span('child1') do |child1|
|
46
|
+
child1.set_attribute('key1', 'value1')
|
47
|
+
child1.record_exception(ArgumentError.new('error1'))
|
48
|
+
end
|
49
|
+
|
50
|
+
tracer.in_span('child2') do |child2|
|
51
|
+
child2.set_attribute('key2', '24')
|
52
|
+
child2.set_attribute('key3', 123.456)
|
53
|
+
end
|
54
|
+
|
55
|
+
puts("trace URL: #{Uptrace.trace_url(span)}")
|
56
|
+
end
|
57
|
+
|
58
|
+
# Send buffered spans.
|
59
|
+
OpenTelemetry.tracer_provider.shutdown
|
60
|
+
```
|
20
61
|
|
21
|
-
|
62
|
+
Please see [uptrace-ruby documentation](https://docs.uptrace.dev/ruby/) for more details.
|
data/RELEASE.md
CHANGED
data/lib/uptrace.rb
CHANGED
@@ -7,8 +7,26 @@ 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
|
+
# @param [optional OpenTelemetry::Trace::Span] span
|
20
|
+
# @return [String]
|
21
|
+
def trace_url(span = nil)
|
22
|
+
client.trace_url(span)
|
23
|
+
end
|
24
|
+
|
25
|
+
def configure_opentelemetry(c, dsn: '')
|
26
|
+
@client = Client.new(dsn: dsn) unless dsn.empty?
|
27
|
+
|
28
|
+
c.add_span_processor(client.span_processor) unless client.disabled?
|
29
|
+
end
|
12
30
|
end
|
13
31
|
|
14
32
|
require 'uptrace/version'
|
data/lib/uptrace/client.rb
CHANGED
@@ -5,58 +5,43 @@ 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
|
-
# @
|
36
|
-
|
37
|
-
|
38
|
-
|
26
|
+
# @param [optional OpenTelemetry::Trace::Span] span
|
27
|
+
# @return [String]
|
28
|
+
def trace_url(span = nil)
|
29
|
+
span = OpenTelemetry::Trace.current_span if span.nil?
|
30
|
+
|
31
|
+
host = @dsn.host.delete_prefix('api.')
|
39
32
|
trace_id = span.context.hex_trace_id
|
40
|
-
"#{dsn.scheme}://#{host}/search/#{dsn.project_id}?q=#{trace_id}"
|
33
|
+
"#{@dsn.scheme}://#{host}/search/#{@dsn.project_id}?q=#{trace_id}"
|
41
34
|
end
|
42
35
|
|
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
|
36
|
+
# @return [OpenTelemetry::SDK::Trace::Export::BatchSpanProcessor]
|
37
|
+
def span_processor
|
38
|
+
exp = Uptrace::Trace::Exporter.new(@dsn)
|
39
|
+
OpenTelemetry::SDK::Trace::Export::BatchSpanProcessor.new(
|
40
|
+
exp,
|
41
|
+
max_queue_size: 1000,
|
42
|
+
max_export_batch_size: 1000,
|
43
|
+
schedule_delay: 5_000
|
44
|
+
)
|
60
45
|
end
|
61
46
|
end
|
62
47
|
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=#{dsn.inspect} does not have a #{k}) 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
|
@@ -53,6 +51,15 @@ module Uptrace
|
|
53
51
|
send({ spans: out }, timeout: timeout)
|
54
52
|
end
|
55
53
|
|
54
|
+
# Called when {OpenTelemetry::SDK::Trace::TracerProvider#force_flush} is called, if
|
55
|
+
# this exporter is registered to a {OpenTelemetry::SDK::Trace::TracerProvider}
|
56
|
+
# object.
|
57
|
+
#
|
58
|
+
# @param [optional Numeric] timeout An optional timeout in seconds.
|
59
|
+
def force_flush(timeout: nil) # rubocop:disable Lint/UnusedMethodArgument
|
60
|
+
SUCCESS
|
61
|
+
end
|
62
|
+
|
56
63
|
# Called when {OpenTelemetry::SDK::Trace::Tracer#shutdown} is called, if
|
57
64
|
# this exporter is registered to a {OpenTelemetry::SDK::Trace::Tracer}
|
58
65
|
# object.
|
@@ -61,6 +68,7 @@ module Uptrace
|
|
61
68
|
def shutdown(timeout: nil) # rubocop:disable Lint/UnusedMethodArgument
|
62
69
|
@shutdown = true
|
63
70
|
@http.finish if @http.started?
|
71
|
+
SUCCESS
|
64
72
|
end
|
65
73
|
|
66
74
|
private
|
@@ -82,18 +90,18 @@ module Uptrace
|
|
82
90
|
attrs: span.attributes
|
83
91
|
}
|
84
92
|
|
85
|
-
out[parentId] = span.parent_span_id.unpack1('Q') if span.parent_span_id
|
93
|
+
out[:parentId] = span.parent_span_id.unpack1('Q') if span.parent_span_id
|
86
94
|
|
87
|
-
out[events] = uptrace_events(span.events) unless span.events.nil?
|
88
|
-
out[links] = uptrace_links(span.links) unless span.links.nil?
|
95
|
+
out[:events] = uptrace_events(span.events) unless span.events.nil?
|
96
|
+
out[:links] = uptrace_links(span.links) unless span.links.nil?
|
89
97
|
|
90
98
|
status = span.status
|
91
|
-
out[statusCode] = status_code_as_str(status.code)
|
92
|
-
out[statusMessage] = status.description unless status.description.empty?
|
99
|
+
out[:statusCode] = status_code_as_str(status.code)
|
100
|
+
out[:statusMessage] = status.description unless status.description.empty?
|
93
101
|
|
94
102
|
il = span.instrumentation_library
|
95
|
-
out[tracerName] = il.name
|
96
|
-
out[tracerVersion] = il.name unless il.version.empty?
|
103
|
+
out[:tracerName] = il.name
|
104
|
+
out[:tracerVersion] = il.name unless il.version.empty?
|
97
105
|
|
98
106
|
out
|
99
107
|
end
|
@@ -133,7 +141,7 @@ module Uptrace
|
|
133
141
|
data = Zstd.compress(data, 3)
|
134
142
|
|
135
143
|
req = Net::HTTP::Post.new(@endpoint)
|
136
|
-
req.add_field('Authorization', "Bearer #{@
|
144
|
+
req.add_field('Authorization', "Bearer #{@dsn.token}")
|
137
145
|
req.add_field('Content-Type', 'application/msgpack')
|
138
146
|
req.add_field('Content-Encoding', 'zstd')
|
139
147
|
req.add_field('Connection', 'keep-alive')
|
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.
|
4
|
+
version: 0.16.0
|
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-23 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.16.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.16.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: zstd-ruby
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -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,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
|