Segments let you logically filter observability data across Dynatrace Apps. To work correctly in
Services and
Smartscape, a segment for services should cover two separate data sources: metrics and topology. This tutorial explains why both data sources are needed and shows you how to create such a service segment.
This tutorial is for platform engineers, SREs, and developers who rely on segments that filter the service list and the topology view to a specific part of their environment, for example, a Kubernetes namespace, a cloud region, or a host group.
By the end of this tutorial, you'll have a working segment that scopes both the service list in
Services and the topology view in
Smartscape to a specific part of your environment.
In this tutorial, you'll learn how to:
Services and
Smartscape in your Dynatrace environment.storage:filter-segments:write and storage:filter-segments:read permissions. To learn how to set up these permissions, see Permissions in Grail.You can also follow along without any setup by using the Dynatrace Playground.
Basic familiarity with the following concepts is helpful but not required, as you'll find instructions and examples throughout this page.
Before you build your segment, review the following information to avoid common pitfalls.
The service list in
Services and the topology view in
Smartscape rely on separate data stores. The service list shows metrics, such as response time, throughput, and failure rate. The topology view maps the relationships: how services relate to hosts, namespaces, and other services. Different slices of data power each view.
A segment that covers only metrics filters the service list but leaves the topology view unfiltered. A segment that covers only topology works in
Smartscape but not in
Services. To scope both apps correctly, your segment should address both data sources: metrics and topology.
dt.entity.* attributesDo not use legacy dt.entity.* attributes in your segments, as they might incorrectly filter the service list in
Services.
dt.entity.service in your segments. Instead, use dt.smartscape.service.dt.entity.* attributes in include blocks in your segments. In an existing segment, you should see a warning if you have an include block with legacy dt.entity.* attributes. Replace such attributes with dt.smartscape.* attributes.When you add an include block to your segment by selecting More in the segment editor, don't use the entries listed under Classic entities (by type). Entity-to-entity relationships in segments apply to legacy dt.entity.* attributes only and don't work with Smartscape entities.
For Smartscape-based service segments, use the DQL variable approach described in this tutorial to derive service IDs instead of relationship traversal.
Follow these steps to create a segment that correctly scopes both
Services and
Smartscape.
To start creating a segment
The segment editor shows the Services by AWS region segment that is visible to everyone. Continue with the following steps to add the required include blocks to your service segment.
To add a Data (all types) include block to your segment
In the segment editor, enter the following filter condition under Data (all types). Do not copy and paste the condition, but manually enter it.
aws.region = $aws.region
The $aws.region variable is added to the Variables section in the segment editor.
Keep the filter conditions dynamic and reference a field with $ instead of a literal, for example, k8s.namespace.name = $k8s.namespace.name or k8s.cluster.name = $k8s.cluster.name. This way, the segment stays flexible and reusable, and you can select the required value when using the segment.
Select Preview to verify the result.
In the preview results, go to the Metrics tab, and confirm that the expected service metrics appear.
At this point, it's expected that the Entities tab doesn't return any service entities.
Select Save.
You've added the Data (all types) include block that scopes
Services.
When you filter using primary Grail fields or tags, Dynatrace automatically carries that attribute through to the matching service metrics. This is why a single Data (all types) include block is enough to filter the service list in
Services. To scope
Smartscape too, continue with the next two steps.
To edit the $aws.region variable of your segment
In the segment editor, select (Edit variables(s)) by the $aws.region variable.
Enter the required variable query in the code field on the left, for example:
metrics| filter isNotNull(aws.region) and aws.region != "" // filter for services that have an AWS region| fields aws.region, dt.smartscape.service| summarize by: aws.region, dt.smartscape.service = collectDistinct(dt.smartscape.service)| sort lower(aws.region)
This variable query looks up which services match your filter. The result is used in the Entities include block that you'll add in the next step.
Select Run to confirm that the correct service list is returned.
Review the table under Preview (2 variables created). The aws.region column contains the values for the primary $aws.region variable, which is the AWS region you select when you apply the segment. The dt.smartscape.service column shows the values for the secondary $dt.smartscape.service variable, which is the list of services for a region. For details, see Primary and secondary variables.
Select Done.
You've edited the $aws.region variable. Now your segment has the primary $aws.region variable and the secondary $dt.smartscape.service variable.
The variable query in this tutorial retrieves matching service IDs from service metrics. This approach works reliably for up to 10,000 services. In environments where your filter matches more services than that—for example, a single segment covering all production services across a large fleet—the variable query may return an incomplete list, leaving some services unfiltered.
If you hit this limit, split a broad segment into narrower ones. For example, create one segment per cluster or per region so that each variable query stays within the 10,000-service threshold.
To add an Entities include block to your segment
In the segment editor, select More > Entities.
Add a filter condition that references the variable from the previous step:
type = "SERVICE" AND id in ($dt.smartscape.service)
Select Preview to confirm that the expected services appear.
Select Save in the upper-right corner of the segment editor.
You've added the Entities include block that scopes
Smartscape.
You've created a service segment! Your segment now contains a Data (all types) include block for metrics, a variable that retrieves matching service IDs, and an Entities include block for topology. The segment is visible to everyone in your environment.
With your segment created, verify that it correctly scopes both
Services and
Smartscape.
To filter the service list in
Services using your new segment
Services > Explorer (Early Access).The service list updates to show only the services matching your segment. Response time, throughput, and failure rate reflect only the metrics included in the segment.
To filter the service nodes in
Smartscape using your new segment
Smartscape > Service dependency graph.The topology view shows only the service nodes matching your segment and their relationships.
The following examples show you how to create segments for two common scenarios. In each case, follow the steps in Create a service segment and replace the filter conditions and variable query with the values provided in the example.
Primary Grail field example
Create the following segment when you want to scope services to a specific host group. Because a host group is not automatically propagated to service metrics, follow all steps in Create a service segment.
Follow the instructions in Start creating a segment.
dt.host_group.id = $dt.host_group.id
metrics| filter isNotNull(dt.host_group.id) and dt.host_group.id != ""| fields dt.host_group.id, dt.smartscape.service| summarize by: dt.host_group.id, dt.smartscape.service = collectDistinct(dt.smartscape.service)| sort lower(dt.host_group.id)
type = "SERVICE" AND id in ($dt.smartscape.service)
Primary Grail tag example
Create the following segment when your services are tagged with a team ownership tag and may span multiple namespaces. Because primary_tags.* fields are propagated to service metrics, the Data (all types) include block can filter the service list in
Services. To scope
Smartscape too, edit a variable and add an Entities include block.
Follow the instructions in Start creating a segment.
primary_tags.team = $primary_tags.team
metrics| filter isNotNull(primary_tags.team) and primary_tags.team = "payments"| fields primary_tags.team, dt.smartscape.service| summarize by: primary_tags.team, dt.smartscape.service = collectDistinct(dt.smartscape.service)| sort lower(primary_tags.team)
type = "SERVICE" AND id in ($dt.smartscape.service)
You've created a service segment that covers both metrics and topology, verified that it correctly scopes
Services and
Smartscape, and explored how to create segments for host groups and team tags. Your segments keep the service list and topology view in sync across both apps.
Services ships with ready-made segments for common dimensions such as an AWS region, Kubernetes namespace, and host group. Check the segment selector in the Explorer (Early Access) view to see which segments are already available in your environment.
Services
Smartscape