RUBY-3612 OpenTelemetry#2957
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds OpenTelemetry tracing support to the MongoDB Ruby driver, enabling distributed tracing capabilities for MongoDB operations and commands following the OpenTelemetry semantic conventions for database instrumentation.
Key changes:
- New tracing infrastructure with
Mongo::Tracing::OpenTelemetry::Tracer,OperationTracer, andCommandTracerclasses - Integration of tracing into client, collection, database, and session operations
- Support for transaction span tracking and cursor context management
- Environment variable configuration for enabling tracing and query text capture
- Comprehensive test suite including unified spec tests for OpenTelemetry
Reviewed changes
Copilot reviewed 62 out of 62 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
lib/mongo/tracing.rb |
Main tracing module with factory method for creating tracers |
lib/mongo/tracing/open_telemetry/tracer.rb |
Core tracer implementation managing operation and command tracing |
lib/mongo/tracing/open_telemetry/operation_tracer.rb |
Tracer for driver-level operations with span attribute management |
lib/mongo/tracing/open_telemetry/command_tracer.rb |
Tracer for server commands with query text capture support |
lib/mongo/client.rb |
Client integration for tracer initialization and configuration |
lib/mongo/session.rb |
Transaction span lifecycle management |
lib/mongo/operation/shared/executable.rb |
Command tracing integration in operation execution |
lib/mongo/collection.rb |
Operation tracing for collection methods |
lib/mongo/collection/view/*.rb |
Tracing integration for view operations |
lib/mongo/index/view.rb |
Index operation tracing |
spec/support/tracing.rb |
Mock tracing infrastructure for testing |
spec/spec_tests/open_telemetry_spec.rb |
Unified spec test runner for OpenTelemetry |
spec/spec_tests/data/open_telemetry/**/*.yml |
Comprehensive test specifications |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
gemfiles/standard.rb
Outdated
| end | ||
| end | ||
|
|
||
| gem 'opentelemetry-api' |
There was a problem hiding this comment.
Is this necessary? It looks like opentelemetry-sdk declares opentelemtry-api as a dependency (here)
There was a problem hiding this comment.
Good point, thank you. Fixed.
| # | ||
| # @return [ String | nil ] the collection name, or nil if not applicable. | ||
| def collection_name(message) | ||
| case message.documents.first.keys.first |
There was a problem hiding this comment.
Will this be stable? Are we guaranteed that the first key will always be the name of the command? Though, honestly, I don't have any better ideas for how to extract the command name here...
Also, perhaps it would be clearer to use the #command_name method here, which has the same logic but also does #to_s.
There was a problem hiding this comment.
I could not find a concrete statement that the first key is always the command name; however, this is so for all the documented command.
| EXCLUDED_KEYS = %w[lsid $db $clusterTime signature].freeze | ||
|
|
||
| # Ellipsis for truncated query text. | ||
| ELLIPSES = '...' |
There was a problem hiding this comment.
"Ellipsis" (with an 'i') is a single set of three dots, e.g. '...'
"Ellipses" (with an 'e') is the plural, referring to multiple sets of three dots. E.g. "I really like ellipses... I use them everywhere..."
| ELLIPSES = '...' | |
| ELLIPSIS = '...' |
This PR introduces native support for OpenTelemetry tracing.
Summary
When the feature is enabled, Ruby driver traces driver operation and the corresponding server commands nested under the operation. Tracing can be enabled per
Mongo::Clientinstance (by setting thetracingoption totrue), or globally via theOTEL_RUBY_INSTRUMENTATION_MONGODB_ENABLEDenvironment variable.