docs/sources/as-code/infrastructure-as-code/terraform/terraform-knowledge-graph/trace-configurations.md
Trace configurations in Knowledge Graph allow you to define how trace data is queried and correlated with entities. You can specify data sources, entity matching rules, and label mappings for distributed tracing.
For information about configuring trace correlation in the Knowledge Graph UI, refer to Configure traces correlation.
Create a file named trace-configs.tf and add the following:
# Basic trace configuration for services
resource "grafana_asserts_trace_config" "production" {
provider = grafana.asserts
name = "production"
priority = 1000
default_config = false
data_source_uid = "grafanacloud-traces"
match {
property = "asserts_entity_type"
op = "="
values = ["Service"]
}
match {
property = "deployment_environment"
op = "="
values = ["production", "staging"]
}
entity_property_to_trace_label_mapping = {
"cluster" = "resource.k8s.cluster.name"
"namespace" = "resource.k8s.namespace"
"container" = "resource.container.name"
"otel_service" = "resource.service.name"
"otel_namespace" = "resource.service.namespace"
}
}
Configure trace correlation with multiple entity matching criteria:
# Development environment trace configuration
resource "grafana_asserts_trace_config" "development" {
provider = grafana.asserts
name = "development"
priority = 2000
default_config = false
data_source_uid = "tempo-dev"
match {
property = "asserts_entity_type"
op = "="
values = ["Service"]
}
match {
property = "deployment_environment"
op = "="
values = ["development", "testing"]
}
match {
property = "asserts_site"
op = "="
values = ["us-east-1"]
}
match {
property = "service"
op = "="
values = ["api"]
}
entity_property_to_trace_label_mapping = {
"cluster" = "resource.k8s.cluster.name"
"namespace" = "resource.k8s.namespace"
"container" = "resource.container.name"
"otel_service" = "resource.service.name"
"otel_namespace" = "resource.service.namespace"
"pod" = "span.k8s.pod.name"
}
}
Create a minimal configuration for all entities:
# Minimal configuration for all entities
resource "grafana_asserts_trace_config" "minimal" {
provider = grafana.asserts
name = "minimal"
priority = 3000
default_config = false
data_source_uid = "tempo-minimal"
match {
property = "asserts_entity_type"
op = "IS NOT NULL"
values = []
}
entity_property_to_trace_label_mapping = {
"cluster" = "resource.k8s.cluster.name"
"otel_service" = "resource.service.name"
"otel_namespace" = "resource.service.namespace"
}
}
Configure traces with multiple operations and advanced match rules:
# Advanced configuration with multiple operations
resource "grafana_asserts_trace_config" "advanced" {
provider = grafana.asserts
name = "advanced"
priority = 1500
default_config = false
data_source_uid = "tempo-advanced"
match {
property = "service_type"
op = "CONTAINS"
values = ["web", "api"]
}
match {
property = "deployment_environment"
op = "<>"
values = ["test"]
}
match {
property = "team"
op = "IS NOT NULL"
values = []
}
match {
property = "priority_level"
op = ">="
values = ["5"]
}
entity_property_to_trace_label_mapping = {
"service_type" = "resource.service.type"
"team" = "resource.team.owner"
"environment" = "resource.deployment.environment"
"version" = "resource.service.version"
"region" = "resource.cloud.region"
}
}
grafana_asserts_trace_configManage Knowledge Graph trace configurations through the Grafana API.
| Name | Type | Required | Description |
|---|---|---|---|
name | string | Yes | The name of the trace configuration. This field is immutable and forces recreation if changed. |
priority | number | Yes | Priority of the trace configuration. A lower number means a higher priority. |
default_config | bool | Yes | Whether this is the default configuration. Default configurations cannot be deleted. |
data_source_uid | string | Yes | DataSource UID to be queried (for example, a Tempo instance). |
match | list(object) | No | List of match rules for entity properties. Refer to match block for details. |
entity_property_to_trace_label_mapping | map(string) | No | Mapping of entity properties to trace labels for correlation. |
Each match block supports the following:
| Name | Type | Required | Description |
|---|---|---|---|
property | string | Yes | Entity property to match against. |
op | string | Yes | Operation to use for matching. One of: =, <>, <, >, <=, >=, IS NULL, IS NOT NULL, STARTS WITH, CONTAINS. |
values | list(string) | Yes | Values to match against. Can be empty for IS NULL and IS NOT NULL operations. |
resource "grafana_asserts_trace_config" "example" {
provider = grafana.asserts
name = "example-traces"
priority = 1000
default_config = false
data_source_uid = "tempo-prod"
match {
property = "asserts_entity_type"
op = "="
values = ["Service", "Pod"]
}
match {
property = "deployment_environment"
op = "STARTS WITH"
values = ["prod"]
}
entity_property_to_trace_label_mapping = {
"service" = "resource.service.name"
"namespace" = "resource.k8s.namespace"
"environment" = "resource.deployment.environment"
"cluster" = "resource.k8s.cluster.name"
}
}
Consider the following best practices when configuring trace correlation with Terraform.
resource.service.name, resource.k8s.namespace)<, >, <=, >=) for numeric or version-based filteringAfter applying the Terraform configuration, verify that: