uptrace 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +8 -0
- data/LICENSE +24 -0
- data/README.md +89 -0
- data/lib/uptrace.rb +15 -0
- data/lib/uptrace/metric.rb +7 -0
- data/lib/uptrace/trace.rb +10 -0
- data/lib/uptrace/trace/config.rb +12 -0
- data/lib/uptrace/trace/exporter.rb +123 -0
- data/lib/uptrace/version.rb +5 -0
- metadata +164 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6fed520ea5aa64b60260f976f155c618852f95c36e0eacfca80dd3b0654cf00f
|
4
|
+
data.tar.gz: b93d8bb971d72e571b9f87c098779c0aede9157d698ea522ea360801d9f133e3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d6f4ae143df5432535606e745907a7dd8ac9e22d9ac08280826b457ad6fd15d9c16fc368baab5616ec655fa0d9a9596edb7dfd0c7802563fe70e1b4cad2aa70d
|
7
|
+
data.tar.gz: 29156234fe786b7ceefa118511153fea5afbc2e4fe7890cdc32eac0cb6d6274a40e6630a3c4fee95aa94203c876438434c17e87f8a443260f480c2b6d437b85a
|
data/.yardopts
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
Copyright (c) 2020 github.com/uptrace/uptrace-ruby Authors. All rights reserved.
|
2
|
+
|
3
|
+
Redistribution and use in source and binary forms, with or without
|
4
|
+
modification, are permitted provided that the following conditions are
|
5
|
+
met:
|
6
|
+
|
7
|
+
* Redistributions of source code must retain the above copyright
|
8
|
+
notice, this list of conditions and the following disclaimer.
|
9
|
+
* Redistributions in binary form must reproduce the above
|
10
|
+
copyright notice, this list of conditions and the following disclaimer
|
11
|
+
in the documentation and/or other materials provided with the
|
12
|
+
distribution.
|
13
|
+
|
14
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
15
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
16
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
17
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
18
|
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
19
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
20
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
21
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
22
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
23
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
24
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
# Uptrace Ruby exporter for OpenTelemetry
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/uptrace/uptrace-ruby.svg?branch=master)](https://travis-ci.org/uptrace/uptrace-ruby)
|
4
|
+
|
5
|
+
## Introduction
|
6
|
+
|
7
|
+
uptrace-ruby is an exporter for [OpenTelemetry](https://opentelemetry.io/) that
|
8
|
+
sends your traces/spans and metrics to [Uptrace.dev](https://uptrace.dev).
|
9
|
+
Briefly the process is the following:
|
10
|
+
|
11
|
+
- OpenTelemetry API is used to instrument your application with spans and
|
12
|
+
metrics.
|
13
|
+
- OpenTelemetry SDK and this exporter send collected information to Uptrace.dev.
|
14
|
+
- Uptrace.dev uses that information to help you pinpoint failures and find
|
15
|
+
performance bottlenecks.
|
16
|
+
|
17
|
+
## Instrumenting code
|
18
|
+
|
19
|
+
You instrument your application by wrapping potentially interesting operations
|
20
|
+
with spans. Each span has:
|
21
|
+
|
22
|
+
- an operation name;
|
23
|
+
- a start time and end time;
|
24
|
+
- a set of key/value attributes containing data about the operation;
|
25
|
+
- a set of timed events representing events, errors, logs, etc.
|
26
|
+
|
27
|
+
You create spans using a tracer:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
require 'opentelemetry'
|
31
|
+
|
32
|
+
// Create a named tracer using your repo as an identifier.
|
33
|
+
tracer = OpenTelemetry.tracer_provider.tracer('github.com/username/app-name', 'semver:1.0')
|
34
|
+
```
|
35
|
+
|
36
|
+
To create a span:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
tracer.in_span('operation-name') do |span|
|
40
|
+
do_some_work
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
Internally that does roughly the following:
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
// Create a span.
|
48
|
+
span = tracer.start_span('operation-name')
|
49
|
+
|
50
|
+
// Activate the span within the current context.
|
51
|
+
tracer.with_span(span) do |span|
|
52
|
+
do_some_work
|
53
|
+
end
|
54
|
+
|
55
|
+
// Finish the span when operation is completed.
|
56
|
+
span.finish
|
57
|
+
```
|
58
|
+
|
59
|
+
To get the active span from the context:
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
span = tracer.current_span
|
63
|
+
```
|
64
|
+
|
65
|
+
Once you have a span you can start adding attributes:
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
span.set_attribute('enduser.id', '123')
|
69
|
+
span.set_attribute('enduser.role', 'admin')
|
70
|
+
```
|
71
|
+
|
72
|
+
or events:
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
span.add_event(name: 'log', attributes: {
|
76
|
+
'log.severity': 'error',
|
77
|
+
'log.message': 'User not found',
|
78
|
+
'enduser.id': '123',
|
79
|
+
})
|
80
|
+
```
|
81
|
+
|
82
|
+
To record an error use `record_error` which internally uses `add_event`. Note
|
83
|
+
that `tracer.in_span` already records resqued exceptions.
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
rescue Exception => e
|
87
|
+
span.record_error(e)
|
88
|
+
end
|
89
|
+
```
|
data/lib/uptrace.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
# Uptrace provides Uptrace exporters for OpenTelemetry.
|
6
|
+
module Uptrace
|
7
|
+
extend self
|
8
|
+
|
9
|
+
attr_accessor :logger
|
10
|
+
|
11
|
+
self.logger = Logger.new(STDOUT)
|
12
|
+
end
|
13
|
+
|
14
|
+
require 'uptrace/version'
|
15
|
+
require 'uptrace/trace'
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Uptrace
|
4
|
+
module Trace
|
5
|
+
# Config is a configuration for Uptrace span exporter.
|
6
|
+
class Config
|
7
|
+
# @return [String] a data source name to connect to uptrace.dev.
|
8
|
+
# @api public
|
9
|
+
attr_accessor :dsn
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
require 'msgpack'
|
6
|
+
require 'lz4-ruby'
|
7
|
+
|
8
|
+
module Uptrace
|
9
|
+
module Trace
|
10
|
+
# @!visibility private
|
11
|
+
ExpoSpan = Struct.new(
|
12
|
+
:id,
|
13
|
+
:parentId,
|
14
|
+
:name,
|
15
|
+
:kind,
|
16
|
+
:startTime,
|
17
|
+
:endTime,
|
18
|
+
:statusCode,
|
19
|
+
:statusMessage,
|
20
|
+
:attrs,
|
21
|
+
:events,
|
22
|
+
:links,
|
23
|
+
:resource
|
24
|
+
)
|
25
|
+
|
26
|
+
# Exporter is a span exporter for OpenTelemetry.
|
27
|
+
class Exporter
|
28
|
+
##
|
29
|
+
# @param [Config] cfg
|
30
|
+
#
|
31
|
+
def initialize(cfg)
|
32
|
+
@cfg = cfg
|
33
|
+
|
34
|
+
begin
|
35
|
+
@uri = URI.parse(cfg.dsn)
|
36
|
+
rescue URI::InvalidURIError => e
|
37
|
+
@disabled = true
|
38
|
+
Uptrace.logger.error("can't parse dsn=#{cfg.dsn}: #{e}")
|
39
|
+
else
|
40
|
+
@endpoint = "#{@uri.scheme}://#{@uri.host}/api/v1/tracing#{@uri.path}/spans"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def export(spans)
|
45
|
+
return if @disabled
|
46
|
+
|
47
|
+
traces = {}
|
48
|
+
|
49
|
+
spans.each do |span|
|
50
|
+
trace = traces[span.trace_id]
|
51
|
+
|
52
|
+
if trace.nil?
|
53
|
+
trace = []
|
54
|
+
traces[span.trace_id] = trace
|
55
|
+
end
|
56
|
+
|
57
|
+
expose = expo_span(span)
|
58
|
+
trace.push(expose)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def send(traces)
|
65
|
+
req = build_request(traces: traces)
|
66
|
+
connection.request(req)
|
67
|
+
end
|
68
|
+
|
69
|
+
##
|
70
|
+
# @return [ExpoSpan]
|
71
|
+
#
|
72
|
+
def expo_span(span)
|
73
|
+
expose = ExpoSpan.new
|
74
|
+
|
75
|
+
expose.id = span.id
|
76
|
+
expose.parentId = span.parent_span_id
|
77
|
+
|
78
|
+
expose.name = span.name
|
79
|
+
expose.kind = span.kind
|
80
|
+
expose.startTime = span.start_timestamp.to_i
|
81
|
+
expose.endTime = span.end_timestamp.to_i
|
82
|
+
expose.statusCode = span.status.canonical_code
|
83
|
+
expose.statusMessage = span.status.description
|
84
|
+
expose.attrs = span.attributes
|
85
|
+
|
86
|
+
expose
|
87
|
+
end
|
88
|
+
|
89
|
+
##
|
90
|
+
# @return [Net::HTTP]
|
91
|
+
#
|
92
|
+
def connection
|
93
|
+
unless @conn
|
94
|
+
@conn = Net::HTTP.new(@uri.host, @uri.port)
|
95
|
+
@conn.use_ssl = @uri.is_a?(URI::HTTPS)
|
96
|
+
@conn.open_timeout = 5
|
97
|
+
@conn.read_timeout = 5
|
98
|
+
@conn.keep_alive_timeout = 30
|
99
|
+
end
|
100
|
+
|
101
|
+
@conn
|
102
|
+
end
|
103
|
+
|
104
|
+
##
|
105
|
+
# @param [Hash] data
|
106
|
+
# @return [Net::HTTP::Post]
|
107
|
+
#
|
108
|
+
def build_request(data)
|
109
|
+
data = data.to_msgpack
|
110
|
+
data = LZ4.compress data
|
111
|
+
|
112
|
+
req = Net::HTTP::Post.new(@endpoint)
|
113
|
+
req['Authorization'] = @uri.user
|
114
|
+
req['Content-Type'] = 'application/msgpack'
|
115
|
+
req['Content-Encoding'] = 'lz4'
|
116
|
+
req['Connection'] = 'keep-alive'
|
117
|
+
req.body = data
|
118
|
+
|
119
|
+
req
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
metadata
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: uptrace
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Uptrace Authors
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-06-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: lz4-ruby
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.3.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.3.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: msgpack
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.17'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.17'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '12.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '12.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.73.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.73.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: yard
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.9'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.9'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: yard-doctest
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.1.6
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.1.6
|
125
|
+
description: Uptrace Ruby exporter for OpenTelemetry
|
126
|
+
email:
|
127
|
+
- support@uptrace.dev
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".yardopts"
|
133
|
+
- LICENSE
|
134
|
+
- README.md
|
135
|
+
- lib/uptrace.rb
|
136
|
+
- lib/uptrace/metric.rb
|
137
|
+
- lib/uptrace/trace.rb
|
138
|
+
- lib/uptrace/trace/config.rb
|
139
|
+
- lib/uptrace/trace/exporter.rb
|
140
|
+
- lib/uptrace/version.rb
|
141
|
+
homepage: https://github.com/uptrace/uptrace-ruby
|
142
|
+
licenses:
|
143
|
+
- BSD-2-Clause
|
144
|
+
metadata: {}
|
145
|
+
post_install_message:
|
146
|
+
rdoc_options: []
|
147
|
+
require_paths:
|
148
|
+
- lib
|
149
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: 2.5.0
|
154
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
159
|
+
requirements: []
|
160
|
+
rubygems_version: 3.1.2
|
161
|
+
signing_key:
|
162
|
+
specification_version: 4
|
163
|
+
summary: Uptrace Ruby exporter for OpenTelemetry
|
164
|
+
test_files: []
|