lightstep 0.12.0 → 0.16.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: 4061236d2e72a5a8af39a92ee36074193a9dfe0bd48032cdecdfcc3d01054557
4
- data.tar.gz: ff20651fafa157cfeeecc789c73fb4a0c5dc4abbe910ef048625a39286251f6f
3
+ metadata.gz: 7b24dcdbee847cd07bfca4f5f6f5752c49eb951323d9c3c0356ad081f68483a0
4
+ data.tar.gz: b22da20413d082e19038a7a571aeb47fbfb8f304f70a3c4559ee765ec06c58bc
5
5
  SHA512:
6
- metadata.gz: 0f7b6a24656af8708d935b7afa2e47f5f7ee3fcd768518679450326140b6ead0ef1191718a487f3bed035eec99f8a263edc1d04b1fb18ea9c05b126ad23a0f88
7
- data.tar.gz: 23bb222bae518baa0bf4151883b9cc525cc6226d485fff7bce7cc13c12b4d7ea3a41821ba30bec0f7a19438b1a2bed039aabed27a947799613f9cf91e8eaff6b
6
+ metadata.gz: dfd268464c0c33e05ef86d250952dca6801b5f355011269d66d68bb98e205b9c9bb09b58ace4beb86af37455b69e21f1e2cabad8e38a6223ed6da63751cf1c47
7
+ data.tar.gz: 1e8df7a7ab819528448a1967585c7cc50816a77fa521b27dc75bf3f9d2174b4423679eae59b6f1cca01b05c4bff4bd3dd4db8551c1199001631074c7f1478a61
@@ -0,0 +1,32 @@
1
+ version: 2
2
+
3
+ jobs:
4
+ test-ruby-24:
5
+ docker:
6
+ - image: circleci/ruby:2.4-stretch
7
+ steps:
8
+ - checkout
9
+ - run: gem install --no-document bundler && bundle install --jobs=3 --retry=3
10
+ - run: bundle exec rake
11
+ test-ruby-25:
12
+ docker:
13
+ - image: circleci/ruby:2.5-stretch
14
+ steps:
15
+ - checkout
16
+ - run: gem install --no-document bundler && bundle install --jobs=3 --retry=3
17
+ - run: bundle exec rake
18
+ test-ruby-26:
19
+ docker:
20
+ - image: circleci/ruby:2.6-stretch
21
+ steps:
22
+ - checkout
23
+ - run: gem install --no-document bundler && bundle install --jobs=3 --retry=3
24
+ - run: bundle exec rake
25
+
26
+ workflows:
27
+ version: 2
28
+ test:
29
+ jobs:
30
+ - test-ruby-24
31
+ - test-ruby-25
32
+ - test-ruby-26
data/.gitignore CHANGED
@@ -1,6 +1,5 @@
1
1
  .bundle/
2
2
  .yardoc
3
- Gemfile.lock
4
3
  _yardoc/
5
4
  coverage/
6
5
  /doc/
@@ -8,6 +7,6 @@ coverage/
8
7
  /spec/reports/
9
8
  /tmp/
10
9
  *~
11
- Gemfile.lock
12
10
  lightstep-tracer*.gem
13
11
  lightstep*.gem
