opencensus 0.3.1 → 0.4.0
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 +5 -5
- data/CHANGELOG.md +23 -0
- data/README.md +14 -3
- data/lib/opencensus.rb +12 -0
- data/lib/opencensus/common.rb +1 -0
- data/lib/opencensus/common/config.rb +1 -0
- data/lib/opencensus/config.rb +5 -3
- data/lib/opencensus/context.rb +1 -0
- data/lib/opencensus/stats.rb +1 -0
- data/lib/opencensus/tags.rb +1 -0
- data/lib/opencensus/trace.rb +31 -11
- data/lib/opencensus/trace/annotation.rb +1 -0
- data/lib/opencensus/trace/config.rb +13 -11
- data/lib/opencensus/trace/exporters.rb +1 -0
- data/lib/opencensus/trace/exporters/logger.rb +4 -3
- data/lib/opencensus/trace/exporters/multi.rb +1 -0
- data/lib/opencensus/trace/formatters.rb +3 -2
- data/lib/opencensus/trace/formatters/binary.rb +1 -0
- data/lib/opencensus/trace/formatters/cloud_trace.rb +1 -0
- data/lib/opencensus/trace/formatters/trace_context.rb +3 -2
- data/lib/opencensus/trace/integrations.rb +1 -0
- data/lib/opencensus/trace/integrations/faraday_middleware.rb +57 -21
- data/lib/opencensus/trace/integrations/rack_middleware.rb +11 -19
- data/lib/opencensus/trace/integrations/rails.rb +1 -0
- data/lib/opencensus/trace/link.rb +17 -7
- data/lib/opencensus/trace/message_event.rb +13 -3
- data/lib/opencensus/trace/samplers.rb +11 -7
- data/lib/opencensus/trace/samplers/always_sample.rb +1 -0
- data/lib/opencensus/trace/samplers/never_sample.rb +1 -0
- data/lib/opencensus/trace/samplers/probability.rb +13 -5
- data/lib/opencensus/trace/samplers/rate_limiting.rb +74 -0
- data/lib/opencensus/trace/span.rb +11 -5
- data/lib/opencensus/trace/span_builder.rb +84 -27
- data/lib/opencensus/trace/span_context.rb +76 -40
- data/lib/opencensus/trace/status.rb +227 -5
- data/lib/opencensus/trace/time_event.rb +1 -0
- data/lib/opencensus/trace/trace_context_data.rb +1 -0
- data/lib/opencensus/trace/truncatable_string.rb +1 -0
- data/lib/opencensus/version.rb +2 -1
- metadata +6 -6
- data/lib/opencensus/trace/samplers/max_qps.rb +0 -55
| @@ -12,6 +12,7 @@ | |
| 12 12 | 
             
            # See the License for the specific language governing permissions and
         | 
| 13 13 | 
             
            # limitations under the License.
         | 
| 14 14 |  | 
| 15 | 
            +
             | 
| 15 16 | 
             
            require "opencensus"
         | 
| 16 17 |  | 
| 17 18 | 
             
            module OpenCensus
         | 
| @@ -76,7 +77,7 @@ module OpenCensus | |
| 76 77 | 
             
                        trace_context: context,
         | 
| 77 78 | 
             
                        same_process_as_parent: false do |span_context|
         | 
| 78 79 | 
             
                        begin
         | 
| 79 | 
            -
                           | 
| 80 | 
            +
                          Trace.in_span get_path(env) do |span|
         | 
| 80 81 | 
             
                            start_request span, env
         | 
| 81 82 | 
             
                            @app.call(env).tap do |response|
         | 
| 82 83 | 
             
                              finish_request span, response
         | 
| @@ -100,30 +101,21 @@ module OpenCensus | |
| 100 101 | 
             
                      env["HTTP_HOST"] || env["SERVER_NAME"]
         | 
| 101 102 | 
             
                    end
         | 
| 102 103 |  | 
| 103 | 
            -
                    def get_url env
         | 
| 104 | 
            -
                      path = get_path env
         | 
| 105 | 
            -
                      host = get_host env
         | 
| 106 | 
            -
                      scheme = env["SERVER_PROTOCOL"]
         | 
| 107 | 
            -
                      query_string = env["QUERY_STRING"].to_s
         | 
| 108 | 
            -
                      url = "#{scheme}://#{host}#{path}"
         | 
| 109 | 
            -
                      url = "#{url}?#{query_string}" unless query_string.empty?
         | 
| 110 | 
            -
                      url
         | 
| 111 | 
            -
                    end
         | 
| 112 | 
            -
             | 
| 113 104 | 
             
                    def start_request span, env
         | 
| 114 105 | 
             
                      span.kind = SpanBuilder::SERVER
         | 
