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

Removing TracerProvider coupling from Tracer init (#1181) #1295

Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(self, *args, **kwargs):

def get_spans(tracer, exporter, shutdown=True):
if shutdown:
tracer.source.shutdown()
tracer.span_processor.shutdown()

spans = [
call_args[-1]["spans"]
Expand Down
2 changes: 2 additions & 0 deletions opentelemetry-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
([#998](https://github.com/open-telemetry/opentelemetry-python/pull/998))
- Samplers to accept parent Context
([#1267](https://github.com/open-telemetry/opentelemetry-python/pull/1267))
- Remove TracerProvider coupling from Tracer init
([#1295](https://github.com/open-telemetry/opentelemetry-python/pull/1295))

## Version 0.14b0

Expand Down
34 changes: 20 additions & 14 deletions opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,19 +706,22 @@ class _Span(Span):

class Tracer(trace_api.Tracer):
lzchen marked this conversation as resolved.
Show resolved Hide resolved
"""See `opentelemetry.trace.Tracer`.

Args:
name: The name of the tracer.
shutdown_on_exit: Register an atexit hook to shut down the tracer when
the application exits.
"""

def __init__(
self,
source: "TracerProvider",
sampler: sampling.Sampler,
resource: Resource,
span_processor: Union[
SynchronousMultiSpanProcessor, ConcurrentMultiSpanProcessor
],
ids_generator: trace_api.IdsGenerator,
instrumentation_info: InstrumentationInfo,
) -> None:
self.source = source
self.sampler = sampler
self.resource = resource
self.span_processor = span_processor
self.ids_generator = ids_generator
self.instrumentation_info = instrumentation_info

def start_as_current_span(
Expand Down Expand Up @@ -760,7 +763,7 @@ def start_span( # pylint: disable=too-many-locals
# is_valid determines root span
if parent_span_context is None or not parent_span_context.is_valid:
parent_span_context = None
trace_id = self.source.ids_generator.generate_trace_id()
trace_id = self.ids_generator.generate_trace_id()
trace_flags = None
trace_state = None
else:
Expand All @@ -773,7 +776,7 @@ def start_span( # pylint: disable=too-many-locals
# exported.
# The sampler may also add attributes to the newly-created span, e.g.
# to include information about the sampling result.
sampling_result = self.source.sampler.should_sample(
sampling_result = self.sampler.should_sample(
context, trace_id, name, attributes, links,
)

Expand All @@ -784,7 +787,7 @@ def start_span( # pylint: disable=too-many-locals
)
span_context = trace_api.SpanContext(
trace_id,
self.source.ids_generator.generate_span_id(),
self.ids_generator.generate_span_id(),
is_remote=False,
trace_flags=trace_flags,
trace_state=trace_state,
Expand All @@ -797,10 +800,10 @@ def start_span( # pylint: disable=too-many-locals
name=name,
context=span_context,
parent=parent_span_context,
sampler=self.source.sampler,
resource=self.source.resource,
sampler=self.sampler,
resource=self.resource,
attributes=sampling_result.attributes.copy(),
span_processor=self.source._active_span_processor,
span_processor=self.span_processor,
kind=kind,
links=links,
instrumentation_info=self.instrumentation_info,
Expand Down Expand Up @@ -884,7 +887,10 @@ def get_tracer(
instrumenting_module_name = "ERROR:MISSING MODULE NAME"
logger.error("get_tracer called with missing module name.")
return Tracer(
self,
self.sampler,
self.resource,
self._active_span_processor,
self.ids_generator,
InstrumentationInfo(
instrumenting_module_name, instrumenting_library_version
),
Expand Down