Skip to content

Commit

Permalink
feat: allow SQL caller logging to be enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Nov 24, 2021
1 parent 27d5948 commit 861d8f2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def self.included(anyway_config)
database_sslmode: nil,
sql_log_level: :debug,
sql_log_warn_duration: 5,
sql_enable_caller_logging: false,
database_max_connections: nil,
database_pool_timeout: 5,
database_connect_max_retries: 0,
Expand All @@ -36,6 +37,7 @@ def database_configuration
encoding: "utf8",
sslmode: database_sslmode,
sql_log_level: sql_log_level,
enable_caller_logging: sql_enable_caller_logging,
log_warn_duration: sql_log_warn_duration,
max_connections: database_max_connections,
pool_timeout: database_pool_timeout,
Expand Down
6 changes: 4 additions & 2 deletions lib/pact_broker/initializers/database_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def self.create_database_connection(config, logger = nil)
sequel_config = config.dup
max_retries = sequel_config.delete(:connect_max_retries) || 0
connection_validation_timeout = config.delete(:connection_validation_timeout)
enable_caller_logging = config.delete(:enable_caller_logging)
configure_logger(sequel_config, logger)
create_sqlite_database_dir(config)

Expand All @@ -18,7 +19,7 @@ def self.create_database_connection(config, logger = nil)

logger&.info "Connected to database #{sequel_config[:database]}"

configure_connection(connection, connection_validation_timeout)
configure_connection(connection, connection_validation_timeout, enable_caller_logging)
end

private_class_method def self.with_retries(max_retries, logger)
Expand Down Expand Up @@ -72,8 +73,9 @@ def self.create_database_connection(config, logger = nil)
# when databases are restarted and connections are killed. This has a performance
# penalty, so consider increasing this timeout if building a frequently accessed service.

private_class_method def self.configure_connection(connection, connection_validation_timeout)
private_class_method def self.configure_connection(connection, connection_validation_timeout, enable_caller_logging)
connection.extension(:connection_validator)
connection.extension(:caller_logging) if enable_caller_logging
connection.pool.connection_validation_timeout = connection_validation_timeout if connection_validation_timeout
connection
end
Expand Down

0 comments on commit 861d8f2

Please sign in to comment.