uptrace 0.17.0 → 1.0.1

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: 3b0f7710f0eae6b7bcd64b9ba4cb6f8e8ea0d038288dc01f173381a1937639c9
4
- data.tar.gz: 160bd219eb212e7e97561b758b1d76cf3a38672aa02e292c218c9694b8f27544
3
+ metadata.gz: c320ccec5439c9c74f4127443eb875ad2426bdb3efb3e83ef246ac8f1a69d4e3
4
+ data.tar.gz: 88449bc895c39171505069b5d10574b807ebdcc3badc95a77792609ef7f63b90
5
5
  SHA512:
6
- metadata.gz: e67923bceb81e39049b4dadf8d0a0740b114300d6c979fb9f720dd3a599adf83c0fb0adfe5b0fece036225863ab27ea05e738df2d547c82d2bff25b3e0c1a6fe
7
- data.tar.gz: 39886118653a1e0f61d6d880c1adda437c337dcff2819f7ffd2d012561dccda10340565aece6b600f7bdcb741881413d925f65ed95cd9463d0502077cb11dfa2
6
+ metadata.gz: aed13462dbcefbceae6a239cc4cf206c46d69740f70a752c0317aac40c4b073d2ae965b413868af63f4520276bbdff39c46ee70cc9f22233d3699d9478c8435b
7
+ data.tar.gz: e8f8e3fd095d9fee1bea930870ca5b330f848510005504c31a5f3c9f610c2eb2897d451ce40a81392b9e50c7c62d66fa767664c290c37caff3dd64d43e82b832
data/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # Changelog
2
2
 
