Class: OpenTelemetry::Instrumentation::Mongo::CommandSerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/opentelemetry/instrumentation/mongo/command_serializer.rb

Overview

Serializes a Mongo command object to be added to the trace

Constant Summary collapse

MASK_VALUE =
'?'
ELLIPSES =
'...'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command) ⇒ CommandSerializer

Returns a new instance of CommandSerializer.



17
18
19
20
21
22
# File 'lib/opentelemetry/instrumentation/mongo/command_serializer.rb', line 17

def initialize(command)
  @command = command
  @command_name, @collection = command.first
  @collection = MASK_VALUE unless @collection.is_a?(String) || @collection.is_a?(Integer)
  @payload = {}
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



15
16
17
# File 'lib/opentelemetry/instrumentation/mongo/command_serializer.rb', line 15

def collection
  @collection
end

#commandObject (readonly)

Returns the value of attribute command.



15
16
17
# File 'lib/opentelemetry/instrumentation/mongo/command_serializer.rb', line 15

def command
  @command
end

#command_nameObject (readonly)

Returns the value of attribute command_name.



15
16
17
# File 'lib/opentelemetry/instrumentation/mongo/command_serializer.rb', line 15

def command_name
  @command_name
end

#payloadObject (readonly)

Returns the value of attribute payload.



15
16
17
# File 'lib/opentelemetry/instrumentation/mongo/command_serializer.rb', line 15

def payload
  @payload
end

Instance Method Details

#serializeObject



24
25
26
27
# File 'lib/opentelemetry/instrumentation/mongo/command_serializer.rb', line 24

def serialize
  build_payload
  payload.to_json.freeze unless payload.empty?
end