Collect OpenTelemetry data and forward to Grafana
You can configure Alloy to collect OpenTelemetry-compatible data and forward it to the Grafana stack.
This topic describes how to:
- Configure Alloy to send your data to Loki.
- Configure Alloy to send your data to Tempo.
- Configure Alloy to send your data to Mimir or Prometheus Remote Write.
Components used in this topic
loki.write
otelcol.auth.basic
otelcol.exporter.loki
otelcol.exporter.otlp
otelcol.exporter.prometheus
otelcol.processor.batch
otelcol.receiver.otlp
prometheus.remote_write
Before you begin
- Ensure that you have basic familiarity with instrumenting applications with OpenTelemetry.
- Have a set of OpenTelemetry applications ready to push telemetry data to Alloy.
- Identify where Alloy writes received telemetry data.
- Be familiar with the concept of Components in Alloy.
- Complete the Collect open telemetry data task.
The pipeline
You can start with the Alloy configuration you created in the Collect open telemetry data task.
The pipeline looks like this:
Metrics, Logs, Traces: OTLP Receiver → batch processor → OTLP Exporter
Grafana Cloud
Grafana Cloud provides OTLP Endpoints that you can use directly from within Alloy.
You can find the OTLP connection details from the OpenTelemetry Details page in the Grafana Cloud Portal.
You must update the configuration file as follows:
otelcol.auth.basic "default" {
username = "<ACCOUNT ID>"
password = "<API TOKEN>"
}
otelcol.exporter.otlphttp "default" {
client {
endpoint = "<OTLP_ENDPOINT>"
auth = otelcol.auth.basic.default.handler
}
}
Replace the following:
<ACCOUNT ID>
: Your Grafana Cloud account ID.<API TOKEN>
: Your Grafana Cloud API token.<OTLP_ENDPOINT>
: Your OTLP endpoint.
This configuration uses the credentials stored in otelcol.auth.basic "default"
to authenticate against the Grafana Cloud OTLP endpoints, and you should start to see your data arrive.
Other platforms (Grafana Enterprise, Grafana Open Source)
You can implement the following pipelines to send your data to Loki, Tempo, and Mimir or Prometheus.
Metrics: OTel → batch processor → Mimir or Prometheus remote write
Logs: OTel → batch processor → Loki exporter
Traces: OTel → batch processor → OTel exporter
Grafana Loki
Grafana Loki is a horizontally scalable, highly available, multi-tenant log aggregation system inspired by Prometheus.
Similar to Prometheus, to send from OTLP to Loki, you can configure pass-through from the otelcol.exporter.loki
component to loki.write
component.
otelcol.exporter.loki "default" {
forward_to = [loki.write.default.receiver]
}
loki.write "default" {
endpoint {
url = "http://loki-endpoint:8080/loki/api/v1/push"
}
}
To use Loki with basic-auth, which is required with Grafana Cloud Logs, you must configure the loki.write
component.
You can get the Loki configuration from the Loki Details page in the Grafana Cloud Portal.
otelcol.exporter.loki "grafana_cloud_logs" {
forward_to = [loki.write.grafana_cloud_logs.receiver]
}
loki.write "grafana_cloud_logs" {
endpoint {
url = "https://logs-prod-us-central1.grafana.net/loki/api/v1/push"
basic_auth {
username = 5252
password = sys.env("GRAFANA_CLOUD_API_KEY")
}
}
}
Grafana Tempo
Grafana Tempo is an open source, easy-to-use, scalable distributed tracing backend. Tempo can ingest OTLP directly, and you can use the OTLP exporter to send the traces to Tempo.
otelcol.exporter.otlp "default" {
client {
endpoint = "tempo-server:4317"
}
}
To use Tempo with basic-auth, which is required with Grafana Cloud Traces, you must use the otelcol.auth.basic component. You can get the Tempo configuration from the Tempo Details page in the Grafana Cloud Portal.
otelcol.exporter.otlp "grafana_cloud_traces" {
client {
endpoint = "tempo-us-central1.grafana.net:443"
auth = otelcol.auth.basic.grafana_cloud_traces.handler
}
}
otelcol.auth.basic "grafana_cloud_traces" {
username = 4094
password = sys.env("GRAFANA_CLOUD_API_KEY")
}
Grafana Mimir or Prometheus Remote Write
Prometheus Remote Write is a popular metrics transmission protocol supported by most metrics systems, including Grafana Mimir and Grafana Cloud.
To send from OTLP to a Prometheus compatible remote_write
endpoint, you can configure pass-through from the otelcol.exporter.prometheus
to the prometheus.remote_write
component.
The Prometheus remote write component in Alloy is a robust protocol implementation, including a Write Ahead Log (WAL) for resiliency.
otelcol.exporter.prometheus "default" {
forward_to = [prometheus.remote_write.default.receiver]
}
prometheus.remote_write "default" {
endpoint {
url = "http://prometheus:9090/api/v1/write"
}
}
To use Prometheus with basic-auth, which is required with Grafana Cloud Metrics, you must configure the prometheus.remote_write
component.
You can get the Prometheus configuration from the Prometheus Details page in the Grafana Cloud Portal.
otelcol.exporter.prometheus "grafana_cloud_metrics" {
forward_to = [prometheus.remote_write.grafana_cloud_metrics.receiver]
}
prometheus.remote_write "grafana_cloud_metrics" {
endpoint {
url = "https://prometheus-us-central1.grafana.net/api/prom/push"
basic_auth {
username = 12690
password = sys.env("GRAFANA_CLOUD_API_KEY")
}
}
}
Put it all together
Instead of referencing otelcol.exporter.otlp.default.input
in the output of otelcol.processor.batch
, you need to reference the three exporters you set up.
The final configuration becomes:
Running Alloy gives you the following:
You can check the pipeline graphically by visiting http://localhost:12345/graph
![Graphical representation of a healthy pipeline](/media/docs/alloy/otlp-lgtm-graph.png)