Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Redshift active record adapter #3032

Merged
merged 6 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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, 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)
tannalynn marked this conversation as resolved.
Show resolved Hide resolved

- **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)
Expand Down
3 changes: 2 additions & 1 deletion lib/new_relic/agent/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ module InstanceIdentification

'postgresql' => :postgres,
'jdbcpostgresql' => :postgres,
'postgis' => :postgres
'postgis' => :postgres,
'redshift' => :postgres
}.freeze

DATASTORE_DEFAULT_PORTS = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]}")
Copy link
Contributor Author

@tannalynn tannalynn Jan 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this rescue here just for extra safety.

I don't think redshift adapters are going to have issues with this, BUT it's also possible people might DIY a redshift adapter, plus there is no way for us to test them all bc there are a lot. So I added this rescue and log message so if an adapter does cause problems, it won't prevent the segment from being created below, it'll simply be missing the info it wasn't able to grab. (and it would have been missing that info anyways since redshift wasn't previously on the adapter list)

tannalynn marked this conversation as resolved.
Show resolved Hide resolved
end

segment = Tracer.start_datastore_segment(product: product,
Expand Down
7 changes: 7 additions & 0 deletions test/new_relic/agent/database_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading