이 콘텐츠는 선택한 언어로 제공되지 않습니다.

Chapter 8. Analyzing outliers and errors with exemplars


Use exemplars to connect a metric to a recorded trace to analyze the root cause of errors or latencies.

Metrics are aggregations over several events, and show you if your system is operating within defined bounds. They are great to monitor error rates or tail latencies and to set up alerting or drive performance optimizations. Still, the aggregation makes it difficult to find root causes for latencies or errors reported in metrics.

Root causes for errors and latencies can be found by enabling tracing. To connect a metric to a recorded trace, there is the concept of exemplars.

Once exemplars are set up, Red Hat build of Keycloak reports metrics with their last recorded trace as an exemplar. A dashboard tool like Grafana can link the exemplar from a metrics dashboard to a trace view.

Metrics that support exemplars are:

  • http_server_requests_seconds_count (including histograms)
    See the chapter HTTP metrics for details on this metric.
  • keycloak_credentials_password_hashing_validations_total
    See the chapter Self-provided metrics for details on this metric.
  • keycloak_user_events_total
    See the chapter Self-provided metrics for details on this metric.

See below for a screenshot of a heatmap visualization for latencies that is showing an exemplar when hovering over one of the pink indicators.

Figure 8.1. Heatmap diagram with exemplar

8.1. Setting up exemplars

To benefit from exemplars, perform the following steps:

  1. Enable metrics for Red Hat build of Keycloak as described in chapter Gaining insights with metrics.
  2. Enable tracing for Red Hat build of Keycloak as described in chapter Root cause analysis with tracing.
  3. Enable exemplar storage in your monitoring system.

    For Prometheus, this is a preview feature that you need to enable.

  4. Scrape the metrics using the OpenMetricsText1.0.0 protocol, which is not enabled by default in Prometheus.

    If you are using PodMonitors or similar in a Kubernetes environment, this can be achieved by adding it to the spec of the custom resource:

    apiVersion: monitoring.coreos.com/v1
    kind: PodMonitor
    metadata:
      ...
    spec:
      scrapeProtocols:
        - OpenMetricsText1.0.0
    Copy to Clipboard Toggle word wrap
  5. Configure your metrics datasource where to link to for traces.

    When using Grafana and Prometheus, this would be setting up a exemplarTraceIdDestinations for the Prometheus datasource, which then points to your tracing datasource that is provided by tools like Jaeger or Tempo.

  6. Enable exemplars in your dashboards.

    Enable the Exemplars toggle in each query on each dashboard where you want to show exemplars. When set up correctly, you will notice little dots or stars in your dashboards that you can click on to view the traces.

Note
  • If you do not specify the scrape protocol, Prometheus will by default not send it in the content negotiation, and Keycloak will then fall back to the PrometheusText protocol which will not contain the exemplars.
  • If you enabled tracing and metrics, but the request sampling did not record a trace, the exposed metric will not contain any exemplars.
  • If you access the metrics endpoint with your browser, the content negotiation will lead to the format PrometheusText being returned, and you will not see any exemplars.

8.2. Verifying that exemplars work as expected

Perform the following steps to verify that Red Hat build of Keycloak is set up correctly for exemplars:

  1. Follow the instructions to set up metrics and tracing for Red Hat build of Keycloak.
  2. For test purposes, record all traces by setting the tracing ration to 1.0. See Root cause analysis with tracing for recommended sampling settings in production systems.
  3. Log in to the Keycloak instance to create some traces.
  4. Scrape the metrics with a command similar to the following and search for those metrics that have an exemplar set:

    $ curl -s http://localhost:9000/metrics \
    -H 'Accept: application/openmetrics-text; version=1.0.0; charset=utf-8' \
    | grep "#.*trace_id"
    Copy to Clipboard Toggle word wrap

    This should result in an output similar to the following. Note the additional # after which the span and trace IDs are added:

    http_server_requests_seconds_count {...} ... # {span_id="...",trace_id="..."} ...
    Copy to Clipboard Toggle word wrap
맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat