OpenTelemetry Collector: Write log data with OTLP API
Last updated on
STACKIT Logs supports ingesting log records via the OpenTelemetry (OTLP) protocol over HTTP. You can configure the OpenTelemetry Collector’s OTLP/HTTP exporter (otlp_http) to forward logs directly to your STACKIT Logs instance.
To authenticate requests, STACKIT Logs supports two authentication methods:
- STACKIT Service Account (recommended): Uses the
oauth2clientextension to exchange service account credentials for short-lived JWT access tokens automatically. - Instance Access Token: Uses the
bearertokenauthextension with a static bearer token created in your Logs instance.
Prerequisites
Section titled “Prerequisites”- STACKIT Logs instance: Create your first STACKIT Logs instance
- Data source URL: Retrieve API URLs for your STACKIT Logs instance
- Credentials:
- For Service Account authentication (recommended):
- A STACKIT Service Account: Create a service account
- A Service Account Key pair: Create a service account key
- An Access Policy configured on your STACKIT Logs instance granting the Service Account write permissions.
- For Access Token authentication:
- An access token with write permissions: Retrieve credentials for STACKIT Logs instance
- For Service Account authentication (recommended):
Authenticate with a STACKIT Service Account (Recommended)
Section titled “Authenticate with a STACKIT Service Account (Recommended)”Using a STACKIT Service Account is the recommended approach for automated and production workloads. The oauth2client extension automatically obtains short-lived JWTs from the STACKIT IAM endpoint, eliminating the need to manage and rotate long-lived access tokens.
Configuration Example
Section titled “Configuration Example”# 1. Define OAuth2 client extensionextensions: oauth2client: client_id: "<sa-credentials-sub>" client_certificate_key_id: "<sa-credentials-kid>" client_certificate_key_file: "<path-to-sa-private-key.pem>" grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer" token_url: "https://accounts.stackit.cloud/oauth/v2/token" signature_algorithm: "RS512" iss: "<service-account-id>" # Service account ID or email audience: "https://accounts.stackit.cloud" expiry_buffer: "2m"
# 2. Define OTLP/HTTP exporterexporters: otlp_http: # NOTE: The collector internally appends '/v1/logs' to this endpoint endpoint: <data-source-url-of-logs-instance>/otlp auth: authenticator: oauth2client
# 3. Configure the collector service and log pipelineservice: extensions: [oauth2client] pipelines: logs: receivers: [...] # Configure receivers according to your use case processors: [...] # Configure processors according to your use case exporters: [otlp_http]Setup Steps
Section titled “Setup Steps”- Open or create your collector configuration file (for example,
/etc/otelcol-contrib/config.yaml). - Add an
oauth2clientextension under theextensionsblock with your service account credentials:client_id: Thesubfield from your service account key JSON file.client_certificate_key_id: Thekidfield from your service account key JSON file.client_certificate_key_file: Path to the private key PEM file associated with the service account key.iss: The service account ID or service account email.token_url:https://accounts.stackit.cloud/oauth/v2/tokengrant_type:urn:ietf:params:oauth:grant-type:jwt-bearersignature_algorithm:RS512audience:https://accounts.stackit.cloud
- Define the
otlp_httpexporter underexporters:- Set
endpointto<data-source-url-of-logs-instance>/otlp. - Set
auth.authenticatortooauth2client.
- Set
- Register
oauth2clientin theservice.extensionslist. - Add
otlp_httpto theservice.pipelines.logs.exporterslist.
Authenticate with an Instance Access Token
Section titled “Authenticate with an Instance Access Token”You can also authenticate using a static access token generated directly from your STACKIT Logs instance. The bearertokenauth extension attaches this token to the Authorization: Bearer <token> header of every exported HTTP request.
Configuration Example
Section titled “Configuration Example”# 1. Define Bearer token authentication extensionextensions: bearertokenauth/stackit_logs: scheme: "Bearer" # Provide the token directly: token: "<Token value from Logs instance Access Token>" # Or load it from an external file: # filename: "/etc/otelcol-contrib/logs-access.token"
# 2. Define OTLP/HTTP exporterexporters: otlp_http: # NOTE: The collector internally appends '/v1/logs' to this endpoint endpoint: <data-source-url-of-logs-instance>/otlp auth: authenticator: bearertokenauth/stackit_logs
# 3. Configure the collector service and log pipelineservice: extensions: [bearertokenauth/stackit_logs] pipelines: logs: receivers: [...] # Configure receivers according to your use case processors: [...] # Configure processors according to your use case exporters: [otlp_http]Setup Steps
Section titled “Setup Steps”- Open or create your collector configuration file (for example,
/etc/otelcol-contrib/config.yaml). - Add a
bearertokenauthextension underextensions:- Set
schemeto"Bearer". - Specify your access token using either the
tokenfield (inline string) or thefilenamefield (path to file containing the token).
- Set
- Define the
otlp_httpexporter underexporters:- Set
endpointto<data-source-url-of-logs-instance>/otlp. - Set
auth.authenticatortobearertokenauth/stackit_logs.
- Set
- Register
bearertokenauth/stackit_logsin theservice.extensionslist. - Add
otlp_httpto theservice.pipelines.logs.exporterslist.