feat!: add global toggle for SQL trace-context annotation (default off) - #156
Merged
Conversation
set_annotation_enabled(false) makes annotate_sql a zero-cost pass-through, restoring prepared-statement reuse for all traffic at the cost of losing statement-level trace correlation. Intended to be set once at process startup from application configuration.
nicolasburtey
marked this pull request as ready for review
July 22, 2026 15:51
Annotation is now opt-in: annotate_sql is a pass-through until set_annotation_enabled(true) is called at process startup. Tests that exercise the annotated path enable it explicitly.
unsampled_span_is_not_annotated passed vacuously once annotation became disabled by default. Enable the flag explicitly so the test still verifies the sampling gate: an un-sampled span is never annotated even when annotation is on.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit a028246. Configure here.
Guard the global flag with an RAII helper that restores the default (disabled) on drop, and tolerate mutex poisoning from a previously panicked test instead of unwrap()-ing the lock.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Adds
sql_commenter::set_annotation_enabled(bool)— disabled by default (opt-in).While disabled (the default),
annotate_sqlis a zero-cost pass-through, soOneTimeExecutordelegates statements untouched: full sqlx prepared-statement reuse for all traffic. Callingset_annotation_enabled(true)once at process startup restores the traceparent annotation introduced in #154.Motivation: annotated statements are executed
persistent(false)— a server-side parse + plan per execution. Under stress-test load (obix outbox checkpoint churn ≈ 250UPDATE job_executions/s) that cost is significant; this makes annotation an explicit choice and gives operators a config lever to reclaim the cost without recompiling.lana-bank wires it to
tracing.annotate_sql_statementsin lana.yml (GaloyMoney/lana-bank#7452).Tests:
annotation_disabled_by_default_and_toggleablecovers the default and the toggle; a mutex serializes toggle-sensitive tests since the flag is global. Thetrace_annotationintegration test opts in explicitly.Note
Medium Risk
Breaking default: annotation is off unless configured, changing observability and DB execution characteristics for existing deployments that relied on implicit annotation.
Overview
SQL
traceparentcomments are now opt-in viasql_commenter::set_annotation_enabled/annotation_enabled, backed by a process-wide atomic flag that defaults to disabled.When the toggle is off,
annotate_sqlreturns the original SQL immediately (Cow::Borrowed), so executors keep full prepared-statement reuse and avoid per-execution parse/plan cost. Enabling it at startup restores sampled-span annotation behavior from the prior feature.Tests gain a mutex-serialized
AnnotationEnabledhelper for the global flag, a case for default-off plus toggle, and the Postgres integration test explicitly callsset_annotation_enabled(true)before exercising the end-to-end path.Reviewed by Cursor Bugbot for commit e724cdf. Bugbot is set up for automated code reviews on this repo. Configure here.