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

Fix use of built-in samplers in SDK configuration #3176

Merged
merged 7 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#3100](https://github.com/open-telemetry/opentelemetry-python/pull/3100))
- Fix formatting of ConsoleMetricExporter.
([#3197](https://github.com/open-telemetry/opentelemetry-python/pull/3197))
- Fix use of built-in samplers in SDK configuration
([#3176](https://github.com/open-telemetry/opentelemetry-python/pull/3176))

## Version 1.16.0/0.37b0 (2023-02-17)
- Change ``__all__`` to be statically defined.
Expand Down
8 changes: 8 additions & 0 deletions opentelemetry-sdk/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ sdk = "opentelemetry.sdk.environment_variables"
[project.entry-points.opentelemetry_id_generator]
random = "opentelemetry.sdk.trace.id_generator:RandomIdGenerator"

[project.entry-points.opentelemetry_traces_sampler]
always_on = "opentelemetry.sdk.trace.sampling:_AlwaysOn"
always_off = "opentelemetry.sdk.trace.sampling:_AlwaysOff"
parentbased_always_on = "opentelemetry.sdk.trace.sampling:_DefaultOn"
srikanthccv marked this conversation as resolved.
Show resolved Hide resolved
parentbased_always_off = "opentelemetry.sdk.trace.sampling:_DefaultOff"
traceidratio = "opentelemetry.sdk.trace.sampling:TraceIdRatioBased"
parentbased_traceidratio = "opentelemetry.sdk.trace.sampling:ParentBasedTraceIdRatio"

[project.entry-points.opentelemetry_logger_provider]
sdk_logger_provider = "opentelemetry.sdk._logs:LoggerProvider"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def _import_sampler(sampler_name: str) -> Optional[Sampler]:
return sampler
except Exception as exc: # pylint: disable=broad-except
_logger.warning(
"Using default sampler. Failed to initialize custom sampler, %s: %s",
"Using default sampler. Failed to initialize sampler, %s: %s",
sampler_name,
exc,
)
Expand Down
15 changes: 15 additions & 0 deletions opentelemetry-sdk/src/opentelemetry/sdk/trace/sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,21 @@ def __init__(self, rate: float):
root = TraceIdRatioBased(rate=rate)
super().__init__(root=root)

class _AlwaysOff(StaticSampler):
def __init__(self, _):
super().__init__(Decision.DROP)

class _AlwaysOn(StaticSampler):
def __init__(self, _):
super().__init__(Decision.RECORD_AND_SAMPLE)

class _DefaultOff(ParentBased):
def __init__(self, _):
super().__init__(ALWAYS_OFF)

class _DefaultOn(ParentBased):
def __init__(self, _):
super().__init__(ALWAYS_ON)

_KNOWN_SAMPLERS = {
"always_on": ALWAYS_ON,
Expand Down