github.com/grafana/pyroscope@v1.18.0/docs/sources/configure-client/grafana-alloy/receive_profiles.md (about)

     1  ---
     2  title: Receive profiles from Pyroscope SDKs
     3  menuTitle: Receive SDK profiles
     4  description: Learn how to configure Grafana Alloy to receive profiles from applications using Pyroscope SDKs.
     5  weight: 10
     6  ---
     7  
     8  # Receive profiles from Pyroscope SDKs
     9  
    10  The `pyroscope.receive_http` component in Alloy receives profiles from applications instrumented with Pyroscope SDKs. This approach provides several benefits:
    11  - Lower latency by sending profiles to a local Alloy instance instead of over internet
    12  - Separation of infrastructure concerns (auth, routing) from application code
    13  - Centralized management of authentication and metadata enrichment
    14  
    15  For more information about this component, refer to the [pyroscope.receive_http component](https://grafana.com/docs/alloy/<ALLOY_VERSION>/reference/components/pyroscope/pyroscope.receive_http/) documentation.
    16  
    17  {{< admonition type="note" >}}
    18  The `pyroscope.receive_http` component is currently in public preview. To use this component, set the `--stability.level` flag to `public-preview`. For more information about Alloy's run usage, refer to the [run command documentation](https://grafana.com/docs/grafana-cloud/send-data/alloy/reference/cli/run/#the-run-command) documentation.
    19  {{< /admonition >}}
    20  
    21  To set up profile receiving, you need to:
    22  1. Configure Alloy components
    23  2. Configure your application's SDK
    24  3. Start Alloy
    25  
    26  ## Configure Alloy components
    27  
    28  The configuration requires at least two components:
    29  - [`pyroscope.receive_http`](https://grafana.com/docs/alloy/<ALLOY_VERSION>/reference/components/pyroscope/pyroscope.receive_http/) to receive profiles via HTTP
    30  - [`pyroscope.write`](https://grafana.com/docs/alloy/<ALLOY_VERSION>/reference/components/pyroscope/pyroscope.write/) to forward profiles to Pyroscope
    31  
    32  Here's a basic configuration that sets up a simple profile collection pipeline.
    33  It creates a receiver to collect profiles from your applications and forwards them through a writer component to send them to the Pyroscope backend:
    34  
    35  ```alloy
    36  // Receives profiles over HTTP
    37  pyroscope.receive_http "default" {
    38     http {
    39         listen_address = "0.0.0.0"
    40         listen_port = 9999
    41     }
    42     forward_to = [pyroscope.write.backend.receiver]
    43  }
    44  
    45  // Forwards profiles to Pyroscope
    46  pyroscope.write "backend" {
    47     endpoint {
    48         url = "http://pyroscope:4040"
    49     }
    50  }
    51  ```
    52  
    53  ## Configure application SDK
    54  Update your application's SDK configuration to point to Alloy's receive endpoint instead of Pyroscope directly. For example, in Go:
    55  ```go
    56  config := pyroscope.Config{
    57      ApplicationName: "my.service.cpu",
    58      ServerAddress:   "http://localhost:9999", // Alloy's receive endpoint
    59  }
    60  ```
    61  Check your specific language SDK documentation for the exact configuration options.
    62  
    63  ## Examples
    64  
    65  The examples in this section provide samples you can use as a starting point for your own configurations. 
    66  
    67  Explore the [example](https://github.com/grafana/pyroscope/tree/main/examples/language-sdk-instrumentation/golang-push/rideshare-alloy) in the Pyroscope GitHub repository to learn how to configure Grafana Alloy to receive profiles from a Golang application instrumented with Pyroscope.
    68  
    69  ### Basic receiving setup
    70  
    71  This example shows a basic setup receiving profiles on port 9090 and forwarding them to a local Pyroscope instance:
    72  
    73  
    74  ```alloy
    75  pyroscope.receive_http "default" {
    76      http {
    77          listen_address = "0.0.0.0"
    78          listen_port = 9090
    79      }
    80      forward_to = [pyroscope.write.production.receiver]
    81  }
    82  
    83  pyroscope.write "production" {
    84      endpoint {
    85          url = "http://localhost:4040"
    86      }
    87  }
    88  ```
    89  
    90  ### Authentication
    91  
    92  To send profiles to an authenticated Pyroscope endpoint:
    93  
    94  ```alloy
    95  pyroscope.write "production" {
    96      endpoint {
    97          url = "http://pyroscope:4040"
    98          basic_auth {
    99              username = env("PYROSCOPE_USERNAME")
   100              password = env("PYROSCOPE_PASSWORD")
   101          }
   102      }
   103  }
   104  ```
   105  
   106  ### Adding external labels
   107  External labels are added to all profiles forwarded through the write component. This is useful for adding infrastructure metadata:
   108  ```alloy
   109  pyroscope.receive_http "default" {
   110      http {
   111          listen_address = "0.0.0.0"
   112          listen_port = 9999
   113      }
   114      forward_to = [pyroscope.write.backend.receiver]
   115  }
   116  
   117  pyroscope.write "backend" {
   118      endpoint {
   119          url = "http://pyroscope:4040"
   120      }
   121      external_labels = {
   122          "env"      = "production",
   123          "region"   = "us-west-1",
   124          "instance" = env("HOSTNAME"),
   125          "cluster"  = "main",
   126      }
   127  }
   128  ```
   129  
   130  ### Multiple destinations
   131  Forward received profiles to multiple destinations - useful for testing or migration scenarios:
   132  ```alloy
   133  pyroscope.receive_http "default" {
   134      http {
   135          listen_address = "0.0.0.0"
   136          listen_port = 9999
   137      }
   138      forward_to = [pyroscope.write.staging.receiver, pyroscope.write.production.receiver]
   139  }
   140  
   141  // Send profiles to staging
   142  pyroscope.write "staging" {
   143      endpoint {
   144          url = "http://pyroscope-staging:4040"
   145      }
   146      external_labels = {
   147          "env" = "staging",
   148      }
   149  }
   150  
   151  // Send profiles to production
   152  pyroscope.write "production" {
   153      endpoint {
   154          url = "http://pyroscope-production:4041"
   155      }
   156      external_labels = {
   157          "env" = "production",
   158      }
   159  }
   160  ```
   161  {{< admonition type="note" >}}
   162  This configuration will duplicate the received profiles and send a copy to each configured `pyroscope.write` component.
   163  {{< /admonition >}}
   164  
   165  Another approach is to configure multiple receivers with multiple destinations:
   166  ```alloy
   167  pyroscope.receive_http "staging" {
   168      http {
   169          listen_address = "0.0.0.0"
   170          listen_port = 9998
   171      }
   172      forward_to = [pyroscope.write.staging.receiver]
   173  }
   174  
   175  pyroscope.receive_http "production" {
   176      http {
   177          listen_address = "0.0.0.0"
   178          listen_port = 9999
   179      }
   180      forward_to = [pyroscope.write.production.receiver]
   181  }
   182  
   183  // Send profiles to staging
   184  pyroscope.write "staging" {
   185      endpoint {
   186          url = "http://pyroscope-staging:4040"
   187      }
   188      external_labels = {
   189          "env" = "staging",
   190      }
   191  }
   192  
   193  // Send profiles to production
   194  pyroscope.write "production" {
   195      endpoint {
   196          url = "http://pyroscope-production:4041"
   197      }
   198      external_labels = {
   199          "env" = "production",
   200      }
   201  }
   202  ```
   203  
   204  For more information about component configuration options, refer to:
   205  
   206  - pyroscope.receive_http [documentation](https://grafana.com/docs/alloy/latest/reference/components/pyroscope/pyroscope.write/)
   207  - pyroscope.write [documentation](https://grafana.com/docs/alloy/latest/reference/components/pyroscope/pyroscope.receive_http/)