Skip to content

Make Slf4jThreadLocalAccessor loadable by ServiceLoader#554

Open
jonatan-ivanov wants to merge 1 commit into
1.1.xfrom
Slf4jThreadLocalAccessor-autoload
Open

Make Slf4jThreadLocalAccessor loadable by ServiceLoader#554
jonatan-ivanov wants to merge 1 commit into
1.1.xfrom
Slf4jThreadLocalAccessor-autoload

Conversation

@jonatan-ivanov

@jonatan-ivanov jonatan-ivanov commented May 28, 2026

Copy link
Copy Markdown
Member

Slf4jThreadLocalAccessor were not loaded by ServiceLoader because it does not have a public, no-arg constructor, producing the following exception:

java.util.ServiceConfigurationError: io.micrometer.context.ThreadLocalAccessor: io.micrometer.context.integration.Slf4jThreadLocalAccessor Unable to get public no-arg constructor

Closes gh-540

Slf4jThreadLocalAccessor were not loaded by ServiceLoader
because it does not have a public, no-arg constructor, producing the
following exception:

java.util.ServiceConfigurationError: io.micrometer.context.ThreadLocalAccessor: io.micrometer.context.integration.Slf4jThreadLocalAccessor Unable to get public no-arg constructor

Closes gh-540
Comment on lines +47 to +48
* Create an instance of {@link Slf4jThreadLocalAccessor}. If used directly or through
* the {@code ServiceLoader}, the entire contents of the {@link MDC} are propagated.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd stick a warning here that using this as a service causes the global variant to be used that catches the entire map backing SLF4J's context. If any other library (e.g. Micrometer itself) stores anything in the context (trace identifiers) this service together with Micrometer would step on each others' toes. I believe this begs for a huge warning.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is why I now think maybe we should keep this as-as and document that this needs to be explicitly registered manually (maybe also giving them a workaround: extending the class and defining a default ctor in the child).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants