uptrace 1.0.0.rc1 → 1.0.0.rc3

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: 5f9a4d977dcec234cd8810306f108488708ca23a30ce0836d71d52e5f759033b
4
- data.tar.gz: 305152b04753b7febe844a76ff675f192f5d0f939f179b77dfb73a4fd21d71fe
3
+ metadata.gz: 56199216a5c7984c7896ed2d2480ec7d3ba062dbddc78feb1a640a8ea16d59a5
4
+ data.tar.gz: f63c2f468a5df9982a7fae3beb3911fe84b8743329f7c73fed8a26aa47851440
5
5
  SHA512:
6
- metadata.gz: c0593e88e857717b329f4f4d21278efddd605412e3ab63d617eccb3547bbabacaf98ff3f7c68630b90215eff7712cc824c7579e2c5edb78617931b3004b1930b
7
- data.tar.gz: d8c976e2e80dbaa0eb323c8c71ee919cac0b53331bec52483b34e0e393dece72914ef21810d4d5c677a1ee8bc8902a6f210d2c814366a9afe940f456ee9fa5c9
6
+ metadata.gz: d6ac6820d74a2df77286ae3d82cc94c91660cb31d04dfbbe5d2128ff0de645338d71e64658a32efb1e396b23ab8cb65ac86b3e1a3e2644ee00b767496627ab38
7
+ data.tar.gz: 1361f3804cfa101e125910035234dcc7dafd1c208babcaaca9d675ebb90e25da8c315f8631f7c9c11b832f6c49afd56a8552ba390b9a8d1a0cc939598a591431
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## v1.0.0.rc3 - 2021-08-17
4
+
5
+ - Updated OpenTelemetry to
6
+ [v1.0.0.rc3](https://github.com/open-telemetry/opentelemetry-ruby/blob/main/api/CHANGELOG.md#v100rc3--2021-08-12).
7
+ - Switched to using OTLP protocol.
8
+
3
9
  ## v1.0.0.rc1 - 2021-05-22
4
10
 
5
11
  - Updated OpenTelemetry to
data/README.md CHANGED
@@ -30,33 +30,35 @@ require 'rubygems'
30
30
  require 'bundler/setup'
31
31
  require 'uptrace'
32
32
 
33
- OpenTelemetry::SDK.configure do |c|
33
+ # Configure OpenTelemetry with sensible defaults.
34
+ # Copy your project DSN here or use UPTRACE_DSN env var.
35
+ Uptrace.configure_opentelemetry(dsn: '') do |c|
36
+ # c is OpenTelemetry::SDK::Configurator
34
37
  c.service_name = 'myservice'
35
38
  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
39
  end
41
40
 
41
+ # Create a tracer. Usually, tracer is a global variable.
42
42
  tracer = OpenTelemetry.tracer_provider.tracer('my_app_or_gem', '0.1.0')
43
43
 
44
- tracer.in_span('main') do |span|
45
- tracer.in_span('child1') do |child1|
44
+ # Create a root span (a trace) to measure some operation.
45
+ tracer.in_span('main-operation') do |main|
46
+ tracer.in_span('child1-of-main') do |child1|
46
47
  child1.set_attribute('key1', 'value1')
47
48
  child1.record_exception(ArgumentError.new('error1'))
48
49
  end
49
50
 
50
- tracer.in_span('child2') do |child2|
51
+ tracer.in_span('child2-of-main') do |child2|
51
52
  child2.set_attribute('key2', '24')
52
53
  child2.set_attribute('key3', 123.456)
53
54
  end
54
55
 
55
- puts("trace URL: #{Uptrace.trace_url(span)}")
56
+ puts("trace URL: #{Uptrace.trace_url(main)}")
56
57
  end
57
58
 
58
- # Send buffered spans.
59
+ # Send buffered spans and free resources.
59
60
  OpenTelemetry.tracer_provider.shutdown
60
61
  ```
61
62
 
62
- Please see [uptrace-ruby documentation](https://docs.uptrace.dev/ruby/) for more details.
63
+ For more details, please see [documentation](https://docs.uptrace.dev/ruby/) and
64
+ [examples](example).
data/lib/uptrace.rb CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  require 'logger'
4
4
 
5
+ require 'opentelemetry/exporter/otlp'
6
+
5
7
  # Uptrace provides Uptrace exporters for OpenTelemetry.
6
8
  module Uptrace
7
9
  extend self
@@ -31,14 +33,30 @@ module Uptrace
31
33
  def configure_opentelemetry(dsn: '')
32
34
  OpenTelemetry::SDK.configure do |c|
33
35
  @client = Client.new(dsn: dsn) unless dsn.empty?
34
- c.add_span_processor(client.span_processor) unless client.disabled?
36
+ c.add_span_processor(span_processor(@client.dsn.to_s)) unless client.disabled?
35
37
 
36
38
  yield c if block_given?
37
39
  end
38
40
  end
41
+
42
+ private
43
+
44
+ def span_processor(dsn)
45
+ exporter = OpenTelemetry::Exporter::OTLP::Exporter.new(
46
+ endpoint: 'https://otlp.uptrace.dev/v1/traces',
47
+ # Set the Uptrace DSN here or use UPTRACE_DSN env var.
48
+ headers: { 'uptrace-dsn': dsn },
49
+ compression: 'gzip'
50
+ )
51
+ OpenTelemetry::SDK::Trace::Export::BatchSpanProcessor.new(
52
+ exporter,
53
+ max_queue_size: 1000,
54
+ max_export_batch_size: 1000,
55
+ schedule_delay: 5_000
56
+ )
57
+ end
39
58
  end
40
59
 
41
60
  require 'uptrace/version'
42
61
  require 'uptrace/dsn'
43
62
  require 'uptrace/client'
44
- require 'uptrace/trace'
@@ -5,6 +5,8 @@ require 'opentelemetry/sdk'
5
5
  module Uptrace
6
6
  # Uptrace client that configures OpenTelemetry SDK to use Uptrace exporter.
7
7
  class Client
8
+ attr_reader :dsn
9
+
8
10
  # @param [string] dsn
9
11
  def initialize(dsn: '')
10
12
  dsn = ENV.fetch('UPTRACE_DSN', '') if dsn.empty?
@@ -32,16 +34,5 @@ module Uptrace
32
34
  trace_id = span.context.hex_trace_id
33
35
  "#{@dsn.scheme}://#{host}/search/#{@dsn.project_id}?q=#{trace_id}"
34
36
  end
35
-
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
- )
45
- end
46
37
  end
47
38
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uptrace
4
- VERSION = '1.0.0.rc1'
4
+ VERSION = '1.0.0.rc3'
5
5
  end
metadata CHANGED
@@ -1,57 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uptrace
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc1
4
+ version: 1.0.0.rc3
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-05-22 00:00:00.000000000 Z
11
+ date: 2021-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: msgpack
14
+ name: opentelemetry-exporter-otlp
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.4.2
19
+ version: 0.20.2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.4.2
26
+ version: 0.20.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: opentelemetry-sdk
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.0.0.rc1
33
+ version: 1.0.0.rc3
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: 1.0.0.rc1
41
- - !ruby/object:Gem::Dependency
42
- name: zstd-ruby
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: 1.4.9.0
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: 1.4.9.0
40
+ version: 1.0.0.rc3
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: bundler
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -179,9 +165,6 @@ files:
179
165
  - lib/uptrace.rb
180
166
  - lib/uptrace/client.rb
181
167
  - lib/uptrace/dsn.rb
182
- - lib/uptrace/metric.rb
183
- - lib/uptrace/trace.rb
184
- - lib/uptrace/trace/exporter.rb
185
168
  - lib/uptrace/version.rb
186
169
  homepage: https://github.com/uptrace/uptrace-ruby
187
170
  licenses:
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Uptrace
4
- # Metric module provides metric exporter for OpenTelemetry.
5
- module Metric
6
- end
7
- end
data/lib/uptrace/trace.rb DELETED
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Uptrace
4
- # Trace module provides trace exporter for OpenTelemetry.
5
- module Trace
6
- end
7
- end
8
-
9
- require 'uptrace/trace/exporter'
@@ -1,224 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'uri'
4
- require 'net/http'
5
- require 'json'
6
-
7
- require 'opentelemetry/sdk'
8
- require 'msgpack'
9
- require 'zstd-ruby'
10
-
11
- module Uptrace
12
- module Trace
13
- # Exporter is a span exporter for OpenTelemetry.
14
- class Exporter
15
- SUCCESS = OpenTelemetry::SDK::Trace::Export::SUCCESS
16
- FAILURE = OpenTelemetry::SDK::Trace::Export::FAILURE
17
- TIMEOUT = OpenTelemetry::SDK::Trace::Export::TIMEOUT
18
- private_constant(:SUCCESS, :FAILURE, :TIMEOUT)
19
-
20
- ##
21
- # @param [Config] cfg
22
- #
23
- def initialize(dsn)
24
- @dsn = dsn
25
- @endpoint = "/api/v1/tracing/#{@dsn.project_id}/spans"
26
-
27
- @http = Net::HTTP.new(@dsn.host, 443)
28
- @http.use_ssl = true
29
- @http.open_timeout = 5
30
- @http.read_timeout = 5
31
- @http.keep_alive_timeout = 30
32
- end
33
-
34
- # Called to export sampled {OpenTelemetry::SDK::Trace::SpanData} structs.
35
- #
36
- # @param [Enumerable<OpenTelemetry::SDK::Trace::SpanData>] spans the
37
- # list of recorded {OpenTelemetry::SDK::Trace::SpanData} structs to be
38
- # exported.
39
- # @param [optional Numeric] timeout An optional timeout in seconds.
40
- # @return [Integer] the result of the export.
41
- def export(spans, timeout: nil)
42
- return SUCCESS if @disabled
43
- return FAILURE if @shutdown
44
-
45
- out = []
46
-
47
- spans.each do |span|
48
- out.push(uptrace_span(span))
49
- end
50
-
51
- send({ spans: out }, timeout: timeout)
52
- end
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
-
63
- # Called when {OpenTelemetry::SDK::Trace::Tracer#shutdown} is called, if
64
- # this exporter is registered to a {OpenTelemetry::SDK::Trace::Tracer}
65
- # object.
66
- #
67
- # @param [optional Numeric] timeout An optional timeout in seconds.
68
- def shutdown(timeout: nil) # rubocop:disable Lint/UnusedMethodArgument
69
- @shutdown = true
70
- @http.finish if @http.started?
71
- SUCCESS
72
- end
73
-
74
- private
75
-
76
- ##
77
- # @return [hash]
78
- #
79
- def uptrace_span(span)
80
- out = {
81
- id: span.span_id.unpack1('Q'),
82
- traceId: span.trace_id,
83
-
84
- name: span.name,
85
- kind: kind_as_str(span.kind),
86
- startTime: span.start_timestamp,
87
- endTime: span.end_timestamp,
88
-
89
- resource: uptrace_resource(span.resource),
90
- attrs: span.attributes
91
- }
92
-
93
- out[:parentId] = span.parent_span_id.unpack1('Q') if span.parent_span_id
94
-
95
- out[:events] = uptrace_events(span.events) unless span.events.nil?
96
- out[:links] = uptrace_links(span.links) unless span.links.nil?
97
-
98
- status = span.status
99
- out[:statusCode] = status_code_as_str(status.code)
100
- out[:statusMessage] = status.description unless status.description.empty?
101
-
102
- il = span.instrumentation_library
103
- out[:tracerName] = il.name
104
- out[:tracerVersion] = il.name unless il.version.empty?
105
-
106
- out
107
- end
108
-
109
- def send(data, timeout: nil) # rubocop:disable Lint/UnusedMethodArgument
110
- req = build_request(data)
111
-
112
- begin
113
- resp = @http.request(req)
114
- rescue Net::OpenTimeout, Net::ReadTimeout
115
- return FAILURE
116
- end
117
-
118
- case resp
119
- when Net::HTTPOK
120
- resp.body # Read and discard body
121
- SUCCESS
122
- when Net::HTTPBadRequest
123
- data = JSON.parse(resp.body)
124
- Uptrace.logger.error("status=#{data['status']}: #{data['message']}")
125
- FAILURE
126
- when Net::HTTPInternalServerError
127
- resp.body
128
- FAILURE
129
- else
130
- @http.finish
131
- FAILURE
132
- end
133
- end
134
-
135
- ##
136
- # @param [Hash] data
137
- # @return [Net::HTTP::Post]
138
- #
139
- def build_request(data)
140
- data = MessagePack.pack(data)
141
- data = Zstd.compress(data, 3)
142
-
143
- req = Net::HTTP::Post.new(@endpoint)
144
- req.add_field('Authorization', "Bearer #{@dsn.token}")
145
- req.add_field('Content-Type', 'application/msgpack')
146
- req.add_field('Content-Encoding', 'zstd')
147
- req.add_field('Connection', 'keep-alive')
148
- req.body = data
149
-
150
- req
151
- end
152
-
153
- # @param [SpanKind] kind
154
- # @return [String]
155
- def kind_as_str(kind)
156
- case kind
157
- when OpenTelemetry::Trace::SpanKind::SERVER
158
- 'server'
159
- when OpenTelemetry::Trace::SpanKind::CLIENT
160
- 'client'
161
- when OpenTelemetry::Trace::SpanKind::PRODUCER
162
- 'producer'
163
- when OpenTelemetry::Trace::SpanKind::CONSUMER
164
- 'consumer'
165
- else
166
- 'internal'
167
- end
168
- end
169
-
170
- ##
171
- # @param [Integer] code
172
- # @return [String]
173
- #
174
- def status_code_as_str(code)
175
- case code
176
- when OpenTelemetry::Trace::Status::OK
177
- 'ok'
178
- when OpenTelemetry::Trace::Status::ERROR
179
- 'error'
180
- else
181
- 'unset'
182
- end
183
- end
184
-
185
- ##
186
- # @param [OpenTelemetry::SDK::Resources::Resource] resource
187
- # @return [Hash]
188
- #
189
- def uptrace_resource(resource)
190
- out = {}
191
- resource.attribute_enumerator.map { |key, value| out[key] = value }
192
- out
193
- end
194
-
195
- def uptrace_events(events)
196
- out = []
197
- events.each do |event|
198
- out.push(
199
- {
200
- name: event.name,
201
- attrs: event.attributes,
202
- time: event.timestamp
203
- }
204
- )
205
- end
206
- out
207
- end
208
-
209
- def uptrace_links(links)
210
- out = []
211
- links.each do |link|
212
- out.push(
213
- {
214
- trace_id => link.span_context.trace_id,
215
- span_id => link.span_context.span_id.unpack1('Q'),
216
- attrs => link.attributes
217
- }
218
- )
219
- end
220
- out
221
- end
222
- end
223
- end
224
- end