File: scope.rb

package info (click to toggle)
ruby-jaeger-client 1.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 624 kB
  • sloc: ruby: 3,381; makefile: 6; sh: 4
file content (39 lines) | stat: -rw-r--r-- 1,005 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# frozen_string_literal: true

module Jaeger
  # Scope represents an OpenTracing Scope
  #
  # See http://www.opentracing.io for more information.
  class Scope
    def initialize(span, scope_stack, finish_on_close:)
      @span = span
      @scope_stack = scope_stack
      @finish_on_close = finish_on_close
      @closed = false
    end

    # Return the Span scoped by this Scope
    #
    # @return [Span]
    attr_reader :span

    # Close scope
    #
    # Mark the end of the active period for the current thread and Scope,
    # updating the ScopeManager#active in the process.
    def close
      raise "Tried to close already closed span: #{inspect}" if @closed

      @closed = true

      @span.finish if @finish_on_close
      removed_scope = @scope_stack.pop

      if removed_scope != self # rubocop:disable Style/GuardClause
        raise 'Removed non-active scope, ' \
              "removed: #{removed_scope.inspect}, "\
              "expected: #{inspect}"
      end
    end
  end
end