Class: Mongo::Tracing::OpenTelemetry::CommandTracer Private
- Inherits:
-
Object
- Object
- Mongo::Tracing::OpenTelemetry::CommandTracer
- 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.
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.
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.
31 32 33 34 35 |
# File 'lib/mongo/tracing/open_telemetry/command_tracer.rb', line 31 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.
42 |
# File 'lib/mongo/tracing/open_telemetry/command_tracer.rb', line 42 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
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/mongo/tracing/open_telemetry/command_tracer.rb', line 59 def trace_command(, _operation_context, connection) # 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 |