12
+ .idea/
@@ -0,0 +1,48 @@
1
+ AllCops:
2
+ Exclude:
3
+ - spec/**/*
4
+ - .bundle/**/*
5
+ - bin/**/*
6
+ - vendor/**/*
7
+ - tmp/**/*
8
+ - log/**/*
9
+ - Rakefile
10
+ - lightstep.gemspec
11
+
12
+ Lint/AmbiguousOperator:
13
+ Enabled: false
14
+
15
+ Metrics/ParameterLists:
16
+ Enabled: false
17
+
18
+ Metrics/AbcSize:
19
+ Max: 147
20
+
21
+ Metrics/BlockNesting:
22
+ Max: 4
23
+
24
+ # Configuration parameters: CountComments.
25
+ Metrics/ClassLength:
26
+ Max: 406
27
+
28
+ Metrics/CyclomaticComplexity:
29
+ Max: 24
30
+
31
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
32
+ # URISchemes: http, https
33
+ Metrics/LineLength:
34
+ Enabled: false
35
+
36
+ # Configuration parameters: CountComments.
37
+ Metrics/MethodLength:
38
+ Max: 88
39
+
40
+ # Configuration parameters: CountComments.
41
+ Metrics/ModuleLength:
42
+ Max: 1000
43
+
44
+ Performance/RedundantBlockCall:
45
+ Enabled: false
46
+
47
+ Style/PercentLiteralDelimiters:
48
+ Enabled: false
@@ -0,0 +1,45 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## v0.16.1
8
+ ### Changed
9
+ - Bump json from 2.2.0 to 2.5.1 ([#98](https://github.com/lightstep/lightstep-tracer-ruby/pull/98))
10
+ - Bump rack from 2.0.7 to 2.2.3 ([#95](https://github.com/lightstep/lightstep-tracer-ruby/pull/98))
11
+ - Update rake requirement from ~> 11.3 to ~> 13.0 ([#94](https://github.com/lightstep/lightstep-tracer-ruby/pull/98))
12
+
13
+ ## v0.16.0
14
+ ### Added
15
+ - The tracer now supports B3 context propagation. Propagation can be set by using the `propagator` keyword argument to `LightStep.configure`. Valid values are `:lightstep` (default), and `:b3`.
16
+
17
+ ## v0.15.1
18
+ ### Fixed
19
+ - The tracer now closes the active scope or finishes the active span even if an error is raised from the yielded code.
20
+
21
+ ### Unreleased
22
+ - In-progress B3 support
23
+
24
+ ## v0.15.0
25
+ ### Added
26
+ - A Changelog
27
+ - Now supports Span#log_kv
28
+ - Updated to opentracing-ruby 0.5.0
29
+ - Now delegates Lightstep#active_span to the tracer
30
+ - Now supports passing a block to #start_span
31
+ - The block forms of #start_span and #start active_span now return the result of executing the block
32
+
33
+ ### Changed
34
+ - Tracer#extract now supports symbols in carrier
35
+
36
+ ### Deprecated
37
+ - Span#log (reflecting deprecation in opentracing 0.4.0)
38
+
39
+ ### Removed
40
+
41
+ ### Fixed
42
+ - Fix handling of non-string tag values in `start_span`.
43
+
44
+ ### Security
45
+
@@ -0,0 +1,58 @@
1
+ # LightStep Community Contributing Guide
2
+
3
+ First, 🎉 **thanks for contributing!** 🎉
4
+
5
+ ## Issues
6
+
7
+ You're encouraged to log issues for any questions or problems you might have. When in doubt, log an issue. The exception to this rule is [security disclosures](#reporting-security-issues).
8
+
9
+ Generally speaking, the more context you can provide, the better. Please add information such as what **version** you're using, **stack traces** and/or **logs** (to the extent that you're able to share them), and whatever else you think may be relevant. Project maintainers may ask for additional clarification, logs, and other pertinent metadata before we can address your issue.
10
+
11
+ For bug submission, we especially appreciate **details on how to reproduce the bug** to the extent you're able to provide them, e.g., an isolated repo or [gist](https://gist.github.com).
12
+
13
+ ### Reporting Security Issues
14
+
15
+ If you find a security issue, please **do not** file a public issue for it. Instead, send your report to us privately at [security@lightstep.com](mailto:security@lightstep.com).
16
+
17
+ ## Contributions
18
+
19
+ All contributions big and small are welcome, from typo corrections to bug fixes to suggested improvements!
20
+
21
+ Any changes to project resources in this repository must be made through a pull request. This includes, but is not limited to, changes affecting:
22
+
23
+ - Documentation
24
+ - Source code
25
+ - Binaries
26
+ - Sample projects or other examples
27
+
28
+ No pull request can be merged without at least one review from a maintainer.
29
+
30
+ By default, contributions are accepted once no committers object to the PR. Specific contributors may be suggested or required to review a pull request based on repository settings.
31
+
32
+ In the event of objections or disagreement, everyone involved should seek to arrive at a consensus around the expressed objections. These can take the form of addressing concerns through changes, compromising around the change, or withdrawing it entirely.
33
+
34
+ ## Development
35
+
36
+ ### Testing
37
+
38
+ To run the tests:
39
+
40
+ ```
41
+ make test
42
+ ```
43
+
44
+ ## Submitting a Pull Request
45
+
46
+ _Note that this section should be treated as a general guideline and replaced with language/repo specific instructions_
47
+
48
+ 1. [Fork the repository.](https://help.github.com/en/github/getting-started-with-github/fork-a-repo)
49
+ 1. Create a new branch.
50
+ 1. Add tests for your change.
51
+ 1. [Run the tests](#testing) to make sure that they don't already pass. If they do (and you're not backfilling test coverage), please modify them.
52
+ 1. Implement the change such that your new tests pass.
53
+ 1. [Commit and push your changes.](https://guides.github.com/introduction/flow/)
54
+ 1. [Submit your pull request.](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests)
55
+ 1. Adjust your pull request based on feedback.
56
+ 1. Get it merged! 🎉
57
+
58
+ We're happy to help with any questions you may have on the git or GitHub side, e.g., how to push a branch to your fork. Just create an issue and we'll try to help answer them :)
@@ -0,0 +1,52 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ lightstep (0.16.1)
5
+ concurrent-ruby (~> 1.0)
6
+ opentracing (~> 0.5.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ bump (0.6.1)
12
+ concurrent-ruby (1.1.7)
13
+ diff-lcs (1.3)
14
+ docile (1.3.2)
15
+ json (2.5.1)
16
+ opentracing (0.5.0)
17
+ rack (2.2.3)
18
+ rake (13.0.1)
19
+ rspec (3.8.0)
20
+ rspec-core (~> 3.8.0)
21
+ rspec-expectations (~> 3.8.0)
22
+ rspec-mocks (~> 3.8.0)
23
+ rspec-core (3.8.2)
24
+ rspec-support (~> 3.8.0)
25
+ rspec-expectations (3.8.4)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.8.0)
28
+ rspec-mocks (3.8.1)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.8.0)
31
+ rspec-support (3.8.2)
32
+ simplecov (0.17.0)
33
+ docile (~> 1.1)
34
+ json (>= 1.8, < 3)
35
+ simplecov-html (~> 0.10.0)
36
+ simplecov-html (0.10.2)
37
+ timecop (0.8.1)
38
+
39
+ PLATFORMS
40
+ ruby
41
+
42
+ DEPENDENCIES
43
+ bump (~> 0.5)
44
+ lightstep!
45
+ rack (~> 2.0)
46
+ rake (~> 13.0)
47
+ rspec (~> 3.0)
48
+ simplecov (~> 0.16)
49
+ timecop (~> 0.8.0)
50
+
51
+ BUNDLED WITH
52
+ 2.0.2
data/Makefile CHANGED
@@ -14,10 +14,10 @@ benchmark:
14
14
  ruby benchmark/threading/thread_test.rb
15
15
 
16
16
  bump-version:
17
- # ruby -e 'require "bump"; Bump::Bump.run("minor")'
18
- # make build # rebuild after version increment
17
+ ruby -e 'require "bump"; Bump::Bump.run("$(RELEASE_TYPE)")'
18
+ make build # rebuild after version increment
19
19
  git tag `ruby scripts/version.rb`
20
- # git push
20
+ git push
21
21
  git push --tags
22
22
 
23
23
  publish: build test benchmark bump-version
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # lightstep-tracer-ruby
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/lightstep-tracer.svg)](https://badge.fury.io/rb/lightstep-tracer) [![Circle CI](https://circleci.com/gh/lightstep/lightstep-tracer-ruby.svg?style=shield)](https://circleci.com/gh/lightstep/lightstep-tracer-ruby) [![MIT license](http://img.shields.io/badge/license-MIT-blue.svg)](http://opensource.org/licenses/MIT) [![Code Climate](https://codeclimate.com/github/lightstep/lightstep-tracer-ruby/badges/gpa.svg)](https://codeclimate.com/github/lightstep/lightstep-tracer-ruby)
3
+ [![Gem Version](https://badge.fury.io/rb/lightstep.svg)](https://badge.fury.io/rb/lightstep) [![Circle CI](https://circleci.com/gh/lightstep/lightstep-tracer-ruby.svg?style=shield)](https://circleci.com/gh/lightstep/lightstep-tracer-ruby) [![MIT license](http://img.shields.io/badge/license-MIT-blue.svg)](http://opensource.org/licenses/MIT) [![Code Climate](https://codeclimate.com/github/lightstep/lightstep-tracer-ruby/badges/gpa.svg)](https://codeclimate.com/github/lightstep/lightstep-tracer-ruby)
4
4
 
5
5
  The LightStep distributed tracing library for Ruby.
6
6
 
@@ -27,6 +27,9 @@ Or install it yourself as:
27
27
  # Initialize the singleton tracer
28
28
  LightStep.configure(component_name: 'lightstep/ruby/example', access_token: 'your_access_token')
29
29
 
30
+ # Specify a propagation format (options are :lightstep (default) and :b3)
31
+ LightStep.configure(component_name: 'lightstep/ruby/example', access_token: 'your_access_token', propagator: :b3)
32
+
30
33
  # Create a basic span and attach a log to the span
31
34
  span = LightStep.start_span('my_span')
32
35
  span.log(event: 'hello world', count: 42)
data/example.rb CHANGED
@@ -11,7 +11,7 @@ LightStep.configure(component_name: 'lightstep/ruby/example', access_token: acce
11
11
  puts 'Starting operation...'
12
12
  span = LightStep.start_span('my_span')
13
13
  thread1 = Thread.new do
14
- for i in 1..10
14
+ (1..10).each do |i|
15
15
  sleep(0.15)
16
16
  puts "Logging event #{i}..."
17
17
  span.log(event: 'hello world', count: i)
@@ -19,7 +19,7 @@ thread1 = Thread.new do
19
19
  end
20
20
  thread2 = Thread.new do
21
21
  current = 1
22
- for i in 1..16
22
+ (1..16).each do |i|
23
23
  child = LightStep.start_span('my_child', child_of: span.span_context)
24
24
  sleep(0.1)
25
25
  current *= 2
@@ -60,7 +60,7 @@ end
60
60
 
61
61
  loop do
62
62
  begin
63
- p Net::HTTP.get(URI("http://localhost:9001/"))
63
+ p Net::HTTP.get(URI("http://127.0.0.1:9001/"))
64
64
  break
65
65
  rescue Errno::ECONNREFUSED
66
66
  sleep 0.05
@@ -15,6 +15,8 @@ module LightStep
15
15
 
16
16
  def_delegator :instance, :configure
17
17
  def_delegator :instance, :start_span
18
+ def_delegator :instance, :start_active_span
19
+ def_delegator :instance, :active_span
18
20
  def_delegator :instance, :disable
19
21
  def_delegator :instance, :enable
20
22
  def_delegator :instance, :flush
@@ -45,3 +47,5 @@ end
45
47
 
46
48
  require 'lightstep/tracer'
47
49
  require 'lightstep/global_tracer'
50
+ require 'lightstep/scope'
51
+ require 'lightstep/scope_manager'
@@ -0,0 +1,25 @@
1
+ #frozen_string_literal: true
2
+
3
+ require 'lightstep/propagation/lightstep_propagator'
4
+ require 'lightstep/propagation/b3_propagator'
5
+
6
+ module LightStep
7
+ module Propagation
8
+ PROPAGATOR_MAP = {
9
+ lightstep: LightStepPropagator,
10
+ b3: B3Propagator
11
+ }
12
+
13
+ class << self
14
+ # Constructs a propagator instance from the given propagator name. If the
15
+ # name is unknown returns the LightStepPropagator as a default
16
+ #
17
+ # @param [Symbol, String] propagator_name One of :lightstep or :b3
18
+ # @return [Propagator]
19
+ def [](propagator_name)
20
+ klass = PROPAGATOR_MAP[propagator_name.to_sym] || LightStepPropagator
21
+ klass.new
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,29 @@
1
+ #frozen_string_literal: true
2
+
3
+ module LightStep
4
+ module Propagation
5
+ class B3Propagator < LightStepPropagator
6
+ CARRIER_TRACER_STATE_PREFIX = 'x-b3-'
7
+ CARRIER_SPAN_ID = 'x-b3-spanid'
8
+ CARRIER_TRACE_ID = 'x-b3-traceid'
9
+ CARRIER_SAMPLED = 'x-b3-sampled'
10
+ TRUE_VALUES = %w[1 true].freeze
11
+
12
+ private
13
+
14
+ # propagate the full 128-bit trace id if the original id was 128-bit,
15
+ # use the 64 bit id otherwise
16
+ def trace_id_from_ctx(ctx)
17
+ ctx.id_truncated? ? ctx.trace_id128 : ctx.trace_id64
18
+ end
19
+
20
+ def sampled_flag_from_ctx(ctx)
21
+ ctx.sampled? ? '1' : '0'
22
+ end
23
+
24
+ def sampled_flag_from_carrier(carrier)
25
+ TRUE_VALUES.include?(carrier[self.class::CARRIER_SAMPLED])
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,127 @@
1
+ #frozen_string_literal: true
2
+
3
+ module LightStep
4
+ module Propagation
5
+ class LightStepPropagator
6
+ CARRIER_TRACER_STATE_PREFIX = 'ot-tracer-'
7
+ CARRIER_SPAN_ID = 'ot-tracer-spanid'
8
+ CARRIER_TRACE_ID = 'ot-tracer-traceid'
9
+ CARRIER_SAMPLED = 'ot-tracer-sampled'
10
+ CARRIER_BAGGAGE_PREFIX = 'ot-baggage-'
11
+
12
+ # Inject a SpanContext into the given carrier
13
+ #
14
+ # @param spancontext [SpanContext]
15
+ # @param format [OpenTracing::FORMAT_TEXT_MAP, OpenTracing::FORMAT_BINARY]
16
+ # @param carrier [Carrier] A carrier object of the type dictated by the specified `format`
17
+ def inject(span_context, format, carrier)
18
+ case format
19
+ when OpenTracing::FORMAT_TEXT_MAP
20
+ inject_to_text_map(span_context, carrier)
21
+ when OpenTracing::FORMAT_BINARY
22
+ warn 'Binary inject format not yet implemented'
23
+ when OpenTracing::FORMAT_RACK
24
+ inject_to_rack(span_context, carrier)
25
+ else
26
+ warn 'Unknown inject format'
27
+ end
28
+ end
29
+
30
+ # Extract a SpanContext from a carrier
31
+ # @param format [OpenTracing::FORMAT_TEXT_MAP, OpenTracing::FORMAT_BINARY, OpenTracing::FORMAT_RACK]
32
+ # @param carrier [Carrier] A carrier object of the type dictated by the specified `format`
33
+ # @return [SpanContext] the extracted SpanContext or nil if none could be found
34
+ def extract(format, carrier)
35
+ case format
36
+ when OpenTracing::FORMAT_TEXT_MAP
37
+ extract_from_text_map(carrier)
38
+ when OpenTracing::FORMAT_BINARY
39
+ warn 'Binary join format not yet implemented'
40
+ nil
41
+ when OpenTracing::FORMAT_RACK
42
+ extract_from_rack(carrier)
43
+ else
44
+ warn 'Unknown join format'
45
+ nil
46
+ end
47
+ end
48
+
49
+ private
50
+
51
+ def inject_to_text_map(span_context, carrier)
52
+ if trace_id = trace_id_from_ctx(span_context)
53
+ carrier[self.class::CARRIER_TRACE_ID] = trace_id
54
+ end
55
+ carrier[self.class::CARRIER_SPAN_ID] = span_context.id
56
+ carrier[self.class::CARRIER_SAMPLED] = sampled_flag_from_ctx(span_context)
57
+
58
+ span_context.baggage.each do |key, value|
59
+ carrier[self.class::CARRIER_BAGGAGE_PREFIX + key] = value
60
+ end
61
+ end
62
+
63
+ def extract_from_text_map(carrier)
64
+ # If the carrier does not have both the span_id and trace_id key
65
+ # skip the processing and just return a normal span
66
+ if !carrier.has_key?(self.class::CARRIER_SPAN_ID) || !carrier.has_key?(self.class::CARRIER_TRACE_ID)
67
+ return nil
68
+ end
69
+
70
+ baggage = carrier.reduce({}) do |baggage, (key, value)|
71
+ if key.start_with?(self.class::CARRIER_BAGGAGE_PREFIX)
72
+ plain_key = key.to_s[self.class::CARRIER_BAGGAGE_PREFIX.length..key.to_s.length]
73
+ baggage[plain_key] = value
74
+ end
75
+ baggage
76
+ end
77
+
78
+ SpanContext.new(
79
+ id: carrier[self.class::CARRIER_SPAN_ID],
80
+ trace_id: carrier[self.class::CARRIER_TRACE_ID],
81
+ sampled: sampled_flag_from_carrier(carrier),
82
+ baggage: baggage,
83
+ )
84
+ end
85
+
86
+ def inject_to_rack(span_context, carrier)
87
+ if trace_id = trace_id_from_ctx(span_context)
88
+ carrier[self.class::CARRIER_TRACE_ID] = trace_id
89
+ end
90
+ carrier[self.class::CARRIER_SPAN_ID] = span_context.id
91
+ carrier[self.class::CARRIER_SAMPLED] = sampled_flag_from_ctx(span_context)
92
+
93
+ span_context.baggage.each do |key, value|
94
+ if key =~ /[^A-Za-z0-9\-_]/
95
+ # TODO: log the error internally
96
+ next
97
+ end
98
+ carrier[self.class::CARRIER_BAGGAGE_PREFIX + key] = value
99
+ end
100
+ end
101
+
102
+ def extract_from_rack(env)
103
+ extract_from_text_map(env.reduce({}){|memo, (raw_header, value)|
104
+ header = raw_header.to_s.gsub(/^HTTP_/, '')
105
+ header.tr!('_', '-')
106
+ header.downcase!
107
+
108
+ memo[header] = value if header.start_with?(self.class::CARRIER_TRACER_STATE_PREFIX,
109
+ self.class::CARRIER_BAGGAGE_PREFIX)
110
+ memo
111
+ })
112
+ end
113
+
114
+ def trace_id_from_ctx(ctx)
115
+ ctx.trace_id
116
+ end
117
+
118
+ def sampled_flag_from_ctx(_)
119
+ 'true'
120
+ end
121
+
122
+ def sampled_flag_from_carrier(_)
123
+ true
124
+ end
125
+ end
126
+ end
127
+ end