| 115 | 
            -
                      span.put_attribute " | 
| 116 | 
            -
                      span.put_attribute " | 
| 117 | 
            -
                      span.put_attribute " | 
| 118 | 
            -
                       | 
| 119 | 
            -
             | 
| 120 | 
            -
                       | 
| 121 | 
            -
                      span.put_attribute "/tid", ::Thread.current.object_id.to_s
         | 
| 106 | 
            +
                      span.put_attribute "http.host", get_host(env)
         | 
| 107 | 
            +
                      span.put_attribute "http.path", get_path(env)
         | 
| 108 | 
            +
                      span.put_attribute "http.method", env["REQUEST_METHOD"].to_s.upcase
         | 
| 109 | 
            +
                      if env["HTTP_USER_AGENT"]
         | 
| 110 | 
            +
                        span.put_attribute "http.user_agent", env["HTTP_USER_AGENT"]
         | 
| 111 | 
            +
                      end
         | 
| 122 112 | 
             
                    end
         | 
| 123 113 |  | 
| 124 114 | 
             
                    def finish_request span, response
         | 
| 125 115 | 
             
                      if response.is_a?(::Array) && response.size == 3
         | 
| 126 | 
            -
                         | 
| 116 | 
            +
                        http_status = response[0]
         | 
| 117 | 
            +
                        span.set_http_status http_status
         | 
| 118 | 
            +
                        span.put_attribute "http.status_code", http_status
         | 
| 127 119 | 
             
                      end
         | 
| 128 120 | 
             
                    end
         | 
| 129 121 | 
             
                  end
         | 
| @@ -12,6 +12,7 @@ | |
| 12 12 | 
             
            # See the License for the specific language governing permissions and
         | 
| 13 13 | 
             
            # limitations under the License.
         | 
| 14 14 |  | 
| 15 | 
            +
             | 
| 15 16 | 
             
            module OpenCensus
         | 
| 16 17 | 
             
              module Trace
         | 
| 17 18 | 
             
                ##
         | 
| @@ -21,15 +22,24 @@ module OpenCensus | |
| 21 22 | 
             
                # traces or when the handler receives a request from a different project.
         | 
| 22 23 | 
             
                #
         | 
| 23 24 | 
             
                class Link
         | 
| 24 | 
            -
                   | 
| 25 | 
            -
                  #  | 
| 26 | 
            -
                   | 
| 25 | 
            +
                  ##
         | 
| 26 | 
            +
                  # A link type, indicating the relationship of the two spans is unknown,
         | 
| 27 | 
            +
                  # or is known but is other than parent-child.
         | 
| 28 | 
            +
                  # @return [Symbol]
         | 
| 29 | 
            +
                  #
         | 
| 30 | 
            +
                  TYPE_UNSPECIFIED = :TYPE_UNSPECIFIED
         | 
| 27 31 |  | 
| 28 | 
            -
                   | 
| 29 | 
            -
                   | 
| 32 | 
            +
                  ##
         | 
| 33 | 
            +
                  # A link type, indicating the linked span is a child of the current span.
         | 
| 34 | 
            +
                  # @return [Symbol]
         | 
| 35 | 
            +
                  #
         | 
| 36 | 
            +
                  CHILD_LINKED_SPAN = :CHILD_LINKED_SPAN
         | 
| 30 37 |  | 
| 31 | 
            -
                   | 
| 32 | 
            -
                   | 
| 38 | 
            +
                  ##
         | 
| 39 | 
            +
                  # A link type, indicating the linked span is a parent of the current span.
         | 
| 40 | 
            +
                  # @return [Symbol]
         | 
| 41 | 
            +
                  #
         | 
| 42 | 
            +
                  PARENT_LINKED_SPAN = :PARENT_LINKED_SPAN
         | 
| 33 43 |  | 
| 34 44 | 
             
                  ##
         | 
| 35 45 | 
             
                  # A unique identifier for a trace. All spans from the same trace share
         | 
| @@ -12,6 +12,7 @@ | |
| 12 12 | 
             
            # See the License for the specific language governing permissions and
         | 
| 13 13 | 
             
            # limitations under the License.
         | 
| 14 14 |  | 
| 15 | 
            +
             | 
| 15 16 | 
             
            require "opencensus/trace/time_event"
         | 
| 16 17 |  | 
| 17 18 | 
             
            module OpenCensus
         | 
| @@ -20,13 +21,22 @@ module OpenCensus | |
| 20 21 | 
             
                # An event describing a message sent/received between Spans.
         | 
| 21 22 | 
             
                #
         | 
| 22 23 | 
             
                class MessageEvent < TimeEvent
         | 
| 23 | 
            -
                   | 
| 24 | 
            +
                  ##
         | 
