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

#301 edits #2

Merged
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
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ pip install -e ./ext/opentelemetry-ext-{integration}
```python
from opentelemetry import trace
from opentelemetry.context import Context
from opentelemetry.sdk.trace import Tracer
from opentelemetry.sdk.trace import TracerSource
from opentelemetry.sdk.trace.export import ConsoleSpanExporter
from opentelemetry.sdk.trace.export import SimpleExportSpanProcessor

trace.set_preferred_tracer_implementation(lambda T: Tracer())
tracer = trace.tracer()
tracer.add_span_processor(
trace.set_preferred_tracer_source_implementation(lambda T: TracerSource())
trace.tracer_source().add_span_processor(
SimpleExportSpanProcessor(ConsoleSpanExporter())
)
tracer = trace.tracer_source().get_tracer("myapp")
with tracer.start_as_current_span('foo'):
with tracer.start_as_current_span('bar'):
with tracer.start_as_current_span('baz'):
Expand Down
6 changes: 3 additions & 3 deletions ext/opentelemetry-ext-jaeger/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ gRPC is still not supported by this implementation.

from opentelemetry import trace
from opentelemetry.ext import jaeger
from opentelemetry.sdk.trace import Tracer
from opentelemetry.sdk.trace import TracerSource
from opentelemetry.sdk.trace.export import BatchExportSpanProcessor

trace.set_preferred_tracer_implementation(lambda T: Tracer())
tracer = trace.tracer()
trace.set_preferred_tracer_source_implementation(lambda T: TracerSource())
tracer = trace.tracer_source().get_tracer("myapp")

# create a JaegerSpanExporter
jaeger_exporter = jaeger.JaegerSpanExporter(
Expand Down
10 changes: 5 additions & 5 deletions ext/opentelemetry-ext-jaeger/examples/jaeger_exporter_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

from opentelemetry import trace
from opentelemetry.ext import jaeger
from opentelemetry.sdk.trace import Tracer
from opentelemetry.sdk.trace import TracerSource
from opentelemetry.sdk.trace.export import BatchExportSpanProcessor

trace.set_preferred_tracer_implementation(lambda T: Tracer())
tracer = trace.tracer()
Copy link

@Oberon00 Oberon00 Dec 9, 2019

Choose a reason for hiding this comment

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

So it seems there isn't any unit test for this? But even the linter should have caught this. I guess we should update tox.ini to lint that.

trace.set_preferred_tracer_source_implementation(lambda T: TracerSource())
tracer = trace.tracer_source().get_tracer("myapp")

# create a JaegerSpanExporter
jaeger_exporter = jaeger.JaegerSpanExporter(
Expand All @@ -25,8 +25,8 @@
# create a BatchExportSpanProcessor and add the exporter to it
span_processor = BatchExportSpanProcessor(jaeger_exporter)

# add to the tracer
tracer.add_span_processor(span_processor)
# add to the tracer factory
trace.tracer_source().add_span_processor(span_processor)

# create some spans for testing
with tracer.start_as_current_span("foo") as foo:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@
import time

from opentelemetry import trace
from opentelemetry.sdk.trace import Tracer
from opentelemetry.sdk.trace import TracerSource
from opentelemetry.ext.opentracing_shim import create_tracer

# Tell OpenTelemetry which Tracer implementation to use.
trace.set_preferred_tracer_implementation(lambda T: Tracer())
trace.set_preferred_tracer_source_implementation(lambda T: TracerSource())

# Create an OpenTelemetry Tracer.
otel_tracer = trace.tracer()
otel_tracer = trace.tracer_source().get_tracer("myapp")

# Create an OpenTracing shim.
shim = create_tracer(otel_tracer)

Expand Down
22 changes: 12 additions & 10 deletions opentelemetry-api/src/opentelemetry/trace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,23 +369,24 @@ def get_tracer(
) -> "Tracer":
"""Returns a `Tracer` for use by the given instrumentation library.

For any two calls it is undefined whether the same or
different `Tracer` instances are returned, even for different library names.
For any two calls it is undefined whether the same or different
`Tracer` instances are returned, even for different library names.

This function may return different `Tracer` types (e.g. a no-op tracer vs.
a functional tracer).
This function may return different `Tracer` types (e.g. a no-op tracer
vs. a functional tracer).

Args:
instrumenting_library_name: The name of the instrumenting library.
This should *not* be the name of the library that is
instrumented but the name of the instrumentation library.
E.g., instead of ``"requests"``, ``"opentelemetry-ext-http-requests"``.
E.g., instead of ``"requests"``,
``"opentelemetry-ext-http-requests"``.

This should be the ``pip install``-able name of the library rather than the
module name (see also the next argument).
This should be the ``pip install``-able name of the library
rather than the module name (see also the next argument).

instrumenting_library_version: Optional. The version string of the instrumenting library.
Usually this should be the same as
instrumenting_library_version: Optional. The version string of the
instrumenting library. Usually this should be the same as
``pkg_resources.get_distribution(instrumenting_library_name).version``.
"""
return Tracer()
Expand Down Expand Up @@ -574,7 +575,8 @@ def set_preferred_tracer_source_implementation(
This function may not be called after a tracer is already loaded.

Args:
factory: Callback that should create a new :class:`TracerSource` instance.
factory: Callback that should create a new :class:`TracerSource`
instance.
"""
global _TRACER_SOURCE_FACTORY # pylint:disable=global-statement

Expand Down
21 changes: 11 additions & 10 deletions opentelemetry-api/src/opentelemetry/util/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

"""
The OpenTelemetry loader module is mainly used internally to load the
implementation for global objects like :func:`opentelemetry.trace.tracer_source`.
implementation for global objects like
:func:`opentelemetry.trace.tracer_source`.

.. _loader-factory:

Expand All @@ -35,17 +36,17 @@ def my_factory_for_t(api_type: typing.Type[T]) -> typing.Optional[T]:
factory function or other means to create the global object:

1. If the environment variable
:samp:`OPENTELEMETRY_PYTHON_IMPLEMENTATION_{getter-name}` (e.g.,
``OPENTELEMETRY_PYTHON_IMPLEMENTATION_TRACERSOURCE``) is set to an nonempty
value, an attempt is made to import a module with that name and use a
factory function named ``get_opentelemetry_implementation`` in it.
2. Otherwise, the same is tried with the environment
variable ``OPENTELEMETRY_PYTHON_IMPLEMENTATION_DEFAULT``.
:samp:`OPENTELEMETRY_PYTHON_IMPLEMENTATION_{getter-name}` (e.g.,
``OPENTELEMETRY_PYTHON_IMPLEMENTATION_TRACERSOURCE``) is set to an
nonempty value, an attempt is made to import a module with that name and
use a factory function named ``get_opentelemetry_implementation`` in it.
2. Otherwise, the same is tried with the environment variable
``OPENTELEMETRY_PYTHON_IMPLEMENTATION_DEFAULT``.
3. Otherwise, if a :samp:`set_preferred_{<type>}_implementation` was
called (e.g.
:func:`opentelemetry.trace.set_preferred_tracer_source_implementation`), the
callback set there is used (that is, the environment variables override
the callback set in code).
:func:`opentelemetry.trace.set_preferred_tracer_source_implementation`),
the callback set there is used (that is, the environment variables
override the callback set in code).
4. Otherwise, if :func:`set_preferred_default_implementation` was called,
the callback set there is used.
5. Otherwise, an attempt is made to import and use the OpenTelemetry SDK.
Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-api/tests/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def setUp(self):
reload(loader)
reload(trace)

# Need to reload self, otherwise DummyTracerSource will have the wrong base
# class after reloading `trace`.
# Need to reload self, otherwise DummyTracerSource will have the wrong
# base class after reloading `trace`.
reload(sys.modules[__name__])

def test_get_default(self):
Expand Down