# File lib/new_relic/agent/instrumentation/active_record.rb, line 39
        def log_with_newrelic_instrumentation(*args, &block) #THREAD_LOCAL_ACCESS
          state = NewRelic::Agent::TransactionState.tl_get

          if !state.is_execution_traced?
            return log_without_newrelic_instrumentation(*args, &block)
          end

          sql, name, _ = args

          product, operation, collection = ActiveRecordHelper.product_operation_collection_for(
            NewRelic::Helper.correctly_encoded(name),
            NewRelic::Helper.correctly_encoded(sql),
            @config && @config[:adapter])

          host = nil
          port_path_or_id = nil
          database = nil

          if ActiveRecordHelper::InstanceIdentification.supported_adapter?(@config)
            host = ActiveRecordHelper::InstanceIdentification.host(@config)
            port_path_or_id = ActiveRecordHelper::InstanceIdentification.port_path_or_id(@config)
            database = @config && @config[:database]
          end

          segment = NewRelic::Agent::Transaction.start_datastore_segment(product, operation, collection, host, port_path_or_id, database)
          segment._notice_sql(sql, @config, EXPLAINER)

          begin
            log_without_newrelic_instrumentation(*args, &block)
          ensure
            segment.finish
          end
        end