datadog_query/lint

Types

pub type BalanceError {
  Unmatched(String)
  Unclosed(String)
}

Constructors

  • Unmatched(String)
  • Unclosed(String)

Values

pub fn at_prefixed_attrs(query: String) -> List(String)

Scans a Datadog query string for @-prefixed attribute names used in filter position (e.g. @type:foo or @type IN (...)).

Datadog metric filters strip the leading @ from log facets when log-based metrics are generated — the metric tag for log facet @type is just type. A query that filters on @type against a log-based metric is rejected by the SLO API with 400: numerator query is invalid.

Returns a deduplicated list of @-prefixed attribute names found.

pub fn dangling_joiner(query: String) -> List(String)

Detects scope-internal artifacts produced by composing tag_in([]) / tag_not_in([]) returning "". Returns the offending fragment(s) when the scope contains a leading/trailing/doubled boolean joiner.

Examples flagged: metric{ AND env:prod} → [“leading AND”] metric{env:prod AND } → [“trailing AND”] metric{env:prod AND AND service:api} → [“doubled joiner”]

pub fn empty_scope_with_grouping(query: String) -> Bool

Detects metric{} by {tag} — a legal but suspicious query (a copy-paste bug that would group a “match-everything” set; usually metric{*} was intended).

pub fn reserved_word_as_tag_name(query: String) -> List(String)

Detects tag names that collide with grammar keywords. Datadog accepts these tokens as separators, so a tag literally named IN produces confusing parse errors.

pub fn unbalanced_braces(
  query: String,
) -> Result(Nil, BalanceError)

Verifies { / } are balanced. Ignores braces inside double-quoted strings so tag:"a{b}c" doesn’t trigger a false positive.

pub fn unbalanced_parens(
  query: String,
) -> Result(Nil, BalanceError)

Verifies ( / ) are balanced (string-aware).

pub fn wildcard_in_quoted_value(query: String) -> Bool

Detects values where wildcards have been collapsed to literals by quoting. Datadog matches * as a wildcard in bare values but as a literal asterisk inside "...".

Example: metric{service:"foo*"} — the * is now literal.

Search Document