opencensus 0.2.1 → 0.2.2
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/CHANGELOG.md +7 -0
- data/README.md +19 -5
- data/lib/opencensus/common/config.rb +1 -1
- data/lib/opencensus/trace/exporters.rb +20 -1
- data/lib/opencensus/trace/exporters/logger.rb +1 -1
- data/lib/opencensus/trace/exporters/multi.rb +56 -0
- data/lib/opencensus/trace/integrations/rails.rb +52 -1
- data/lib/opencensus/version.rb +1 -1
- data/opencensus.gemspec +1 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b61331cb69913aa2a85bed2353045cf10b97d99
|
4
|
+
data.tar.gz: 6fed28a666fa2741fd7de32a3608c0089b8f7b8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1afcf27bef5d796b2b08f31bebaccd78ed03ff93e463c24ecaae4a4ff98dd20cc6ccbf9c953cbbfe477018a2ae4091589fdca4584c78a17154961592d0a41e0f
|
7
|
+
data.tar.gz: 4daea1fabb7dff90fbccbb9e043489c6c9f9a5c16714058d9cb87783d025aa5a8adaef175aed3953127ae0a6c653078a8c9c95bd8439c5b9ce75b3d11d42fc07
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# Release History
|
2
2
|
|
3
|
+
### 0.2.2 / 2018-03-09
|
4
|
+
|
5
|
+
* Railtie now adds the middleware at the end of the stack by default, and provides a config that can customize the position
|
6
|
+
* Provided a multi exporter
|
7
|
+
* Document exporter interface
|
8
|
+
* Fix some broken links in the documentation
|
9
|
+
|
3
10
|
### 0.2.1 / 2018-03-05
|
4
11
|
|
5
12
|
* Clarify Ruby version requirement (2.2+)
|
data/README.md
CHANGED
@@ -48,6 +48,10 @@ To enable Rails integration, require this file during application startup:
|
|
48
48
|
require "opencensus/trace/integrations/rails"
|
49
49
|
```
|
50
50
|
|
51
|
+
See the documentation for the
|
52
|
+
[Rails integration class](http://www.rubydoc.info/gems/opencensus/OpenCensus/Trace/Integrations/Rails)
|
53
|
+
for more information.
|
54
|
+
|
51
55
|
### Getting started with other Rack-based frameworks
|
52
56
|
|
53
57
|
Other Rack-based frameworks, such as Sinatra, can use the Rack Middleware
|
@@ -81,7 +85,7 @@ conn.get "/"
|
|
81
85
|
```
|
82
86
|
|
83
87
|
See the documentation for the
|
84
|
-
[FaradayMiddleware](http://
|
88
|
+
[FaradayMiddleware](http://www.rubydoc.info/gems/opencensus/OpenCensus/Trace/Integrations/FaradayMiddleware)
|
85
89
|
class for more info.
|
86
90
|
|
87
91
|
### Adding Custom Trace Spans
|
@@ -101,15 +105,18 @@ end
|
|
101
105
|
```
|
102
106
|
|
103
107
|
See the documentation for the
|
104
|
-
[OpenCensus::Trace](http://
|
108
|
+
[OpenCensus::Trace](http://www.rubydoc.info/gems/opencensus/OpenCensus/Trace)
|
105
109
|
module for more info.
|
106
110
|
|
107
111
|
### Exporting traces
|
108
112
|
|
109
113
|
By default, OpenCensus will log request trace data as JSON. To export traces to
|
110
|
-
your favorite analytics backend, install an export plugin.
|
114
|
+
your favorite analytics backend, install an export plugin. Plugins are
|
111
115
|
currently being developed for Stackdriver, Zipkin, and other services.
|
112
116
|
|
117
|
+
You may also create your own
|
118
|
+
[Exporter](http://www.rubydoc.info/gems/opencensus/OpenCensus/Trace/Exporters)
|
119
|
+
|
113
120
|
### Configuring the library
|
114
121
|
|
115
122
|
OpenCensus allows configuration of a number of aspects via the configuration
|
@@ -142,9 +149,9 @@ Additionally, integrations and other plugins might have their own
|
|
142
149
|
configurations.
|
143
150
|
|
144
151
|
For more information, consult the documentation for
|
145
|
-
[OpenCensus.configure](http://
|
152
|
+
[OpenCensus.configure](http://www.rubydoc.info/gems/opencensus/OpenCensus#configure-class_method)
|
146
153
|
and
|
147
|
-
[OpenCensus::Trace.configure](http://
|
154
|
+
[OpenCensus::Trace.configure](http://www.rubydoc.info/gems/opencensus/OpenCensus/Trace#configure-class_method).
|
148
155
|
|
149
156
|
## About the library
|
150
157
|
|
@@ -152,6 +159,13 @@ and
|
|
152
159
|
|
153
160
|
This library is supported on Ruby 2.2+.
|
154
161
|
|
162
|
+
However, Ruby 2.3 or later is strongly recommended, as earlier releases have
|
163
|
+
reached or are nearing end-of-life. After June 1, 2018, OpenCensus will provide
|
164
|
+
official support only for Ruby versions that are considered current and
|
165
|
+
supported by Ruby Core (that is, Ruby versions that are either in normal
|
166
|
+
maintenance or in security maintenance).
|
167
|
+
See https://www.ruby-lang.org/en/downloads/branches/ for further details.
|
168
|
+
|
155
169
|
### Versioning
|
156
170
|
|
157
171
|
This library follows [Semantic Versioning](http://semver.org/).
|
@@ -13,12 +13,31 @@
|
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
15
|
require "opencensus/trace/exporters/logger"
|
16
|
+
require "opencensus/trace/exporters/multi"
|
16
17
|
|
17
18
|
module OpenCensus
|
18
19
|
module Trace
|
19
20
|
##
|
20
21
|
# The Exporters module provides integrations for exporting collected trace
|
21
|
-
# spans to an external or local service.
|
22
|
+
# spans to an external or local service. Exporter classes may be put inside
|
23
|
+
# this module, but are not required to be located here.
|
24
|
+
#
|
25
|
+
# An exporter is an object that must respond to the following method:
|
26
|
+
#
|
27
|
+
# def export(spans)
|
28
|
+
#
|
29
|
+
# Where `spans` is an array of {OpenCensus::Trace::Span} objects to export.
|
30
|
+
# The method _must_ tolerate any number of spans in the `spans` array,
|
31
|
+
# including an empty array.
|
32
|
+
#
|
33
|
+
# The method return value is not defined.
|
34
|
+
#
|
35
|
+
# The exporter object may interpret the `export` message in whatever way it
|
36
|
+
# deems appropriate. For example, it may write the data to a log file, it
|
37
|
+
# may transmit it to a monitoring service, or it may do nothing at all.
|
38
|
+
# An exporter may also queue the request for later asynchronous processing,
|
39
|
+
# and indeed this is recommended if the export involves time consuming
|
40
|
+
# operations such as remote API calls.
|
22
41
|
#
|
23
42
|
module Exporters
|
24
43
|
end
|
@@ -40,10 +40,10 @@ module OpenCensus
|
|
40
40
|
# Export the captured spans to the configured logger.
|
41
41
|
#
|
42
42
|
# @param [Array<Span>] spans The captured spans.
|
43
|
-
# @return [Boolean]
|
44
43
|
#
|
45
44
|
def export spans
|
46
45
|
@logger.log @level, spans.map { |span| format_span(span) }.to_json
|
46
|
+
nil
|
47
47
|
end
|
48
48
|
|
49
49
|
private
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# Copyright 2018 OpenCensus Authors
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require "delegate"
|
16
|
+
|
17
|
+
module OpenCensus
|
18
|
+
module Trace
|
19
|
+
module Exporters
|
20
|
+
##
|
21
|
+
# The Multi exporter multiplexes captured spans to a set of delegate
|
22
|
+
# exporters. It is useful if you need to export to more than one
|
23
|
+
# destination. You may also use it as a "null" exporter by providing
|
24
|
+
# no delegates.
|
25
|
+
#
|
26
|
+
# Multi delegates to an array of the exporter objects. You can manage
|
27
|
+
# the list of exporters using any method of Array. For example:
|
28
|
+
#
|
29
|
+
# multi = OpenCensus::Trace::Exporters::Multi.new
|
30
|
+
# multi.export(spans) # Does nothing
|
31
|
+
# multi << OpenCensus::Trace::Exporters::Logger.new
|
32
|
+
# multi.export(spans) # Exports to the logger
|
33
|
+
#
|
34
|
+
class Multi < SimpleDelegator
|
35
|
+
##
|
36
|
+
# Create a new Multi exporter
|
37
|
+
#
|
38
|
+
# @param [Array<#export>] delegates An array of exporters
|
39
|
+
#
|
40
|
+
def initialize *delegates
|
41
|
+
super(delegates.flatten)
|
42
|
+
end
|
43
|
+
|
44
|
+
##
|
45
|
+
# Pass the captured spans to the delegates.
|
46
|
+
#
|
47
|
+
# @param [Array<Span>] spans The captured spans.
|
48
|
+
#
|
49
|
+
def export spans
|
50
|
+
each { |delegate| delegate.export spans }
|
51
|
+
nil
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -36,6 +36,8 @@ module OpenCensus
|
|
36
36
|
#
|
37
37
|
# config.opencensus.trace.default_max_attributes = 64
|
38
38
|
#
|
39
|
+
# ### Configuring ActiveSupport Notifications
|
40
|
+
#
|
39
41
|
# This Railtie also provides a `notifications` configuration that
|
40
42
|
# supports the following fields:
|
41
43
|
#
|
@@ -56,6 +58,37 @@ module OpenCensus
|
|
56
58
|
#
|
57
59
|
# config.opencensus.trace.notifications.attribute_namespace = "myapp/"
|
58
60
|
#
|
61
|
+
# ### Configuring Middleware Placement
|
62
|
+
#
|
63
|
+
# By default, the Railtie places the OpenCensus middleware at the end of
|
64
|
+
# the middleware stack. This means it will measure your application code
|
65
|
+
# but not the effect of other middleware, including middlware that is
|
66
|
+
# part of the Rails stack or any custom middleware you have installed.
|
67
|
+
# If you would rather place the middleware at the beginning of the stack
|
68
|
+
# where it surrounds all other middleware, set the this configuration:
|
69
|
+
#
|
70
|
+
# OpenCensus::Trace.config do |config|
|
71
|
+
# config.middleware_placement = :begin
|
72
|
+
# end
|
73
|
+
#
|
74
|
+
# Or, using Rails:
|
75
|
+
#
|
76
|
+
# config.opencensus.trace.middleware_placement = :begin
|
77
|
+
#
|
78
|
+
# This effectively causes the Railtie to use `unshift` rather than `use`
|
79
|
+
# to add the OpenCensus middleware to the middleware stack.
|
80
|
+
# You may also set this configuration to an existing middleware class to
|
81
|
+
# cause the OpenCensus middleware to be inserted before that middleware
|
82
|
+
# in the stack. For example:
|
83
|
+
#
|
84
|
+
# OpenCensus::Trace.config do |config|
|
85
|
+
# config.middleware_placement = ::Rails::Rack::Logger
|
86
|
+
# end
|
87
|
+
#
|
88
|
+
# Or, using Rails:
|
89
|
+
#
|
90
|
+
# config.opencensus.trace.middleware_placement = ::Rails::Rack::Logger
|
91
|
+
#
|
59
92
|
class Rails < ::Rails::Railtie
|
60
93
|
##
|
61
94
|
# The ActiveSupport notifications that will be reported as spans by
|
@@ -75,6 +108,8 @@ module OpenCensus
|
|
75
108
|
rc.add_option! :events, DEFAULT_NOTIFICATION_EVENTS.dup
|
76
109
|
rc.add_option! :attribute_namespace, "rails/"
|
77
110
|
end
|
111
|
+
c.add_option! :middleware_placement, :end,
|
112
|
+
match: [:begin, :end, Class]
|
78
113
|
end
|
79
114
|
|
80
115
|
unless config.respond_to? :opencensus
|
@@ -82,10 +117,26 @@ module OpenCensus
|
|
82
117
|
end
|
83
118
|
|
84
119
|
initializer "opencensus.trace" do |app|
|
85
|
-
app.middleware
|
120
|
+
setup_middleware app.middleware
|
86
121
|
setup_notifications
|
87
122
|
end
|
88
123
|
|
124
|
+
##
|
125
|
+
# Insert middleware into the middleware stack
|
126
|
+
# @private
|
127
|
+
#
|
128
|
+
def setup_middleware middleware_stack
|
129
|
+
where = OpenCensus::Trace.configure.middleware_placement
|
130
|
+
case where
|
131
|
+
when Class
|
132
|
+
middleware_stack.insert_before where, RackMiddleware
|
133
|
+
when :begin
|
134
|
+
middleware_stack.unshift RackMiddleware
|
135
|
+
else
|
136
|
+
middleware_stack.use RackMiddleware
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
89
140
|
##
|
90
141
|
# Initialize notifications
|
91
142
|
# @private
|
data/lib/opencensus/version.rb
CHANGED
data/opencensus.gemspec
CHANGED
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_development_dependency "bundler", "~> 1.16"
|
27
27
|
spec.add_development_dependency "rake", "~> 12.0"
|
28
28
|
spec.add_development_dependency "minitest", "~> 5.0"
|
29
|
+
spec.add_development_dependency "minitest-focus", "~> 1.1"
|
29
30
|
spec.add_development_dependency "faraday", "~> 0.13"
|
30
31
|
spec.add_development_dependency "rails", "~> 5.1.4"
|
31
32
|
spec.add_development_dependency "rubocop", "~> 0.52"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opencensus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Ching
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-03-
|
12
|
+
date: 2018-03-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -53,6 +53,20 @@ dependencies:
|
|
53
53
|
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '5.0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: minitest-focus
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '1.1'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '1.1'
|
56
70
|
- !ruby/object:Gem::Dependency
|
57
71
|
name: faraday
|
58
72
|
requirement: !ruby/object:Gem::Requirement
|
@@ -162,6 +176,7 @@ files:
|
|
162
176
|
- lib/opencensus/trace/config.rb
|
163
177
|
- lib/opencensus/trace/exporters.rb
|
164
178
|
- lib/opencensus/trace/exporters/logger.rb
|
179
|
+
- lib/opencensus/trace/exporters/multi.rb
|
165
180
|
- lib/opencensus/trace/formatters.rb
|
166
181
|
- lib/opencensus/trace/formatters/binary.rb
|
167
182
|
- lib/opencensus/trace/formatters/cloud_trace.rb
|