-
Notifications
You must be signed in to change notification settings - Fork 929
Add AlwaysRecordSampler #5354
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
Open
carlosalberto
wants to merge
9
commits into
open-telemetry:main
Choose a base branch
from
carlosalberto:always-record-sampler
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+114
−0
Open
Add AlwaysRecordSampler #5354
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
93a29f2
feat: Add AlwaysRecordSampler
majanjua-amzn 3ccb094
Apply feedback.
carlosalberto 7c9afe9
Prepare for merging upstream.
carlosalberto 578ec9b
Merge branch 'main' into always-record-sampler
carlosalberto 6333264
restore tests.
carlosalberto ed36624
Lint.
carlosalberto 75cadc4
Fix typo.
carlosalberto 0a9656b
Add CHANGELOG entry.
carlosalberto 144bcc4
Merge branch 'main' into always-record-sampler
herin049 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| `opentelemetry-sdk`: add the new stable `AlwaysRecordSampler` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -369,6 +369,55 @@ def get_description(self): | |
| return f"ParentBased{{root:{self._root.get_description()},remoteParentSampled:{self._remote_parent_sampled.get_description()},remoteParentNotSampled:{self._remote_parent_not_sampled.get_description()},localParentSampled:{self._local_parent_sampled.get_description()},localParentNotSampled:{self._local_parent_not_sampled.get_description()}}}" | ||
|
|
||
|
|
||
| class AlwaysRecordSampler(Sampler): | ||
| """ | ||
| This sampler will return the sampling result of the provided `root`, unless the | ||
| sampling result contains the sampling decision `Decision.DROP`, in which case, a | ||
| new sampling result will be returned that is functionally equivalent to the original, except that | ||
| it contains the sampling decision `Decision.RECORD_ONLY`. This ensures that all | ||
| spans are recorded, with no change to sampling. | ||
|
|
||
| The intended use case of this sampler is to provide a means of sending all spans to a | ||
| processor without having an impact on the sampling rate. This may be desirable if a user wishes | ||
| to count or otherwise measure all spans produced in a service, without incurring the cost of 100% | ||
| sampling. | ||
| """ | ||
|
|
||
| def __init__(self, root: Sampler): | ||
| if root is None: | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm tempted to remove this check as such wrapped sampler check doesn't exist in current samplers, e.g. ParentBased sampler. |
||
| raise ValueError("root must not be None") | ||
| self._root = root | ||
|
|
||
| def should_sample( | ||
| self, | ||
| parent_context: Context | None, | ||
| trace_id: int, | ||
| name: str, | ||
| kind: SpanKind | None = None, | ||
| attributes: Attributes = None, | ||
| links: Sequence[Link] | None = None, | ||
| trace_state: TraceState | None = None, | ||
| ) -> SamplingResult: | ||
| result: SamplingResult = self._root.should_sample( | ||
| parent_context, | ||
| trace_id, | ||
| name, | ||
| kind, | ||
| attributes, | ||
| links, | ||
| trace_state, | ||
| ) | ||
| if result.decision is Decision.DROP: | ||
| result = SamplingResult( | ||
| Decision.RECORD_ONLY, result.attributes, result.trace_state | ||
| ) | ||
|
|
||
| return result | ||
|
|
||
| def get_description(self): | ||
| return f"AlwaysRecordSampler{{{self._root.get_description()}}}" | ||
|
|
||
|
|
||
| DEFAULT_OFF = ParentBased(ALWAYS_OFF) | ||
| """Sampler that respects its parent span's sampling decision, but otherwise never samples.""" | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be added here?