current_query_name (db/query_context.py)

omnigent · omnigent/db/query_context.py · python · Apache-2.0
database

Context‑local helper for naming database queries for observability, using contextvars.

# Source: https://github.com/omnigent-ai/omnigent | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
# Provided via justclaw.it.com; keep this notice with the code.
"""Context-local names for database query observability."""

from __future__ import annotations

from collections.abc import Iterator
from contextlib import contextmanager
from contextvars import ContextVar

_current_query_name: ContextVar[str | None] = ContextVar("omnigent_query_name", default=None)


def current_query_name() -> str | None:
    """Return the semantic name of the query currently being executed, if any.

    Database instrumentation can read this value without coupling application
    stores to a particular query-comment format, tracer, or logger.
    """
    return _cu

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key