bc-lightstep-ruby 1.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +52 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/README.md +90 -0
- data/bc-lightstep-ruby.gemspec +40 -0
- data/lib/bigcommerce/lightstep.rb +93 -0
- data/lib/bigcommerce/lightstep/configuration.rb +111 -0
- data/lib/bigcommerce/lightstep/errors.rb +23 -0
- data/lib/bigcommerce/lightstep/middleware/faraday.rb +111 -0
- data/lib/bigcommerce/lightstep/rails_controller_instrumentation.rb +65 -0
- data/lib/bigcommerce/lightstep/tracer.rb +127 -0
- data/lib/bigcommerce/lightstep/transport.rb +123 -0
- data/lib/bigcommerce/lightstep/transport_factory.rb +38 -0
- data/lib/bigcommerce/lightstep/version.rb +20 -0
- metadata +141 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ae2b58de5cad4cb1d3f95f0392e8e5a2f26bc92d7166f0786973d1db2365c34c
|
4
|
+
data.tar.gz: fb76f4e5520ae29ba6c9cf51765ea4ef29b953478edece1d0d613bd38969b7a1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ce9814bbece997fe409cf3bf369a7c4ee086b14c486e9d16eeae7bd10ffe9a9a69b2d60c591dd111587dbfa5d485da82091211b72d829b27fb2ee22e2c21ff41
|
7
|
+
data.tar.gz: 6112a5d04acc35a38109cc5541fd88d2571e7ba699ec64a1bde19007bf442ed2c482619de4b65b8ae035a94eb4d5c9554c5dc10c9065891833b6744543074932
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
Changelog for the bc-lightstep-ruby gem.
|
2
|
+
|
3
|
+
h3. Pending Release
|
4
|
+
|
5
|
+
h3. 1.1.6
|
6
|
+
|
7
|
+
- First OSS release
|
8
|
+
|
9
|
+
h3. 1.1.5
|
10
|
+
|
11
|
+
- Pin lightstep gem to 0.11.x due to backwards-incompatible change in 0.12.x
|
12
|
+
|
13
|
+
h3. 1.1.4
|
14
|
+
|
15
|
+
- Add enabled setting to explicitly disable lightstep at runtime. Can be toggled with LIGHTSTEP_ENABLED ENV var.
|
16
|
+
|
17
|
+
h3. 1.1.3
|
18
|
+
|
19
|
+
- Have http1 errors only flag as error if they are 500+ status codes
|
20
|
+
|
21
|
+
h3. 1.1.2
|
22
|
+
|
23
|
+
- Prevent span from starting if the reporter is not yet configured, as LightStep gem does not guard this case
|
24
|
+
|
25
|
+
h3. 1.1.1
|
26
|
+
|
27
|
+
- Fix issues where Rack/Rails is prepending HTTP_ to headers, ensure right key format into carrier
|
28
|
+
|
29
|
+
h3. 1.1.0
|
30
|
+
|
31
|
+
- Add Faraday middleware for automatic tracing of outbound service calls
|
32
|
+
|
33
|
+
h3. 1.0.5
|
34
|
+
|
35
|
+
- Do not send GET params in rails controller instrumentation for http.url tag
|
36
|
+
|
37
|
+
h3. 1.0.4
|
38
|
+
|
39
|
+
- Rename span tags to fit the BigCommerce standardized tags
|
40
|
+
- Handle 500 errors in H1 requests properly
|
41
|
+
|
42
|
+
h3. 1.0.3
|
43
|
+
|
44
|
+
- Fix bug where active parent span was persisting between requests in rails controller requests
|
45
|
+
|
46
|
+
h3. 1.0.2
|
47
|
+
|
48
|
+
- Add Bigcommerce::Lightstep::Rails::ControllerInstrumentation module for tracing H1 controllers in Rails
|
49
|
+
|
50
|
+
h3. 1.0.0
|
51
|
+
|
52
|
+
- Initial public release
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at splittingred@gmail.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/README.md
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
# bc-lightstep-ruby - LightStep distributed tracing
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.com/bigcommerce/bc-lightstep-ruby.svg?token=D3Cc4LCF9BgpUx4dpPpv&branch=master)](https://travis-ci.com/bigcommerce/bc-lightstep-ruby)
|
4
|
+
|
5
|
+
Adds [LightStep](https://lightstep.com) tracing support for Ruby. This is an extension of the
|
6
|
+
[LightStep ruby gem](https://github.com/lightstep/lightstep-tracer-ruby) and adds extra functionality and resiliency.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'bc-lightstep-ruby', git: 'git@github.com/bigcommerce/bc-lightstep-ruby'
|
12
|
+
```
|
13
|
+
|
14
|
+
Then in an initializer or before use:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
require 'bigcommerce/lightstep'
|
18
|
+
Bigcommerce::Lightstep.configure do |c|
|
19
|
+
c.component_name = 'myapp'
|
20
|
+
c.access_token = 'abcdefg'
|
21
|
+
c.host = 'my.lightstep.service.io'
|
22
|
+
c.port = 8080
|
23
|
+
c.verbosity = 1
|
24
|
+
end
|
25
|
+
```
|
26
|
+
|
27
|
+
Then in your script:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
tracer = Bigcommerce::Lightstep::Tracer.instance
|
31
|
+
tracer.start_span('my-span', context: request.headers) do |span|
|
32
|
+
span.set_tag('my-tag', 'value')
|
33
|
+
# do thing to measure
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
### Environment Config
|
38
|
+
|
39
|
+
bc-lightstep-ruby can be automatically configured from these ENV vars, if you'd rather use that instead:
|
40
|
+
|
41
|
+
| Name | Description |
|
42
|
+
| ---- | ----------- |
|
43
|
+
| LIGHTSTEP_ENABLED | Flag to determine whether to broadcast spans. Defaults to 1 (enabled) and 0 will disable.|
|
44
|
+
| LIGHTSTEP_COMPONENT_NAME | The component name to use |
|
45
|
+
| LIGHTSTEP_ACCESS_TOKEN | The access token to use to connect to the collector |
|
46
|
+
| LIGHTSTEP_HOST | Host of the collector. Defaults to `lightstep-collector.linkerd` |
|
47
|
+
| LIGHTSTEP_PORT | Port of the collector. Defaults to `4140` |
|
48
|
+
| LIGHTSTEP_SSL_VERIFY_PEER | If using 443 as the port, toggle SSL verification. Defaults to true. |
|
49
|
+
| LIGHTSTEP_VERBOSITY | The verbosity level of lightstep logs. Defaults to 1. |
|
50
|
+
|
51
|
+
Most BC systems will only need to customize the component name.
|
52
|
+
|
53
|
+
### Instrumenting Rails Controllers
|
54
|
+
|
55
|
+
Just drop this include into ApplicationController:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
include Bigcommerce::Lightstep::RailsControllerInstrumentation
|
59
|
+
```
|
60
|
+
|
61
|
+
### Faraday Middleware
|
62
|
+
|
63
|
+
To use the supplied faraday middleware, simply:
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
Faraday.new do |faraday|
|
67
|
+
faraday.use Bigcommerce::Lightstep::Middleware::Faraday, 'name-of-external-service'
|
68
|
+
end
|
69
|
+
```
|
70
|
+
|
71
|
+
Spans will be built with the external service name. It's generally _not_ a good idea to use the Faraday adapter
|
72
|
+
with internal services that are also instrumented with LightStep - use the Faraday adapter on external services
|
73
|
+
or systems outside of our instrumenting control.
|
74
|
+
|
75
|
+
## License
|
76
|
+
|
77
|
+
Copyright (c) 2018-present, BigCommerce Pty. Ltd. All rights reserved
|
78
|
+
|
79
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
80
|
+
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|
81
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
82
|
+
persons to whom the Software is furnished to do so, subject to the following conditions:
|
83
|
+
|
84
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
85
|
+
Software.
|
86
|
+
|
87
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
88
|
+
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
89
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
90
|
+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# Copyright (c) 2018-present, BigCommerce Pty. Ltd. All rights reserved
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
4
|
+
# documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|
5
|
+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
6
|
+
# persons to whom the Software is furnished to do so, subject to the following conditions:
|
7
|
+
#
|
8
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
9
|
+
# Software.
|
10
|
+
#
|
11
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
12
|
+
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
13
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
14
|
+
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
15
|
+
#
|
16
|
+
$:.push File.expand_path('../lib', __FILE__)
|
17
|
+
require 'bigcommerce/lightstep/version'
|
18
|
+
|
19
|
+
Gem::Specification.new do |spec|
|
20
|
+
spec.name = 'bc-lightstep-ruby'
|
21
|
+
spec.version = Bigcommerce::Lightstep::VERSION
|
22
|
+
spec.authors = ['Shaun McCormick']
|
23
|
+
spec.email = ['shaun.mccormick@bigcommerce.com']
|
24
|
+
|
25
|
+
spec.summary = %q{Gem for lightstep distributed tracing}
|
26
|
+
spec.description = spec.summary
|
27
|
+
spec.homepage = 'https://github.com/bigcommerce/bc-lightstep-ruby'
|
28
|
+
spec.license = 'MIT'
|
29
|
+
|
30
|
+
spec.files = Dir['README.md', 'CHANGELOG.md', 'CODE_OF_CONDUCT.md', 'lib/**/*', 'bc-lightstep-ruby.gemspec']
|
31
|
+
spec.require_paths = ['lib']
|
32
|
+
|
33
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
34
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
35
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
36
|
+
spec.add_development_dependency 'pry'
|
37
|
+
|
38
|
+
spec.add_runtime_dependency 'lightstep', '~> 0.11.2'
|
39
|
+
spec.add_runtime_dependency 'faraday', '~> 0.8'
|
40
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# Copyright (c) 2018-present, BigCommerce Pty. Ltd. All rights reserved
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
4
|
+
# documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|
5
|
+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
6
|
+
# persons to whom the Software is furnished to do so, subject to the following conditions:
|
7
|
+
#
|
8
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
9
|
+
# Software.
|
10
|
+
#
|
11
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
12
|
+
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
13
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
14
|
+
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
15
|
+
#
|
16
|
+
require 'lightstep'
|
17
|
+
require 'faraday'
|
18
|
+
require_relative 'lightstep/version'
|
19
|
+
require_relative 'lightstep/errors'
|
20
|
+
require_relative 'lightstep/configuration'
|
21
|
+
require_relative 'lightstep/tracer'
|
22
|
+
require_relative 'lightstep/transport_factory'
|
23
|
+
require_relative 'lightstep/transport'
|
24
|
+
require_relative 'lightstep/rails_controller_instrumentation'
|
25
|
+
require_relative 'lightstep/middleware/faraday'
|
26
|
+
|
27
|
+
##
|
28
|
+
# Main base module
|
29
|
+
module Bigcommerce
|
30
|
+
##
|
31
|
+
# Lightstep module
|
32
|
+
#
|
33
|
+
module Lightstep
|
34
|
+
extend Configuration
|
35
|
+
|
36
|
+
def self.start(component_name: nil, transport_factory: nil)
|
37
|
+
component_name ||= ::Bigcommerce::Lightstep.component_name
|
38
|
+
transport_factory ||= ::Bigcommerce::Lightstep::TransportFactory.new
|
39
|
+
::LightStep.logger = logger
|
40
|
+
::LightStep.configure(
|
41
|
+
component_name: component_name,
|
42
|
+
transport: transport_factory.build
|
43
|
+
)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# :nocov:
|
49
|
+
module LightStep
|
50
|
+
##
|
51
|
+
# Monkey patch of the LightStep library to make it not swallow reporting errors
|
52
|
+
#
|
53
|
+
class Reporter
|
54
|
+
def flush
|
55
|
+
reset_on_fork
|
56
|
+
|
57
|
+
return if @span_records.empty?
|
58
|
+
|
59
|
+
now = ::LightStep.micros(Time.now)
|
60
|
+
|
61
|
+
span_records = @span_records.slice!(0, @span_records.length)
|
62
|
+
dropped_spans = 0
|
63
|
+
@dropped_spans.update do |old|
|
64
|
+
dropped_spans = old
|
65
|
+
0
|
66
|
+
end
|
67
|
+
|
68
|
+
report_request = {
|
69
|
+
runtime: @runtime,
|
70
|
+
oldest_micros: @report_start_time,
|
71
|
+
youngest_micros: now,
|
72
|
+
span_records: span_records,
|
73
|
+
internal_metrics: {
|
74
|
+
counts: [
|
75
|
+
{ name: 'spans.dropped', int64_value: dropped_spans }
|
76
|
+
]
|
77
|
+
}
|
78
|
+
}
|
79
|
+
|
80
|
+
@report_start_time = now
|
81
|
+
|
82
|
+
begin
|
83
|
+
@transport.report(report_request)
|
84
|
+
rescue StandardError => e
|
85
|
+
Bigcommerce::Lightstep.logger.error "Failed to send request to collector: #{e.message}"
|
86
|
+
# an error occurs, add the previous dropped_spans and count of spans
|
87
|
+
# that would have been recorded
|
88
|
+
@dropped_spans.increment(dropped_spans + span_records.length)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
# :nocov:
|
@@ -0,0 +1,111 @@
|
|
1
|
+
# Copyright (c) 2018-present, BigCommerce Pty. Ltd. All rights reserved
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
4
|
+
# documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|
5
|
+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
6
|
+
# persons to whom the Software is furnished to do so, subject to the following conditions:
|
7
|
+
#
|
8
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
9
|
+
# Software.
|
10
|
+
#
|
11
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
12
|
+
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
13
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
14
|
+
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
15
|
+
#
|
16
|
+
|
17
|
+
module Bigcommerce
|
18
|
+
module Lightstep
|
19
|
+
##
|
20
|
+
# General configuration for lightstep integration
|
21
|
+
#
|
22
|
+
module Configuration
|
23
|
+
VALID_CONFIG_KEYS = {
|
24
|
+
component_name: '',
|
25
|
+
controller_trace_prefix: 'controllers.',
|
26
|
+
access_token: '',
|
27
|
+
host: 'lightstep-collector.linkerd',
|
28
|
+
port: 4140,
|
29
|
+
ssl_verify_peer: true,
|
30
|
+
open_timeout: 20,
|
31
|
+
read_timeout: 20,
|
32
|
+
continue_timeout: nil,
|
33
|
+
keep_alive_timeout: 2,
|
34
|
+
logger: nil,
|
35
|
+
verbosity: 1,
|
36
|
+
http1_error_code: 500,
|
37
|
+
http1_error_code_minimum: 500,
|
38
|
+
enabled: true
|
39
|
+
}.freeze
|
40
|
+
|
41
|
+
attr_accessor *VALID_CONFIG_KEYS.keys
|
42
|
+
|
43
|
+
##
|
44
|
+
# Whenever this is extended into a class, setup the defaults
|
45
|
+
#
|
46
|
+
def self.extended(base)
|
47
|
+
base.reset
|
48
|
+
end
|
49
|
+
|
50
|
+
##
|
51
|
+
# Yield self for ruby-style initialization
|
52
|
+
#
|
53
|
+
# @yields [Bigcommerce::Instrumentation::Configuration]
|
54
|
+
# @return [Bigcommerce::Instrumentation::Configuration]
|
55
|
+
#
|
56
|
+
def configure
|
57
|
+
reset unless @configured
|
58
|
+
yield self
|
59
|
+
@configured = true
|
60
|
+
end
|
61
|
+
|
62
|
+
##
|
63
|
+
# @return [Boolean]
|
64
|
+
#
|
65
|
+
def configured?
|
66
|
+
@configured
|
67
|
+
end
|
68
|
+
|
69
|
+
##
|
70
|
+
# Return the current configuration options as a Hash
|
71
|
+
#
|
72
|
+
# @return [Hash]
|
73
|
+
#
|
74
|
+
def options
|
75
|
+
opts = {}
|
76
|
+
VALID_CONFIG_KEYS.each_key do |k|
|
77
|
+
opts.merge!(k => send(k))
|
78
|
+
end
|
79
|
+
opts
|
80
|
+
end
|
81
|
+
|
82
|
+
##
|
83
|
+
# Set the default configuration onto the extended class
|
84
|
+
#
|
85
|
+
def reset
|
86
|
+
VALID_CONFIG_KEYS.each do |k, v|
|
87
|
+
send("#{k}=".to_sym, v)
|
88
|
+
end
|
89
|
+
self.component_name = ENV.fetch('LIGHTSTEP_COMPONENT_NAME', '')
|
90
|
+
self.access_token = ENV.fetch('LIGHTSTEP_ACCESS_TOKEN', '')
|
91
|
+
self.host = ENV.fetch('LIGHTSTEP_HOST', 'lightstep-collector.linkerd')
|
92
|
+
self.port = ENV.fetch('LIGHTSTEP_PORT', 4140).to_i
|
93
|
+
self.ssl_verify_peer = ENV.fetch('LIGHTSTEP_SSL_VERIFY_PEER', true)
|
94
|
+
self.verbosity = ENV.fetch('LIGHTSTEP_VERBOSITY', 1).to_i
|
95
|
+
self.logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
|
96
|
+
self.enabled = ENV.fetch('LIGHTSTEP_ENABLED', 1).to_i > 0
|
97
|
+
end
|
98
|
+
|
99
|
+
##
|
100
|
+
# Automatically determine environment
|
101
|
+
#
|
102
|
+
def environment
|
103
|
+
if defined?(Rails)
|
104
|
+
Rails.env
|
105
|
+
else
|
106
|
+
ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development'
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# Copyright (c) 2018-present, BigCommerce Pty. Ltd. All rights reserved
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
4
|
+
# documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|
5
|
+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
6
|
+
# persons to whom the Software is furnished to do so, subject to the following conditions:
|
7
|
+
#
|
8
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
9
|
+
# Software.
|
10
|
+
#
|
11
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
12
|
+
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
13
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
14
|
+
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
15
|
+
#
|
16
|
+
module Bigcommerce
|
17
|
+
module Lightstep
|
18
|
+
module Errors
|
19
|
+
class Error < StandardError; end
|
20
|
+
class InvalidAccessToken < Error; end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
# Copyright (c) 2018-present, BigCommerce Pty. Ltd. All rights reserved
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
4
|
+
# documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|
5
|
+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
6
|
+
# persons to whom the Software is furnished to do so, subject to the following conditions:
|
7
|
+
#
|
8
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
9
|
+
# Software.
|
10
|
+
#
|
11
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
12
|
+
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
13
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
14
|
+
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
15
|
+
#
|
16
|
+
module Bigcommerce
|
17
|
+
module Lightstep
|
18
|
+
module Middleware
|
19
|
+
# Faraday middleware. It will add appropriate OT tags and trace IDs to outgoing connections done by Faraday
|
20
|
+
class Faraday < ::Faraday::Middleware
|
21
|
+
HTTP_ERROR_STATUS_THRESHOLD = 400
|
22
|
+
HTTP_STATUS_REQUEST_TIMEOUT = 408
|
23
|
+
HTTP_STATUS_INTERNAL_ERROR = 500
|
24
|
+
HTTP_STATUS_SERVICE_UNAVAIL = 503
|
25
|
+
|
26
|
+
OT_TAG_TRACE_ID = 'ot-tracer-traceid'.freeze
|
27
|
+
OT_TAG_SPAN_ID = 'ot-tracer-spanid'.freeze
|
28
|
+
OT_TAG_SAMPLED = 'ot-tracer-sampled'.freeze
|
29
|
+
|
30
|
+
def initialize(app, service_name = nil)
|
31
|
+
@app = app
|
32
|
+
@service_name = (service_name || 'external').to_s
|
33
|
+
end
|
34
|
+
|
35
|
+
def call(request_env)
|
36
|
+
uri = uri_from_env(request_env)
|
37
|
+
tracer = ::Bigcommerce::Lightstep::Tracer.instance
|
38
|
+
|
39
|
+
tracer.start_span(service_key, context: request_env[:request_headers]) do |span|
|
40
|
+
span.set_tag('http.url', uri.to_s.split('?').first)
|
41
|
+
span.set_tag('http.method', request_env[:method].to_s.downcase)
|
42
|
+
span.set_tag('http.external-service', true)
|
43
|
+
|
44
|
+
inject_ot_tags!(request_env, span)
|
45
|
+
|
46
|
+
begin
|
47
|
+
response = @app.call(request_env).on_complete do |response_env|
|
48
|
+
span.set_tag('http.status_code', response_env[:status].to_s)
|
49
|
+
span.set_tag('error', true) if response_env[:status].to_i >= HTTP_ERROR_STATUS_THRESHOLD
|
50
|
+
response_env
|
51
|
+
end
|
52
|
+
rescue ::Net::ReadTimeout
|
53
|
+
span.set_tag('error', true)
|
54
|
+
span.set_tag('http.status_code', HTTP_STATUS_REQUEST_TIMEOUT)
|
55
|
+
raise
|
56
|
+
rescue ::Faraday::ConnectionFailed
|
57
|
+
span.set_tag('error', true)
|
58
|
+
span.set_tag('http.status_code', HTTP_STATUS_SERVICE_UNAVAIL)
|
59
|
+
raise
|
60
|
+
rescue ::Faraday::ClientError
|
61
|
+
span.set_tag('error', true)
|
62
|
+
span.set_tag('http.status_code', HTTP_STATUS_INTERNAL_ERROR)
|
63
|
+
raise
|
64
|
+
end
|
65
|
+
|
66
|
+
response
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
##
|
73
|
+
# @param [Hash] request_env
|
74
|
+
# @param [::LightStep::Span] span
|
75
|
+
#
|
76
|
+
def inject_ot_tags!(request_env, span)
|
77
|
+
request_env[:request_headers].merge!(
|
78
|
+
OT_TAG_TRACE_ID => span.span_context.trace_id.to_s,
|
79
|
+
OT_TAG_SPAN_ID => span.span_context.id.to_s,
|
80
|
+
OT_TAG_SAMPLED => 'true'
|
81
|
+
)
|
82
|
+
end
|
83
|
+
|
84
|
+
##
|
85
|
+
# Handle either a URI object (passed by Faraday v0.8.x in testing), or something string-izable
|
86
|
+
#
|
87
|
+
# @param [Hash] env
|
88
|
+
# @return [URI::HTTP]
|
89
|
+
#
|
90
|
+
def uri_from_env(env)
|
91
|
+
env[:url].respond_to?(:host) ? env[:url] : URI.parse(env[:url].to_s)
|
92
|
+
end
|
93
|
+
|
94
|
+
##
|
95
|
+
# @param [URI::HTTP] uri
|
96
|
+
# @return [String]
|
97
|
+
#
|
98
|
+
def path_key_for_uri(uri)
|
99
|
+
uri.path.tr('/', '_').reverse.chomp('_').reverse.chomp
|
100
|
+
end
|
101
|
+
|
102
|
+
##
|
103
|
+
# @return [String]
|
104
|
+
#
|
105
|
+
def service_key
|
106
|
+
@service_name.to_s.downcase.tr('-', '_').tr('.', '_')
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Bigcommerce
|
2
|
+
module Lightstep
|
3
|
+
##
|
4
|
+
# Helper module that can be included into Rails controllers to automatically instrument them with LightStep
|
5
|
+
#
|
6
|
+
module RailsControllerInstrumentation
|
7
|
+
OPEN_TRACING_HEADER_KEYS = %w[ot-tracer-traceid ot-tracer-spanid ot-tracer-sampled].freeze
|
8
|
+
|
9
|
+
def self.included(base)
|
10
|
+
base.send(:around_action, :lightstep_trace)
|
11
|
+
end
|
12
|
+
|
13
|
+
protected
|
14
|
+
|
15
|
+
##
|
16
|
+
# Trace the controller method
|
17
|
+
#
|
18
|
+
def lightstep_trace
|
19
|
+
prefix = ::Bigcommerce::Lightstep.controller_trace_prefix
|
20
|
+
key = "#{prefix}#{controller_name}.#{action_name}"
|
21
|
+
headers = lightstep_filtered_headers
|
22
|
+
tracer = ::Bigcommerce::Lightstep::Tracer.instance
|
23
|
+
result = tracer.start_span(key, context: headers) do |span|
|
24
|
+
span.set_tag('controller.name', controller_name)
|
25
|
+
span.set_tag('action.name', action_name)
|
26
|
+
span.set_tag('http.url', request.original_url.split('?').first)
|
27
|
+
span.set_tag('http.method', request.method)
|
28
|
+
span.set_tag('http.content_type', request.format)
|
29
|
+
span.set_tag('http.host', request.host)
|
30
|
+
begin
|
31
|
+
resp = yield
|
32
|
+
rescue StandardError => _
|
33
|
+
span.set_tag('error', true)
|
34
|
+
span.set_tag('http.status_code', Bigcommerce::Lightstep.http1_error_code)
|
35
|
+
tracer.clear_active_span!
|
36
|
+
span.finish
|
37
|
+
raise # re-raise the error
|
38
|
+
end
|
39
|
+
span.set_tag('http.status_code', response.status)
|
40
|
+
# 400+ HTTP status codes are errors: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status
|
41
|
+
span.set_tag('error', true) if response.status >= Bigcommerce::Lightstep.http1_error_code_minimum
|
42
|
+
resp
|
43
|
+
end
|
44
|
+
tracer.clear_active_span!
|
45
|
+
result
|
46
|
+
end
|
47
|
+
|
48
|
+
##
|
49
|
+
# Get only the open tracing headers
|
50
|
+
#
|
51
|
+
# @return [Hash]
|
52
|
+
#
|
53
|
+
def lightstep_filtered_headers
|
54
|
+
filtered_ot_headers = {}
|
55
|
+
headers = request.headers.to_h
|
56
|
+
headers.each do |k, v|
|
57
|
+
fk = k.to_s.downcase.gsub('http_', '').tr('_', '-')
|
58
|
+
next unless OPEN_TRACING_HEADER_KEYS.include?(fk)
|
59
|
+
filtered_ot_headers[fk] = v
|
60
|
+
end
|
61
|
+
filtered_ot_headers
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
# Copyright (c) 2018-present, BigCommerce Pty. Ltd. All rights reserved
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
4
|
+
# documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|
5
|
+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
6
|
+
# persons to whom the Software is furnished to do so, subject to the following conditions:
|
7
|
+
#
|
8
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
9
|
+
# Software.
|
10
|
+
#
|
11
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
12
|
+
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
13
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
14
|
+
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
15
|
+
#
|
16
|
+
module Bigcommerce
|
17
|
+
module Lightstep
|
18
|
+
##
|
19
|
+
# Global tracer
|
20
|
+
#
|
21
|
+
class Tracer
|
22
|
+
private
|
23
|
+
|
24
|
+
def initialize; end
|
25
|
+
|
26
|
+
public
|
27
|
+
|
28
|
+
include Singleton
|
29
|
+
|
30
|
+
##
|
31
|
+
# Start a new span
|
32
|
+
#
|
33
|
+
# @param [String] name The operation name for the Span
|
34
|
+
# @param [Hash|::LightStep::SpanContext] context (Optional)
|
35
|
+
# @param [Time] start_time (Optional)
|
36
|
+
# @param [Hash] tags (Optional)
|
37
|
+
#
|
38
|
+
def start_span(name, context: nil, start_time: nil, tags: nil)
|
39
|
+
if Bigcommerce::Lightstep.enabled
|
40
|
+
# enable the tracer (for fork support)
|
41
|
+
tracer.enable
|
42
|
+
elsif tracer.enabled?
|
43
|
+
# We are not enabled and the tracer is currently on
|
44
|
+
# https://github.com/lightstep/lightstep-tracer-ruby/blob/master/lib/lightstep/tracer.rb#L129-L130
|
45
|
+
tracer.disable(discard: true)
|
46
|
+
end
|
47
|
+
|
48
|
+
# find the currently active span
|
49
|
+
last_active_span = active_span
|
50
|
+
|
51
|
+
# determine who is the actual parent span
|
52
|
+
current_parent = determine_parent(context: context)
|
53
|
+
|
54
|
+
# create new span
|
55
|
+
span = ::LightStep.start_span(name, child_of: current_parent, start_time: start_time, tags: tags)
|
56
|
+
|
57
|
+
# set it as the active span
|
58
|
+
self.active_span = span
|
59
|
+
|
60
|
+
# run the process
|
61
|
+
result = yield span
|
62
|
+
|
63
|
+
# finish this span if the reporter is initialized
|
64
|
+
span.finish if reporter_initialized?
|
65
|
+
|
66
|
+
# now set back the parent as the active span
|
67
|
+
self.active_span = last_active_span
|
68
|
+
|
69
|
+
# return result
|
70
|
+
result
|
71
|
+
end
|
72
|
+
|
73
|
+
##
|
74
|
+
# Return the active span
|
75
|
+
#
|
76
|
+
# @return [::LightStep::Span|NilClass]
|
77
|
+
#
|
78
|
+
def active_span
|
79
|
+
Thread.current[:lightstep_active_span]
|
80
|
+
end
|
81
|
+
|
82
|
+
##
|
83
|
+
# Clear the active span
|
84
|
+
#
|
85
|
+
def clear_active_span!
|
86
|
+
Thread.current[:lightstep_active_span] = nil
|
87
|
+
end
|
88
|
+
|
89
|
+
##
|
90
|
+
# @return [Boolean]
|
91
|
+
#
|
92
|
+
def reporter_initialized?
|
93
|
+
tracer.instance_variable_defined?(:@reporter) && !tracer.instance_variable_get(:@reporter).nil?
|
94
|
+
end
|
95
|
+
|
96
|
+
private
|
97
|
+
|
98
|
+
##
|
99
|
+
# Determine the active parent
|
100
|
+
#
|
101
|
+
# @param [Hash|::LightStep::SpanContext] context
|
102
|
+
# @return [::LightStep::SpanContext]
|
103
|
+
#
|
104
|
+
def determine_parent(context:)
|
105
|
+
# first attempt to find parent from args, if not, use carrier (headers) to lookup parent
|
106
|
+
current_parent = context.is_a?(::LightStep::SpanContext) ? context : tracer.extract(::LightStep::Tracer::FORMAT_TEXT_MAP, context || {})
|
107
|
+
# if no passed in parent, use the active thread parent
|
108
|
+
current_parent = active_span if current_parent.nil?
|
109
|
+
current_parent
|
110
|
+
end
|
111
|
+
|
112
|
+
##
|
113
|
+
# @param [::LightStep::Span] span
|
114
|
+
#
|
115
|
+
def active_span=(span)
|
116
|
+
Thread.current[:lightstep_active_span] = span
|
117
|
+
end
|
118
|
+
|
119
|
+
##
|
120
|
+
# @return [::LightStep::Tracer]
|
121
|
+
#
|
122
|
+
def tracer
|
123
|
+
LightStep.instance
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
# Copyright (c) 2018-present, BigCommerce Pty. Ltd. All rights reserved
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
4
|
+
# documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|
5
|
+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
6
|
+
# persons to whom the Software is furnished to do so, subject to the following conditions:
|
7
|
+
#
|
8
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
9
|
+
# Software.
|
10
|
+
#
|
11
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
12
|
+
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
13
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
14
|
+
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
15
|
+
#
|
16
|
+
require 'net/http'
|
17
|
+
require 'lightstep/transport/base'
|
18
|
+
require 'logger'
|
19
|
+
|
20
|
+
module Bigcommerce
|
21
|
+
module Lightstep
|
22
|
+
# This is a transport that sends reports via HTTP in JSON format.
|
23
|
+
# It is thread-safe, however it is *not* fork-safe. When forking, all items
|
24
|
+
# in the queue will be copied and sent in duplicate.
|
25
|
+
class Transport < ::LightStep::Transport::Base
|
26
|
+
class InvalidAccessTokenError < StandardError; end
|
27
|
+
|
28
|
+
ENCRYPTION_TLS = 'tls'.freeze
|
29
|
+
ENCRYPTION_NONE = 'none'.freeze
|
30
|
+
HEADER_ACCESS_TOKEN = 'LightStep-Access-Token'.freeze
|
31
|
+
LIGHTSTEP_HOST = 'collector.lightstep.com'.freeze
|
32
|
+
LIGHTSTEP_PORT = 443
|
33
|
+
REPORTS_API_ENDPOINT = '/api/v0/reports'.freeze
|
34
|
+
|
35
|
+
# Initialize the transport
|
36
|
+
# @param host [String] host of the domain to the endpoind to push data
|
37
|
+
# @param port [Numeric] port on which to connect
|
38
|
+
# @param verbose [Numeric] verbosity level. Right now 0-3 are supported
|
39
|
+
# @param encryption [ENCRYPTION_TLS, ENCRYPTION_NONE] kind of encryption to use
|
40
|
+
# @param ssl_verify_peer [Boolean]
|
41
|
+
# @param access_token [String] access token for LightStep server
|
42
|
+
# @return [Transport]
|
43
|
+
def initialize(
|
44
|
+
access_token:,
|
45
|
+
host: LIGHTSTEP_HOST,
|
46
|
+
port: LIGHTSTEP_PORT,
|
47
|
+
verbose: 0,
|
48
|
+
encryption: ENCRYPTION_TLS,
|
49
|
+
ssl_verify_peer: true,
|
50
|
+
open_timeout: 20,
|
51
|
+
read_timeout: 20,
|
52
|
+
continue_timeout: nil,
|
53
|
+
keep_alive_timeout: 2,
|
54
|
+
logger: nil
|
55
|
+
)
|
56
|
+
@host = host
|
57
|
+
@port = port
|
58
|
+
@verbose = verbose
|
59
|
+
@encryption = encryption
|
60
|
+
@ssl_verify_peer = ssl_verify_peer
|
61
|
+
@open_timeout = open_timeout.to_i
|
62
|
+
@read_timeout = read_timeout.to_i
|
63
|
+
@continue_timeout = continue_timeout
|
64
|
+
@keep_alive_timeout = keep_alive_timeout.to_i
|
65
|
+
|
66
|
+
raise ::Bigcommerce::Lightstep::Errors::InvalidAccessToken, 'access_token must be a string' unless access_token.is_a?(String)
|
67
|
+
raise ::Bigcommerce::Lightstep::Errors::InvalidAccessToken, 'access_token cannot be blank' if access_token.empty?
|
68
|
+
@access_token = access_token.to_s
|
69
|
+
@logger = logger || ::Logger.new(STDOUT)
|
70
|
+
end
|
71
|
+
|
72
|
+
##
|
73
|
+
# Queue a report for sending
|
74
|
+
#
|
75
|
+
# @param [Hash] report
|
76
|
+
# @return [NilClass]
|
77
|
+
#
|
78
|
+
def report(report)
|
79
|
+
@logger.info report if @verbose >= 3
|
80
|
+
|
81
|
+
req = build_request(report)
|
82
|
+
res = connection.request(req)
|
83
|
+
|
84
|
+
@logger.info res.to_s if @verbose >= 3
|
85
|
+
|
86
|
+
nil
|
87
|
+
end
|
88
|
+
|
89
|
+
private
|
90
|
+
|
91
|
+
##
|
92
|
+
# @param [Hash] report
|
93
|
+
# @return [Net::HTTP::Post]
|
94
|
+
#
|
95
|
+
def build_request(report)
|
96
|
+
req = Net::HTTP::Post.new(REPORTS_API_ENDPOINT)
|
97
|
+
req[HEADER_ACCESS_TOKEN] = @access_token
|
98
|
+
req['Content-Type'] = 'application/json'
|
99
|
+
req['Connection'] = 'keep-alive'
|
100
|
+
req.body = report.to_json
|
101
|
+
req
|
102
|
+
end
|
103
|
+
|
104
|
+
##
|
105
|
+
# @return [Net::HTTP]
|
106
|
+
#
|
107
|
+
def connection
|
108
|
+
unless @connection
|
109
|
+
@connection = ::Net::HTTP.new(@host, @port)
|
110
|
+
if @port == 443
|
111
|
+
@connection.use_ssl = @encryption == ENCRYPTION_TLS
|
112
|
+
@connection.verify_mode = ::OpenSSL::SSL::VERIFY_NONE unless @ssl_verify_peer
|
113
|
+
end
|
114
|
+
@connection.open_timeout = @open_timeout
|
115
|
+
@connection.read_timeout = @read_timeout
|
116
|
+
@connection.continue_timeout = @continue_timeout
|
117
|
+
@connection.keep_alive_timeout = @keep_alive_timeout
|
118
|
+
end
|
119
|
+
@connection
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# Copyright (c) 2018-present, BigCommerce Pty. Ltd. All rights reserved
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
4
|
+
# documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|
5
|
+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
6
|
+
# persons to whom the Software is furnished to do so, subject to the following conditions:
|
7
|
+
#
|
8
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
9
|
+
# Software.
|
10
|
+
#
|
11
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
12
|
+
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
13
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
14
|
+
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
15
|
+
#
|
16
|
+
module Bigcommerce
|
17
|
+
module Lightstep
|
18
|
+
##
|
19
|
+
# Build transports for the lightstep connection
|
20
|
+
#
|
21
|
+
class TransportFactory
|
22
|
+
##
|
23
|
+
# @return [::Bigcommerce::Lightstep::Transport]
|
24
|
+
#
|
25
|
+
def build
|
26
|
+
::Bigcommerce::Lightstep::Transport.new(
|
27
|
+
host: ::Bigcommerce::Lightstep.host,
|
28
|
+
port: ::Bigcommerce::Lightstep.port.to_i,
|
29
|
+
verbose: ::Bigcommerce::Lightstep.verbosity.to_i,
|
30
|
+
encryption: ::Bigcommerce::Lightstep.port.to_i == 443 ? ::Bigcommerce::Lightstep::Transport::ENCRYPTION_TLS : ::Bigcommerce::Lightstep::Transport::ENCRYPTION_NONE,
|
31
|
+
ssl_verify_peer: ::Bigcommerce::Lightstep.ssl_verify_peer,
|
32
|
+
access_token: ::Bigcommerce::Lightstep.access_token,
|
33
|
+
logger: ::Bigcommerce::Lightstep.logger
|
34
|
+
)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# Copyright (c) 2018-present, BigCommerce Pty. Ltd. All rights reserved
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
4
|
+
# documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|
5
|
+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
6
|
+
# persons to whom the Software is furnished to do so, subject to the following conditions:
|
7
|
+
#
|
8
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
9
|
+
# Software.
|
10
|
+
#
|
11
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
12
|
+
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
13
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
14
|
+
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
15
|
+
#
|
16
|
+
module Bigcommerce
|
17
|
+
module Lightstep
|
18
|
+
VERSION = '1.1.6'.freeze
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bc-lightstep-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.6
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Shaun McCormick
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-09-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: lightstep
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.11.2
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.11.2
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: faraday
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.8'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.8'
|
97
|
+
description: Gem for lightstep distributed tracing
|
98
|
+
email:
|
99
|
+
- shaun.mccormick@bigcommerce.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- CHANGELOG.md
|
105
|
+
- CODE_OF_CONDUCT.md
|
106
|
+
- README.md
|
107
|
+
- bc-lightstep-ruby.gemspec
|
108
|
+
- lib/bigcommerce/lightstep.rb
|
109
|
+
- lib/bigcommerce/lightstep/configuration.rb
|
110
|
+
- lib/bigcommerce/lightstep/errors.rb
|
111
|
+
- lib/bigcommerce/lightstep/middleware/faraday.rb
|
112
|
+
- lib/bigcommerce/lightstep/rails_controller_instrumentation.rb
|
113
|
+
- lib/bigcommerce/lightstep/tracer.rb
|
114
|
+
- lib/bigcommerce/lightstep/transport.rb
|
115
|
+
- lib/bigcommerce/lightstep/transport_factory.rb
|
116
|
+
- lib/bigcommerce/lightstep/version.rb
|
117
|
+
homepage: https://github.com/bigcommerce/bc-lightstep-ruby
|
118
|
+
licenses:
|
119
|
+
- MIT
|
120
|
+
metadata: {}
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options: []
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
requirements: []
|
136
|
+
rubyforge_project:
|
137
|
+
rubygems_version: 2.7.7
|
138
|
+
signing_key:
|
139
|
+
specification_version: 4
|
140
|
+
summary: Gem for lightstep distributed tracing
|
141
|
+
test_files: []
|