Skip to content

Commit ce515a0

Browse files
authored
Removing TracerProvider coupling from Tracer init (#1295)
1 parent 4680594 commit ce515a0

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

Diff for: exporter/opentelemetry-exporter-datadog/tests/test_datadog_exporter.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def __init__(self, *args, **kwargs):
4040

4141
def get_spans(tracer, exporter, shutdown=True):
4242
if shutdown:
43-
tracer.source.shutdown()
43+
tracer.span_processor.shutdown()
4444

4545
spans = [
4646
call_args[-1]["spans"]

Diff for: opentelemetry-sdk/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
([#1289](https://github.com/open-telemetry/opentelemetry-python/pull/1289))
1717
- Set initial checkpoint timestamp in aggregators
1818
([#1237](https://github.com/open-telemetry/opentelemetry-python/pull/1237))
19+
- Remove TracerProvider coupling from Tracer init
20+
([#1295](https://github.com/open-telemetry/opentelemetry-python/pull/1295))
1921

2022
## Version 0.14b0
2123

Diff for: opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py

+20-14
Original file line numberDiff line numberDiff line change
@@ -705,19 +705,22 @@ class _Span(Span):
705705

706706
class Tracer(trace_api.Tracer):
707707
"""See `opentelemetry.trace.Tracer`.
708-
709-
Args:
710-
name: The name of the tracer.
711-
shutdown_on_exit: Register an atexit hook to shut down the tracer when
712-
the application exits.
713708
"""
714709

715710
def __init__(
716711
self,
717-
source: "TracerProvider",
712+
sampler: sampling.Sampler,
713+
resource: Resource,
714+
span_processor: Union[
715+
SynchronousMultiSpanProcessor, ConcurrentMultiSpanProcessor
716+
],
717+
ids_generator: trace_api.IdsGenerator,
718718
instrumentation_info: InstrumentationInfo,
719719
) -> None:
720-
self.source = source
720+
self.sampler = sampler
721+
self.resource = resource
722+
self.span_processor = span_processor
723+
self.ids_generator = ids_generator
721724
self.instrumentation_info = instrumentation_info
722725

723726
def start_as_current_span(
@@ -759,7 +762,7 @@ def start_span( # pylint: disable=too-many-locals
759762
# is_valid determines root span
760763
if parent_span_context is None or not parent_span_context.is_valid:
761764
parent_span_context = None
762-
trace_id = self.source.ids_generator.generate_trace_id()
765+
trace_id = self.ids_generator.generate_trace_id()
763766
trace_flags = None
764767
trace_state = None
765768
else:
@@ -772,7 +775,7 @@ def start_span( # pylint: disable=too-many-locals
772775
# exported.
773776
# The sampler may also add attributes to the newly-created span, e.g.
774777
# to include information about the sampling result.
775-
sampling_result = self.source.sampler.should_sample(
778+
sampling_result = self.sampler.should_sample(
776779
context, trace_id, name, attributes, links,
777780
)
778781

@@ -783,7 +786,7 @@ def start_span( # pylint: disable=too-many-locals
783786
)
784787
span_context = trace_api.SpanContext(
785788
trace_id,
786-
self.source.ids_generator.generate_span_id(),
789+
self.ids_generator.generate_span_id(),
787790
is_remote=False,
788791
trace_flags=trace_flags,
789792
trace_state=trace_state,
@@ -796,10 +799,10 @@ def start_span( # pylint: disable=too-many-locals
796799
name=name,
797800
context=span_context,
798801
parent=parent_span_context,
799-
sampler=self.source.sampler,
800-
resource=self.source.resource,
802+
sampler=self.sampler,
803+
resource=self.resource,
801804
attributes=sampling_result.attributes.copy(),
802-
span_processor=self.source._active_span_processor,
805+
span_processor=self.span_processor,
803806
kind=kind,
804807
links=links,
805808
instrumentation_info=self.instrumentation_info,
@@ -888,7 +891,10 @@ def get_tracer(
888891
instrumenting_module_name = "ERROR:MISSING MODULE NAME"
889892
logger.error("get_tracer called with missing module name.")
890893
return Tracer(
891-
self,
894+
self.sampler,
895+
self.resource,
896+
self._active_span_processor,
897+
self.ids_generator,
892898
InstrumentationInfo(
893899
instrumenting_module_name, instrumenting_library_version
894900
),

0 commit comments

Comments
 (0)