| 25 | 
            +
                  # An event type, indicating the type is unknown.
         | 
| 26 | 
            +
                  # @return [Symbol]
         | 
| 27 | 
            +
                  #
         | 
| 24 28 | 
             
                  TYPE_UNSPECIFIED = :TYPE_UNSPECIFIED
         | 
| 25 29 |  | 
| 26 | 
            -
                   | 
| 30 | 
            +
                  ##
         | 
| 31 | 
            +
                  # An event type, indicating a sent message.
         | 
| 32 | 
            +
                  # @return [Symbol]
         | 
| 33 | 
            +
                  #
         | 
| 27 34 | 
             
                  SENT = :SENT
         | 
| 28 35 |  | 
| 29 | 
            -
                   | 
| 36 | 
            +
                  ##
         | 
| 37 | 
            +
                  # An event type, indicating a received message.
         | 
| 38 | 
            +
                  # @return [Symbol]
         | 
| 39 | 
            +
                  #
         | 
| 30 40 | 
             
                  RECEIVED = :RECEIVED
         | 
| 31 41 |  | 
| 32 42 | 
             
                  ##
         | 
| @@ -12,10 +12,11 @@ | |
| 12 12 | 
             
            # See the License for the specific language governing permissions and
         | 
| 13 13 | 
             
            # limitations under the License.
         | 
| 14 14 |  | 
| 15 | 
            +
             | 
| 15 16 | 
             
            require "opencensus/trace/samplers/always_sample"
         | 
| 16 17 | 
             
            require "opencensus/trace/samplers/never_sample"
         | 
| 17 18 | 
             
            require "opencensus/trace/samplers/probability"
         | 
| 18 | 
            -
            require "opencensus/trace/samplers/ | 
| 19 | 
            +
            require "opencensus/trace/samplers/rate_limiting"
         | 
| 19 20 |  | 
| 20 21 | 
             
            module OpenCensus
         | 
| 21 22 | 
             
              module Trace
         | 
| @@ -26,19 +27,22 @@ module OpenCensus | |
| 26 27 | 
             
                # use a sampler to decide, for a given request, whether to report its
         | 
| 27 28 | 
             
                # trace.
         | 
| 28 29 | 
             
                #
         | 
| 29 | 
            -
                # The OpenCensus specification defines  | 
| 30 | 
            -
                #  | 
| 31 | 
            -
                #  | 
| 30 | 
            +
                # The OpenCensus specification defines four samplers:
         | 
| 31 | 
            +
                # {OpenCensus::Trace::Samplers::AlwaysSample},
         | 
| 32 | 
            +
                # {OpenCensus::Trace::Samplers::NeverSample},
         | 
| 33 | 
            +
                # {OpenCensus::Trace::Samplers::Probability}, and
         | 
| 34 | 
            +
                # {OpenCensus::Trace::Samplers::RateLimiting}.
         | 
| 32 35 | 
             
                #
         | 
| 33 | 
            -
                # A sampler is a Proc that takes a hash of environment information and
         | 
| 36 | 
            +
                # A sampler is a `Proc` that takes a hash of environment information and
         | 
| 34 37 | 
             
                # returns a boolean indicating whether or not to sample the current
         | 
| 35 | 
            -
                # request. Alternately, it could be an object that duck-types the Proc
         | 
| 38 | 
            +
                # request. Alternately, it could be an object that duck-types the `Proc`
         | 
| 36 39 | 
             
                # interface by implementing the `call` method. The hash passed to `call`
         | 
| 37 40 | 
             
                # may contain the following keys, all of which are optional. Samplers must
         | 
| 38 41 | 
             
                # adjust their behavior to account for the availability or absence of any
         | 
| 39 42 | 
             
                # environment information:
         | 
| 40 43 | 
             
                #
         | 
| 41 | 
            -
                # *   `span_context` The SpanContext that created the | 
| 44 | 
            +
                # *   `span_context` The {OpenCensus::Trace::SpanContext} that created the
         | 
| 45 | 
            +
                #      span being sampled.
         | 
| 42 46 | 
             
                # *   `rack_env` The hash of Rack environment information
         | 
| 43 47 | 
             
                #
         | 
| 44 48 | 
             
                # Applications may set a default sampler in the config. In addition, the
         | 
| @@ -12,6 +12,9 @@ | |
| 12 12 | 
             
            # See the License for the specific language governing permissions and
         | 
| 13 13 | 
             
            # limitations under the License.
         | 
| 14 14 |  | 
| 15 | 
            +
             | 
| 16 | 
            +
            require "monitor"
         | 
| 17 | 
            +
             | 
| 15 18 | 
             
            module OpenCensus
         | 
| 16 19 | 
             
              module Trace
         | 
