Chapter 1. Centralize your observability stack with OpenTelemetry


Learn about OpenTelemetry integration for centralized observability and telemetry data.

OpenTelemetry (OTel) is an open-source observability framework designed to provide consistent and reliable ways to collect telemetry data across distributed systems. It is a project under the Cloud Native Computing Foundation (CNCF) as an incubating project. Its goal is to provide a unified standard and toolset for instrumenting, generating, and exporting telemetry data from modern applications, making it easier to monitor, debug, and understand complex services.

The goal of Red Hat build of Keycloak is to support OpenTelemetry Logs, Metrics, and Traces to create a centralized observability stack without any additional deployment overhead.

1.1. General options

Red Hat build of Keycloak provides support for global settings of telemetry data export. It means that you can configure connection parameters to a single OpenTelemetry collector that will be used for all supported components.

In order to have OpenTelemetry enabled, at least one component needs to be turned on, for example Traces.

Note

The OpenTelemetry feature is enabled by default. Disable the feature in order to disable OpenTelemetry components.

1.1.1. Endpoint

You can configure the OpenTelemetry collector’s global endpoint that is shared across all components by using the telemetry-endpoint option. The default value is http://localhost:4317.

You can change the endpoint via CLI as follows:

bin/kc.[sh|bat] start --telemetry-endpoint=http://my-otel-endpoint:4317

1.1.2. Service name

You can configure the global OpenTelemetry service name used for identifying the exporter of the telemetry data. The default service name is keycloak, specified via the telemetry-service-name property, which takes precedence over service.name defined in the telemetry-resource-attributes property.

You can change the service name via CLI as follows:

bin/kc.[sh|bat] start --telemetry-service-name=my-keycloak-iam

1.1.3. Protocol

You can configure the global OpenTelemetry transport protocol used as a communication channel between Red Hat build of Keycloak and the OpenTelemetry collector. The default value is grpc.

Red Hat build of Keycloak supports these communication protocols:

  • grpc (default)
  • http/protobuf

You can change the protocol via CLI as follows:

bin/kc.[sh|bat] start --telemetry-protocol=http/protobuf

1.1.4. Request headers

You can configure custom request headers that will be sent when exporting telemetry data to the OpenTelemetry collector. This is useful for providing authentication tokens or other custom headers required by your telemetry backend.

Use the telemetry-header-<header> option to set headers for all telemetry components (logs, metrics, and traces).

Replace <header> with your custom header name in the option name.

bin/kc.[sh|bat] start --telemetry-header-Authorization='Bearer my-token' --telemetry-header-X-Custom-Header=custom-value
Note

Component-specific headers take precedence over general headers for their respective components.

1.2. Configuration via Keycloak CR (Operator)

The Keycloak CR has first-class citizen configuration options for telemetry. These may be configured under the spec.telemtry stanza as follows:

apiVersion: k8s.keycloak.org/v2beta1
kind: Keycloak
metadata:
  name: example-kc
spec:
  telemetry:
    endpoint: http://my-telemetry:4317          # default 'http://localhost:4317'
    serviceName: my-best-keycloak-telemetry     # default 'keycloak'
    protocol: http/protobuf                     # default 'grpc'
    resourceAttributes:
      service.namespace: keycloak-namespace-telemetry

These fields should reflect a 1:1 association with telemetry-* server options.

1.2.1. Enable all OpenTelemetry components

To enable OpenTelemetry metrics, logs, and traces, you can configure the Keycloak CR as follows:

Warning

OpenTelemetry Logs and Metrics are preview/experimental features.

apiVersion: k8s.keycloak.org/v2alpha1
kind: Keycloak
metadata:
  name: example-kc
spec:
  features:
    enabled:
      - opentelemetry-logs
      - opentelemetry-metrics
  telemetry:
    endpoint: http://my-telemetry:4317
    serviceName: my-best-keycloak-telemetry
    protocol: grpc
  tracing:
    enabled: true
  additionalOptions:
    - name: telemetry-logs-enabled
      value: "true"
    - name: telemetry-metrics-enabled
      value: "true"
    - name: metrics-enabled
      value: "true"

1.3. Traces

See the Root cause analysis with tracing guide.

You can override the global OpenTelemetry settings via the Tracing options if you want to export traces to a different OpenTelemetry collector.

1.4. Logs

Note

OpenTelemetry Logs support is Technology Preview and is not fully supported. This feature is disabled by default.

To enable start the server with --features=preview or --features=opentelemetry-logs

Note

The OpenTelemetry feature (opentelemetry) needs to be turned on (by default).

It is possible to export Red Hat build of Keycloak’s logs to the OpenTelemetry collector and be managed by various logging backends that support OpenTelemetry.

1.4.1. Enable Logs

You can enable OpenTelemetry Logs via CLI as follows:

bin/kc.[sh|bat] start --features=opentelemetry-logs --telemetry-logs-enabled=true

For more information on how to set up logging, see the Configuring Logging guide.

1.4.2. Log level

