Skip to content

Latest commit

 

History

History
177 lines (128 loc) · 6.42 KB

filter-segments.md

File metadata and controls

177 lines (128 loc) · 6.42 KB

Filter Segments

Grail filter segments are reusable, named filter definitions that logically structure observability data across the Dynatrace platform. They act as query-time context, where Grail evaluates only the segment includes relevant to the queried data type. dtctl provides full CRUD management and query-time integration for segments (see DQL Queries for using segments with dtctl query).

dtctl docs / Resources / Filter Segments

Supported operations

Operation Resource Command syntax Description Mutating Access
create segment dtctl create segment Create resources from files yes write
delete segment dtctl delete segment Delete resources yes delete
describe segment dtctl describe segment Show details of a specific resource no read
edit segment dtctl edit segment Edit a resource yes write
get segments dtctl get segments Display one or many resources no read

Flags

These commands take dtctl's global flags (-o/--output, --context, --jq, -v, and more). Some verbs add their own flags (apply, diff, query, inventory); see the verb in COMMANDS.md. Individual commands may take further flags of their own — run dtctl <verb> <resource> --help for the authoritative list.

Required token scopes

Safety level Scopes
delete storage:filter-segments:delete
read storage:filter-segments:read
write storage:filter-segments:write

Output

get segments prints a compact table; -o wide adds description and owner. describe segment shows a segment's includes, variables, and visibility, for example:

Name:          my-k8s-segment
UID:           abc123-def456
Description:   Filters data for Kubernetes cluster alpha
Public:        Yes
Owner:         user@example.invalid
Version:       3

Includes:
  DATA OBJECT         FILTER
  All data objects    k8s.cluster.name = "alpha"
  Logs                dt.system.bucket = "custom-logs"

Variables:
  Type:     query
  Value:    data record(ns="namespace-a"), record(ns="namespace-b")

Examples

# List all segments
dtctl get segments

# Wide output (includes description and owner)
dtctl get segments -o wide

# JSON for scripting
dtctl get segments -o json

Describe a segment by UID or by name (interactive disambiguation if ambiguous):

dtctl describe segment abc123-def456
dtctl describe segment my-k8s-segment

Define a segment in YAML and create or apply it:

name: my-k8s-segment
description: Filters data for Kubernetes cluster alpha
isPublic: true
includes:
  - dataObject: _all_data_object
    filter: 'k8s.cluster.name = "alpha"'
  - dataObject: logs
    filter: 'dt.system.bucket = "custom-logs"'
variables:
  type: query
  value: 'data record(ns="namespace-a"), record(ns="namespace-b")'
# Create (fails if the segment already exists)
dtctl create segment -f segment.yaml

# Apply (creates if new, updates if existing)
dtctl apply -f segment.yaml

# Dry-run to preview what would happen
dtctl create segment -f segment.yaml --dry-run

Edit a segment in your editor — this opens the segment YAML in $EDITOR and applies the changes on save; the optimistic locking version is handled automatically:

dtctl edit segment my-k8s-segment

Apply segments at query time to narrow results (AND-combined when multiple are specified):

# Apply a single segment, or by short form
dtctl query "fetch logs | limit 10" --segment my-segment-uid
dtctl query "fetch logs | limit 10" -S my-segment-uid

# Bind variables inline (URL-query style)
dtctl query "fetch logs | limit 10" -S "my-segment?host=HOST-001"

# Use a YAML file for complex cases with multiple segments and variables
dtctl query "fetch logs | limit 10" --segments-file segments.yaml

Delete a segment (dtctl prompts for confirmation in interactive mode; use --plain to skip it in CI):

dtctl delete segment abc123-def456
dtctl delete segment abc123-def456 -y

Notes

Segment YAML field reference

The fields available when defining a segment in YAML for create segment or apply:

Field Description
name Human-readable segment name
description Optional description
isPublic true for environment-wide visibility, false for owner-only (default)
includes Array of filter rules. Each specifies a dataObject and a filter expression. Includes are OR-combined within a segment.
dataObject Data type to filter: logs, spans, events, metrics, entities, or _all_data_object for all
filter DQL filter expression applied to the data object. dtctl automatically converts DQL to the API's internal JSON AST format on create/update, and converts back to DQL on get/describe. You can also provide a raw JSON AST string (starting with {), which is passed through unchanged.
variables Optional variable definition with type and value fields

Combining segments and variables in queries

Beyond a single --segment/-S flag, you can pass the flag multiple times to AND-combine several segments, and bind more than one variable value or more than one variable per segment:

# Apply multiple segments (AND-combined per Grail semantics)
dtctl query "fetch logs | limit 10" --segment seg-1 --segment seg-2

# Multiple values for a variable
dtctl query "fetch logs | limit 10" -S "my-segment?host=HOST-001,HOST-002"

# Multiple variables on one segment
dtctl query "fetch logs | limit 10" -S "my-segment?host=HOST-001&ns=production"

# By name (resolved via API)
dtctl query "fetch logs | limit 10" --segment my-k8s-segment

Aliases

Segments support multiple aliases for convenience:

Context Primary Aliases
get segments segment, seg, filter-segments, filter-segment
describe segment seg, filter-segment
create segment seg, filter-segment
edit segment seg, filter-segment
delete segment segments, seg, filter-segment, filter-segments