Technology
Keycloak
Monitor Keycloak authentication traffic, error rates, latency, and resource usage with OpenTelemetry in Dash0.
Overview
Overview
Keycloak is a widely used open-source identity and access management server, providing single sign-on, authentication, and authorization for web applications and services. Because most other services depend on it to authenticate their users, Keycloak's own availability and latency have an outsized impact on everything behind it.
Keycloak exposes Prometheus-format metrics through its management interface, includes a native OpenTelemetry tracer, and can emit structured JSON logs, so the Dash0 integration can collect all three signals using only the OpenTelemetry Collector.
Use Cases
- Monitor request rate, error rate, and latency for login, token, and admin API traffic.
- Track database connection pool usage and JVM resource consumption to catch capacity issues early.
- Analyze traces and structured audit logs together to investigate individual login attempts end to end.
- Understand how authentication load and failures change during incidents or traffic spikes.
Setup
Overview
Keycloak collects Prometheus-format metrics through its management interface, supports structured JSON logging, and includes a native OpenTelemetry tracer. This guide configures an OpenTelemetry Collector to scrape and receive Keycloak's telemetry and forward it to Dash0.
For metrics and logs, Keycloak currently offers two paths: a mature, stable path used in this guide by default, and a newer path that exports directly over OTLP. Keycloak's own documentation marks the OTLP metrics exporter as experimental and the OTLP logs exporter as preview, both "not recommended for production" as of Keycloak 26. Both paths are documented below so you can pick either, but the stable path is the default recommendation.
Prerequisites
Before setting up Keycloak monitoring, ensure:
- Keycloak 26 or later is running and its management interface (port
9000by default) is reachable from the collector. - You control Keycloak's startup configuration (CLI flags, environment variables, or a Keycloak Operator custom resource).
You'll need an OpenTelemetry Collector deployed. Consider using:
- Dash0 operator for Kubernetes (recommended)
- OpenTelemetry Operator for Kubernetes
-
Helm Chart for The OpenTelemetry Collector
Configure Keycloak
Metrics
Enable the stable Prometheus metrics endpoint:
kc.sh start --metrics-enabled=trueThis exposes OpenMetrics-format metrics at /metrics on the management interface (port 9000 by default).
Experimental alternative: Keycloak can instead export metrics directly over OTLP using a Micrometer-to-OpenTelemetry bridge. Keycloak's own documentation currently marks this as experimental and not recommended for production:
kc.sh start --features=opentelemetry-metrics \
--telemetry-metrics-enabled=true \
--telemetry-endpoint=http://otel-collector:4317 \
--telemetry-protocol=grpcIf you use this path, skip the prometheus receiver below and add an otlp receiver instead (the same one used
for traces and, optionally, logs).
Traces
Enable Keycloak's native OpenTelemetry tracer:
kc.sh start --tracing-enabled=true \
--tracing-endpoint=http://otel-collector:4317 \
--telemetry-service-name=keycloakBy default, Keycloak samples all traces (tracing-sampler-ratio=1.0). Lower this for production traffic volumes.
Logs
Enable structured JSON console logging:
kc.sh start --log-console-output=jsonPreview alternative: Keycloak can instead export logs directly over OTLP. Keycloak's own documentation currently marks this as a preview feature that is not fully supported:
kc.sh start --features=opentelemetry-logs \
--telemetry-logs-enabled=true \
--telemetry-endpoint=http://otel-collector:4317 \
--telemetry-protocol=grpcDon't enable both the file-based and OTLP log paths at once, since Keycloak's structured log lines (including its
org.keycloak.events audit logger, which records login attempts) will otherwise be collected twice.
Collector Configuration
Configure the collector to scrape Keycloak's stable metrics endpoint and receive traces (and logs, if you use the OTLP log path) over OTLP:
receivers:
prometheus:
config:
scrape_configs:
- job_name: "keycloak"
scrape_interval: 15s
metrics_path: /metrics
static_configs:
- targets: ["keycloak:9000"]
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317If you're using the stable, file-based logging path instead of the OTLP logs exporter, collect Keycloak's JSON log
file with a filelog receiver:
receivers:
filelog:
include: ["/opt/keycloak/data/log/keycloak.log"]
operators:
- type: json_parser
timestamp:
parse_from: attributes.timestamp
layout: "%Y-%m-%dT%H:%M:%S.%f%z"
- type: severity_parser
parse_from: attributes.level
- type: move
from: attributes.message
to: bodyKeycloak includes traceId and spanId in each log record's MDC when tracing is enabled, so logs and traces
correlate automatically once both are flowing into Dash0.
Verification
- Check collector logs for successful scrapes and no export errors.
- Navigate to Metrics Explorer in Dash0 and search for metrics with prefix
http_server_,agroal_, orjvm_. - Navigate to Logging and filter for your Keycloak service name. Try a failed login to confirm
LOGIN_ERRORaudit events arrive. - Navigate to Tracing and confirm spans for
POST /realms/{realm}/protocol/{protocol}/token(and similar routes) appear for authentication requests.
