Skip to content

Add AlwaysRecordSampler#5354

Open
carlosalberto wants to merge 6 commits into
open-telemetry:mainfrom
carlosalberto:always-record-sampler
Open

Add AlwaysRecordSampler#5354
carlosalberto wants to merge 6 commits into
open-telemetry:mainfrom
carlosalberto:always-record-sampler

Conversation

@carlosalberto

Copy link
Copy Markdown
Contributor

Took the initial effort of #4823 and updated it to:

  • Put it in the main sampling files, as it's now stable.
  • Simplified it wherever possible, plus applying the feedback from the original PR review.

@carlosalberto carlosalberto requested a review from a team as a code owner June 25, 2026 16:06
"""

def __init__(self, root: Sampler):
if root is None:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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.

self.sampler: sampling.Sampler = sampling.AlwaysRecordSampler(self.mock_sampler)

def test_get_description(self):
static_sampler: sampling.Sampler = sampling.StaticSampler(sampling.Decision.DROP)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We don't seem to be using type hints at local variables level, so OK to remove them?

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):

Copy link
Copy Markdown
Contributor

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?

trace_state: trace.TraceState = trace.TraceState()
trace_state.add("key", root_decision.name)
root_result: sampling.SamplingResult = sampling.SamplingResult(
attributes={"key", root_decision.name},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a set, not a dict, maybe that's why tests are failing?

Suggested change
attributes={"key", root_decision.name},
attributes={"key": root_decision.name},

@github-project-automation github-project-automation Bot moved this to Reviewed PRs that need fixes in Python PR digest Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Reviewed PRs that need fixes

Development

Successfully merging this pull request may close these issues.

3 participants