Module: NewRelic::Agent::Instrumentation::Firehose

Included in:
Firehose::Prepend
Defined in:
lib/new_relic/agent/instrumentation/aws_sdk_firehose/instrumentation.rb

Defined Under Namespace

Modules: Chain, Prepend

Constant Summary collapse

INSTRUMENTED_METHODS =
%w[
  create_delivery_stream
  delete_delivery_stream
  describe_delivery_stream
  list_delivery_streams
  list_tags_for_delivery_stream
  put_record
  put_record_batch
  start_delivery_stream_encryption
  stop_delivery_stream_encryption
  tag_delivery_stream
  untag_delivery_stream
  update_destination
].freeze
FIREHOSE =
'Firehose'
AWS_KINESIS_DELIVERY_STREAMS =
'aws_kinesis_delivery_streams'

Instance Method Summary collapse

Instance Method Details

#get_arn(params) ⇒ Object

[View source]

58
59
60
61
62
63
64
# File 'lib/new_relic/agent/instrumentation/aws_sdk_firehose/instrumentation.rb', line 58

def get_arn(params)
  stream_arn = params&.dig(:delivery_stream_arn)
  return stream_arn if stream_arn

  stream_name = params&.dig(:delivery_stream_name)
  NewRelic::Agent::Aws.create_arn(FIREHOSE.downcase, "deliverystream/#{stream_name}", config&.region, ) if stream_name
end

#get_segment_name(method_name, params) ⇒ Object

[View source]

43
44
45
46
47
48
49
50
# File 'lib/new_relic/agent/instrumentation/aws_sdk_firehose/instrumentation.rb', line 43

def get_segment_name(method_name, params)
  stream_name = params&.dig(:delivery_stream_name)
  return "#{FIREHOSE}/#{method_name}/#{stream_name}" if stream_name

  "#{FIREHOSE}/#{method_name}"
rescue => e
  NewRelic::Agent.logger.warn("Failed to create segment name: #{e}")
end

#instrument_method_with_new_relic(method_name, *args) ⇒ Object

[View source]

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/new_relic/agent/instrumentation/aws_sdk_firehose/instrumentation.rb', line 25

def instrument_method_with_new_relic(method_name, *args)
  return yield unless NewRelic::Agent::Tracer.tracing_enabled?

  NewRelic::Agent.record_instrumentation_invocation(FIREHOSE)

  params = args[0]
  segment = NewRelic::Agent::Tracer.start_segment(name: get_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_DELIVERY_STREAMS)
    segment&.finish
  end
end

#nr_account_idObject

[View source]

52
53
54
55
56
# File 'lib/new_relic/agent/instrumentation/aws_sdk_firehose/instrumentation.rb', line 52

def 
  return @nr_account_id if defined?(@nr_account_id)

  @nr_account_id = NewRelic::Agent::Aws.(config)
end