Module: NewRelic::Agent::Instrumentation::DynamoDB
- Included in:
- DynamoDB::Prepend
- Defined in:
- lib/new_relic/agent/instrumentation/dynamodb/instrumentation.rb
Defined Under Namespace
Constant Summary collapse
- INSTRUMENTED_METHODS =
%w[ create_table delete_item delete_table get_item put_item query scan update_item ].freeze
- PRODUCT =
'DynamoDB'
- DEFAULT_HOST =
'dynamodb.amazonaws.com'
Instance Method Summary collapse
- #build_request_with_new_relic(*args) ⇒ Object
- #get_arn(params) ⇒ Object
- #instrument_method_with_new_relic(method_name, *args) ⇒ Object
Instance Method Details
#build_request_with_new_relic(*args) ⇒ Object
48 49 50 |
# File 'lib/new_relic/agent/instrumentation/dynamodb/instrumentation.rb', line 48 def build_request_with_new_relic(*args) @nr_captured_request = yield end |
#get_arn(params) ⇒ Object
52 53 54 55 56 |
# File 'lib/new_relic/agent/instrumentation/dynamodb/instrumentation.rb', line 52 def get_arn(params) return unless params[:table_name] NewRelic::Agent::Aws.create_arn(PRODUCT.downcase, "table/#{params[:table_name]}", config&.region) end |
#instrument_method_with_new_relic(method_name, *args) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/new_relic/agent/instrumentation/dynamodb/instrumentation.rb', line 21 def instrument_method_with_new_relic(method_name, *args) return yield unless NewRelic::Agent::Tracer.tracing_enabled? NewRelic::Agent.record_instrumentation_invocation(PRODUCT) segment = NewRelic::Agent::Tracer.start_datastore_segment( product: PRODUCT, operation: method_name, host: config&.endpoint&.host || DEFAULT_HOST, port_path_or_id: config&.endpoint&.port, collection: args[0][:table_name] ) arn = get_arn(args[0]) segment&.add_agent_attribute('cloud.resource_id', arn) if arn @nr_captured_request = nil # clear request just in case begin NewRelic::Agent::Tracer.capture_segment_error(segment) { yield } ensure segment&.add_agent_attribute('aws.operation', method_name) segment&.add_agent_attribute('aws.requestId', @nr_captured_request&.context&.http_response&.headers&.[]('x-amzn-requestid')) segment&.add_agent_attribute('aws.region', config&.region) segment&.finish end end |