By default, all log levels are exported by Red Hat build of Keycloak. You can optionally configure the most verbose log level to be exported via the telemetry-logs-level option.

The telemetry-logs-level option filters which logs are exported to OpenTelemetry, while log-level and log-level-<category> control which logs Red Hat build of Keycloak generates.

The telemetry filter is applied to already-generated logs, so setting telemetry-logs-level=DEBUG will not export DEBUG logs if log-level=WARN.

For example, if you want only to export WARN and ERROR logs, you can change the log level via the CLI as follows:

bin/kc.[sh|bat] start --telemetry-logs-level=WARN

1.4.3. Request headers

As stated for the general configuration of headers, you can configure custom request headers that will be used when exporting logs.

bin/kc.[sh|bat] start --telemetry-logs-header-Authorization='Bearer logs-token'

1.5. Metrics

Warning

The OpenTelemetry Metrics feature is currently experimental, and it is not recommended for use in production.

Note

In order for the Metrics feature to function, the OpenTelemetry feature opentelemetry cannot be disabled.

For integrating OpenTelemetry Metrics, Red Hat build of Keycloak uses the Micrometer-to-OpenTelemetry bridge, which provides the functionality to export metrics created by Micrometer to the OpenTelemetry Collector. This means that all metrics created via Micrometer or OpenTelemetry metrics will be exported to the OpenTelemetry.

There are some API, and Semantic convention differences for Micrometer vs OTel Metrics, so you should check if all required metrics are exported.

1.5.1. Enable Metrics

You can enable the OpenTelemetry Metrics via CLI as follows:

bin/kc.[sh|bat] start --features=opentelemetry-metrics --telemetry-metrics-enabled=true --metrics-enabled=true
Note

Metrics (metrics-enabled) needs to be enabled as well

For more information on how to set up metrics, see the configuration options below or visit the Gaining insights with metrics guide.

1.5.2. Request headers

As stated for the general configuration of headers, you can configure custom request headers that will be used when exporting metrics.

bin/kc.[sh|bat] start --telemetry-metrics-header-Authorization='Bearer metrics-token'

1.6. Relevant options

 Type or ValuesDefault

telemetry-endpoint

OpenTelemetry endpoint to connect to.

CLI: --telemetry-endpoint
Env: KC_TELEMETRY_ENDPOINT

Available only when any of available OpenTelemetry components (Logs, Metrics, Traces) is turned on

String

http://localhost:4317

telemetry-header-<header>

General OpenTelemetry header that will be part of the exporter request (mainly useful for providing Authorization header).

Check the documentation on how to set environment variables for headers containing special characters or custom case-sensitive headers.

CLI: --telemetry-header-<header>
Env: KC_TELEMETRY_HEADER_<HEADER>

Available only when any of available OpenTelemetry components (Logs, Metrics, Traces) is turned on

String

 

telemetry-protocol

OpenTelemetry protocol used for the communication between server and OpenTelemetry collector.

CLI: --telemetry-protocol
Env: KC_TELEMETRY_PROTOCOL

Available only when any of available OpenTelemetry components (Logs, Metrics, Traces) is turned on

grpc, http/protobuf

grpc

telemetry-resource-attributes

OpenTelemetry resource attributes characterize the telemetry producer.

Values in format key1=val1,key2=val2.

CLI: --telemetry-resource-attributes
Env: KC_TELEMETRY_RESOURCE_ATTRIBUTES

Available only when any of available OpenTelemetry components (Logs, Metrics, Traces) is turned on

List

 

telemetry-service-name

OpenTelemetry service name.

Takes precedence over service.name defined in the telemetry-resource-attributes property.

CLI: --telemetry-service-name
Env: KC_TELEMETRY_SERVICE_NAME

Available only when any of available OpenTelemetry components (Logs, Metrics, Traces) is turned on

String

keycloak

1.6.1. Traces

 Type or ValuesDefault

tracing-enabled 🛠

Enables the OpenTelemetry tracing.

CLI: --tracing-enabled
Env: KC_TRACING_ENABLED

Available only when 'opentelemetry' feature is enabled

true, false

false

tracing-endpoint

OpenTelemetry endpoint to connect to for traces.

If not given, the value is inherited from the telemetry-endpoint option.

CLI: --tracing-endpoint
Env: KC_TRACING_ENDPOINT

Available only when Tracing is enabled

String

http://localhost:4317

tracing-protocol

OpenTelemetry protocol used for the telemetry data.

If not given, the value is inherited from the telemetry-protocol option.

CLI: --tracing-protocol
Env: KC_TRACING_PROTOCOL

Available only when Tracing is enabled

grpc, http/protobuf

grpc

tracing-resource-attributes

OpenTelemetry resource attributes present in the exported trace to characterize the telemetry producer.

Values in format key1=val1,key2=val2. If not given, the value is inherited from the telemetry-resource-attributes option. For more information, check the Tracing guide.

CLI: --tracing-resource-attributes
Env: KC_TRACING_RESOURCE_ATTRIBUTES

Available only when Tracing is enabled

DEPRECATED. Resource attributes are not directly related to Tracing and you should use the Telemetry option which takes precedence. Use: telemetry-resource-attributes.

List

 

tracing-service-name

OpenTelemetry service name.

Takes precedence over service.name defined in the tracing-resource-attributes property. If not given, the value is inherited from the telemetry-service-name option.

CLI: --tracing-service-name
Env: KC_TRACING_SERVICE_NAME

Available only when Tracing is enabled

DEPRECATED. Service name is not directly related to Tracing and you should use the Telemetry option which takes precedence. Use: telemetry-service-name.

String

keycloak

1.6.2. Logs

 Type or ValuesDefault

telemetry-logs-enabled 🛠

Enables exporting logs to a destination handling OpenTelemetry logs.

CLI: --telemetry-logs-enabled
Env: KC_TELEMETRY_LOGS_ENABLED

Available only when feature 'opentelemetry-logs:v1' is enabled

true, false

false

telemetry-logs-endpoint

OpenTelemetry endpoint to export logs to.

If not given, the value is inherited from the telemetry-endpoint option.

CLI: --telemetry-logs-endpoint
Env: KC_TELEMETRY_LOGS_ENDPOINT

Available only when Telemetry Logs functionality ('telemetry-logs-enabled') is enabled

String

 

telemetry-logs-header-<header>

OpenTelemetry header that will be part of the log exporter request (mainly useful for providing Authorization header).

Check the documentation on how to set environment variables for headers containing special characters or custom case-sensitive headers.

CLI: --telemetry-logs-header-<header>
Env: KC_TELEMETRY_LOGS_HEADER_<HEADER>

Available only when Telemetry Logs functionality ('telemetry-logs-enabled') is enabled

String

 

telemetry-logs-level

The most verbose log level exported to the telemetry endpoint.

For more information, check the Telemetry guide.

CLI: --telemetry-logs-level
Env: KC_TELEMETRY_LOGS_LEVEL

Available only when Telemetry Logs functionality ('telemetry-logs-enabled') is enabled

off, fatal, error, warn, info, debug, trace, all

all

telemetry-logs-protocol

OpenTelemetry protocol used for exporting logs.

If not given, the value is inherited from the telemetry-protocol option.

CLI: --telemetry-logs-protocol
Env: KC_TELEMETRY_LOGS_PROTOCOL

Available only when Telemetry Logs functionality ('telemetry-logs-enabled') is enabled

grpc, http/protobuf

 

1.6.3. Metrics

 Type or ValuesDefault

metrics-enabled 🛠

If the server should expose metrics.

If enabled, metrics are available at the /metrics endpoint.

CLI: --metrics-enabled
Env: KC_METRICS_ENABLED

true, false

false

telemetry-metrics-enabled 🛠

Enables exporting metrics to a destination handling OpenTelemetry metrics.

CLI: --telemetry-metrics-enabled
Env: KC_TELEMETRY_METRICS_ENABLED

Available only when metrics and feature 'opentelemetry-metrics:v1' are enabled

true, false

false

telemetry-metrics-endpoint

OpenTelemetry endpoint to connect to for Metrics.

If not given, the value is inherited from the telemetry-endpoint option.

CLI: --telemetry-metrics-endpoint
Env: KC_TELEMETRY_METRICS_ENDPOINT

Available only when metrics ('metrics-enabled') and Telemetry Metrics functionality ('telemetry-metrics-enabled') are enabled

String

 

telemetry-metrics-header-<header>

OpenTelemetry header that will be part of the metrics exporter request (mainly useful for providing Authorization header).

Check the documentation on how to set environment variables for headers containing special characters or custom case-sensitive headers.

CLI: --telemetry-metrics-header-<header>
Env: KC_TELEMETRY_METRICS_HEADER_<HEADER>

Available only when metrics ('metrics-enabled') and Telemetry Metrics functionality ('telemetry-metrics-enabled') are enabled

String

 

telemetry-metrics-interval

The interval between the start of two metric export attempts to the destination handling OpenTelemetry metrics data.

It accepts simplified format for time units as java.time.Duration (like 5000ms, 30s, 5m, 1h). If the value is only a number, it represents time in seconds.

CLI: --telemetry-metrics-interval
Env: KC_TELEMETRY_METRICS_INTERVAL

Available only when metrics ('metrics-enabled') and Telemetry Metrics functionality ('telemetry-metrics-enabled') are enabled

String

60s

telemetry-metrics-protocol

OpenTelemetry protocol used for the metrics telemetry data.

If not given, the value is inherited from the telemetry-protocol option.

CLI: --telemetry-metrics-protocol
Env: KC_TELEMETRY_METRICS_PROTOCOL

Available only when metrics ('metrics-enabled') and Telemetry Metrics functionality ('telemetry-metrics-enabled') are enabled

grpc, http/protobuf

 
Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat Documentation

Legal Notice

Theme

© 2026 Red Hat
Back to top