feat: capture current ScopeContext #249
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds methods to capture the current thread's profiling labels. Closes #237 .
The problem
Java applications use asynchronous execution patterns where work started by one thread, completes on another. If we want dynamic labels to propagate between threads, the only option is to pass the labels in business methods, and wrap each async call with
Pyroscope.LabelsWrapper.run(). This will make business logic and monitoring code tightly coupled.It is also impossible to retrieve the current profiling labels if we are not the code that actually set them.
Solution
Add methods which allow capturing the current profiling labels.
This is analogous to OpenTelemetry's
Context.current().Example Use Case
This functionality helped us implement a Microprofile thread context provider to propagate the labels across threads, without polluting all of our business logic methods with label parameters.
Since this is an unsolicited contribution, feel free to close if it's not something you'd like to support right now.