Skip to content

Commit

Permalink
Rename RequestsInstrumentation to RequestsInstrumentor to follow conv…
Browse files Browse the repository at this point in the history
…entions
  • Loading branch information
oxeye-nikolay committed Sep 19, 2021
1 parent 315b438 commit d73b88f
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 21 deletions.
8 changes: 4 additions & 4 deletions instrumentation/opentelemetry-instrumentation-pika/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ Usage
.. code-block:: python
import pika
from opentelemetry.instrumentation.pika import PikaInstrumentation
from opentelemetry.instrumentation.pika import PikaInstrumentor
connection = pika.BlockingConnection(pika.URLParameters('amqp://localhost'))
channel = connection.channel()
channel.queue_declare(queue='hello')
pika_instrumentation = PikaInstrumentation()
pika_instrumentation = PikaInstrumentor()
pika_instrumentation.instrument(channel=channel)
Expand All @@ -45,11 +45,11 @@ Usage
pika_instrumentation.uninstrument(channel=channel)
* PikaInstrumentation also supports instrumentation without creating an object, and receiving a tracer_provider
* PikaInstrumentor also supports instrumentation without creating an object, and receiving a tracer_provider

.. code-block:: python
PikaInstrumentation.instrument_channel(channel, tracer_provider=tracer_provider)
PikaInstrumentor.instrument_channel(channel, tracer_provider=tracer_provider)
References
----------
Expand Down
3 changes: 3 additions & 0 deletions instrumentation/opentelemetry-instrumentation-pika/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,6 @@ test =
[options.packages.find]
where = src

[options.entry_points]
opentelemetry_instrumentor =
pika = opentelemetry.instrumentation.pika:PikaInstrumentor
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
.. code-block:: python
import pika
from opentelemetry.instrumentation.pika import PikaInstrumentation
from opentelemetry.instrumentation.pika import PikaInstrumentor
connection = pika.BlockingConnection(pika.URLParameters('amqp://localhost'))
channel = connection.channel()
channel.queue_declare(queue='hello')
pika_instrumentation = PikaInstrumentation()
pika_instrumentation = PikaInstrumentor()
pika_instrumentation.instrument(channel=channel)
Expand All @@ -44,16 +44,16 @@
pika_instrumentation.uninstrument(channel=channel)
* PikaInstrumentation also supports instrumentation without creating an object, and receiving a tracer_provider
* PikaInstrumentor also supports instrumentation without creating an object, and receiving a tracer_provider
.. code-block:: python
PikaInstrumentation.instrument_channel(channel, tracer_provider=tracer_provider)
PikaInstrumentor.instrument_channel(channel, tracer_provider=tracer_provider)
API
---
"""


from .pika_instrumentor import PikaInstrumentation
from .pika_instrumentor import PikaInstrumentor
from .version import __version__
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
FUNCTIONS_TO_UNINSTRUMENT = ["basic_publish"]


class PikaInstrumentation(BaseInstrumentor): # type: ignore
class PikaInstrumentor(BaseInstrumentor): # type: ignore
@staticmethod
def _instrument_consumers(
consumers_dict: Dict[str, Callable[..., Any]], tracer: Tracer
Expand All @@ -54,7 +54,7 @@ def _instrument_channel_functions(
channel: Channel, tracer: Tracer
) -> None:
if hasattr(channel, "basic_publish"):
PikaInstrumentation._instrument_basic_publish(channel, tracer)
PikaInstrumentor._instrument_basic_publish(channel, tracer)

@staticmethod
def _uninstrument_channel_functions(channel: Channel) -> None:
Expand All @@ -75,17 +75,17 @@ def instrument_channel(
tracer = trace.get_tracer(__name__, __version__, tracer_provider)
channel.__setattr__("__opentelemetry_tracer", tracer)
if channel._impl._consumers:
PikaInstrumentation._instrument_consumers(
PikaInstrumentor._instrument_consumers(
channel._impl._consumers, tracer
)
PikaInstrumentation._instrument_channel_functions(channel, tracer)
PikaInstrumentor._instrument_channel_functions(channel, tracer)

def _instrument(self, **kwargs: Dict[str, Any]) -> None:
channel: Channel = kwargs.get("channel", None)
if not channel or not isinstance(channel, Channel):
return
tracer_provider: TracerProvider = kwargs.get("tracer_provider", None)
PikaInstrumentation.instrument_channel(
PikaInstrumentor.instrument_channel(
channel, tracer_provider=tracer_provider
)

Expand All @@ -99,7 +99,7 @@ def _uninstrument(self, **kwargs: Dict[str, Any]) -> None:
for key, callback in channel._impl._consumers.items():
if hasattr(callback, "_original_callback"):
channel._impl._consumers[key] = callback._original_callback
PikaInstrumentation._uninstrument_channel_functions(channel)
PikaInstrumentor._uninstrument_channel_functions(channel)

def instrumentation_dependencies(self) -> Collection[str]:
return _instruments
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from pika.adapters import BaseConnection
from pika.channel import Channel

from opentelemetry.instrumentation.pika import PikaInstrumentation
from opentelemetry.instrumentation.pika import PikaInstrumentor
from opentelemetry.trace import Tracer


Expand All @@ -38,7 +38,7 @@ def test_instrument_api(
uninstrument_channel_functions: mock.MagicMock,
instrument_channel: mock.MagicMock,
) -> None:
instrumentation = PikaInstrumentation()
instrumentation = PikaInstrumentor()
instrumentation.instrument(channel=self.channel)
instrument_channel.assert_called_once_with(
self.channel, tracer_provider=None
Expand All @@ -64,7 +64,7 @@ def test_instrument(
instrument_consumers: mock.MagicMock,
instrument_channel_functions: mock.MagicMock,
):
PikaInstrumentation.instrument_channel(channel=self.channel)
PikaInstrumentor.instrument_channel(channel=self.channel)
assert hasattr(
self.channel, "__opentelemetry_tracer"
), "Tracer not set for the channel!"
Expand All @@ -80,7 +80,7 @@ def test_instrument_consumers(
mock.call(value, tracer, key)
for key, value in self.channel._impl._consumers.items()
]
PikaInstrumentation._instrument_consumers(
PikaInstrumentor._instrument_consumers(
self.channel._impl._consumers, tracer
)
decorate_callback.assert_has_calls(
Expand All @@ -99,7 +99,7 @@ def test_instrument_basic_publish(
) -> None:
tracer = mock.MagicMock(spec=Tracer)
original_function = self.channel.basic_publish
PikaInstrumentation._instrument_basic_publish(self.channel, tracer)
PikaInstrumentor._instrument_basic_publish(self.channel, tracer)
decorate_basic_publish.assert_called_once_with(
original_function, self.channel, tracer
)
Expand All @@ -114,5 +114,5 @@ def test_uninstrument_channel_functions(self) -> None:
original_function = self.channel.basic_publish
self.channel.basic_publish = mock.MagicMock()
self.channel.basic_publish._original_function = original_function
PikaInstrumentation._uninstrument_channel_functions(self.channel)
PikaInstrumentor._uninstrument_channel_functions(self.channel)
self.assertEqual(self.channel.basic_publish, original_function)

0 comments on commit d73b88f

Please sign in to comment.