Skip to content

RUBY-3952 Cache tracing values that do not change - #3126

Merged
comandeo-mongo merged 2 commits into
mongodb:masterfrom
comandeo-mongo:3952-otel-caches-pr
Nov 4, 2026
Merged

comandeo-mongo merged 2 commits into
mongodb:masterfrom
comandeo-mongo:3952-otel-caches-pr

Conversation

@comandeo-mongo

Copy link
Copy Markdown
Contributor

The tracers rebuilt the same values for every operation and command: connection attributes, the lsid string, operation names and the transaction key. This builds each once and reuses it, as the OpenTelemetry spec's guidelines in mongodb/specifications#1986 suggest. The caches that more than one thread can write are guarded by a mutex, and the lsid cache is bounded. Recorded spans look the same as before. Follows #3124.

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

The tracers rebuilt the same values on every operation and command:
the connection attributes, the lsid string, the operation name and the
transaction key. Build each once and reuse it, as the OpenTelemetry
spec's performance guidelines recommend: connection attributes per
connection, lsid strings in a small bounded cache, operation names per
class, and the transaction key per transaction. The caches that more
than one thread can write are guarded by a mutex.
@comandeo-mongo
comandeo-mongo marked this pull request as ready for review November 3, 2026 09:51
@comandeo-mongo
comandeo-mongo requested a review from a team as a code owner November 3, 2026 09:51
@comandeo-mongo
comandeo-mongo requested a review from jamis November 3, 2026 09:51
The tracer stored the connection attributes and the transaction key
in instance variables of Connection and Session that those classes
did not declare, through instance_variable_get and _set. Declare them
as private accessors on the classes that own the state, so they are
visible where the objects are defined.

@jamis jamis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

@comandeo-mongo
comandeo-mongo merged commit e212395 into mongodb:master Nov 4, 2026
238 of 241 checks passed
@comandeo-mongo
comandeo-mongo deleted the 3952-otel-caches-pr branch November 4, 2026 12:28
@jamis jamis added the bug label Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants