Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use micrometer context propagation for virtual thread executor #1875

Merged
merged 1 commit into from
Apr 8, 2024

Conversation

paulbakker
Copy link
Collaborator

Pull Request type

  • Bugfix
  • [x ] Feature
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Other (please describe):

Changes in this PR

Set up a Micrometer ContextSnapshotFactory and use this to wrap tasks in VirtualThreadTaskExecutor. This enables context propagation using the micrometer context-propagation library.
By default it registers the SLF4j MDC propagation that comes out of the box with micrometer context. A user can provide more accessors by either registering them in META-INF/services, which is the SPI Micrometer uses, or you can override the bean definition that's now in the DGS autoconfiguration:

@Bean
    @ConditionalOnMissingBean
    open fun dgsMicrometerContextRegistry(): ContextRegistry {
        return ContextRegistry.getInstance()
            .registerThreadLocalAccessor(Slf4jThreadLocalAccessor())
    }

WIth this PR, a datafetcher that runs on a virtual thread, has context propagated, so you can for example rely on MDC.

@srinivasankavitha
Copy link
Contributor

Should the micrometer dependency be pinned here? Should we add it to the BOM instead?

@paulbakker
Copy link
Collaborator Author

Should the micrometer dependency be pinned here? Should we add it to the BOM instead?

Yes, good idea. Done.
There's one place I couldn't get rid of the version because the multi-release java21Implementation syntax didn't work with a BOM version.

@paulbakker paulbakker merged commit 83fd939 into master Apr 8, 2024
3 checks passed
@paulbakker paulbakker deleted the feature/context-propagation branch April 8, 2024 16:56
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.

3 participants