3
+ ## v1.0.1 - 2021-11-08
4
+
5
+ - Updated OpenTelemetry to
6
+ [v1.0.1](https://github.com/open-telemetry/opentelemetry-ruby/blob/main/sdk/CHANGELOG.md#v101--2021-10-29).
7
+
8
+ ## v1.0.0 - 2021-10-06
9
+
10
+ - Updated OpenTelemetry to
11
+ [v1.0.0](https://github.com/open-telemetry/opentelemetry-ruby/blob/main/api/CHANGELOG.md#v100--2021-09-29).
12
+
13
+ ## v1.0.0.rc3 - 2021-08-17
14
+
15
+ - Updated OpenTelemetry to
16
+ [v1.0.0.rc3](https://github.com/open-telemetry/opentelemetry-ruby/blob/main/api/CHANGELOG.md#v100rc3--2021-08-12).
17
+ - Switched to using OTLP protocol.
18
+
19
+ ## v1.0.0.rc1 - 2021-05-22
20
+
21
+ - Updated OpenTelemetry to
22
+ [v1.0.0.rc1](https://github.com/open-telemetry/opentelemetry-ruby/blob/main/api/CHANGELOG.md#v100rc1--2021-05-21).
23
+
3
24
  ## v0.17.0 - 2021-04-24
4
25
 
5
26
  - Updated OpenTelemetry to
data/README.md CHANGED
@@ -1,16 +1,16 @@
1
1
  # Uptrace Ruby exporter for OpenTelemetry
2
2
 
3
3
  ![build workflow](https://github.com/uptrace/uptrace-ruby/actions/workflows/build.yml/badge.svg)
4
- [![Documentation](https://img.shields.io/badge/uptrace-documentation-informational)](https://docs.uptrace.dev/ruby/)
4
+ [![Documentation](https://img.shields.io/badge/uptrace-documentation-informational)](https://docs.uptrace.dev/guide/ruby.html)
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
11
11
 
12
12
  uptrace-ruby is an OpenTelemery distribution configured to export
13
- [traces](https://docs.uptrace.dev/tracing/#spans) to Uptrace.
13
+ [traces](https://opentelemetry.uptrace.dev/guide/distributed-tracing.html) to Uptrace.
14
14
 
15
15
  ## Quickstart
16
16
 
@@ -30,33 +30,38 @@ 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
+ ## Links
64
+
65
+ - [Examples](example)
66
+ - [Documentation](https://docs.uptrace.dev/guide/ruby.html)
67
+ - [Instrumentations](https://opentelemetry.uptrace.dev/instrumentations.html?lang=ruby)
@@ -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?
@@ -22,26 +24,5 @@ module Uptrace
22
24
  def disabled?
23
25
  @disabled
24
26
  end
25
-
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.')
32
- trace_id = span.context.hex_trace_id
33
- "#{@dsn.scheme}://#{host}/search/#{@dsn.project_id}?q=#{trace_id}"
34
- 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
27
  end
47
28
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uptrace
4
- VERSION = '0.17.0'
4
+ VERSION = '1.0.1'
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
@@ -19,7 +21,9 @@ module Uptrace
19
21
  # @param [optional OpenTelemetry::Trace::Span] span
20
22
  # @return [String]
21
23
  def trace_url(span = nil)
22
- client.trace_url(span)
24
+ span = OpenTelemetry::Trace.current_span if span.nil?
25
+ trace_id = span.context.hex_trace_id
26
+ "https://app.uptrace.dev/traces/#{trace_id}"
23
27
  end
24
28
 
25
29
  # ConfigureOpentelemetry configures OpenTelemetry to export data to Uptrace.
@@ -31,14 +35,30 @@ module Uptrace
31
35
  def configure_opentelemetry(dsn: '')
32
36
  OpenTelemetry::SDK.configure do |c|
33
37
  @client = Client.new(dsn: dsn) unless dsn.empty?
34
- c.add_span_processor(client.span_processor) unless client.disabled?
38
+ c.add_span_processor(span_processor(@client.dsn.to_s)) unless client.disabled?
35
39
 
36
40
  yield c if block_given?
37
41
  end
38
42
  end
43
+
44
+ private
45
+
46
+ def span_processor(dsn)
47
+ exporter = OpenTelemetry::Exporter::OTLP::Exporter.new(
48
+ endpoint: 'https://otlp.uptrace.dev/v1/traces',
49
+ # Set the Uptrace DSN here or use UPTRACE_DSN env var.
50
+ headers: { 'uptrace-dsn': dsn },
51
+ compression: 'gzip'
52
+ )
53
+ OpenTelemetry::SDK::Trace::Export::BatchSpanProcessor.new(
54
+ exporter,
55
+ max_queue_size: 1000,
56
+ max_export_batch_size: 1000,
57
+ schedule_delay: 5_000
58
+ )
59
+ end
39
60
  end
40
61
 
41
62
  require 'uptrace/version'
42
63
  require 'uptrace/dsn'
43
64
  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.17.0
4
+ version: 1.0.1
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-04-24 00:00:00.000000000 Z
11
+ date: 2021-11-08 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.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.4.2
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.17.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.17.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.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
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
@@ -86,56 +72,56 @@ dependencies:
86
72
  requirements:
87
73
  - - "~>"
88
74
  - !ruby/object:Gem::Version
89
- version: '12.0'
75
+ version: '13.0'
90
76
  type: :development
91
77
  prerelease: false
92
78
  version_requirements: !ruby/object:Gem::Requirement
93
79
  requirements:
94
80
  - - "~>"
95
81
  - !ruby/object:Gem::Version
96
- version: '12.0'
82
+ version: '13.0'
97
83
  - !ruby/object:Gem::Dependency
98
84
  name: rubocop
99
85
  requirement: !ruby/object:Gem::Requirement
100
86
  requirements:
101
87
  - - "~>"
102
88
  - !ruby/object:Gem::Version
103
- version: 1.10.0
89
+ version: 1.22.3
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.22.3
111
97
  - !ruby/object:Gem::Dependency
112
98
  name: rubocop-minitest
113
99
  requirement: !ruby/object:Gem::Requirement
114
100
  requirements:
115
101
  - - "~>"
116
102
  - !ruby/object:Gem::Version
117
- version: 0.10.2
103
+ version: 0.15.2
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
107
  requirements:
122
108
  - - "~>"
123
109
  - !ruby/object:Gem::Version
124
- version: 0.10.2
110
+ version: 0.15.2
125
111
  - !ruby/object:Gem::Dependency
126
112
  name: rubocop-rake
127
113
  requirement: !ruby/object:Gem::Requirement
128
114
  requirements:
129
115
  - - "~>"
130
116
  - !ruby/object:Gem::Version
131
- version: 0.5.1
117
+ version: 0.6.0
132
118
  type: :development
133
119
  prerelease: false
134
120
  version_requirements: !ruby/object:Gem::Requirement
135
121
  requirements:
136
122
  - - "~>"
137
123
  - !ruby/object:Gem::Version
138
- version: 0.5.1
124
+ version: 0.6.0
139
125
  - !ruby/object:Gem::Dependency
140
126
  name: yard
141
127
  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'