Skip to content

RUBY-3952 Reduce OpenTelemetry tracing overhead - #3122

Closed
comandeo-mongo wants to merge 11 commits into
mongodb:masterfrom
comandeo-mongo:3952-otel-tracing-overhead
Closed

comandeo-mongo wants to merge 11 commits into
mongodb:masterfrom
comandeo-mongo:3952-otel-tracing-overhead

Conversation

@comandeo-mongo

Copy link
Copy Markdown
Contributor

Tracing cost up to 26% of throughput on small-document tasks, mostly from building span attributes before the driver knew whether the span would be recorded. This follows the guidelines in mongodb/specifications#1986: spans start with a small set of cheap attributes, spans with an invalid context get no work at all, and spans that aren't recording get no more attributes and no outcome. Values that don't change are cached. The benchmark from #3121 measures the result.

Recorded spans now take db.mongodb.server_connection_id from the command's own connection instead of the monitoring connection. db.operation.summary stays in the operation span's creation set because in Ruby it is the span name, which is built anyway.

Jira: https://jira.mongodb.org/browse/RUBY-3952

The command span read db.mongodb.server_connection_id from the server
description, which comes from the monitoring connection's hello, not
from the connection the command ran on. Since connection attributes are
now cached per connection, that wrong value was also frozen for the
connection's lifetime. Use the connection's own description, as command
monitoring already does.
The OpenTelemetry spec's performance guidelines now say that a span
that is not recording is still made current but gets no outcome, and
that a span with an invalid context gets no work at all.

Error attributes, exceptions, the error status and the reply's cursor
id were still recorded on non-recording spans, and invalid spans were
still finished because the early return ran inside the method's
rescue and ensure. Move the span work into a helper so that an invalid
context returns before it, and gate the outcome on recording?.
CommandTracer includes Secure, which now defines the same
HELLO_COMMANDS. process_cursor_context defaulted its recording flag to
true, so a caller that left it out would record attributes on a span
that is not recording.
@comandeo-mongo
comandeo-mongo marked this pull request as ready for review October 29, 2026 12:56
@comandeo-mongo
comandeo-mongo requested a review from a team as a code owner October 29, 2026 12:56
@comandeo-mongo
comandeo-mongo requested a review from jamis October 29, 2026 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant