Overview
Tags in Slung allow you to filter time-series data using boolean logic. The tag syntax supports infix notation with three operators:AND, OR, and NOT.
Syntax
Tags are specified as the third component of a query, enclosed in square brackets:Basic Tag Filtering
A simple tag filter:env=prod tag.
Empty Tag Filters
You can use empty brackets to match all data points:When tags are empty (
[]), all data points are matched regardless of their tags.Tag Operators
AND - Logical AND
Both conditions must be true. Syntax:env=prod and host=h-9 tags.
Test Case from Source:
(site=eu AND env=prod) OR region=west.
OR - Logical OR
At least one condition must be true. Syntax:service=db or do not have the muted tag.
NOT - Logical NOT
Negates the following tag. Syntax (Binary):tag1 but not tag2.
Syntax (Unary):
tag1.
Example:
region=us-west but excludes those with host=test.
Unary NOT Example:
muted tag.
Tag Format
Tags are typically key-value pairs separated by=, but Slung treats the entire string as the tag:
env=prod- Standard key-value formatregion=us-west- Multi-part valueenabled- Boolean-style tag (no value)muted- Simple flag
Operator Precedence
Slung evaluates tag expressions left-to-right with equal precedence for all operators:(tag1 AND tag2) OR tag3
NOT as Binary Operator
WhenNOT appears between two tags, it’s treated as a binary operator equivalent to AND NOT:
tag1 AND (NOT tag2)
NOT as Unary Operator
WhenNOT appears before a tag (no tag preceding it), it’s a unary operator:
tag1 but do have tag2.
Real-World Examples
Production Environment, Specific Host
h-9.
Test Verification:
Database Service or Non-Muted
service=db tag, or any data point without the muted tag.
Test Verification:
Complex Multi-Region Query
us-west region, excluding test hosts, over the last hour.
Multiple ORs
Tag Parsing Rules
Space-Separated Tokens
Tags and operators are separated by spaces:Case Insensitivity for Operators
Operators are case-insensitive:Whitespace Handling
Extra whitespace is ignored:Error Cases
Missing Tag After Operator
NOT) require a tag on both sides.
Missing Brackets
Operator at End
Implementation Details
Tag Token Structure
Internally, tags are parsed into tokens:[site=eu AND env=prod OR region=west]:
TagToken{ .tag = "site=eu" }TagToken{ .op = .and_op }TagToken{ .tag = "env=prod" }TagToken{ .op = .or_op }TagToken{ .tag = "region=west" }
Maximum Tags
Slung supports up to 32 tag tokens (tags + operators combined) per query:error.TooManyTags.
Tag Matching Algorithm
ThematchesTags function evaluates the parsed tag expression against a data point’s tags:
- Start with the first operand (tag or NOT expression)
- For each operator, consume the next operand
- Apply the operator (AND/OR) to combine results
- Return the final boolean result
- Unary
NOTnegates the following operand - Binary
NOTis converted toAND NOTinternally
Related Topics
Query Syntax
Complete query DSL overview
Aggregations
Aggregation operations