uptrace 0.16.2 → 1.0.0

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: 6e560d02dc7fff00fe1417273235f621093fddf1dd2b89fec8eb26f25ec77137
4
- data.tar.gz: f4425d572581c3b8863891e7f1df56c1acc2a8df19e96d56c5fadc138b147fd6
3
+ metadata.gz: 72bfd8148792008a3e5b234beb4394e78aeb5daf7e1e58e4be6cf17307426c83
4
+ data.tar.gz: 5dcb5720cdcfd03a638c714ed5348b3a59a495e4545d77ab17c2ee8c491545c8
5
5
  SHA512:
6
- metadata.gz: f9d888b255f9b97deb19d115bfc0a16eca449a79df08c6262557be002f98460a3ba1db188caf5cf2266e7cbbe92aefd5fec1567a7c398ddcd04021f4315324e2
7
- data.tar.gz: d831ec671858212f78caeadba72689d0735b0c85579af3bcec992e5df83c62d40af0a447dea647f0a28c993f277f8e3ecfbaa9aa9ef348734912523ecc947f26
6
+ metadata.gz: 32797cae23ce4a51cf174cd2b9140398e2e824c19e2f1ddc0a90bbe6e991ec0d77ef44525979a1490fad4f5da866eef281e3bef1af0bbb62596cb8d10a0b01c8
7
+ data.tar.gz: 1fda6cbf14c17f2db89812bd282d24c6b0c23fcf7a74afbbfa0584e6dd06795dcd10e9a17c31552ae5e279a15d7f3d0a064ba454b0c6d87c12dbc0e66c0ace9b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # Changelog
2
2
 
3
+ ## v1.0.0 - 2021-10-06
4
+
5
+ - Updated OpenTelemetry to
6
+ [v1.0.0](https://github.com/open-telemetry/opentelemetry-ruby/blob/main/api/CHANGELOG.md#v100--2021-09-29).
7
+
8
+ ## v1.0.0.rc3 - 2021-08-17
9
+
10
+ - Updated OpenTelemetry to
11
+ [v1.0.0.rc3](https://github.com/open-telemetry/opentelemetry-ruby/blob/main/api/CHANGELOG.md#v100rc3--2021-08-12).
12
+ - Switched to using OTLP protocol.
13
+
14
+ ## v1.0.0.rc1 - 2021-05-22
15
+
16
+ - Updated OpenTelemetry to
17
+ [v1.0.0.rc1](https://github.com/open-telemetry/opentelemetry-ruby/blob/main/api/CHANGELOG.md#v100rc1--2021-05-21).
18
+
19
+ ## v0.17.0 - 2021-04-24
20
+
21
+ - Updated OpenTelemetry to
22
+ [v0.17.0](https://github.com/open-telemetry/opentelemetry-ruby/blob/main/api/CHANGELOG.md#v0170--2021-04-22).
23
+
3
24
  ## v0.16.2 - 2021-03-28
4
25
 
5
26
  - Updated OpenTelemetry to
data/README.md CHANGED
@@ -3,8 +3,8 @@
3
3
  ![build workflow](https://github.com/uptrace/uptrace-ruby/actions/workflows/build.yml/badge.svg)
4
4
  [![Documentation](https://img.shields.io/badge/uptrace-documentation-informational)](https://docs.uptrace.dev/ruby/)
5
5
 
6
- <a href="https://docs.uptrace.dev/ruby/">
7
- <img src="https://docs.uptrace.dev/devicons/ruby-original.svg" height="200px" />
6
+ <a href="https://docs.uptrace.dev/guide/ruby.html">
7
+ <img src="https://docs.uptrace.dev/devicon/ruby-original.svg" height="200px" />
8
8
  </a>
9
9
 
10
10
  ## Introduction
@@ -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).
@@ -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 = '0.16.2'
4
+ VERSION = '1.0.0'
5
5
  end
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'
metadata CHANGED
@@ -1,71 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uptrace
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.2
4
+ version: 1.0.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-03-28 00:00:00.000000000 Z
11
+ date: 2021-10-06 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.3'
19
+ version: 0.20.5
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.3'
26
+ version: 0.20.5
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: 0.16.0
33
+ version: 1.0.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.16.0
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.5.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.5.0
40
+ version: 1.0.0
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: bundler
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
- - - ">="
45
+ - - "~>"
60
46
  - !ruby/object:Gem::Version
61
- version: '1.17'
47
+ version: '2.2'
62
48
  type: :development
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
- - - ">="
52
+ - - "~>"
67
53
  - !ruby/object:Gem::Version
68
- version: '1.17'
54
+ version: '2.2'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: minitest
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -100,14 +86,14 @@ dependencies:
100
86
  requirements:
101
87
  - - "~>"
102
88
  - !ruby/object:Gem::Version
103
- version: 1.10.0
89
+ version: 1.12.0
104
90
  type: :development
105
91
  prerelease: false
106
92
  version_requirements: !ruby/object:Gem::Requirement
107
93
  requirements:
108
94
  - - "~>"
109
95
  - !ruby/object:Gem::Version
110
- version: 1.10.0
96
+ version: 1.12.0
111
97
  - !ruby/object:Gem::Dependency
112
98
  name: rubocop-minitest
113
99
  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
@@ -1,232 +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: as_unix_nano(span.start_timestamp),
87
- endTime: as_unix_nano(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] timestamp
172
- # @return [Integer]
173
- #
174
- def as_unix_nano(timestamp)
175
- (timestamp.to_r * 1_000_000_000).to_i
176
- end
177
-
178
- ##
179
- # @param [Integer] code
180
- # @return [String]
181
- #
182
- def status_code_as_str(code)
183
- case code
184
- when OpenTelemetry::Trace::Status::OK
185
- 'ok'
186
- when OpenTelemetry::Trace::Status::ERROR
187
- 'error'
188
- else
189
- 'unset'
190
- end
191
- end
192
-
193
- ##
194
- # @param [OpenTelemetry::SDK::Resources::Resource] resource
195
- # @return [Hash]
196
- #
197
- def uptrace_resource(resource)
198
- out = {}
199
- resource.attribute_enumerator.map { |key, value| out[key] = value }
200
- out
201
- end
202
-
203
- def uptrace_events(events)
204
- out = []
205
- events.each do |event|
206
- out.push(
207
- {
208
- name: event.name,
209
- attrs: event.attributes,
210
- time: as_unix_nano(event.timestamp)
211
- }
212
- )
213
- end
214
- out
215
- end
216
-
217
- def uptrace_links(links)
218
- out = []
219
- links.each do |link|
220
- out.push(
221
- {
222
- trace_id => link.span_context.trace_id,
223
- span_id => link.span_context.span_id.unpack1('Q'),
224
- attrs => link.attributes
225
- }
226
- )
227
- end
228
- out
229
- end
230
- end
231
- end
232
- 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'