7575class _UnresolvedTracingOptions (TypedDict ):
7676 """The ``MongoClient`` ``tracing`` option as validated from user input.
7777
78- ``query_text_max_length`` is None when the user set no value, which is
79- distinct from an explicit 0: None leaves the environment variable free to
80- supply a length, 0 turns ``db.query.text`` off outright. Short-lived, since
81- :func:`_resolve_tracing_options` runs while the client is being built.
78+ ``query_text_max_length`` is None when unset, which is distinct from an
79+ explicit 0: None lets the environment variable supply a length, 0 turns
80+ ``db.query.text`` off.
8281 """
8382
8483 enabled : bool
@@ -88,9 +87,8 @@ class _UnresolvedTracingOptions(TypedDict):
8887class TracingOptions (TypedDict ):
8988 """The ``MongoClient`` ``tracing`` option as a client holds it.
9089
91- Both fields have been through :func:`_resolve_tracing_options`, so they
92- account for the two environment variables and need no further
93- interpretation: ``query_text_max_length`` is an int of 0 or more.
90+ :func:`_resolve_tracing_options` has folded in the environment variables,
91+ so ``query_text_max_length`` is an int of 0 or more.
9492 """
9593
9694 enabled : bool
@@ -226,22 +224,8 @@ def _build_query_summary(command_name: str, dbname: str, collection: Optional[st
226224 return f"{ command_name } { dbname } "
227225
228226
229- # db.operation.name is the command name for nearly every operation, so `_Op`
230- # values (which are the wire names) carry straight through. These are the
231- # exceptions the spec's covered operations table names differently.
232- #
233- # "dropCollection" and "createCollection" are known deviations: their commands
234- # are "drop" and "create", and the table departs from its own command-name rule
235- # for no stated reason. The spec is expected to correct them, at which point
236- # both entries here go away, but the change alters an exported attribute value
237- # and so has to land on a major version boundary, in step with the other
238- # drivers and the spec's own fixtures.
239- #
240- # "dropSearchIndexes" is ours, not the spec's: the command really is the
241- # singular "dropSearchIndex" and only our `_Op` member is plural.
242- #
243- # Operations absent from the table (rename, whose command is "renameCollection")
244- # have no agreed cross-driver name to match and keep their `_Op` value.
227+ # Spec operation names that differ from our `_Op` values. "dropCollection" and
228+ # "createCollection" contradict the spec's own command-name rule, unresolved.
245229_OPERATION_NAME_OVERRIDES = {
246230 "drop" : "dropCollection" ,
247231 "create" : "createCollection" ,
@@ -302,29 +286,18 @@ def start_command_span(
302286) -> Optional [Span ]:
303287 """Start and return a CLIENT-kind span for a server command, or None.
304288
305- Returns None in two cases. With tracing off the call is a no-op. With a
306- sensitive command it is not: the span is suppressed, mirroring the
307- redaction applied to logs, but the current operation span is still
308- backfilled from it, since that span needs the namespace and summary even
309- when the command itself gets no span.
310-
311- One span per wire-protocol message, so a retried operation produces one per
312- attempt. The span takes whichever operation span is current as its parent,
313- but is returned rather than made current itself, so nothing else nests
314- inside it. The caller holds it for the command's duration.
289+ Returns None when tracing is off, and for a sensitive command, which still
290+ backfills the current operation span before being suppressed. One span per
291+ wire-protocol message, returned rather than made current, so nothing nests
292+ inside it.
315293 """
316294 if not _is_tracing_enabled (tracing_options ):
317295 return None
318296
319297 collection = _extract_collection_name (command_name , dbname , cmd )
320- # Backfill the operation span's name/namespace/summary from the command built
321- # inside it. Before the sensitive-command return below, since the operation
322- # span needs those attributes even when the command gets no span. This runs
323- # once per attempt rather than once per operation: an attempt that fails
324- # before building a command never reaches here, so a retry can be where the
325- # operation span first learns its namespace. Repeating it costs a few
326- # attribute writes and is otherwise a no-op, since every attempt of one
327- # operation carries the same namespace.
298+ # Runs per attempt, not per operation: an attempt that fails before building
299+ # a command never reaches here, so a retry may be where the span learns its
300+ # namespace.
328301 current_operation = _CURRENT_OPERATION_NAME .get ()
329302 if current_operation is not None :
330303 current_span = trace .get_current_span ()
0 commit comments