Class: Mongo::Tracing::OpenTelemetry::OperationTracer Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/mongo/tracing/open_telemetry/operation_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.

OperationTracer is responsible for tracing MongoDB driver operations using OpenTelemetry.

Instance Method Summary collapse

Constructor Details

#initialize(otel_tracer, parent_tracer) ⇒ OperationTracer

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 OperationTracer.

Parameters:

  • otel_tracer (OpenTelemetry::Trace::Tracer)

    the OpenTelemetry tracer.

  • parent_tracer (Mongo::Tracing::OpenTelemetry::Tracer)

    the parent tracer for accessing shared context maps.



37
38
39
40
# File 'lib/mongo/tracing/open_telemetry/operation_tracer.rb', line 37

def initialize(otel_tracer, parent_tracer)
  @otel_tracer = otel_tracer
  @parent_tracer = parent_tracer
end

Instance Method Details

#trace_operation(operation, operation_context, op_name: nil) { ... } ⇒ 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 operation.

Creates an OpenTelemetry span for the operation, capturing attributes such as database name, collection name, operation name, and cursor ID. The span is finished automatically when the operation completes or fails.

rubocop:disable Lint/RescueException

Parameters:

  • operation (Mongo::Operation)

    the MongoDB operation to trace.

  • operation_context (Mongo::Operation::Context)

    the context of the operation.

  • op_name (String | nil) (defaults to: nil)

    an optional name for the operation. If nil, the operation class name is used.

Yields:

  • the block representing the operation to be traced.

Returns:

  • (Object)

    the result of the operation.



58
59
60
61
62
63
64
65
66
# File 'lib/mongo/tracing/open_telemetry/operation_tracer.rb', line 58

def trace_operation(operation, operation_context, op_name: nil, &block)
  span = create_operation_span(operation, operation_context, op_name)
  execute_with_span(span, operation, &block)
rescue Exception => e
  handle_span_exception(span, e)
  raise e
ensure
  span&.finish
end