Class: StackifyRubyAPM::Spies::DynamoDBSpy Private

Inherits:
Object
  • Object
show all
Defined in:
lib/stackify_apm/spies/dynamo_db.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

TYPE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

'db.dynamo.aws'.freeze

Instance Method Summary collapse

Instance Method Details

#installObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

rubocop:disable Metrics/CyclomaticComplexity



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/stackify_apm/spies/dynamo_db.rb', line 10

def install
  Aws::DynamoDB::Client.class_eval do
    # Alias all available operations
    api.operation_names.each do |operation_name|
      alias_method "#{operation_name}_without_apm", "#{operation_name}"

      define_method(operation_name) do |params = {}, options = {}|
        original_method = method("#{operation_name}_without_apm")
        return original_method.call(params, options) unless StackifyRubyAPM.current_transaction

        result = nil

        begin
          name = operation_name
          ctx = Span::Context.new(
            CATEGORY: 'Database',
            SUBCATEGORY: 'DynamoDB',
            ACTION: operation_name,
            URL: self.config.endpoint,
          )
        rescue Exception => e
          StackifyRubyAPM.agent.error "[DynamoDBSpy] Error: creating span context."
          StackifyRubyAPM.agent.error "[DynamoDBSpy] #{e.inspect}"
          return original_method.call(params, options)
        end

        StackifyRubyAPM.span name, TYPE, context: ctx do
          result = original_method.call(params, options)
          return result
        end
      end
    end
  end
end