Skip to main content
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

Both tags 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:
Filter with IN, which checks array membership. tags = 'row-type:a' doesn’t match the array.
On the trace shape, wrap the condition in ANY_SPAN() to match traces where any span has the tag:

Option 2: Store the flag as a metadata field

A metadata 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 metadata keys, but avoid selecting them when you only need scalar fields. Selecting arbitrary metadata keys fetches the full document for every matching row.
  • Grouping on an arbitrary metadata key uses the slower aggregation path. When you can, filter on the metadata key and group on a fast field such as span_attributes.type.
See SQL best practices for details.

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_type appears in the metadata of the span you logged it on.

Notes