sqlcommenter

package
v0.9.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2026 License: Apache-2.0, Apache-2.0 Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendLabels

func AppendLabels(ctx context.Context, labels map[string]string, dbSystemName string, sourceOverride *bool) map[string]string

AppendLabels is the job-label counterpart to PrependComment for sources that attach metadata to jobs natively instead of embedding SQL comments (e.g. BigQuery). It merges the SQLCommenter attributes into the given job labels and returns the result; labels already present always win on key collisions, so tool-supplied labels are never overwritten. Labels surface in the source's own job metadata (for BigQuery: INFORMATION_SCHEMA.JOBS and billing exports), so no query text parsing is needed to recover them.

The attribute set matches PrependComment exactly. Attribute keys and values are machine-derived (e.g. client "name/version", model "gemini-2.5-flash") and routinely contain characters BigQuery rejects with an invalid-label error, so both are sanitized to the label constraints: only lowercase letters, digits, underscores, and dashes, at most 63 characters each, and keys must begin with a letter. Attribute names map punctuation to underscores, e.g. tool.name becomes tool_name. The 64-labels-per-job limit is deliberately left to the API, which rejects excess labels with a clear error rather than silently dropping telemetry.

Sanitization is lossy: values longer than 63 characters are silently truncated, so two values sharing a long prefix can become indistinguishable, and in principle two attribute names could sanitize to the same label key. Attributes are applied in sorted name order, so any such collision resolves deterministically.

sourceOverride behaves as in PrependComment: when non-nil it takes priority over the global sql-commenter flag from the context. Returns the input labels unchanged (including nil) when the commenter is disabled or no attributes are available.

func PrependComment

func PrependComment(ctx context.Context, statement string, dbSystemName string, sourceOverride *bool) string

PrependComment prepends a SQLCommenter-format comment to the given SQL statement. It gathers attributes from the context (trace, server, client, tool metadata) and the provided dbSystemName, then prepends them as key='value' pairs sorted alphabetically.

sourceOverride is the per-source `sqlCommenter` setting from tools.yaml. When non-nil it takes priority over the global sql-commenter flag; when nil the global flag (from context) is used.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL