Menu
Grafana Cloud

Application Observability export with Grafana Agent

Grafana Agent Flow is the recommended way to send OpenTelemetry data to Grafana Cloud. Grafana Agent will act as an outbound gateway providing reliability and scalability.

Prerequisites

To set up Grafana Agent to export to Grafana Cloud first:

Configuration

An agent-config.river configuration file is needed for the Grafana Agent to run successfully in flow mode. It is recommended to use the OpenTelemetry (OTLP) integration to generate a configuration file.

Navigate to the OpenTelemetry Application page and click the Add service button. Choose the OpenTelemetry (OTLP) integration from the list.

OpenTelemetry Integration

The OpenTelemetry (OTLP) integration will generate a Grafana Agent configuration to use with Grafana Application Observability:

river
otelcol.receiver.otlp "default" {
	// https://grafana.com/docs/agent/latest/static/flow/reference/components/otelcol.receiver.otlp/

	// configures the default grpc endpoint "0.0.0.0:4317"
	grpc { }
	// configures the default http/protobuf endpoint "0.0.0.0:4318"
	http { }

	output {
		metrics = [otelcol.processor.transform.add_resource_attributes_as_metric_attributes.input]
		logs    = [otelcol.processor.batch.default.input]
		traces  = [otelcol.processor.batch.default.input]
	}
}

otelcol.processor.transform "add_resource_attributes_as_metric_attributes" {
	// https://grafana.com/docs/agent/latest/flow/reference/components/otelcol.processor.transform/
	error_mode = "ignore"
	metric_statements {
		context = "datapoint"
		statements = [
			"set(attributes[\"deployment.environment\"], resource.attributes[\"deployment.environment\"])",
			"set(attributes[\"service.version\"], resource.attributes[\"service.version\"])",
		]
	}
	output {
		metrics = [otelcol.processor.batch.default.input]
	}
}

otelcol.processor.batch "default" {
	// https://grafana.com/docs/agent/latest/flow/reference/components/otelcol.processor.batch/
	output {
		metrics = [otelcol.exporter.prometheus.grafana_cloud_prometheus.input]
		logs    = [otelcol.exporter.loki.grafana_cloud_loki.input]
		traces  = [otelcol.exporter.otlp.grafana_cloud_tempo.input]
	}
}

otelcol.exporter.loki "grafana_cloud_loki" {
	// https://grafana.com/docs/agent/latest/flow/reference/components/otelcol.exporter.loki/
	forward_to = [loki.write.grafana_cloud_loki.receiver]
}

otelcol.exporter.prometheus "grafana_cloud_prometheus" {
	// https://grafana.com/docs/agent/latest/flow/reference/components/otelcol.exporter.prometheus/
	add_metric_suffixes = false
	forward_to = [prometheus.remote_write.grafana_cloud_prometheus.receiver]
}

prometheus.remote_write "grafana_cloud_prometheus" {
	// https://grafana.com/docs/agent/latest/flow/reference/components/prometheus.remote_write/
	endpoint {
		url = env("GRAFANA_CLOUD_PROMETHEUS_URL")

		basic_auth {
			username = env("GRAFANA_CLOUD_PROMETHEUS_USERNAME")
			password = env("GRAFANA_CLOUD_API_KEY")
		}
	}
}

loki.write "grafana_cloud_loki" {
	// https://grafana.com/docs/agent/latest/flow/reference/components/loki.write/
	endpoint {
		url = env("GRAFANA_CLOUD_LOKI_URL")

		basic_auth {
			username = env("GRAFANA_CLOUD_LOKI_USERNAME")
			password = env("GRAFANA_CLOUD_API_KEY")
		}
	}
}

otelcol.exporter.otlp "grafana_cloud_tempo" {
	// https://grafana.com/docs/agent/latest/flow/reference/components/otelcol.exporter.otlp/
	client {
		endpoint = env("GRAFANA_CLOUD_TEMPO_ENDPOINT")
		auth     = otelcol.auth.basic.grafana_cloud_tempo.handler
	}
}

otelcol.auth.basic "grafana_cloud_tempo" {
	// https://grafana.com/docs/agent/latest/flow/reference/components/otelcol.auth.basic/
	username = env("GRAFANA_CLOUD_TEMPO_USERNAME")
    password = env("GRAFANA_CLOUD_API_KEY")
}

The configuration file requires several environmental variable to be set:

Environment VariableDescriptionExample
GRAFANA_CLOUD_API_KEYAPI key generated aboveeyJvSomeLongStringJ9fQ==
GRAFANA_CLOUD_PROMETHEUS_URLRemote Write Endpoint from Grafana Cloud > Prometheus > Detailshttps://prometheus-prod-***.grafana.net/api/prom/push
GRAFANA_CLOUD_PROMETHEUS_USERNAMEUsername/Instance ID from the Grafana Cloud > Prometheus > Details11111
GRAFANA_CLOUD_LOKI_URLurl (without the username and password) from Grafana Cloud > Loki > Details > From a standalone hosthttps://logs-prod-***.grafana.net/loki/api/v1/push
GRAFANA_CLOUD_LOKI_USERNAMEUser from Grafana Cloud > Loki > Details11112
GRAFANA_CLOUD_TEMPO_ENDPOINTendpoint from the Grafana Cloud > Tempo > Details > Sending Data to Tempotempo-***.grafana.net:443
GRAFANA_CLOUD_TEMPO_USERNAMEUser from Grafana Cloud > Tempo > Details11113

Run Grafana Agent

Create the agent-config.river file, set the necessary environment variables, and start the Grafana Agent in flow mode.