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
- LSID_CACHE_MAX =
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.
Upper bound of the lsid string cache (see #lsid).
128
Constants included from Monitoring::Event::Secure
Monitoring::Event::Secure::HELLO_COMMANDS, 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.
36 37 38 39 40 41 42 |
# File 'lib/mongo/tracing/open_telemetry/command_tracer.rb', line 36 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 @lsid_cache = {} @lsid_cache_mutex = Mutex.new 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.
49 |
# File 'lib/mongo/tracing/open_telemetry/command_tracer.rb', line 49 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.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/mongo/tracing/open_telemetry/command_tracer.rb', line 65 def trace_command(, _operation_context, connection, &block) # Read the command document and name once and pass them on: every # read of message.documents allocates. doc = .documents.first name = command_name(doc) return yield if skip_tracing?(doc, name) # 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(name, doc, connection) # With no SDK and no valid parent, the API returns a span with an # invalid context. It cannot be made current, recorded or # propagated, so it gets no work at all, not even finishing it. return yield unless span.context.valid? trace_with_span(span, , name, doc, &block) end |