fix:Add factories for SamplingResult #3354#3360
fix:Add factories for SamplingResult #3354#3360Rocksnake wants to merge 8 commits intoopen-telemetry:mainfrom Rocksnake:fix/add_factories_for_samplingResult
Conversation
|
|
|
Could anybody help to approve running these workflows, great thanks! |
|
For the future: Please also mention the ticket number in the description as "Fixes #3354". GitHub does not link issues from the title.
I have an "Approve and run" button and clicked it and it seemed to have started but now it seems stuck. Probably an actual maintainer needs to approve the run. EDIT: Oh, it seems to have worked. Probably each new push has to be re-approved. |
| * @return A {@link SamplingResult} with the attributes equivalent to {@code attributes} and the | ||
| * {@link SamplingDecision#RECORD_AND_SAMPLE} | ||
| */ | ||
| static SamplingResult recordAndSample(Attributes attributes) { |
There was a problem hiding this comment.
I wouldn't create these overloads with attributes. As @anuraaga mentioned, the existing method works fine for that, and actually does create a new object when being called.
There was a problem hiding this comment.
Thanks, but in the project, RateLimitingSampler calls the method with parameters. I think the method with parameters is necessary when we need specific sampling. I'm a first-time contributor, I hope you can give me some guidance.
There was a problem hiding this comment.
@Rocksnake Thanks for the help - as per the below comment, we won't be (can't) removing the create methods. We should continue to use create for creating the results with attributes
There was a problem hiding this comment.
Ok, thanks. And in my last commit, I have restored the original create method.
| static final SamplingResult EMPTY_RECORDED_SAMPLING_RESULT = | ||
| ImmutableSamplingResult.createWithoutAttributes(SamplingDecision.RECORD_ONLY); | ||
|
|
||
| static SamplingResult getEmptyRecordedAndSampledSamplingResult() { |
There was a problem hiding this comment.
small thing, but I might just call this recordAndSample(). It's much easier to read and there's fewer words to parse through to get to what it's doing. I know this isn't public, but I think it would be more readable to have a shorter, less wordy method name. Same for the other methods.
There was a problem hiding this comment.
actually...do we even need these methods at all? The things that need them can just use the fields like they are today. I think we should stick with that.
There was a problem hiding this comment.
yes, let's get rid of these methods and just let the package access the package-protected constants like it has been.
There was a problem hiding this comment.
@Rocksnake please get rid of these methods. thanks!
| * @param decision The decision made on the span. | ||
| * @return A {@link SamplingResult} with empty attributes and the provided {@code decision}. | ||
| */ | ||
| static SamplingResult create(SamplingDecision decision) { |
There was a problem hiding this comment.
we can't delete this public method. That would be a breaking change.
There was a problem hiding this comment.
I think it's fine to keep it here. we could deprecate at some point, but it's not harmful or bad to use this method, just slightly confusing since it won't actually create anything.
|
@Rocksnake please run the |
| ***! MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.trace.samplers.SamplingResult (not serializable) | ||
| === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 | ||
| +++! NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.trace.samplers.SamplingResult drop() | ||
| +++! NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.trace.samplers.SamplingResult drop(io.opentelemetry.api.common.Attributes) |
There was a problem hiding this comment.
we'd still like to get rid of these overloads that have attributes as a parameter. Thanks.
There was a problem hiding this comment.
Based on all the above, I feel that we should keep the old calls with attributes, and use the new short method in the future development process. I have achieved this idea and hope you approve.
|
I have resolve all the problems, could anyone help to approve running these workflows and merge in main branch, great thanks! |
| * @param decision The decision made on the span. | ||
| * @return A {@link SamplingResult} with empty attributes and the provided {@code decision}. | ||
| */ | ||
| @SuppressWarnings("UngroupedOverloads") |
There was a problem hiding this comment.
I don't think you need this suppress warnings
| * @param decision The decision made on the span. | ||
| * @return A {@link SamplingResult} with empty attributes and the provided {@code decision}. | ||
| */ | ||
| static SamplingResult create(SamplingDecision decision) { |
| * @return A {@link SamplingResult} with the attributes equivalent to {@code attributes} and the | ||
| * provided {@code decision}. | ||
| */ | ||
| @SuppressWarnings("UngroupedOverloads") |
There was a problem hiding this comment.
It would be better if we can make sure we group the overloads so we don't need this warning.
There was a problem hiding this comment.
I have removed them, could you please trigger the check for me again. Thanks~
| * <p>This is meant for use by custom {@link Sampler} implementations. | ||
| * | ||
| * @return A {@link SamplingResult} with empty attributes and the provided {@code decision}. |
There was a problem hiding this comment.
| * <p>This is meant for use by custom {@link Sampler} implementations. | |
| * | |
| * @return A {@link SamplingResult} with empty attributes and the provided {@code decision}. | |
| * <p>This is meant for use by custom {@link Sampler} implementations and is equivalent to calling | |
| * {@code SamplingResult.create(SamplingDecision.RECORD_AND_SAMPLE)}. | |
| * | |
| * @return A {@link SamplingResult} with empty attributes and the provided {@code decision}. |
Let's add something like this to the three methods.
There was a problem hiding this comment.
I have added them, could you check for me and merge it please. Thanks.
|
Could anyone merge this branch into main, I have solved all above problem, great thanks. |
You still haven't removed the methods I asked you to. Please do so. |
I haved removed these methods, please check again, thank you! |
|
This PR needs to be rebased against the main branch before we can merge it. |
|
@Rocksnake this needs a rebase. Will you be able to get to it soon? |
Ok, I will rebased it this day. |


Add three methods to get the factory to replace the original create
Modify all the places where SamplingResult.create is used in the project
Write unit test and pass the test
Remarks:since the create method with parameters is used in RateLimitingSampler, I keep the versions with Attributes