Sha256: 8ef7a6fc75f986764c08aa7cd0f348c1c856394107ace8a898938d8db4a010b6

Contents?: true

Size: 1.04 KB

Versions: 30

Compression:

Stored size: 1.04 KB

Contents

# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2021

module Instana
  class Mongo
    REMOVED_COMMAND_ELEMENTS = %w[lsid $db documents].freeze

    def initialize
      @requests = {}
    end

    def started(event)
      tags = {
        namespace: event.database_name,
        command: event.command_name,
        peer: {
          hostname: event.address.host,
          port: event.address.port
        },
        json: filter_statement(event.command)
      }

      @requests[event.request_id] = ::Instana.tracer.log_async_entry(:mongo, {mongo: tags})
    end

    def failed(event)
      span = @requests.delete(event.request_id)
      span.add_error(Exception.new(event.message))

      ::Instana.tracer.log_async_exit(:mongo, {}, span)
    end

    def succeeded(event)
      span = @requests.delete(event.request_id)
      ::Instana.tracer.log_async_exit(:mongo, {}, span)
    end

    private

    def filter_statement(command)
      command.delete_if { |k, _| REMOVED_COMMAND_ELEMENTS.include?(k) }

      JSON.dump(command)
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
instana-1.217.1 lib/instana/instrumentation/mongo.rb
instana-1.217.0 lib/instana/instrumentation/mongo.rb
instana-1.216.0 lib/instana/instrumentation/mongo.rb
instana-1.215.1 lib/instana/instrumentation/mongo.rb
instana-1.215.0 lib/instana/instrumentation/mongo.rb
instana-1.214.4 lib/instana/instrumentation/mongo.rb
instana-1.214.3 lib/instana/instrumentation/mongo.rb
instana-1.214.2 lib/instana/instrumentation/mongo.rb
instana-1.214.1 lib/instana/instrumentation/mongo.rb
instana-1.214.0 lib/instana/instrumentation/mongo.rb
instana-1.213.3 lib/instana/instrumentation/mongo.rb
instana-1.213.2 lib/instana/instrumentation/mongo.rb
instana-1.213.1 lib/instana/instrumentation/mongo.rb
instana-1.213.0 lib/instana/instrumentation/mongo.rb
instana-1.212.0 lib/instana/instrumentation/mongo.rb
instana-1.211.0 lib/instana/instrumentation/mongo.rb
instana-1.210.1 lib/instana/instrumentation/mongo.rb
instana-1.210.0 lib/instana/instrumentation/mongo.rb
instana-1.209.8 lib/instana/instrumentation/mongo.rb
instana-1.209.7 lib/instana/instrumentation/mongo.rb