| 17 20 | 
             
                module Samplers
         | 
| @@ -21,9 +24,9 @@ module OpenCensus | |
| 21 24 | 
             
                  #
         | 
| 22 25 | 
             
                  class Probability
         | 
| 23 26 | 
             
                    ##
         | 
| 24 | 
            -
                    # The default sampling probability.
         | 
| 27 | 
            +
                    # The default sampling probability, equal to 1/10000.
         | 
| 25 28 | 
             
                    #
         | 
| 26 | 
            -
                    DEFAULT_RATE = 0. | 
| 29 | 
            +
                    DEFAULT_RATE = 0.0001
         | 
| 27 30 |  | 
| 28 31 | 
             
                    ##
         | 
| 29 32 | 
             
                    # Create a sampler for the given probability.
         | 
| @@ -39,6 +42,7 @@ module OpenCensus | |
| 39 42 | 
             
                      end
         | 
| 40 43 | 
             
                      @rate = rate
         | 
| 41 44 | 
             
                      @rng = rng || Random.new
         | 
| 45 | 
            +
                      @lock = Monitor.new
         | 
| 42 46 | 
             
                    end
         | 
| 43 47 |  | 
| 44 48 | 
             
                    ##
         | 
| @@ -47,8 +51,10 @@ module OpenCensus | |
| 47 51 | 
             
                    #
         | 
| 48 52 | 
             
                    # @param [Hash] opts The options to sample with.
         | 
| 49 53 | 
             
                    # @option opts [SpanContext] :span_context If provided, the span context
         | 
| 50 | 
            -
                    #         will be  | 
| 51 | 
            -
                    #          | 
| 54 | 
            +
                    #         will be checked and the parent's sampling decision will be
         | 
| 55 | 
            +
                    #         propagated if the parent was sampled. The span context will
         | 
| 56 | 
            +
                    #         also be used to generate a deterministic value in place of the
         | 
| 57 | 
            +
                    #         pseudo-random number generator.
         | 
| 52 58 | 
             
                    # @return [boolean] Whether to sample at this time.
         | 
| 53 59 | 
             
                    #
         | 
| 54 60 | 
             
                    def call opts = {}
         | 
| @@ -59,7 +65,9 @@ module OpenCensus | |
| 59 65 | 
             
                          (span_context.trace_id.to_i(16) % 0x10000000000000000).to_f /
         | 
| 60 66 | 
             
                            0x10000000000000000
         | 
| 61 67 | 
             
                        else
         | 
| 62 | 
            -
                          @ | 
| 68 | 
            +
                          @lock.synchronize do
         | 
| 69 | 
            +
                            @rng.rand
         | 
| 70 | 
            +
                          end
         | 
| 63 71 | 
             
                        end
         | 
| 64 72 | 
             
                      value <= @rate
         | 
| 65 73 | 
             
                    end
         | 
| @@ -0,0 +1,74 @@ | |
| 1 | 
            +
            # Copyright 2017 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 | 
            +
             | 
| 16 | 
            +
            require "monitor"
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            module OpenCensus
         | 
| 19 | 
            +
              module Trace
         | 
| 20 | 
            +
                module Samplers
         | 
| 21 | 
            +
                  ##
         | 
| 22 | 
            +
                  # The RateLimiting sampler delays a minimum amount of time between each
         | 
| 23 | 
            +
                  # sample, enforcing a maximum QPS across traces that use this sampler.
         | 
| 24 | 
            +
                  #
         | 
| 25 | 
            +
                  class RateLimiting
         | 
| 26 | 
            +
                    ##
         | 
| 27 | 
            +
                    # Default rate in samples per second.
         | 
| 28 | 
            +
                    #
         | 
| 29 | 
            +
                    DEFAULT_RATE = 0.1
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                    ##
         | 
| 32 | 
            +
                    # Create a sampler for the given QPS.
         | 
| 33 | 
            +
                    #
         | 
| 34 | 
            +
                    # @param [Number] qps Samples per second. Default is {DEFAULT_RATE}.
         | 
| 35 | 
            +
                    # @param [#rand] rng The random number generator to use. Default is a
         | 
| 36 | 
            +
                    #     new `::Random` instance.
         | 
| 37 | 
            +
                    # @param [#now] time_class The time class to use. Default is `::Time`.
         | 
| 38 | 
            +
                    #     Generally used for testing.
         | 
| 39 | 
            +
                    #
         | 
| 40 | 
            +
                    def initialize qps = DEFAULT_RATE, rng: nil, time_class: nil
         | 
| 41 | 
            +
                      @qps = qps
         | 
| 42 | 
            +
                      @time_class = time_class || Time
         | 
| 43 | 
            +
                      @rng = rng || Random.new
         | 
