Skip to content

Commit

Permalink
Rename TracerSource to TracerProvider (#441)
Browse files Browse the repository at this point in the history
Following discussion in #434, align the name with the specification.

Co-authored-by: Chris Kleinknecht <[email protected]>
  • Loading branch information
mauriciovasquezbernal and c24t authored Feb 21, 2020
1 parent 52fcd2f commit ed25287
Show file tree
Hide file tree
Showing 33 changed files with 196 additions and 193 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ pip install -e ./ext/opentelemetry-ext-{integration}

```python
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerSource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import ConsoleSpanExporter
from opentelemetry.sdk.trace.export import SimpleExportSpanProcessor

trace.set_preferred_tracer_source_implementation(lambda T: TracerSource())
trace.tracer_source().add_span_processor(
trace.set_preferred_tracer_provider_implementation(lambda T: TracerProvider())
trace.tracer_provider().add_span_processor(
SimpleExportSpanProcessor(ConsoleSpanExporter())
)
tracer = trace.get_tracer(__name__)
Expand Down
6 changes: 3 additions & 3 deletions examples/basic_tracer/tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import os

from opentelemetry import trace
from opentelemetry.sdk.trace import TracerSource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import (
BatchExportSpanProcessor,
ConsoleSpanExporter,
Expand All @@ -36,7 +36,7 @@

# The preferred tracer implementation must be set, as the opentelemetry-api
# defines the interface with a no-op implementation.
trace.set_preferred_tracer_source_implementation(lambda T: TracerSource())
trace.set_preferred_tracer_provider_implementation(lambda T: TracerProvider())

# We tell OpenTelemetry who it is that is creating spans. In this case, we have
# no real name (no setup.py), so we make one up. If we had a version, we would
Expand All @@ -46,7 +46,7 @@
# SpanExporter receives the spans and send them to the target location.
span_processor = BatchExportSpanProcessor(exporter)

trace.tracer_source().add_span_processor(span_processor)
trace.tracer_provider().add_span_processor(span_processor)
with tracer.start_as_current_span("foo"):
with tracer.start_as_current_span("bar"):
with tracer.start_as_current_span("baz"):
Expand Down
8 changes: 4 additions & 4 deletions examples/http/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from opentelemetry import trace
from opentelemetry.ext import http_requests
from opentelemetry.ext.wsgi import OpenTelemetryMiddleware
from opentelemetry.sdk.trace import TracerSource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import (
BatchExportSpanProcessor,
ConsoleSpanExporter,
Expand All @@ -41,17 +41,17 @@

# The preferred tracer implementation must be set, as the opentelemetry-api
# defines the interface with a no-op implementation.
trace.set_preferred_tracer_source_implementation(lambda T: TracerSource())
trace.set_preferred_tracer_provider_implementation(lambda T: TracerProvider())
tracer = trace.get_tracer(__name__)

# SpanExporter receives the spans and send them to the target location.
span_processor = BatchExportSpanProcessor(exporter)
trace.tracer_source().add_span_processor(span_processor)
trace.tracer_provider().add_span_processor(span_processor)

# Integrations are the glue that binds the OpenTelemetry API and the
# frameworks and libraries that are used together, automatically creating
# Spans and propagating context as appropriate.
http_requests.enable(trace.tracer_source())
http_requests.enable(trace.tracer_provider())
app = flask.Flask(__name__)
app.wsgi_app = OpenTelemetryMiddleware(app.wsgi_app)

Expand Down
10 changes: 5 additions & 5 deletions examples/http/tracer_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from opentelemetry import trace
from opentelemetry.ext import http_requests
from opentelemetry.sdk.trace import TracerSource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import (
BatchExportSpanProcessor,
ConsoleSpanExporter,
Expand All @@ -39,15 +39,15 @@

# The preferred tracer implementation must be set, as the opentelemetry-api
# defines the interface with a no-op implementation.
trace.set_preferred_tracer_source_implementation(lambda T: TracerSource())
tracer_source = trace.tracer_source()
trace.set_preferred_tracer_provider_implementation(lambda T: TracerProvider())
tracer_provider = trace.tracer_provider()

# SpanExporter receives the spans and send them to the target location.
span_processor = BatchExportSpanProcessor(exporter)
tracer_source.add_span_processor(span_processor)
tracer_provider.add_span_processor(span_processor)

# Integrations are the glue that binds the OpenTelemetry API and the
# frameworks and libraries that are used together, automatically creating
# Spans and propagating context as appropriate.
http_requests.enable(tracer_source)
http_requests.enable(tracer_provider)
response = requests.get(url="http://127.0.0.1:5000/")
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import opentelemetry.ext.http_requests
from opentelemetry import trace
from opentelemetry.ext.flask import instrument_app
from opentelemetry.sdk.trace import TracerSource
from opentelemetry.sdk.trace import TracerProvider


def configure_opentelemetry(flask_app: flask.Flask):
Expand All @@ -45,15 +45,17 @@ def configure_opentelemetry(flask_app: flask.Flask):
# The preferred implementation of these objects must be set,
# as the opentelemetry-api defines the interface with a no-op
# implementation.
trace.set_preferred_tracer_source_implementation(lambda _: TracerSource())
trace.set_preferred_tracer_provider_implementation(
lambda _: TracerProvider()
)

# Next, we need to configure how the values that are used by
# traces and metrics are propagated (such as what specific headers
# carry this value).
# Integrations are the glue that binds the OpenTelemetry API
# and the frameworks and libraries that are used together, automatically
# creating Spans and propagating context as appropriate.
opentelemetry.ext.http_requests.enable(trace.tracer_source())
opentelemetry.ext.http_requests.enable(trace.tracer_provider())
instrument_app(flask_app)


Expand Down
10 changes: 5 additions & 5 deletions examples/opentracing/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
from opentelemetry import trace
from opentelemetry.ext import opentracing_shim
from opentelemetry.ext.jaeger import JaegerSpanExporter
from opentelemetry.sdk.trace import TracerSource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleExportSpanProcessor
from rediscache import RedisCache

# Configure the tracer using the default implementation
trace.set_preferred_tracer_source_implementation(lambda T: TracerSource())
tracer_source = trace.tracer_source()
trace.set_preferred_tracer_provider_implementation(lambda T: TracerProvider())
tracer_provider = trace.tracer_provider()

# Configure the tracer to export traces to Jaeger
jaeger_exporter = JaegerSpanExporter(
Expand All @@ -18,11 +18,11 @@
agent_port=6831,
)
span_processor = SimpleExportSpanProcessor(jaeger_exporter)
tracer_source.add_span_processor(span_processor)
tracer_provider.add_span_processor(span_processor)

# Create an OpenTracing shim. This implements the OpenTracing tracer API, but
# forwards calls to the underlying OpenTelemetry tracer.
opentracing_tracer = opentracing_shim.create_tracer(tracer_source)
opentracing_tracer = opentracing_shim.create_tracer(tracer_provider)

# Our example caching library expects an OpenTracing-compliant tracer.
redis_cache = RedisCache(opentracing_tracer)
Expand Down
6 changes: 3 additions & 3 deletions ext/opentelemetry-ext-dbapi/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ Usage
.. code:: python
import mysql.connector
from opentelemetry.trace import tracer_source
from opentelemetry.trace import tracer_provider
from opentelemetry.ext.dbapi import trace_integration
trace.set_preferred_tracer_source_implementation(lambda T: TracerSource())
trace.set_preferred_tracer_provider_implementation(lambda T: TracerProvider())
tracer = trace.get_tracer(__name__)
# Ex: mysql.connector
trace_integration(tracer_source(), mysql.connector, "connect", "mysql")
trace_integration(tracer_provider(), mysql.connector, "connect", "mysql")
References
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from opentelemetry import trace as trace_api
from opentelemetry.ext.pymongo import trace_integration
from opentelemetry.sdk.trace import Span, Tracer, TracerSource
from opentelemetry.sdk.trace import Span, Tracer, TracerProvider
from opentelemetry.sdk.trace.export import SimpleExportSpanProcessor
from opentelemetry.sdk.trace.export.in_memory_span_exporter import (
InMemorySpanExporter,
Expand All @@ -35,11 +35,11 @@
class TestFunctionalPymongo(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls._tracer_source = TracerSource()
cls._tracer = Tracer(cls._tracer_source, None)
cls._tracer_provider = TracerProvider()
cls._tracer = Tracer(cls._tracer_provider, None)
cls._span_exporter = InMemorySpanExporter()
cls._span_processor = SimpleExportSpanProcessor(cls._span_exporter)
cls._tracer_source.add_span_processor(cls._span_processor)
cls._tracer_provider.add_span_processor(cls._span_processor)
trace_integration(cls._tracer)
client = MongoClient(
MONGODB_HOST, MONGODB_PORT, serverSelectionTimeoutMS=2000
Expand Down
4 changes: 2 additions & 2 deletions ext/opentelemetry-ext-http-requests/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ Usage
import requests
import opentelemetry.ext.http_requests
from opentelemetry.trace import tracer_source
from opentelemetry.trace import tracer_provider
opentelemetry.ext.http_requests.enable(tracer_source())
opentelemetry.ext.http_requests.enable(tracer_provider())
response = requests.get(url='https://www.example.org/')
Limitations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
# if the SDK/tracer is already using `requests` they may, in theory, bypass our
# instrumentation when using `import from`, etc. (currently we only instrument
# a instance method so the probability for that is very low).
def enable(tracer_source):
def enable(tracer_provider):
"""Enables tracing of all requests calls that go through
:code:`requests.session.Session.request` (this includes
:code:`requests.get`, etc.)."""
Expand All @@ -47,7 +47,7 @@ def enable(tracer_source):
# Guard against double instrumentation
disable()

tracer = tracer_source.get_tracer(__name__, __version__)
tracer = tracer_provider.get_tracer(__name__, __version__)

wrapped = Session.request

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ class TestRequestsIntegration(unittest.TestCase):
# TODO: Copy & paste from test_wsgi_middleware
def setUp(self):
self.span_attrs = {}
self.tracer_source = trace.DefaultTracerSource()
self.tracer_provider = trace.DefaultTracerProvider()
self.tracer = trace.DefaultTracer()
self.get_tracer_patcher = mock.patch.object(
self.tracer_source,
self.tracer_provider,
"get_tracer",
autospec=True,
spec_set=True,
Expand Down Expand Up @@ -70,7 +70,7 @@ def setspanattr(key, value):
self.start_as_current_span = self.start_span_patcher.start()
self.send = self.send_patcher.start()

opentelemetry.ext.http_requests.enable(self.tracer_source)
opentelemetry.ext.http_requests.enable(self.tracer_provider)
distver = pkg_resources.get_distribution(
"opentelemetry-ext-http-requests"
).version
Expand Down
4 changes: 2 additions & 2 deletions ext/opentelemetry-ext-jaeger/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ gRPC is still not supported by this implementation.
from opentelemetry import trace
from opentelemetry.ext import jaeger
from opentelemetry.sdk.trace import TracerSource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchExportSpanProcessor
trace.set_preferred_tracer_source_implementation(lambda T: TracerSource())
trace.set_preferred_tracer_provider_implementation(lambda T: TracerProvider())
tracer = trace.get_tracer(__name__)
# create a JaegerSpanExporter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

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

trace.set_preferred_tracer_source_implementation(lambda T: TracerSource())
trace.set_preferred_tracer_provider_implementation(lambda T: TracerProvider())
tracer = trace.get_tracer(__name__)

# create a JaegerSpanExporter
Expand All @@ -26,7 +26,7 @@
span_processor = BatchExportSpanProcessor(jaeger_exporter)

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

# create some spans for testing
with tracer.start_as_current_span("foo") as foo:
Expand Down
4 changes: 2 additions & 2 deletions ext/opentelemetry-ext-mysql/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ Usage
.. code:: python
import mysql.connector
from opentelemetry.trace import tracer_source
from opentelemetry.trace import tracer_provider
from opentelemetry.ext.mysql import trace_integration
trace_integration(tracer_source())
trace_integration(tracer_provider())
cnx = mysql.connector.connect(database='MySQL_Database')
cursor = cnx.cursor()
cursor.execute("INSERT INTO test (testField) VALUES (123)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
import time
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerSource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.ext.opentracing_shim import create_tracer
# Tell OpenTelemetry which Tracer implementation to use.
trace.set_preferred_tracer_source_implementation(lambda T: TracerSource())
trace.set_preferred_tracer_provider_implementation(lambda T: TracerProvider())
# Create an OpenTelemetry Tracer.
otel_tracer = trace.get_tracer(__name__)
Expand Down Expand Up @@ -97,15 +97,15 @@
logger = logging.getLogger(__name__)


def create_tracer(otel_tracer_source):
def create_tracer(otel_tracer_provider):
"""Creates a :class:`TracerShim` object from the provided OpenTelemetry
:class:`opentelemetry.trace.TracerSource`.
:class:`opentelemetry.trace.TracerProvider`.
The returned :class:`TracerShim` is an implementation of
:class:`opentracing.Tracer` using OpenTelemetry under the hood.
Args:
otel_tracer_source: A :class:`opentelemetry.trace.TracerSource` to be
otel_tracer_provider: A :class:`opentelemetry.trace.TracerProvider` to be
used for constructing the :class:`TracerShim`. A tracer from this
source will be used to perform the actual tracing when user code is
instrumented using the OpenTracing API.
Expand All @@ -114,7 +114,7 @@ def create_tracer(otel_tracer_source):
The created :class:`TracerShim`.
"""

return TracerShim(otel_tracer_source.get_tracer(__name__, __version__))
return TracerShim(otel_tracer_provider.get_tracer(__name__, __version__))


class SpanContextShim(opentracing.SpanContext):
Expand Down
8 changes: 4 additions & 4 deletions ext/opentelemetry-ext-opentracing-shim/tests/test_shim.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from opentelemetry import propagators, trace
from opentelemetry.context.propagation.httptextformat import HTTPTextFormat
from opentelemetry.ext.opentracing_shim import util
from opentelemetry.sdk.trace import TracerSource
from opentelemetry.sdk.trace import TracerProvider


class TestShim(TestCase):
Expand All @@ -33,16 +33,16 @@ class TestShim(TestCase):
def setUp(self):
"""Create an OpenTelemetry tracer and a shim before every test case."""

self.shim = opentracingshim.create_tracer(trace.tracer_source())
self.shim = opentracingshim.create_tracer(trace.tracer_provider())

@classmethod
def setUpClass(cls):
"""Set preferred tracer implementation only once rather than before
every test method.
"""

trace.set_preferred_tracer_source_implementation(
lambda T: TracerSource()
trace.set_preferred_tracer_provider_implementation(
lambda T: TracerProvider()
)

# Save current propagator to be restored on teardown.
Expand Down
4 changes: 2 additions & 2 deletions ext/opentelemetry-ext-psycopg2/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ Usage
.. code:: python
import psycopg2
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerSource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.trace.ext.psycopg2 import trace_integration
trace.set_preferred_tracer_source_implementation(lambda T: TracerSource())
trace.set_preferred_tracer_provider_implementation(lambda T: TracerProvider())
tracer = trace.get_tracer(__name__)
trace_integration(tracer)
cnx = psycopg2.connect(database='Database')
Expand Down
4 changes: 2 additions & 2 deletions ext/opentelemetry-ext-pymongo/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ Usage
.. code:: python
from pymongo import MongoClient
from opentelemetry.trace import tracer_source
from opentelemetry.trace import tracer_provider
from opentelemetry.trace.ext.pymongo import trace_integration
trace_integration(tracer_source())
trace_integration(tracer_provider())
client = MongoClient()
db = client["MongoDB_Database"]
collection = db["MongoDB_Collection"]
Expand Down
Loading

0 comments on commit ed25287

Please sign in to comment.