---
title: "pyroscope.enrich | Grafana Cloud documentation"
description: "Learn about pyroscope.enrich"
---

# `pyroscope.enrich`

> **EXPERIMENTAL**: This is an [experimental](/docs/release-life-cycle/) 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.level` [flag](/docs/alloy/latest/reference/cli/run/) to `experimental`.

`pyroscope.enrich` enriches profiles with additional labels from service discovery targets. It matches a label from incoming profiles against a label from discovered targets, and copies specified labels from the matched target to the profile.

## Usage

Alloy ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```alloy
pyroscope.enrich "<LABEL>" {
  targets = <DISCOVERY_COMPONENT>.targets
  target_match_label = "<LABEL>"
  forward_to = [<RECEIVER_LIST>]
}
```

## Arguments

You can use the following arguments with `pyroscope.enrich`:

Expand table

| Name                   | Type                     | Description                                                                                  | Default | Required |
|------------------------|--------------------------|----------------------------------------------------------------------------------------------|---------|----------|
| `forward_to`           | `list(ProfilesReceiver)` | List of receivers to send enriched profiles to.                                              |         | yes      |
| `target_match_label`   | `string`                 | The label from discovered targets to match against.                                          |         | yes      |
| `targets`              | `list(Target)`           | List of targets from a discovery component.                                                  |         | yes      |
| `labels_to_copy`       | `list(string)`           | List of labels to copy from discovered targets to profiles. If empty, all labels are copied. |         | no       |
| `profiles_match_label` | `string`                 | The label from incoming profiles to match against discovered targets.                        |         | no       |

If `profiles_match_label` isn’t provided, the component uses `target_match_label` for matching profile labels.

## Blocks

`pyroscope.enrich` doesn’t support any blocks. Configure this component with arguments.

## Exported fields

The following fields are exported and can be referenced by other components:

Expand table

| Name       | Type               | Description                |
|------------|--------------------|----------------------------|
| `receiver` | `ProfilesReceiver` | The receiver for profiles. |

## Component health

`pyroscope.enrich` is only reported as unhealthy if given an invalid configuration.

## Debug information

`pyroscope.enrich` doesn’t expose debug information.

## Debug metrics

`pyroscope.enrich` doesn’t expose additional metrics.

## Example

This example enriches profiles received over HTTP with metadata from Kubernetes service discovery:

Alloy ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```alloy
// Discover Kubernetes pods
discovery.kubernetes "pods" {
  role = "pod"
}

// Add custom labels from Kubernetes metadata
discovery.relabel "pods" {
  targets = discovery.kubernetes.pods.targets

  rule {
    source_labels = ["__meta_kubernetes_namespace"]
    target_label  = "namespace"
  }

  rule {
    source_labels = ["__meta_kubernetes_pod_node_name"]
    target_label  = "node"
  }

  rule {
    source_labels = ["__meta_kubernetes_pod_label_app"]
    target_label  = "app"
  }

  rule {
    source_labels = ["__meta_kubernetes_pod_label_environment"]
    target_label  = "environment"
  }

  rule {
    source_labels = ["__meta_kubernetes_pod_ip"]
    target_label  = "pod_ip"
  }
}

// Receive profiles over HTTP
pyroscope.receive_http "default" {
  http {
    listen_address = "0.0.0.0"
    listen_port    = 4040
  }
  forward_to = [pyroscope.enrich.metadata.receiver]
}

// Enrich profiles with Kubernetes metadata
pyroscope.enrich "metadata" {
  targets               = discovery.relabel.pods.output
  target_match_label    = "pod_ip"
  profiles_match_label  = "service_name"
  labels_to_copy        = ["namespace", "node", "app", "environment"]
  forward_to            = [pyroscope.write.default.receiver]
}

// Write profiles to Pyroscope
pyroscope.write "default" {
  endpoint {
    url = "http://pyroscope:4040"
  }
}
```

## Component behavior

The component matches profiles to discovered targets and enriches them with additional labels:

1. For each profile, it looks up the value of `profiles_match_label` from the profile’s labels, or `target_match_label` if `profiles_match_label` isn’t specified.
2. It matches this value against the `target_match_label` in discovered targets.
3. When it finds a match, it copies the requested `labels_to_copy` from the discovered target to the profile. If `labels_to_copy` is empty, it copies all labels.
4. The component forwards the profile, enriched or unchanged, to the configured receivers.

> Caution
> 
> By default, `pyroscope.enrich` is ready as it starts, even if discovery doesn’t find targets. If you send profiles to this component before the metadata synchronizes, the component passes them through as-is, without enrichment. This is most likely to impact `pyroscope.enrich` on startup for a short time before discovery components send a list of targets.

## Compatible components

`pyroscope.enrich` can accept arguments from the following components:

- Components that export [Targets](/docs/grafana-cloud/send-data/alloy/reference/compatibility/#targets-exporters)
- Components that export [Pyroscope `ProfilesReceiver`](/docs/grafana-cloud/send-data/alloy/reference/compatibility/#pyroscope-profilesreceiver-exporters)

`pyroscope.enrich` has exports that can be consumed by the following components:

- Components that consume [Pyroscope `ProfilesReceiver`](/docs/grafana-cloud/send-data/alloy/reference/compatibility/#pyroscope-profilesreceiver-consumers)

> 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.