| 44 | 
            +
                      @last_time = @time_class.now.to_f
         | 
| 45 | 
            +
                      @lock = Monitor.new
         | 
| 46 | 
            +
                    end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                    ##
         | 
| 49 | 
            +
                    # Implements the sampler contract. Checks to see whether a sample
         | 
| 50 | 
            +
                    # should be taken at this time.
         | 
| 51 | 
            +
                    #
         | 
| 52 | 
            +
                    # @param [Hash] opts The options to sample with.
         | 
| 53 | 
            +
                    # @option opts [SpanContext] :span_context If provided, the span context
         | 
| 54 | 
            +
                    #         will be checked and the parent's sampling decision will be
         | 
| 55 | 
            +
                    #         propagated if the parent was sampled.
         | 
| 56 | 
            +
                    # @return [boolean] Whether to sample at this time.
         | 
| 57 | 
            +
                    #
         | 
| 58 | 
            +
                    def call opts = {}
         | 
| 59 | 
            +
                      span_context = opts[:span_context]
         | 
| 60 | 
            +
                      return true if span_context && span_context.sampled?
         | 
| 61 | 
            +
                      @lock.synchronize do
         | 
| 62 | 
            +
                        time = @time_class.now.to_f
         | 
| 63 | 
            +
                        elapsed = time - @last_time
         | 
| 64 | 
            +
                        @last_time = time
         | 
| 65 | 
            +
                        @rng.rand <= elapsed * @qps
         | 
| 66 | 
            +
                      end
         | 
| 67 | 
            +
                    end
         | 
| 68 | 
            +
                  end
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                  # MaxQPS is an older, deprecated name for the RateLimiting sampler.
         | 
| 71 | 
            +
                  MaxQPS = RateLimiting
         | 
| 72 | 
            +
                end
         | 
| 73 | 
            +
              end
         | 
| 74 | 
            +
            end
         | 
| @@ -12,6 +12,7 @@ | |
| 12 12 | 
             
            # See the License for the specific language governing permissions and
         | 
| 13 13 | 
             
            # limitations under the License.
         | 
| 14 14 |  | 
| 15 | 
            +
             | 
| 15 16 | 
             
            module OpenCensus
         | 
| 16 17 | 
             
              module Trace
         | 
| 17 18 | 
             
                ##
         | 
| @@ -20,18 +21,23 @@ module OpenCensus | |
| 20 21 | 
             
                # or have a parent span, and may have zero or more children.
         | 
| 21 22 | 
             
                #
         | 
| 22 23 | 
             
                class Span
         | 
| 23 | 
            -
                  ## | 
| 24 | 
            +
                  ##
         | 
| 25 | 
            +
                  # A span kind, indicating the span kind is unspecified.
         | 
| 26 | 
            +
                  # @return [Symbol]
         | 
| 27 | 
            +
                  #
         | 
| 24 28 | 
             
                  SPAN_KIND_UNSPECIFIED = :SPAN_KIND_UNSPECIFIED
         | 
| 25 29 |  | 
| 26 30 | 
             
                  ##
         | 
| 27 | 
            -
                  #  | 
| 28 | 
            -
                  # remote network request.
         | 
| 31 | 
            +
                  # A span kind, indicating that the span covers server-side handling of an
         | 
| 32 | 
            +
                  # RPC or other remote network request.
         | 
| 33 | 
            +
                  # @return [Symbol]
         | 
| 29 34 | 
             
                  #
         | 
| 30 35 | 
             
                  SERVER = :SERVER
         | 
| 31 36 |  | 
| 32 37 | 
             
                  ##
         | 
| 33 | 
            -
                  #  | 
| 34 | 
            -
                  # or other remote request.
         | 
| 38 | 
            +
                  # A span kind, indicating that the span covers the client-side wrapper
         | 
| 39 | 
            +
                  # around an RPC or other remote request.
         | 
| 40 | 
            +
                  # @return [Symbol]
         | 
| 35 41 | 
             
                  #
         | 
| 36 42 | 
             
                  CLIENT = :CLIENT
         | 
| 37 43 |  | 
| @@ -12,39 +12,62 @@ | |
| 12 12 | 
             
            # See the License for the specific language governing permissions and
         | 
| 13 13 | 
             
            # limitations under the License.
         | 
| 14 14 |  | 
| 15 | 
            +
             | 
| 15 16 | 
             
            module OpenCensus
         | 
| 16 17 | 
             
              module Trace
         | 
| 17 18 | 
             
                ##
         | 
| 18 19 | 
             
                # Span represents a single span within a request trace.
         | 
| 19 20 | 
             
                #
         | 
| 20 21 | 
             
                class SpanBuilder
         | 
