Sha256: a6faecbef7989843badda7e1ee158d7ce5efce23023de69e15f435c6b8aec948

Contents?: true

Size: 1.48 KB

Versions: 22

Compression:

Stored size: 1.48 KB

Contents

# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
# frozen_string_literal: true

module NewRelic
  #
  # This class allows the current transaction to be passed to a Thread so that nested segments can be created from the operations performed within the Thread's block.
  # To have the New Relic Ruby agent automatically trace all of your applications threads,
  # enable the +instrumentation.thread.tracing+ configuration option in your newrelic.yml.
  #
  # Note: disabling the configuration option +instrumentation.thread+ while using this class can cause incorrectly nested spans.
  #
  # @api public
  class TracedThread < Thread
    #
    # Creates a new Thread whose work will be traced by New Relic.
    # Use this class as a replacement for the native Thread class.
    # Example: Instead of using +Thread.new+, use:
    #
    #     NewRelic::TracedThread.new { execute_some_code }
    #
    # @api public
    def initialize(*args, &block)
      NewRelic::Agent.record_api_supportability_metric(:traced_thread)
      traced_block = create_traced_block(&block)
      super(*args, &traced_block)
    end

    def create_traced_block(&block)
      return block if NewRelic::Agent.config[:'instrumentation.thread.tracing'] # if this is on, don't double trace

      NewRelic::Agent::Tracer.thread_block_with_current_transaction(
        segment_name: 'Ruby/TracedThread',
        &block
      )
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
newrelic_rpm-9.17.0 lib/new_relic/traced_thread.rb
newrelic_rpm-9.16.1 lib/new_relic/traced_thread.rb
newrelic_rpm-9.16.0 lib/new_relic/traced_thread.rb
newrelic_rpm-9.15.0 lib/new_relic/traced_thread.rb
newrelic_rpm-9.14.0 lib/new_relic/traced_thread.rb
newrelic_rpm-9.13.0 lib/new_relic/traced_thread.rb
newrelic_rpm-9.12.0 lib/new_relic/traced_thread.rb
newrelic_rpm-9.11.0 lib/new_relic/traced_thread.rb
newrelic_rpm-9.10.2 lib/new_relic/traced_thread.rb
newrelic_rpm-9.10.1 lib/new_relic/traced_thread.rb
newrelic_rpm-9.10.0 lib/new_relic/traced_thread.rb
newrelic_rpm-9.9.0 lib/new_relic/traced_thread.rb
newrelic_rpm-9.8.0 lib/new_relic/traced_thread.rb
newrelic_rpm-9.7.1 lib/new_relic/traced_thread.rb
newrelic_rpm-9.7.0 lib/new_relic/traced_thread.rb
newrelic_rpm-9.6.0 lib/new_relic/traced_thread.rb
newrelic_rpm-9.5.0 lib/new_relic/traced_thread.rb
newrelic_rpm-9.4.2 lib/new_relic/traced_thread.rb
newrelic_rpm-9.4.1 lib/new_relic/traced_thread.rb
newrelic_rpm-9.4.0 lib/new_relic/traced_thread.rb