Applies to:
- Plan - Any
- Deployment - Any
- Use case - Mark logs, experiment rows, or dataset records with a categorical flag and filter or group on it
Summary
Bothtags and metadata fields can carry a categorical flag, such as a row type with two or three values. Use tags for labels that apply to a whole trace, including labels that reviewers add in the UI. Use a top-level metadata field, such as metadata.row_type, for a key-value attribute that belongs to a specific span or that can take many values. Filter tags with IN, not =.
What is happening
tags and metadata behave differently:
Tags are configured per project in Settings > Tags and shared across logs, experiments, dataset records, and datasets.
Fix or suggestion
Option 1: Store the flag as a tag
Tags fit flags that describe a whole trace, such as a row type set on the root span. Log the tag on the span:IN, which checks array membership. tags = 'row-type:a' doesn’t match the array.
ANY_SPAN() to match traces where any span has the tag:
Option 2: Store the flag as a metadata field
Ametadata field fits values that belong to a specific span, or values that change from span to span within a trace. Log it as a top-level key so that filters stay efficient:
Keep metadata queries fast
- A flag with only a few distinct values scans efficiently without an index. For high-cardinality keys that you filter on often, such as
metadata.user_id, add a subfield index in Settings > Query optimization. See Speed up log filtering. - Filter on
metadatakeys, but avoid selecting them when you only need scalar fields. Selecting arbitrarymetadatakeys fetches the full document for every matching row. - Grouping on an arbitrary
metadatakey uses the slower aggregation path. When you can, filter on the metadata key and group on a fast field such asspan_attributes.type.
How to confirm it worked
- Run the filter query for your flag value and check that it returns the rows you labeled.
- Open a trace in Logs and check that the tag appears on the trace, or that
row_typeappears in the metadata of the span you logged it on.
Notes
- If you need both behaviors, log the value in both fields. Write both from the same code path so they stay consistent.
- In the logs filter UI, use the includes operator for tags. See Log filtering with tags stalls after 50 results.