| 21 | 
            -
                  ## | 
| 22 | 
            +
                  ##
         | 
| 23 | 
            +
                  # This value may be used as an event type or a link type, and indicates
         | 
| 24 | 
            +
                  # that the type is unknown.
         | 
| 25 | 
            +
                  # @return [Symbol]
         | 
| 26 | 
            +
                  #
         | 
| 22 27 | 
             
                  TYPE_UNSPECIFIED = :TYPE_UNSPECIFIED
         | 
| 23 28 |  | 
| 24 | 
            -
                  ## | 
| 29 | 
            +
                  ##
         | 
| 30 | 
            +
                  # An event type, indicating a sent message.
         | 
| 31 | 
            +
                  # @return [Symbol]
         | 
| 32 | 
            +
                  #
         | 
| 25 33 | 
             
                  SENT = :SENT
         | 
| 26 34 |  | 
| 27 | 
            -
                  ## | 
| 35 | 
            +
                  ##
         | 
| 36 | 
            +
                  # An event type, indicating a received message.
         | 
| 37 | 
            +
                  # @return [Symbol]
         | 
| 38 | 
            +
                  #
         | 
| 28 39 | 
             
                  RECEIVED = :RECEIVED
         | 
| 29 40 |  | 
| 30 | 
            -
                  ## | 
| 41 | 
            +
                  ##
         | 
| 42 | 
            +
                  # A link type, indicating the linked span is a child of the current span.
         | 
| 43 | 
            +
                  # @return [Symbol]
         | 
| 44 | 
            +
                  #
         | 
| 31 45 | 
             
                  CHILD_LINKED_SPAN = :CHILD_LINKED_SPAN
         | 
| 32 46 |  | 
| 33 | 
            -
                  ## | 
| 47 | 
            +
                  ##
         | 
| 48 | 
            +
                  # A link type, indicating the linked span is a parent of the current span.
         | 
| 49 | 
            +
                  # @return [Symbol]
         | 
| 50 | 
            +
                  #
         | 
| 34 51 | 
             
                  PARENT_LINKED_SPAN = :PARENT_LINKED_SPAN
         | 
| 35 52 |  | 
| 36 | 
            -
                  ## | 
| 53 | 
            +
                  ##
         | 
| 54 | 
            +
                  # A span kind, indicating that the span is either neither a server nor
         | 
| 55 | 
            +
                  # a client, or is unknown.
         | 
| 56 | 
            +
                  # @return [Symbol]
         | 
| 57 | 
            +
                  #
         | 
| 37 58 | 
             
                  SPAN_KIND_UNSPECIFIED = :SPAN_KIND_UNSPECIFIED
         | 
| 38 59 |  | 
| 39 60 | 
             
                  ##
         | 
| 40 | 
            -
                  #  | 
| 41 | 
            -
                  # remote network request.
         | 
| 61 | 
            +
                  # A span kind, indicating that the span covers server-side handling of an
         | 
| 62 | 
            +
                  # RPC or other remote network request.
         | 
| 63 | 
            +
                  # @return [Symbol]
         | 
| 42 64 | 
             
                  #
         | 
| 43 65 | 
             
                  SERVER = :SERVER
         | 
| 44 66 |  | 
| 45 67 | 
             
                  ##
         | 
| 46 | 
            -
                  #  | 
| 47 | 
            -
                  # or other remote request.
         | 
| 68 | 
            +
                  # A span kind, indicating that the span covers the client-side wrapper
         | 
| 69 | 
            +
                  # around an RPC or other remote request.
         | 
| 70 | 
            +
                  # @return [Symbol]
         | 
| 48 71 | 
             
                  #
         | 
| 49 72 | 
             
                  CLIENT = :CLIENT
         | 
| 50 73 |  | 
| @@ -84,12 +107,14 @@ module OpenCensus | |
| 84 107 | 
             
                  end
         | 
| 85 108 |  | 
| 86 109 | 
             
                  ##
         | 
| 87 | 
            -
                  # Sampling decision for this span. | 
| 88 | 
            -
                  # span is first created. However, you can also change it after the fact.
         | 
| 110 | 
            +
                  # Sampling decision for this span.
         | 
| 89 111 | 
             
                  #
         | 
| 90 112 | 
             
                  # @return [boolean]
         | 
| 91 113 | 
             
                  #
         | 
| 92 | 
            -
                   | 
| 114 | 
            +
                  def sampled?
         | 
| 115 | 
            +
                    context.sampled?
         | 
| 116 | 
            +
                  end
         | 
| 117 | 
            +
                  alias sampled sampled?
         | 
| 93 118 |  | 
| 94 119 | 
             
                  ##
         | 
| 95 120 | 
             
                  # A description of the span's operation.
         | 
