diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e1114222a..e931409cfa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,10 @@ When the agent is started within an [Agent Control](https://docs-preview.newrelic.com/docs/new-relic-agent-control) environment, a health check file will be created at the configured file location for every agent process. By default, this location is: '/newrelic/apm/health'. The health check files will be updated at the configured frequency, which defaults to every five seconds. [PR#2995](https://github.com/newrelic/newrelic-ruby-agent/pull/2995) +- **Feature: Add Redshift as recognized ActiveRecord adapter** + + When the agent does not recognize an ActiveRecord adapter, the host, port, and database name information is not added to the datastore span. Redshift will now be treated like PostgreSQL, and the agent will save the host, port, and database name on the span. [PR#3032](https://github.com/newrelic/newrelic-ruby-agent/pull/3032) + - **Feature: Add instrumentation for aws-sdk-kinesis** The agent now has instrumentation for the [aws-sdk-kinesis](https://rubygems.org/gems/aws-sdk-kinesis) gem. It will record message broker segments for `get_records`, `put_record`, and `put_records` operations. All other operations will record standard segments. [PR#2974](https://github.com/newrelic/newrelic-ruby-agent/pull/2974) diff --git a/lib/new_relic/agent/database.rb b/lib/new_relic/agent/database.rb index 174e364f7c..cf4c73fc1f 100644 --- a/lib/new_relic/agent/database.rb +++ b/lib/new_relic/agent/database.rb @@ -278,9 +278,10 @@ def append_sql(new_sql) MYSQL2_PREFIX = 'mysql2'.freeze SQLITE_PREFIX = 'sqlite'.freeze TRILOGY_PREFIX = 'trilogy'.freeze + REDSHIFT_PREFIX = 'redshift'.freeze def symbolized_adapter(adapter) - if adapter.start_with?(POSTGRES_PREFIX) || adapter == POSTGIS_PREFIX + if adapter.start_with?(POSTGRES_PREFIX) || adapter == POSTGIS_PREFIX || adapter == REDSHIFT_PREFIX :postgres elsif adapter == MYSQL_PREFIX :mysql diff --git a/lib/new_relic/agent/instrumentation/active_record_helper.rb b/lib/new_relic/agent/instrumentation/active_record_helper.rb index 8fa4939b56..014c75b609 100644 --- a/lib/new_relic/agent/instrumentation/active_record_helper.rb +++ b/lib/new_relic/agent/instrumentation/active_record_helper.rb @@ -225,7 +225,8 @@ module InstanceIdentification 'postgresql' => :postgres, 'jdbcpostgresql' => :postgres, - 'postgis' => :postgres + 'postgis' => :postgres, + 'redshift' => :postgres }.freeze DATASTORE_DEFAULT_PORTS = { diff --git a/lib/new_relic/agent/instrumentation/active_record_subscriber.rb b/lib/new_relic/agent/instrumentation/active_record_subscriber.rb index d455770c7d..9f0c3574c5 100644 --- a/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +++ b/lib/new_relic/agent/instrumentation/active_record_subscriber.rb @@ -116,10 +116,14 @@ def start_segment(config, payload) 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] + begin + 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 + rescue + NewRelic::Agent.logger.debug("Failed to retrieve ActiveRecord host, port, and database details for adapter: #{config && config[:adapter]}") end segment = Tracer.start_datastore_segment(product: product, diff --git a/test/new_relic/agent/database_test.rb b/test/new_relic/agent/database_test.rb index 26179b5872..5af2a7917b 100644 --- a/test/new_relic/agent/database_test.rb +++ b/test/new_relic/agent/database_test.rb @@ -52,6 +52,13 @@ def test_adapter_from_config_string_postgis assert_equal(:postgres, statement.adapter) end + def test_adapter_from_config_string_redshift + config = {:adapter => 'redshift'} + statement = NewRelic::Agent::Database::Statement.new('some query', config) + + assert_equal(:postgres, statement.adapter) + end + def test_adapter_from_config_trilogy config = {:adapter => 'trilogy'} statement = NewRelic::Agent::Database::Statement.new('some query', config)