-
Notifications
You must be signed in to change notification settings - Fork 598
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
Kinesis instrumentation #2974
Draft
hannahramadan
wants to merge
5
commits into
dev
Choose a base branch
from
kinesis_instrumentation
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+694
−0
Draft
Kinesis instrumentation #2974
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
28c8b5f
WIP: base instrumentation and tests
hannahramadan 308f730
Tests and things
hannahramadan 79cf8e4
Merge branch 'dev' into kinesis_instrumentation
hannahramadan cb65b75
Wire up account_id for ARN
hannahramadan 202538a
Rubocop - trailing whitespace
hannahramadan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# This file is distributed under New Relic's license terms. | ||
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details. | ||
# frozen_string_literal: true | ||
|
||
require_relative 'kinesis/instrumentation' | ||
require_relative 'kinesis/chain' | ||
require_relative 'kinesis/prepend' | ||
|
||
DependencyDetection.defer do | ||
named :kinesis | ||
|
||
depends_on do | ||
defined?(Aws::Kinesis::Client) | ||
end | ||
executes do | ||
if use_prepend? | ||
prepend_instrument Aws::Kinesis::Client, NewRelic::Agent::Instrumentation::Kinesis::Prepend | ||
else | ||
chain_instrument NewRelic::Agent::Instrumentation::Kinesis::Chain | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# This file is distributed under New Relic's license terms. | ||
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details. | ||
# frozen_string_literal: true | ||
|
||
module NewRelic::Agent::Instrumentation | ||
module Kinesis::Chain | ||
def self.instrument! | ||
::Aws::Kinesis::Client.class_eval do | ||
include NewRelic::Agent::Instrumentation::Kinesis | ||
|
||
NewRelic::Agent::Instrumentation::Kinesis::INSTRUMENTED_METHODS.each do |method_name| | ||
alias_method("#{method_name}_without_new_relic".to_sym, method_name.to_sym) | ||
|
||
define_method(method_name) do |*args| | ||
instrument_method_with_new_relic(method_name, *args) { send("#{method_name}_without_new_relic".to_sym, *args) } | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
71 changes: 71 additions & 0 deletions
71
lib/new_relic/agent/instrumentation/kinesis/instrumentation.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# This file is distributed under New Relic's license terms. | ||
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details. | ||
# frozen_string_literal: true | ||
|
||
module NewRelic::Agent::Instrumentation | ||
module Kinesis | ||
INSTRUMENTED_METHODS = %w[ | ||
add_tags_to_stream | ||
create_stream | ||
decrease_stream_retention_period | ||
delete_stream | ||
describe_limits | ||
describe_stream | ||
disable_enhanced_monitoring | ||
enable_enhanced_monitoring | ||
get_records | ||
get_shard_iterator | ||
increase_stream_retention_period | ||
list_streams | ||
list_tags_for_stream | ||
merge_shards | ||
put_record | ||
put_records | ||
remove_tags_from_stream | ||
split_shard | ||
update_shard_count | ||
].freeze | ||
|
||
KINESIS = 'Kinesis' | ||
AWS_KINESIS_DATA_STREAMS = 'aws_kinesis_data_streams' | ||
|
||
def instrument_method_with_new_relic(method_name, *args) | ||
return yield unless NewRelic::Agent::Tracer.tracing_enabled? | ||
|
||
NewRelic::Agent.record_instrumentation_invocation(KINESIS) | ||
|
||
params = args[0] | ||
segment = NewRelic::Agent::Tracer.start_segment(name: segment_name(method_name, params)) | ||
arn = get_arn(params) if params | ||
segment&.add_agent_attribute('cloud.resource_id', arn) if arn | ||
|
||
begin | ||
NewRelic::Agent::Tracer.capture_segment_error(segment) { yield } | ||
ensure | ||
segment&.add_agent_attribute('cloud.platform', AWS_KINESIS_DATA_STREAMS) | ||
segment&.add_agent_attribute('name', segment_name(method_name, params)) | ||
segment&.finish | ||
end | ||
end | ||
|
||
def segment_name(method_name, params) | ||
return "#{KINESIS}/#{method_name}/#{params[:stream_name]}" if params&.dig(:stream_name) | ||
|
||
"#{KINESIS}/#{method_name}" | ||
rescue => e | ||
NewRelic::Agent.logger.warn("Failed to create segment name: #{e}") | ||
end | ||
|
||
def nr_account_id | ||
return @nr_account_id if defined?(@nr_account_id) | ||
|
||
@nr_account_id = NewRelic::Agent::Aws.get_account_id(config) | ||
end | ||
|
||
def get_arn(params) | ||
return params[:stream_arn] if params[:stream_arn] | ||
|
||
NewRelic::Agent::Aws.create_arn(KINESIS.downcase, "stream/#{params[:stream_name]}", config&.region, nr_account_id) if params[:stream_name] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# This file is distributed under New Relic's license terms. | ||
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details. | ||
# frozen_string_literal: true | ||
|
||
module NewRelic::Agent::Instrumentation | ||
module Kinesis::Prepend | ||
include NewRelic::Agent::Instrumentation::Kinesis | ||
|
||
INSTRUMENTED_METHODS.each do |method_name| | ||
define_method(method_name) do |*args| | ||
instrument_method_with_new_relic(method_name, *args) { super(*args) } | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# This file is distributed under New Relic's license terms. | ||
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details. | ||
# frozen_string_literal: true | ||
|
||
instrumentation_methods :chain, :prepend | ||
|
||
gemfile <<~RB | ||
gem 'aws-sdk-kinesis' | ||
RB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
development: | ||
error_collector: | ||
enabled: true | ||
apdex_t: 0.5 | ||
monitor_mode: true | ||
license_key: bootstrap_newrelic_admin_license_key_000 | ||
instrumentation: | ||
kinesis: <%= $instrumentation_method %> | ||
app_name: test | ||
log_level: debug | ||
host: 127.0.0.1 | ||
api_host: 127.0.0.1 | ||
transaction_trace: | ||
record_sql: obfuscated | ||
enabled: true | ||
stack_trace_threshold: 0.5 | ||
transaction_threshold: 1.0 | ||
capture_params: false |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
James had a question about the consistency of our aws sdk config options. For most of our
instrumentation.*
configs, the snake cased name of the gem is used. However, we're not consistent with our AWS configs. Some are snake case, others are just smaller portions of the name, likeinstrumentation.dynamodb
. Do we want to establish more consistency? What do you think about using the gem name vs. the AWS service name?