Sha256: 06f6cf09ccb26f394865474a9e4e37bac5b59fd5460ec716796a01dbd2cbb4e9

Contents?: true

Size: 839 Bytes

Versions: 5

Compression:

Stored size: 839 Bytes

Contents

# typed: true
module Datadog
  module OpenTracer
    # OpenTracing adapter for thread local scopes
    class ThreadLocalScope < Scope
      attr_reader \
        :finish_on_close

      def initialize(
        manager:,
        span:,
        finish_on_close: true
      )
        super(manager: manager, span: span)
        @finish_on_close = finish_on_close
        @previous_scope = manager.active
      end

      # Mark the end of the active period for the current thread and Scope,
      # updating the ScopeManager#active in the process.
      #
      # NOTE: Calling close more than once on a single Scope instance leads to
      # undefined behavior.
      def close
        return unless equal?(manager.active)

        span.finish if finish_on_close
        manager.send(:set_scope, @previous_scope)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ddtrace-0.54.2 lib/ddtrace/opentracer/thread_local_scope.rb
ddtrace-0.54.1 lib/ddtrace/opentracer/thread_local_scope.rb
ddtrace-0.54.0 lib/ddtrace/opentracer/thread_local_scope.rb
ddtrace-0.53.0 lib/ddtrace/opentracer/thread_local_scope.rb
ddtrace-0.52.0 lib/ddtrace/opentracer/thread_local_scope.rb