Skip to content

Move samplers to SDK package #1023

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

Merged
merged 9 commits into from
Aug 20, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion docs/api/trace.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ Submodules

.. toctree::

trace.sampling
trace.status
trace.span

Expand Down
7 changes: 0 additions & 7 deletions docs/api/trace.sampling.rst

This file was deleted.

1 change: 1 addition & 0 deletions docs/sdk/trace.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Submodules
.. toctree::

trace.export
trace.sampling
util.instrumentation

.. automodule:: opentelemetry.sdk.trace
Expand Down
7 changes: 7 additions & 0 deletions docs/sdk/trace.sampling.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
opentelemetry.sdk.trace.sampling
==========================================

.. automodule:: opentelemetry.sdk.trace.sampling
:members:
:undoc-members:
:show-inheritance:
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from ddtrace.span import Span as DatadogSpan

import opentelemetry.trace as trace_api
from opentelemetry.sdk.trace import sampling
from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult
from opentelemetry.trace.status import StatusCanonicalCode

Expand Down Expand Up @@ -246,7 +247,7 @@ def _get_sampling_rate(span):
return (
span.sampler.rate
if ctx.trace_flags.sampled
and isinstance(span.sampler, trace_api.sampling.ProbabilitySampler)
and isinstance(span.sampler, sampling.ProbabilitySampler)
else None
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from opentelemetry import trace as trace_api
from opentelemetry.exporter import datadog
from opentelemetry.sdk import trace
from opentelemetry.sdk.trace import sampling
from opentelemetry.sdk.util.instrumentation import InstrumentationInfo


Expand Down Expand Up @@ -497,7 +498,7 @@ def test_sampling_rate(self):
is_remote=False,
trace_flags=trace_api.TraceFlags(trace_api.TraceFlags.SAMPLED),
)
sampler = trace_api.sampling.ProbabilitySampler(0.5)
sampler = sampling.ProbabilitySampler(0.5)

span = trace.Span(
name="sampled", context=context, parent=None, sampler=sampler
Expand Down
3 changes: 3 additions & 0 deletions opentelemetry-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

- Moved samplers from API to SDK
([#1023](https://github.com/open-telemetry/opentelemetry-python/pull/1023))

## Version 0.12b0

Released 2020-08-14
Expand Down
4 changes: 4 additions & 0 deletions opentelemetry-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

## Unreleased

- Moved samplers from API to SDK
([#1023](https://github.com/open-telemetry/opentelemetry-python/pull/1023))

## Version 0.12b0

Released 2020-08-14

- Changed default Sampler to `ParentOrElse(AlwaysOn)`
([#960](https://github.com/open-telemetry/opentelemetry-python/pull/960))
- Update environment variable names, prefix changed from `OPENTELEMETRY` to `OTEL`
([#904](https://github.com/open-telemetry/opentelemetry-python/pull/904))
- Implement Views in metrics SDK
Expand Down
5 changes: 3 additions & 2 deletions opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@
from opentelemetry import trace as trace_api
from opentelemetry.sdk import util
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import sampling
from opentelemetry.sdk.util import BoundedDict, BoundedList
from opentelemetry.sdk.util.instrumentation import InstrumentationInfo
from opentelemetry.trace import SpanContext, sampling
from opentelemetry.trace import SpanContext
from opentelemetry.trace.propagation import SPAN_KEY
from opentelemetry.trace.status import Status, StatusCanonicalCode
from opentelemetry.util import time_ns, types
Expand Down Expand Up @@ -869,7 +870,7 @@ def use_span(
class TracerProvider(trace_api.TracerProvider):
def __init__(
self,
sampler: sampling.Sampler = trace_api.sampling.DEFAULT_ON,
sampler: sampling.Sampler = sampling.DEFAULT_ON,
resource: Resource = Resource.create_empty(),
shutdown_on_exit: bool = True,
active_span_processor: Union[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@
.. code:: python

from opentelemetry import trace
from opentelemetry.trace.sampling import ProbabilitySampler
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import (
ConsoleSpanExporter,
SimpleExportSpanProcessor,
)
from opentelemetry.sdk.trace.sampling import ProbabilitySampler

# sample 1 in every 1000 traces
sampler = ProbabilitySampler(1/1000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import unittest

from opentelemetry import trace
from opentelemetry.trace import sampling
from opentelemetry.sdk.trace import sampling

TO_DEFAULT = trace.TraceFlags(trace.TraceFlags.DEFAULT)
TO_SAMPLED = trace.TraceFlags(trace.TraceFlags.SAMPLED)
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-sdk/tests/trace/test_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

from opentelemetry import trace as trace_api
from opentelemetry.sdk import resources, trace
from opentelemetry.sdk.trace import sampling
from opentelemetry.sdk.util.instrumentation import InstrumentationInfo
from opentelemetry.trace import sampling
from opentelemetry.trace.status import StatusCanonicalCode
from opentelemetry.util import time_ns

Expand Down