| @@ -108,8 +133,9 @@ module OpenCensus | |
| 108 133 | 
             
                  ##
         | 
| 109 134 | 
             
                  # The kind of span. Can be used to specify additional relationships
         | 
| 110 135 | 
             
                  # between spans in addition to a parent/child relationship.
         | 
| 111 | 
            -
                  # Valid values are  | 
| 112 | 
            -
                  #  | 
| 136 | 
            +
                  # Valid values are {OpenCensus::Trace::SpanBuilder::CLIENT},
         | 
| 137 | 
            +
                  # {OpenCensus::Trace::SpanBuilder::SERVER}, and
         | 
| 138 | 
            +
                  # {OpenCensus::Trace::SpanBuilder::SPAN_KIND_UNSPECIFIED}.
         | 
| 113 139 | 
             
                  #
         | 
| 114 140 | 
             
                  # This field is required.
         | 
| 115 141 | 
             
                  #
         | 
| @@ -135,7 +161,7 @@ module OpenCensus | |
| 135 161 | 
             
                  # the local machine where the span execution ends. On the server side,
         | 
| 136 162 | 
             
                  # this is the time when the server application handler stops running.
         | 
| 137 163 | 
             
                  #
         | 
| 138 | 
            -
                  # In Ruby, this is represented by a Time object in UTC, or `nil` if the
         | 
| 164 | 
            +
                  # In Ruby, this is represented by a `Time` object in UTC, or `nil` if the
         | 
| 139 165 | 
             
                  # starting timestamp has not yet been populated.
         | 
| 140 166 | 
             
                  #
         | 
| 141 167 | 
             
                  # @return [Time, nil]
         | 
| @@ -214,12 +240,14 @@ module OpenCensus | |
| 214 240 | 
             
                  # Add an event describing a message sent/received between spans.
         | 
| 215 241 | 
             
                  #
         | 
| 216 242 | 
             
                  # @param [Symbol] type The type of MessageEvent. Indicates whether the
         | 
| 217 | 
            -
                  #     message was sent or received. Valid values are | 
| 218 | 
            -
                  #      | 
| 243 | 
            +
                  #     message was sent or received. Valid values are
         | 
| 244 | 
            +
                  #     {OpenCensus::Trace::SpanBuilder::SENT},
         | 
| 245 | 
            +
                  #     {OpenCensus::Trace::SpanBuilder::RECEIVED}, and
         | 
| 246 | 
            +
                  #     {OpenCensus::Trace::SpanBuilder::TYPE_UNSPECIFIED}.
         | 
| 219 247 | 
             
                  # @param [Integer] id An identifier for the MessageEvent's message that
         | 
| 220 248 | 
             
                  #     can be used to match SENT and RECEIVED events. For example, this
         | 
| 221 249 | 
             
                  #     field could represent a sequence ID for a streaming RPC. It is
         | 
| 222 | 
            -
                  #     recommended to be unique within a  | 
| 250 | 
            +
                  #     recommended to be unique within a span. The valid range is 64-bit
         | 
| 223 251 | 
             
                  #     unsigned `(0..2^64-1)`
         | 
| 224 252 | 
             
                  # @param [Integer] uncompressed_size The number of uncompressed bytes
         | 
| 225 253 | 
             
                  #     sent or received.
         | 
| @@ -250,9 +278,10 @@ module OpenCensus | |
| 250 278 | 
             
                  # @param [String] span_id The unique identifier for a span within a trace.
         | 
| 251 279 | 
             
                  #     An 8-byte array expressed as 16 hex digits.
         | 
| 252 280 | 
             
                  # @param [Symbol] type The relationship of the current span relative to
         | 
| 253 | 
            -
                  #     the linked span. Valid values are | 
| 254 | 
            -
                  #      | 
| 255 | 
            -
                  #      | 
| 281 | 
            +
                  #     the linked span. Valid values are
         | 
| 282 | 
            +
                  #     {OpenCensus::Trace::SpanBuilder::CHILD_LINKED_SPAN},
         | 
| 283 | 
            +
                  #     {OpenCensus::Trace::SpanBuilder::PARENT_LINKED_SPAN}, and
         | 
| 284 | 
            +
                  #     {OpenCensus::Trace::SpanBuilder::TYPE_UNSPECIFIED}.
         | 
| 256 285 | 
             
                  # @param [String] attributes Key-value pairs providing additional
         | 
| 257 286 | 
             
                  #     properties of the link. Keys must be strings, and values are
         | 
| 258 287 | 
             
                  #     restricted to the same types as attributes (see #put_attribute).
         | 
| @@ -269,21 +298,33 @@ module OpenCensus | |
| 269 298 | 
             
                  # @param [Integer] code Status code as a 32-bit signed integer
         | 
