Class: Mongo::Tracing::OpenTelemetry::CommandTracer Private
- Inherits:
-
Object
- Object
- Mongo::Tracing::OpenTelemetry::CommandTracer
- Includes:
- Monitoring::Event::Secure
- Defined in:
- lib/mongo/tracing/open_telemetry/command_tracer.rb
Overview
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.
CommandTracer is responsible for tracing MongoDB server commands using OpenTelemetry.
Constant Summary collapse
- HELLO_COMMANDS =
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.
Commands for which a span MUST NOT be created. The OpenTelemetry spec requires drivers to skip command spans for sensitive commands listed in the Command Logging and Monitoring spec. We additionally skip hello / legacy hello in all forms — these are handshake/heartbeat traffic and would only add noise to traces.
%w[hello ismaster isMaster].freeze
Constants included from Monitoring::Event::Secure
Monitoring::Event::Secure::REDACTED_COMMANDS
Instance Method Summary collapse
-
#initialize(otel_tracer, parent_tracer, query_text_max_length: 0) ⇒ CommandTracer
constructor
private
Initializes a new CommandTracer.
-
#start_span(message, operation_context, connection) ⇒ Object
private
Starts a span for a MongoDB command.
-
#trace_command(message, _operation_context, connection) { ... } ⇒ Object
private
Trace a MongoDB command.
Methods included from Monitoring::Event::Secure
#compression_allowed?, #redacted, #sensitive?
Constructor Details
#initialize(otel_tracer, parent_tracer, query_text_max_length: 0) ⇒ CommandTracer
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.
Initializes a new CommandTracer.
40 41 42 43 44 |
# File 'lib/mongo/tracing/open_telemetry/command_tracer.rb', line 40 def initialize(otel_tracer, parent_tracer, query_text_max_length: 0) @otel_tracer = otel_tracer @parent_tracer = parent_tracer @query_text_max_length = query_text_max_length end |
Instance Method Details
#start_span(message, operation_context, connection) ⇒ Object
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.
Starts a span for a MongoDB command.
51 |
# File 'lib/mongo/tracing/open_telemetry/command_tracer.rb', line 51 def start_span(, operation_context, connection); end |
#trace_command(message, _operation_context, connection) { ... } ⇒ Object
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.
Trace a MongoDB command.
Creates an OpenTelemetry span for the command, capturing attributes such as command name, database name, collection name, server address, connection IDs, and optionally query text. The span is automatically nested under the current operation span and is finished when the command completes or fails.
rubocop:disable Lint/RescueException
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/mongo/tracing/open_telemetry/command_tracer.rb', line 68 def trace_command(, _operation_context, connection) return yield if skip_tracing?() # Commands should always be nested under their operation span, not directly under # the transaction span. Don't pass with_parent to use automatic parent resolution # from the currently active span (the operation span). span = create_command_span(, connection) ::OpenTelemetry::Trace.with_span(span) do |s, c| yield.tap do |result| process_command_result(result, cursor_id(), c, s) end end rescue Exception => e handle_command_exception(span, e) raise e ensure span&.finish end |