@@ -15,7 +15,7 @@ use std::net::TcpListener;
1515use std:: ops:: Deref ;
1616#[ cfg( feature = "bundled" ) ]
1717use std:: str:: FromStr ;
18- use tracing:: debug;
18+ use tracing:: { debug, instrument } ;
1919
2020use crate :: command:: psql:: PsqlBuilder ;
2121use crate :: Error :: { CreateDatabaseError , DatabaseExistsError , DropDatabaseError } ;
@@ -90,6 +90,7 @@ impl PostgreSQL {
9090 }
9191
9292 /// Get the [status](Status) of the PostgreSQL server
93+ #[ instrument( level = "debug" ) ]
9394 pub fn status ( & self ) -> Status {
9495 if self . is_running ( ) {
9596 Status :: Started
@@ -136,6 +137,7 @@ impl PostgreSQL {
136137 /// Set up the database by extracting the archive and initializing the database.
137138 /// If the installation directory already exists, the archive will not be extracted.
138139 /// If the data directory already exists, the database will not be initialized.
140+ #[ instrument]
139141 pub async fn setup ( & mut self ) -> Result < ( ) > {
140142 if !self . is_installed ( ) {
141143 self . install ( ) . await ?;
@@ -153,6 +155,7 @@ impl PostgreSQL {
153155 /// hash does not match the expected hash, an error will be returned. If the installation directory
154156 /// already exists, the archive will not be extracted. If the archive is not found, an error will be
155157 /// returned.
158+ #[ instrument]
156159 async fn install ( & mut self ) -> Result < ( ) > {
157160 debug ! ( "Starting installation process for version {}" , self . version) ;
158161
@@ -201,6 +204,7 @@ impl PostgreSQL {
201204
202205 /// Initialize the database in the data directory. This will create the necessary files and
203206 /// directories to start the database.
207+ #[ instrument]
204208 async fn initialize ( & mut self ) -> Result < ( ) > {
205209 if !self . settings . password_file . exists ( ) {
206210 let mut file = std:: fs:: File :: create ( & self . settings . password_file ) ?;
@@ -234,6 +238,7 @@ impl PostgreSQL {
234238
235239 /// Start the database and wait for the startup to complete.
236240 /// If the port is set to `0`, the database will be started on a random port.
241+ #[ instrument]
237242 pub async fn start ( & mut self ) -> Result < ( ) > {
238243 if self . settings . port == 0 {
239244 let listener = TcpListener :: bind ( ( "0.0.0.0" , 0 ) ) ?;
@@ -269,6 +274,7 @@ impl PostgreSQL {
269274 }
270275
271276 /// Stop the database gracefully (smart mode) and wait for the shutdown to complete.
277+ #[ instrument]
272278 pub async fn stop ( & self ) -> Result < ( ) > {
273279 debug ! (
274280 "Stopping database {}" ,
@@ -294,6 +300,7 @@ impl PostgreSQL {
294300 }
295301
296302 /// Create a new database with the given name.
303+ #[ instrument( skip( database_name) ) ]
297304 pub async fn create_database < S : AsRef < str > > ( & self , database_name : S ) -> Result < ( ) > {
298305 debug ! (
299306 "Creating database {} for {}:{}" ,
@@ -327,6 +334,7 @@ impl PostgreSQL {
327334 }
328335
329336 /// Check if a database with the given name exists.
337+ #[ instrument( skip( database_name) ) ]
330338 pub async fn database_exists < S : AsRef < str > > ( & self , database_name : S ) -> Result < bool > {
331339 debug ! (
332340 "Checking if database {} exists for {}:{}" ,
@@ -358,6 +366,7 @@ impl PostgreSQL {
358366 }
359367
360368 /// Drop a database with the given name.
369+ #[ instrument( skip( database_name) ) ]
361370 pub async fn drop_database < S : AsRef < str > > ( & self , database_name : S ) -> Result < ( ) > {
362371 debug ! (
363372 "Dropping database {} for {}:{}" ,
@@ -405,6 +414,7 @@ impl PostgreSQL {
405414
406415 #[ cfg( feature = "tokio" ) ]
407416 /// Execute a command and return the stdout and stderr as strings.
417+ #[ instrument( level = "debug" ) ]
408418 async fn execute_command < B : CommandBuilder > (
409419 & self ,
410420 command_builder : B ,
0 commit comments