# Keycloak Metrics SPI doesnt work with Keycloak v16

**URL:** <https://forum.keycloak.org/t/keycloak-metrics-spi-doesnt-work-with-keycloak-v16/12688>\
**Category:** Configuring the server\
**Created:** [December 18, 2021, 4:43pm UTC](https://forum.keycloak.org/t/keycloak-metrics-spi-doesnt-work-with-keycloak-v16/12688 "2021-12-18T16:43:31Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![PeterSilva](https://avatars.discourse-cdn.com/v4/letter/p/b5ac83/32.png) [@PeterSilva](https://forum.keycloak.org/u/PeterSilva)\
**Post date:** [December 18, 2021, 4:43pm UTC](https://forum.keycloak.org/t/keycloak-metrics-spi-doesnt-work-with-keycloak-v16/12688/1 "2021-12-18T16:43:31Z")

</div>

I have setup it up just fine on previous versions but with the new release, you get all kinds of fatal errors on server startup.

> <https://github.com/aerogear/keycloak-metrics-spi/blob/master/README.md>

---

<div class="post-metadata">

**Author:** ![jangaraj](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/jangaraj/32/5175_2.png) [@jangaraj](https://forum.keycloak.org/u/jangaraj)\
**Post date:** [December 18, 2021, 6:11pm UTC](https://forum.keycloak.org/t/keycloak-metrics-spi-doesnt-work-with-keycloak-v16/12688/2 "2021-12-18T18:11:34Z")

</div>

BTW: This SPI is also not working in quarkus distribution, which will be main distribution soon.

IMHO if you have proper log management and log parsing then you can get metrics from those logs.

---

<div class="post-metadata">

**Author:** ![PeterSilva](https://avatars.discourse-cdn.com/v4/letter/p/b5ac83/32.png) [@PeterSilva](https://forum.keycloak.org/u/PeterSilva)\
**Post date:** [December 18, 2021, 6:28pm UTC](https://forum.keycloak.org/t/keycloak-metrics-spi-doesnt-work-with-keycloak-v16/12688/3 "2021-12-18T18:28:13Z")

</div>

Thanks for the reply.

Indeed, but that work has already been done and this SPI is listed at

> **[Extensions - Keycloak](https://www.keycloak.org/extensions.html)**
>
> Keycloak is an open source identity and access management solution

so I guess it must have some valor.

---

<div class="post-metadata">

**Author:** ![PeterSilva](https://avatars.discourse-cdn.com/v4/letter/p/b5ac83/32.png) [@PeterSilva](https://forum.keycloak.org/u/PeterSilva)\
**Post date:** [December 18, 2021, 6:34pm UTC](https://forum.keycloak.org/t/keycloak-metrics-spi-doesnt-work-with-keycloak-v16/12688/4 "2021-12-18T18:34:22Z")

</div>

How does one ping the lead developers of this extension to this here thread ?

---

<div class="post-metadata">

**Author:** ![semangard](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/semangard/32/1922_2.png) [@semangard](https://forum.keycloak.org/u/semangard)\
**Post date:** [December 18, 2021, 7:06pm UTC](https://forum.keycloak.org/t/keycloak-metrics-spi-doesnt-work-with-keycloak-v16/12688/5 "2021-12-18T19:06:03Z")

</div>

> <https://github.com/aerogear/keycloak-metrics-spi/issues/107>
>
> \## Description
> keycloak-metrics-spi is breaking startup of Keycloak.X 14.0.0.
> …Are there any plans to support Keycloak.X distribution?
> 
> \## Actual Behavior
> \`2021-06-30 10:19:59,785 ERROR \[org.key.cli.Picocli\] (main) ERROR: Failed to start server using profile (dev).
> 2021-06-30 10:19:59,786 ERROR \[org.key.cli.Picocli\] (main) ERROR: Details:: java.lang.NoSuchMethodError: org.jboss.resteasy.spi.ResteasyProviderFactory.getContainerRequestFilterRegistry()Lorg/jboss/resteasy/core/interception/ContainerRequestFilterRegistry;
> at org.jboss.aerogear.keycloak.metrics.MetricsEndpointFactory.init(MetricsEndpointFactory.java:18)
> at org.keycloak.QuarkusKeycloakSessionFactory.init(QuarkusKeycloakSessionFactory.java:68)
> at org.keycloak.QuarkusKeycloakApplication.initializeKeycloakSessionFactory(QuarkusKeycloakApplication.java:52)
> at org.keycloak.QuarkusKeycloakApplication.startup(QuarkusKeycloakApplication.java:31)
> at org.keycloak.provider.quarkus.QuarkusLifecycleObserver.onStartupEvent(QuarkusLifecycleObserver.java:47)
> at org.keycloak.provider.quarkus.QuarkusLifecycleObserver\_Observer\_onStartupEvent\_8292a286c9778cb4a07bc3314fcbfb61e7fe81a0.notify(QuarkusLifecycleObserver\_Observer\_onStartupEvent\_8292a286c9778cb4a07bc331
> 4fcbfb61e7fe81a0.zig:147)
> at io.quarkus.arc.impl.EventImpl$Notifier.notifyObservers(EventImpl.java:283)
> at io.quarkus.arc.impl.EventImpl$Notifier.notify(EventImpl.java:268)
> at io.quarkus.arc.impl.EventImpl.fire(EventImpl.java:70)
> at io.quarkus.arc.runtime.ArcRecorder.fireLifecycleEvent(ArcRecorder.java:128)
> at io.quarkus.arc.runtime.ArcRecorder.handleLifecycleEvents(ArcRecorder.java:97)
> at io.quarkus.deployment.steps.LifecycleEventsBuildStep$startupEvent1144526294.deploy\_0(LifecycleEventsBuildStep$startupEvent1144526294.zig:87)
> at io.quarkus.deployment.steps.LifecycleEventsBuildStep$startupEvent1144526294.deploy(LifecycleEventsBuildStep$startupEvent1144526294.zig:40)
> at io.quarkus.runner.ApplicationImpl.doStart(ApplicationImpl.zig:794)
> at io.quarkus.runtime.Application.start(Application.java:90)
> at io.quarkus.runtime.ApplicationLifecycleManager.run(ApplicationLifecycleManager.java:100)
> at io.quarkus.runtime.Quarkus.run(Quarkus.java:66)
> at org.keycloak.cli.KeycloakMain.start(KeycloakMain.java:66)
> at org.keycloak.cli.KeycloakMain.start(KeycloakMain.java:62)
> at org.keycloak.cli.MainCommand.startDev(MainCommand.java:114)
> at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
> at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> at java.base/java.lang.reflect.Method.invoke(Unknown Source)
> at picocli.CommandLine.executeUserObject(CommandLine.java:1972)
> at picocli.CommandLine.access$1300(CommandLine.java:145)
> at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2352)
> at picocli.CommandLine$RunLast.handle(CommandLine.java:2346)
> at picocli.CommandLine$RunLast.handle(CommandLine.java:2311)
> at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2179)
> at picocli.CommandLine.execute(CommandLine.java:2078)
> at org.keycloak.cli.KeycloakMain.parseAndRun(KeycloakMain.java:99)
> at org.keycloak.cli.KeycloakMain.main(KeycloakMain.java:58)
> at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
> at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> at java.base/java.lang.reflect.Method.invoke(Unknown Source)
> at io.quarkus.bootstrap.runner.QuarkusEntryPoint.doRun(QuarkusEntryPoint.java:48)
> at io.quarkus.bootstrap.runner.QuarkusEntryPoint.main(QuarkusEntryPoint.java:25)
> \`
> 
> \## Environment
> 
> \* Operating system: Windows 10
> \* Project Versions: 
> \* Keycloak.X 14.0.0
> \* keycloak-metrics-spi 2.4.0
> 
> \## Steps to reproduce
> 1. Download \[keycloak.x-preview-14.0.0.zip\](https://github.com/keycloak/keycloak/releases/download/14.0.0/keycloak.x-preview-14.0.0.zip)
> 2. Download \[keycloak-metrics-spi-2.4.0.jar\](https://github.com/aerogear/keycloak-metrics-spi/releases/download/2.4.0/keycloak-metrics-spi-2.4.0.jar)
> 
> 3. Unzip keycloak.x-preview-14.0.0.zip
> 4. cd keycloak.x-14.0.0/
> 5. Copy keycloak-metrics-spi-2.4.0.jar into providers/
> 6. Run bin/kc.sh config
> 7. Run bin/kc.sh start-dev --verbose

and

> <https://github.com/aerogear/keycloak-metrics-spi/pull/120>
>
> \## Motivation
> 
> Currently the keycloak-metrics-spi does not work with Keycloak.…X because
> the \`MetricsEndpointFactory\` explicitly registers a \`MetricsFilter\` instance 
> via the \`ResteasyProviderFactory\`, that uses Resteasy 3 API, which is not available 
> in Keycloak.X.
> 
> \## What
> Add a workaround to be able to use keycloak-metrics-spi with Keycloak and Keycloak.X.
> 
> \## Why
> keycloak-metrics-spi did not work with Keycloak.X,
> 
> \## How
> This PR adds a guard around the \`MetricsFilter\` registration in the \`MetricsEndpointFactory\`,
> which uses the Resteasy 3 API only if available.
> 
> To register the \`MetricsFilter\` in Keycloak.X environments, we use the JAX-RS providers 
> support of of the Quarkus platform, which dynamically discovers and registers 
> the \`MetricsFilterProvider\`, which delegates filter invocations to the \`MetricsFilter\` instance.
> 
> \## Verification Steps
> Add the steps required to check this change. Following an example.
>  
> 1. Build the .jar
> 2. Deploy the jar to Keycloak
> 3. Deploy the jar to Keycloak.X
> 4. Verify both servers can start and expose the metrics endpoint
> 5. Login to the Keycloak admin-console and inspect http://localhost:8080/realms/realms/master/metrics
> 6. Login to the Keycloak.X admin-console and inspect http://localhost:8080/realms/master/metrics
> 
> \## Checklist
> \[x\] Code has been tested locally by PR requester
> \[\] Changes have been successfully verified by another team member
> 
> \## Progress
> \[x\] Finished task
> 
> \## Additional Notes
> 
> Updated the keycloak version to 15.0.2
> Updated the prometheus client version to 0.12.0
> Fixed broken references in readme
> 
> Fixes https://github.com/aerogear/keycloak-metrics-spi/issues/107

quite annoying indeed…

---

<div class="post-metadata">

**Author:** ![PeterSilva](https://avatars.discourse-cdn.com/v4/letter/p/b5ac83/32.png) [@PeterSilva](https://forum.keycloak.org/u/PeterSilva)\
**Post date:** [December 18, 2021, 7:27pm UTC](https://forum.keycloak.org/t/keycloak-metrics-spi-doesnt-work-with-keycloak-v16/12688/6 "2021-12-18T19:27:37Z")

</div>

Hi, up until 15.1 I had no issue with the extension. Only with 16.0 that I get KO

---

<div class="post-metadata">

**Author:** ![jangaraj](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/jangaraj/32/5175_2.png) [@jangaraj](https://forum.keycloak.org/u/jangaraj)\
**Post date:** [December 18, 2021, 9:08pm UTC](https://forum.keycloak.org/t/keycloak-metrics-spi-doesnt-work-with-keycloak-v16/12688/7 "2021-12-18T21:08:14Z")

</div>

Yes, but it is not clear from initial comment `you get all kinds of fatal errors on server startup` that’s really the issue, which you linked and that linked PR will solve it.

BTW: please don’t post comment `+1` to Github PRs/issues, that’s annoying for users who are watching those PRs/issues (it generates notification, which are not getting any usefull information for that PR/issue). Please use [reactions](https://docs.github.com/en/rest/reference/reactions) to “like” them instead.

---

<div class="post-metadata">

**Author:** ![semangard](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/semangard/32/1922_2.png) [@semangard](https://forum.keycloak.org/u/semangard)\
**Post date:** [December 19, 2021, 4:31am UTC](https://forum.keycloak.org/t/keycloak-metrics-spi-doesnt-work-with-keycloak-v16/12688/8 "2021-12-19T04:31:36Z")

</div>

I tested :

- if you keep the extension it does not start (cf. below)
- if you remove it starts

The error while starting with the extension:

 ![image](https://global.discourse-cdn.com/free1/uploads/keycloak/original/2X/d/d0778ca7d8d4eac744d5042ca20d137964a21dc6.png)

---

<div class="post-metadata">

**Author:** ![PeterSilva](https://avatars.discourse-cdn.com/v4/letter/p/b5ac83/32.png) [@PeterSilva](https://forum.keycloak.org/u/PeterSilva)\
**Post date:** [December 19, 2021, 7:49am UTC](https://forum.keycloak.org/t/keycloak-metrics-spi-doesnt-work-with-keycloak-v16/12688/9 "2021-12-19T07:49:02Z")

</div>

@semangard  
Thanks.  
I tried that, no errors but that didnt accomplish anything for me.  
I will not find metrics-listener in the Events Config section list in the KC GUI ( _Manage → Events → Config_ . The _Event Listeners_ configuration should have an entry named `metrics-listener`)  
Also, if you touch a file without the extension.dodeploy next to it (in the standalone/deployments folder) you’ll immediately start getting errors in KC

---

<div class="post-metadata">

**Author:** ![PeterSilva](https://avatars.discourse-cdn.com/v4/letter/p/b5ac83/32.png) [@PeterSilva](https://forum.keycloak.org/u/PeterSilva)\
**Post date:** [December 27, 2021, 7:50am UTC](https://forum.keycloak.org/t/keycloak-metrics-spi-doesnt-work-with-keycloak-v16/12688/10 "2021-12-27T07:50:43Z")

</div>

release 2.5.3 is out, compatible with v15+

Thanks all
