Sha256: 179b230a954cd337c23297ea7b7d7ffc21dc97600d4b82c0af83163b41883116

Contents?: true

Size: 1.59 KB

Versions: 27

Compression:

Stored size: 1.59 KB

Contents

# frozen_string_literal: true

require_relative "span"

module Datadog
  module CI
    # Represents a single part of a test run that can be safely shared between threads.
    # Examples of shared objects are: TestSession, TestModule, TestSpan.
    #
    # @public_api
    class ConcurrentSpan < Span
      def initialize(tracer_span)
        super

        # we use Monitor instead of Mutex because it is reentrant
        @mutex = Monitor.new
      end

      # Gets tag value by key. This method is thread-safe.
      # @param [String] key the key of the tag.
      # @return [String] the value of the tag.
      def get_tag(key)
        synchronize { super }
      end

      # Sets tag value by key. This method is thread-safe.
      # @param [String] key the key of the tag.
      # @param [String] value the value of the tag.
      # @return [void]
      def set_tag(key, value)
        synchronize { super }
      end

      # Sets metric value by key. This method is thread-safe.
      # @param [String] key the key of the metric.
      # @param [Numeric] value the value of the metric.
      # @return [void]
      def set_metric(key, value)
        synchronize { super }
      end

      # Finishes the span. This method is thread-safe.
      # @return [void]
      def finish
        synchronize { super }
      end

      # Sets multiple tags at once. This method is thread-safe.
      # @param [Hash[String, String]] tags the tags to set.
      # @return [void]
      def set_tags(tags)
        synchronize { super }
      end

      def synchronize
        @mutex.synchronize { yield }
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
datadog-ci-1.14.0 lib/datadog/ci/concurrent_span.rb
datadog-ci-1.13.0 lib/datadog/ci/concurrent_span.rb
datadog-ci-1.12.0 lib/datadog/ci/concurrent_span.rb
datadog-ci-1.11.0 lib/datadog/ci/concurrent_span.rb
datadog-ci-1.10.0 lib/datadog/ci/concurrent_span.rb
datadog-ci-1.9.0 lib/datadog/ci/concurrent_span.rb
datadog-ci-1.8.1 lib/datadog/ci/concurrent_span.rb
datadog-ci-1.8.0 lib/datadog/ci/concurrent_span.rb
datadog-ci-1.7.0 lib/datadog/ci/concurrent_span.rb
datadog-ci-1.6.0 lib/datadog/ci/concurrent_span.rb
datadog-ci-1.5.0 lib/datadog/ci/concurrent_span.rb
datadog-ci-1.4.1 lib/datadog/ci/concurrent_span.rb
datadog-ci-1.4.0 lib/datadog/ci/concurrent_span.rb
datadog-ci-1.3.0 lib/datadog/ci/concurrent_span.rb
datadog-ci-1.2.0 lib/datadog/ci/concurrent_span.rb
datadog-ci-1.1.0 lib/datadog/ci/concurrent_span.rb
datadog-ci-1.0.1 lib/datadog/ci/concurrent_span.rb
datadog-ci-1.0.0 lib/datadog/ci/concurrent_span.rb
datadog-ci-1.0.0.beta6 lib/datadog/ci/concurrent_span.rb
datadog-ci-1.0.0.beta3 lib/datadog/ci/concurrent_span.rb