Caution
Grafana Alloy is the new name for our distribution of the OTel collector. Grafana Agent has been deprecated and is in Long-Term Support (LTS) through October 31, 2025. Grafana Agent will reach an End-of-Life (EOL) on November 1, 2025. Read more about why we recommend migrating to Grafana Alloy.
Important: This documentation is about an older version. It's relevant only to the release noted, many of the features and functions have been updated or replaced. Please view the current version.
Collect OpenTelemetry data
Grafana Agent Flow can be configured to collect OpenTelemetry-compatible data and forward it to any OpenTelemetry-compatible endpoint.
This topic describes how to:
- Configure OpenTelemetry data delivery
- Configure batching
- Receive OpenTelemetry data over OTLP
Components used in this topic
- otelcol.auth.basic
- otelcol.exporter.otlp
- otelcol.exporter.otlphttp
- otelcol.processor.batch
- otelcol.receiver.otlp
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 Grafana Agent Flow.
- Identify where Grafana Agent Flow will write received telemetry data.
- Be familiar with the concept of Components in Grafana Agent Flow.
Configure an OpenTelemetry Protocol exporter
Before components can receive OpenTelemetry data, you must have a component responsible for exporting the OpenTelemetry data. An OpenTelemetry exporter component is responsible for writing (that is, exporting) OpenTelemetry data to an external system.
In this task, we will use the otelcol.exporter.otlp component to send OpenTelemetry data to a server using the OpenTelemetry Protocol (OTLP). Once an exporter component is defined, other Grafana Agent Flow components can be used to forward data to it.
Refer to the list of available Components for the full list of
otelcol.exportercomponents that can be used to export OpenTelemetry data.
To configure an otelcol.exporter.otlp component for exporting OpenTelemetry
data using OTLP, complete the following steps:
Add the following
otelcol.exporter.otlpcomponent to your configuration file:otelcol.exporter.otlp "EXPORTER_LABEL" { client { url = "HOST:PORT" } }Replace
EXPORTER_LABELwith a label to use for the component, such asdefault. The label chosen must be unique across allotelcol.exporter.otlpcomponents in the same configuration file.Replace
HOSTwith the hostname or IP address of the server to send OTLP requests to.Replace
PORTwith the port of the server to send OTLP requests to.
If your server requires basic authentication, complete the following:
Add the following
otelcol.auth.basiccomponent to your configuration file:otelcol.auth.basic "BASIC_AUTH_LABEL" { username = "USERNAME" password = "PASSWORD" }Replace
BASIC_AUTH_LABELwith a label to use for the component, such asdefault. The label chosen must be unique across allotelcol.auth.basiccomponents in the same configuration file.Replace
USERNAMEwith the basic authentication username to use.Replace
PASSWORDwith the basic authentication password or API key to use.
Add the following line inside of the
clientblock of yourotelcol.exporter.otlpcomponent:auth = otelcol.auth.basic.BASIC_AUTH_LABEL.handler- Replace
BASIC_AUTH_LABELwith the label used for theotelcol.auth.basiccomponent in step 2.1.1.
- Replace
If you have more than one server to export metrics to, create a new
otelcol.exporter.otlpcomponent for each additional server.
otelcol.exporter.otlpsends data using OTLP over gRPC (HTTP/2). To send to a server using HTTP/1.1, follow the steps above but use the otelcol.exporter.otlphttp component instead.
The following example demonstrates configuring otelcol.exporter.otlp with
authentication and a component which forwards data to it:
otelcol.exporter.otlp "default" {
client {
endpoint = "my-otlp-grpc-server:4317"
auth = otelcol.auth.basic.credentials.handler
}
}
otelcol.auth.basic "credentials" {
// Retrieve credentials using environment variables.
username = env("BASIC_AUTH_USER")
password = env("API_KEY")
}
otelcol.receiver.otlp "example" {
grpc {
endpoint = "127.0.0.1:4317"
}
http {
endpoint = "127.0.0.1:4318"
}
output {
metrics = [otelcol.exporter.otlp.default.input]
logs = [otelcol.exporter.otlp.default.input]
traces = [otelcol.exporter.otlp.default.input]
}
}For more information on writing OpenTelemetry data using the OpenTelemetry Protocol, refer to otelcol.exporter.otlp.
Configure batching
Production-ready Grafana Agent Flow configurations should not send OpenTelemetry data directly to an exporter for delivery. Instead, data is usually sent to one or more processor components that perform various transformations on the data.
Ensuring data is batched is a production-readiness step to improve the compression of data and reduce the number of outgoing network requests to external systems.
In this task, we will configure an otelcol.processor.batch component to batch data before sending it to our exporter.
Refer to the list of available Components for the full list of
otelcol.processorcomponents that can be used to process OpenTelemetry data. You can chain processors by having one processor send data to another processor.
To configure an otelcol.processor.batch component, complete the following
steps:
Follow Configure an OpenTelemetry Protocol exporter to ensure received data can be written to an external system.
Add the following
otelcol.processor.batchcomponent into your configuration file:otelcol.processor.batch "PROCESSOR_LABEL" { output { metrics = [otelcol.exporter.otlp.EXPORTER_LABEL.input] logs = [otelcol.exporter.otlp.EXPORTER_LABEL.input] traces = [otelcol.exporter.otlp.EXPORTER_LABEL.input] } }Replace
PROCESSOR_LABELwith a label to use for the component, such asdefault. The label chosen must be unique across allotelcol.processor.batchcomponents in the same configuration file.Replace
EXPORTER_LABELwith the label for your existingotelcol.exporter.otlpcomponent.To disable one of the telemetry types, set the relevant type in the
outputblock to the empty list, such asmetrics = [].To send batched data to another processor, replace the components in the
outputlist with the processor components to use.
The following example demonstrates configuring a sequence of
otelcol.processor components before ultimately being exported:
otelcol.processor.memory_limiter "default" {
check_interval = "1s"
limit = "1GiB"
output {
metrics = [otelcol.processor.batch.default.input]
logs = [otelcol.processor.batch.default.input]
traces = [otelcol.processor.batch.default.input]
}
}
otelcol.processor.batch "default" {
output {
metrics = [otelcol.exporter.otlp.default.input]
logs = [otelcol.exporter.otlp.default.input]
traces = [otelcol.exporter.otlp.default.input]
}
}
otelcol.exporter.otlp "default" {
client {
endpoint = "my-otlp-grpc-server:4317"
}
}For more information on configuring OpenTelemetry data batching, refer to otelcol.processor.batch.
Configure an OpenTelemetry Protocol receiver
Grafana Agent Flow can be configured to receive OpenTelemetry metrics, logs, and traces. An OpenTelemetry receiver component is responsible for receiving OpenTelemetry data from an external system.
In this task, we will use the otelcol.receiver.otlp component to receive OpenTelemetry data over the network using the OpenTelemetry Protocol (OTLP). A receiver component can be configured to forward received data to other Grafana Agent Flow components.
Refer to the list of available Components for the full list of
otelcol.receivercomponents that can be used to receive OpenTelemetry-compatible data.
To configure an otelcol.receiver.otlp component for receiving OTLP data,
complete the following steps:
Follow Configure an OpenTelemetry Protocol exporter to ensure received data can be written to an external system.
Optional: Follow Configure batching to improve compression and reduce the total amount of network requests.
Add the following
otelcol.receiver.otlpcomponent to your configuration file:otelcol.receiver.otlp "LABEL" { output { metrics = [COMPONENT_INPUT_LIST] logs = [COMPONENT_INPUT_LIST] traces = [COMPONENT_INPUT_LIST] } }Replace
LABELwith a label to use for the component, such asdefault. The label chosen must be unique across allotelcol.receiver.otlpcomponents in the same configuration file.Replace
COMPONENT_INPUT_LISTwith a comma-delimited list of component inputs to forward received data to. For example, to send data to an existing batch processor component, useotelcol.processor.batch.PROCESSOR_LABEL.input. To send data directly to an existing exporter component, useotelcol.exporter.otlp.EXPORTER_LABEL.input.To allow applications to send OTLP data over gRPC on port
4317, add the following to yourotelcol.receiver.otlpcomponent:grpc { endpoint = "HOST:4317" }- Replace
HOSTwith a host to listen to traffic on. It is recommended to use a narrowly-scoped listen address whenever possible. To listen on all network interfaces, replaceHOSTwith0.0.0.0.
- Replace
To allow applications to send OTLP data over HTTP/1.1 on port
4318, add the following to yourotelcol.receiver.otlpcomponent:http { endpoint = "HOST:4318" }- Replace
HOSTwith a host to listen to traffic on. It is recommended to use a narrowly-scoped listen address whenever possible. To listen on all network interfaces, replaceHOSTwith0.0.0.0.
- Replace
To disable one of the telemetry types, set the relevant type in the
outputblock to the empty list, such asmetrics = [].
The following example demonstrates configuring otelcol.receiver.otlp and
sending it to an exporter:
otelcol.receiver.otlp "example" {
grpc {
endpoint = "127.0.0.1:4317"
}
http {
endpoint = "127.0.0.1:4318"
}
output {
metrics = [otelcol.processor.batch.example.input]
logs = [otelcol.processor.batch.example.input]
traces = [otelcol.processor.batch.example.input]
}
}
otelcol.processor.batch "example" {
output {
metrics = [otelcol.exporter.otlp.default.input]
logs = [otelcol.exporter.otlp.default.input]
traces = [otelcol.exporter.otlp.default.input]
}
}
otelcol.exporter.otlp "default" {
client {
endpoint = "my-otlp-grpc-server:4317"
}
}For more information on receiving OpenTelemetry data using the OpenTelemetry Protocol, refer to otelcol.receiver.otlp.



