This is documentation for the next version of Grafana Alloy Documentation. For the latest stable release, go to the latest version.
loki.enrich
EXPERIMENTAL: This is an experimental component. Experimental components are subject to frequent breaking changes, and may be removed with no equivalent replacement. To enable and use an experimental component, you must set the
stability.levelflag toexperimental.
The loki.enrich component enriches logs with additional labels from service discovery targets.
It matches labels from incoming logs against labels from discovered targets, and copies specified labels from the matched target to the log entry.
If no match occurs, the component forwards the log entry unchanged.
Use the target_to_log_match argument to specify which target labels correspond to which log labels.
The map keys are target label names and the values are the corresponding log label names.
All labels in the map must match for enrichment to occur.
Warning
The
target_match_labelandlogs_match_labelarguments are deprecated in favor oftarget_to_log_match. These deprecated arguments will be removed in a future release.The deprecated arguments behave as follows:
target_match_labelis the target label to match against.logs_match_labelis the log label to match againsttarget_match_label. If you don’t set it, the component uses the value oftarget_match_label.- If you set
logs_match_labelwithouttarget_match_labelortarget_to_log_match, the component fails to start.- If you set
target_to_log_match, the component ignorestarget_match_labelandlogs_match_label.To migrate, replace
target_match_label = "hostname"withtarget_to_log_match = {"hostname" = "hostname"}. If you also setlogs_match_label, use it as the map value. For example, replacetarget_match_label = "hostname"andlogs_match_label = "host"withtarget_to_log_match = {"hostname" = "host"}.
Usage
loki.enrich "<LABEL>" {
targets = <DISCOVERY_COMPONENT>.targets
target_to_log_match = {
"<TARGET_LABEL_1>" = "<LOG_LABEL_1>",
"<TARGET_LABEL_2>" = "<LOG_LABEL_2>",
}
labels_to_copy = ["<LABEL>", ...]
forward_to = [<RECEIVER_LIST>]
}Arguments
You can use the following arguments with loki.enrich:
Note
target_to_log_matchandtarget_match_labelare both optional, but you must set at least one of them. If you set neither, the component fails to start.
The keys and values in target_to_log_match can’t be empty strings.
Blocks
The loki.enrich component doesn’t support any blocks. You can configure this component with arguments.
Exports
The following values are exported:
Example
The following example enriches syslog entries with labels from an HTTP service discovery target. It matches the connection IP address and tenant label before it forwards entries to Loki.
// Configure HTTP discovery
discovery.http "default" {
url = "http://network-inventory.example.com/prometheus_sd"
}
discovery.relabel "default" {
targets = discovery.http.default.targets
rule {
action = "replace"
source_labels = ["__inventory_rack"]
target_label = "rack"
}
rule {
action = "replace"
source_labels = ["__inventory_datacenter"]
target_label = "datacenter"
}
rule {
action = "replace"
source_labels = ["__inventory_environment"]
target_label = "environment"
}
rule {
action = "replace"
source_labels = ["__inventory_tenant"]
target_label = "tenant"
}
rule {
action = "replace"
source_labels = ["__inventory_primary_ip"]
target_label = "primary_ip"
}
}
loki.relabel "syslog" {
forward_to = []
rule {
source_labels = ["__syslog_connection_ip_address"]
target_label = "source_ip"
}
}
// Receive syslog messages
loki.source.syslog "incoming" {
listener {
address = ":514"
protocol = "tcp"
labels = {
job = "syslog",
tenant = "production",
}
}
relabel_rules = loki.relabel.syslog.rules
forward_to = [loki.enrich.default.receiver]
}
// Enrich logs using HTTP discovery
loki.enrich "default" {
// Use targets from HTTP discovery (after relabeling)
targets = discovery.relabel.default.output
target_to_log_match = {
"primary_ip" = "source_ip",
"tenant" = "tenant",
}
forward_to = [loki.write.default.receiver]
}
loki.write "default" {
endpoint {
url = "http://loki:3100/loki/api/v1/push"
}
}Component behavior
The component matches logs to discovered targets and enriches them with additional labels:
- For each log entry, it looks up the log labels specified by
target_to_log_match. - It matches those values against the corresponding target labels. All label pairs must match the same target.
- If a match is found, it copies the requested
labels_to_copyfrom the discovered target to the log entry. Iflabels_to_copyis empty, all labels are copied. - The log entry, enriched or unchanged, is forwarded to the configured receivers.
The component handles the following cases:
- If no target matches a log entry, the component forwards the log entry unchanged.
- If a log entry is missing any of the labels in
target_to_log_match, or any of those labels has an empty value, the component forwards the log entry unchanged. - If a target is missing any of the matching labels, or any of them has an empty value, the component ignores that target.
- If multiple targets have the same values for all matching labels, the component uses the last of those targets in the
targetslist. The discovery component determines the order of targets, and the order can change between updates. To get predictable results, make sure the matching labels identify a single target.
Caution
By default,
loki.enrichis ready as soon as it starts, even if no targets have been discovered. If telemetry is sent to this component before the metadata is synced, then it will be passed though as-is, without enrichment. This is most likely to impactloki.enrichon startup for a short time before thediscoverycomponents have sent a new list of targets.
Compatible components
loki.enrich can accept arguments from the following components:
- Components that export Targets
- Components that export Loki
LogsReceiver
loki.enrich has exports that can be consumed by the following components:
- Components that consume Loki
LogsReceiver
Note
Connecting some components may not be sensible or components may require further configuration to make the connection work correctly. Refer to the linked documentation for more details.


