Caution
Grafana Agent has reached End-of-Life (EOL) on November 1, 2025. Agent is no longer receiving vendor support and will no longer receive security or bug fixes. Current users of Agent Static mode, Agent Flow mode, and Agent Operator should proceed with migrating to Grafana Alloy. If you have already migrated to Alloy, no further action is required. Read more about why we recommend migrating to Grafana Alloy.
otelcol.auth.oauth2
otelcol.auth.oauth2 exposes a handler that can be used by other otelcol
components to authenticate requests using OAuth 2.0.
The authorization tokens can be used by HTTP and gRPC based OpenTelemetry exporters. This component can fetch and refresh expired tokens automatically. For further details about OAuth 2.0 Client Credentials flow (2-legged workflow) see this document.
NOTE:
otelcol.auth.oauth2is a wrapper over the upstream OpenTelemetry Collectoroauth2clientextension. Bug reports or feature requests will be redirected to the upstream repository, if necessary.
Multiple otelcol.auth.oauth2 components can be specified by giving them
different labels.
Usage
otelcol.auth.oauth2 "LABEL" {
client_id = "CLIENT_ID"
client_secret = "CLIENT_SECRET"
token_url = "TOKEN_URL"
}Arguments
The timeout argument is used both for requesting initial tokens and for refreshing tokens. "0s" implies no timeout.
At least one of the client_id and client_id_file pair of arguments must be
set. In case both are set, client_id_file takes precedence.
Similarly, at least one of the client_secret and client_secret_file pair of
arguments must be set. In case both are set, client_secret_file also takes
precedence.
Blocks
The following blocks are supported inside the definition of
otelcol.auth.oauth2:
tls block
The tls block configures TLS settings used for connecting to the token client. If the tls block isn’t provided,
TLS won’t be used for communication.
The following arguments are supported:
If the server doesn’t support TLS, you must set the insecure argument to true.
To disable tls for connections to the server, set the insecure argument to true.
If reload_interval is set to "0s", the certificate never reloaded.
The following pairs of arguments are mutually exclusive and can’t both be set simultaneously:
ca_pemandca_filecert_pemandcert_filekey_pemandkey_file
If cipher_suites is left blank, a safe default list is used.
See the Go TLS documentation for a list of supported cipher suites.
Exported fields
The following fields are exported and can be referenced by other components:
Component health
otelcol.auth.oauth2 is only reported as unhealthy if given an invalid
configuration.
Debug information
otelcol.auth.oauth2 does not expose any component-specific debug information.
Example
This example configures otelcol.exporter.otlp to use OAuth 2.0 for authentication:
otelcol.exporter.otlp "example" {
client {
endpoint = "my-otlp-grpc-server:4317"
auth = otelcol.auth.oauth2.creds.handler
}
}
otelcol.auth.oauth2 "creds" {
client_id = "someclientid"
client_secret = "someclientsecret"
token_url = "https://example.com/oauth2/default/v1/token"
}Here is another example with some optional attributes specified:
otelcol.exporter.otlp "example" {
client {
endpoint = "my-otlp-grpc-server:4317"
auth = otelcol.auth.oauth2.creds.handler
}
}
otelcol.auth.oauth2 "creds" {
client_id = "someclientid2"
client_secret = "someclientsecret2"
token_url = "https://example.com/oauth2/default/v1/token"
endpoint_params = {"audience" = ["someaudience"]}
scopes = ["api.metrics"]
timeout = "3600s"
}