| 270 299 | 
             
                  # @param [String] message A developer-facing error message, which should
         | 
| 271 300 | 
             
                  #     be in English.
         | 
| 301 | 
            +
                  #
         | 
| 272 302 | 
             
                  def set_status code, message = ""
         | 
| 273 303 | 
             
                    @status_code = code
         | 
| 274 304 | 
             
                    @status_message = message
         | 
| 275 305 | 
             
                    self
         | 
| 276 306 | 
             
                  end
         | 
| 277 307 |  | 
| 308 | 
            +
                  ##
         | 
| 309 | 
            +
                  # Set the optional final status for the span using an http status code.
         | 
| 310 | 
            +
                  #
         | 
| 311 | 
            +
                  # @param [Integer] code HTTP status code as a 32-bit signed integer
         | 
| 312 | 
            +
                  # @param [String] message A developer-facing error message, which should
         | 
| 313 | 
            +
                  #     be in English.
         | 
| 314 | 
            +
                  #
         | 
| 315 | 
            +
                  def set_http_status code, message = ""
         | 
| 316 | 
            +
                    set_status map_http_status(code), message
         | 
| 317 | 
            +
                  end
         | 
| 318 | 
            +
             | 
| 278 319 | 
             
                  ##
         | 
| 279 320 | 
             
                  # Set the stack trace for this span.
         | 
| 280 | 
            -
                  # You may call this in one of three ways:
         | 
| 281 321 | 
             
                  #
         | 
| 322 | 
            +
                  # You may call this in one of three ways:
         | 
| 282 323 | 
             
                  # *   Pass in no argument to use the caller's stack trace.
         | 
| 283 324 | 
             
                  # *   Pass in an integer to use the caller's stack trace, but skip
         | 
| 284 325 | 
             
                  #     additional stack frames.
         | 
| 285 | 
            -
                  # *   Pass in an explicit array of Thread::Backtrace::Location as
         | 
| 286 | 
            -
                  #     returned from Kernel#caller_locations
         | 
| 326 | 
            +
                  # *   Pass in an explicit array of `Thread::Backtrace::Location` as
         | 
| 327 | 
            +
                  #     returned from `Kernel#caller_locations`
         | 
| 287 328 | 
             
                  #
         | 
| 288 329 | 
             
                  # @param [Array<Thread::Backtrace::Location>, Integer] stack_trace
         | 
| 289 330 | 
             
                  #
         | 
| @@ -381,9 +422,8 @@ module OpenCensus | |
| 381 422 | 
             
                  #
         | 
| 382 423 | 
             
                  # @private
         | 
| 383 424 | 
             
                  #
         | 
| 384 | 
            -
                  def initialize span_context,  | 
| 425 | 
            +
                  def initialize span_context, skip_frames: 0
         | 
| 385 426 | 
             
                    @context = span_context
         | 
| 386 | 
            -
                    @sampled = sampled
         | 
| 387 427 | 
             
                    @name = ""
         | 
| 388 428 | 
             
                    @kind = SPAN_KIND_UNSPECIFIED
         | 
| 389 429 | 
             
                    @start_time = nil
         | 
| @@ -601,6 +641,23 @@ module OpenCensus | |
| 601 641 | 
             
                      tstr
         | 
| 602 642 | 
             
                    end
         | 
| 603 643 | 
             
                  end
         | 
| 644 | 
            +
             | 
| 645 | 
            +
                  private
         | 
| 646 | 
            +
             | 
| 647 | 
            +
                  def map_http_status http_status
         | 
| 648 | 
            +
                    case http_status
         | 
| 649 | 
            +
                    when 200..399 then Status::OK
         | 
| 650 | 
            +
                    when 400 then Status::INVALID_ARGUMENT
         | 
| 651 | 
            +
                    when 401 then Status::UNAUTHENTICATED
         | 
| 652 | 
            +
                    when 403 then Status::PERMISSION_DENIED
         | 
| 653 | 
            +
                    when 404 then Status::NOT_FOUND
         | 
| 654 | 
            +
                    when 429 then Status::RESOURCE_EXHAUSTED
         | 
| 655 | 
            +
                    when 501 then Status::UNIMPLEMENTED
         | 
| 656 | 
            +
                    when 503 then Status::UNAVAILABLE
         | 
| 657 | 
            +
                    when 504 then Status::DEADLINE_EXCEEDED
         | 
| 658 | 
            +
                    else Status::UNKNOWN
         | 
| 659 | 
            +
                    end
         | 
| 660 | 
            +
                  end
         | 
| 604 661 | 
             
                end
         | 
| 605 662 | 
             
              end
         | 
| 606 663 | 
             
            end
         |