module NewRelic::Agent::Instrumentation::AwsSdkLambda
Constants
- AWS_SERVICE
- CLOUD_PLATFORM
- INSTRUMENTATION_NAME
- WRAPPED_RESPONSE
Public Instance Methods
Source
# File lib/new_relic/agent/instrumentation/aws_sdk_lambda/instrumentation.rb, line 18 def invoke_async_with_new_relic(*args) with_tracing(:invoke_async, *args) { yield } end
Source
# File lib/new_relic/agent/instrumentation/aws_sdk_lambda/instrumentation.rb, line 14 def invoke_with_new_relic(*args) with_tracing(:invoke, *args) { yield } end
Source
# File lib/new_relic/agent/instrumentation/aws_sdk_lambda/instrumentation.rb, line 22 def invoke_with_response_stream_with_new_relic(*args) with_tracing(:invoke_with_response_stream, *args) { yield } end
Private Instance Methods
Source
# File lib/new_relic/agent/instrumentation/aws_sdk_lambda/instrumentation.rb, line 83 def aws_arn(function, region) NewRelic::Agent::Aws.create_arn(AWS_SERVICE, "function:#{function}", region, nr_account_id) end
Source
# File lib/new_relic/agent/instrumentation/aws_sdk_lambda/instrumentation.rb, line 79 def aws_region config&.region if self.respond_to?(:config) end
Source
# File lib/new_relic/agent/instrumentation/aws_sdk_lambda/instrumentation.rb, line 75 def function_name(options = {}) (options.fetch(:function_name, nil) if options.respond_to?(:fetch)) || NewRelic::UNKNOWN end
Source
# File lib/new_relic/agent/instrumentation/aws_sdk_lambda/instrumentation.rb, line 63 def generate_segment(action, options = {}) function = function_name(options) region = aws_region arn = aws_arn(function, region) segment = NewRelic::Agent::Tracer.start_segment(name: "Lambda/#{action}/#{function}") segment.add_agent_attribute('cloud.account.id', nr_account_id) segment.add_agent_attribute('cloud.platform', CLOUD_PLATFORM) segment.add_agent_attribute('cloud.region', region) segment.add_agent_attribute('cloud.resource_id', arn) if arn segment end
Source
# File lib/new_relic/agent/instrumentation/aws_sdk_lambda/instrumentation.rb, line 87 def nr_account_id return @nr_account_id if defined?(@nr_account_id) @nr_account_id = NewRelic::Agent::Aws.get_account_id(config) end
Source
# File lib/new_relic/agent/instrumentation/aws_sdk_lambda/instrumentation.rb, line 49 def process_function_error(response) function_error = response.function_error return unless function_error msg = "[#{function_error}]" payload = response.payload&.string if response.respond_to?(:payload) payload_hash = JSON.parse(payload) if payload msg = "#{msg} #{payload_hash['errorType']} - #{payload_hash['errorMessage']}" if payload_hash e = StandardError.new(msg) e.set_backtrace(payload_hash['stackTrace']) if payload_hash NewRelic::Agent.notice_error(e) end
notice error that was raised / unhandled by the function
Source
# File lib/new_relic/agent/instrumentation/aws_sdk_lambda/instrumentation.rb, line 42 def process_response(response, segment) process_function_error(response) if response.respond_to?(:function_error) rescue => e NewRelic::Agent.logger.error("Error processing aws-sdk-lambda invocation response: #{e}") end
Source
# File lib/new_relic/agent/instrumentation/aws_sdk_lambda/instrumentation.rb, line 28 def with_tracing(action, *args) segment = generate_segment(action, *args) # prevent additional instrumentation for things like Net::HTTP from # creating any segments that may appear as redundant / confusing NewRelic::Agent.disable_all_tracing do response = NewRelic::Agent::Tracer.capture_segment_error(segment) { yield } process_response(response, segment) response end ensure segment&.finish end