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

[Sampler.AWS] Wrapped root sampler with ParentBasedSampler #2188

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

AsakerMohd
Copy link
Contributor

Fixes #
Design discussion issue #

Changes

The current implementation of the X-Ray sampler has 2 levels: The X-Ray Sampler itself which is made up two different samplers for X-Ray purposes. Those two different samplers are wrapped by parentBasedSampler so that the children inherit the parent sampling decision. However, on the CloudWatch console, we are adding the children sampling decision into the stats section. This means: if we have 1 parent and 9 children, the CW console will show that 10 spans are sampled which isn't correct. It should show only 1 span being sampled. This PR moves the ParentBasedSampler wrapper to be on the root level of the X-Ray sampler. This means that the builder doesn't return AWSXrayRemoteSampler anymore but returns ParentBasedSampler(new AWSXrayRemoteSampler). This keeps the same parentBasedSampling logic but is instead on the root level thus skipping the stat aggregation for the children.

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

@AsakerMohd AsakerMohd requested a review from a team as a code owner October 7, 2024 23:33
@github-actions github-actions bot added the comp:sampler.aws Things related to OpenTelemetry.Samplers.AWS label Oct 7, 2024
Copy link

@vastin vastin left a comment

Choose a reason for hiding this comment

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

LGTM

/// <returns>an instance of <see cref="AWSXRayRemoteSampler"/>.</returns>
public AWSXRayRemoteSampler Build()
/// <returns>an instance of <see cref="ParentBasedSampler"/>.</returns>
public ParentBasedSampler Build()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public ParentBasedSampler Build()
public Sampler Build()

Shouldn't it be just Sampler to avoid any future breaking changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call. Updated the return type to be Trace.Sampler instead of ParentBasedSampler.

@AsakerMohd AsakerMohd requested a review from Kielek October 9, 2024 18:10
@Kielek Kielek changed the title Wrapped root sampler with ParentBasedSampler [Sampler.AWS] Wrapped root sampler with ParentBasedSampler Oct 10, 2024
// This is intended for testing to check that the XRayRemoteSampler is built with the correct attributes
// Should not be exposed to public as the public build method should return the sampler wrapped inside
// ParentBasedSampler.
internal AWSXRayRemoteSampler BuildXraySampler()
Copy link
Member

Choose a reason for hiding this comment

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

Is there a way to avoid needing a special constructor just for testing?

Could the tests call Build, get the ParentBasedSampler and then access the AWSXrayRemoteSampler from that class some way?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using reflection allows us to get the private sampler in the ParentBasedSampler class. However doing so is kindoff a code smell since at this point we are relying on the internal variable naming of ParentBasedSampler and if that changes, the test breaks. I would prefer using the special constructor in this case since it's being used in the actual public facing Build function and can be used to test the AWSXrayRemoteSampler being built properly.

Copy link

codecov bot commented Oct 16, 2024

Codecov Report

Attention: Patch coverage is 66.66667% with 3 lines in your changes missing coverage. Please review.

Project coverage is 87.28%. Comparing base (71655ce) to head (a5efb24).
Report is 539 commits behind head on main.

Files with missing lines Patch % Lines
...lemetry.Sampler.AWS/AWSXRayRemoteSamplerBuilder.cs 0.00% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #2188       +/-   ##
===========================================
+ Coverage   73.91%   87.28%   +13.36%     
===========================================
  Files         267       20      -247     
  Lines        9615      574     -9041     
===========================================
- Hits         7107      501     -6606     
+ Misses       2508       73     -2435     
Flag Coverage Δ
unittests-Sampler.AWS 87.28% <66.66%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/OpenTelemetry.Sampler.AWS/FallbackSampler.cs 55.55% <100.00%> (ø)
...c/OpenTelemetry.Sampler.AWS/SamplingRuleApplier.cs 98.56% <100.00%> (ø)
...lemetry.Sampler.AWS/AWSXRayRemoteSamplerBuilder.cs 70.00% <0.00%> (-12.36%) ⬇️

... and 261 files with indirect coverage changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:sampler.aws Things related to OpenTelemetry.Samplers.AWS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants