From 56a7c2d67535911ccab7d96c10ea792d6efb3b2a Mon Sep 17 00:00:00 2001 From: Adrien Bennatan Date: Wed, 20 Apr 2022 17:31:57 +0200 Subject: [PATCH 01/31] feat: add basic remoulade instrumentation --- .../MANIFEST.in | 9 ++ .../README.rst | 59 ++++++++++++ .../setup.cfg | 58 ++++++++++++ .../setup.py | 89 +++++++++++++++++++ .../instrumentation/remoulade/__init__.py | 83 +++++++++++++++++ .../instrumentation/remoulade/package.py | 16 ++++ .../instrumentation/remoulade/utils.py | 10 +++ .../instrumentation/remoulade/version.py | 15 ++++ .../instrumentation/bootstrap_gen.py | 4 + tox.ini | 4 + 10 files changed, 347 insertions(+) create mode 100644 instrumentation/opentelemetry-instrumentation-remoulade/MANIFEST.in create mode 100644 instrumentation/opentelemetry-instrumentation-remoulade/README.rst create mode 100644 instrumentation/opentelemetry-instrumentation-remoulade/setup.cfg create mode 100644 instrumentation/opentelemetry-instrumentation-remoulade/setup.py create mode 100644 instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py create mode 100644 instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/package.py create mode 100644 instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/utils.py create mode 100644 instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/version.py diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/MANIFEST.in b/instrumentation/opentelemetry-instrumentation-remoulade/MANIFEST.in new file mode 100644 index 0000000000..aed3e33273 --- /dev/null +++ b/instrumentation/opentelemetry-instrumentation-remoulade/MANIFEST.in @@ -0,0 +1,9 @@ +graft src +graft tests +global-exclude *.pyc +global-exclude *.pyo +global-exclude __pycache__/* +include CHANGELOG.md +include MANIFEST.in +include README.rst +include LICENSE diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/README.rst b/instrumentation/opentelemetry-instrumentation-remoulade/README.rst new file mode 100644 index 0000000000..2de1da31bc --- /dev/null +++ b/instrumentation/opentelemetry-instrumentation-remoulade/README.rst @@ -0,0 +1,59 @@ +OpenTelemetry Redis Instrumentation +=================================== + +|pypi| + +.. |pypi| image:: https://badge.fury.io/py/opentelemetry-instrumentation-redis.svg + :target: https://pypi.org/project/opentelemetry-instrumentation-redis/ + +This library allows tracing requests made by the Redis library. + +Installation +------------ + +:: + + pip install opentelemetry-instrumentation-redis + +Usage +----- + +* Start broker backend + +:: + + docker run -p 5672:5672 rabbitmq + +* Run instrumented actor + +.. code-block:: python + + from remoulade.brokers.rabbitmq import RabbitmqBroker + import remoulade + + broker = RabbitmqBroker() + remoulade.set_broker(broker) + + RemouladeInstrumentor().instrument() + + @remoulade.actor + def multiply(x, y): + return x * y + + broker.declare_actor(count_words) + + multiply.send(43, 51) + + +Setting up tracing +-------------------- + The ``instrument()`` method of the RemouladeInstrumentor should always be called after the broker is set, because the instrumentation is attached to the broker. + + + +References +---------- + +* `OpenTelemetry Redis Instrumentation `_ +* `OpenTelemetry Project `_ +* `OpenTelemetry Python Examples `_ diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/setup.cfg b/instrumentation/opentelemetry-instrumentation-remoulade/setup.cfg new file mode 100644 index 0000000000..7271cbb295 --- /dev/null +++ b/instrumentation/opentelemetry-instrumentation-remoulade/setup.cfg @@ -0,0 +1,58 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +[metadata] +name = opentelemetry-instrumentation-remoulade +description = OpenTelemetry remoulade instrumentation +long_description = file: README.rst +long_description_content_type = text/x-rst +author = OpenTelemetry Authors +author_email = cncf-opentelemetry-contributors@lists.cncf.io +url = https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-remoulade +platforms = any +license = Apache-2.0 +classifiers = + Development Status :: 4 - Beta + Intended Audience :: Developers + License :: OSI Approved :: Apache Software License + Programming Language :: Python + Programming Language :: Python :: 3 + Programming Language :: Python :: 3.6 + Programming Language :: Python :: 3.7 + Programming Language :: Python :: 3.8 + Programming Language :: Python :: 3.9 + Programming Language :: Python :: 3.10 + +[options] +python_requires = >=3.6 +package_dir= + =src +packages=find_namespace: +install_requires = + opentelemetry-api ~= 1.3 + opentelemetry-semantic-conventions == 0.30b0 + opentelemetry-instrumentation == 0.30b0 + wrapt >= 1.12.1 + +[options.extras_require] +test = + opentelemetry-test-utils == 0.30b0 + opentelemetry-sdk ~= 1.3 + +[options.packages.find] +where = src + +[options.entry_points] +opentelemetry_instrumentor = + redis = opentelemetry.instrumentation.remoulade:RemouladeInstrumentor diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/setup.py b/instrumentation/opentelemetry-instrumentation-remoulade/setup.py new file mode 100644 index 0000000000..f969faf71f --- /dev/null +++ b/instrumentation/opentelemetry-instrumentation-remoulade/setup.py @@ -0,0 +1,89 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +# DO NOT EDIT. THIS FILE WAS AUTOGENERATED FROM templates/instrumentation_setup.py.txt. +# RUN `python scripts/generate_setup.py` TO REGENERATE. + + +import distutils.cmd +import json +import os +from configparser import ConfigParser + +import setuptools + +config = ConfigParser() +config.read("setup.cfg") + +# We provide extras_require parameter to setuptools.setup later which +# overwrites the extras_require section from setup.cfg. To support extras_require +# section in setup.cfg, we load it here and merge it with the extras_require param. +extras_require = {} +if "options.extras_require" in config: + for key, value in config["options.extras_require"].items(): + extras_require[key] = [v for v in value.split("\n") if v.strip()] + +BASE_DIR = os.path.dirname(__file__) +PACKAGE_INFO = {} + +VERSION_FILENAME = os.path.join( + BASE_DIR, "src", "opentelemetry", "instrumentation", "remoulade", "version.py" +) +with open(VERSION_FILENAME, encoding="utf-8") as f: + exec(f.read(), PACKAGE_INFO) + +PACKAGE_FILENAME = os.path.join( + BASE_DIR, "src", "opentelemetry", "instrumentation", "remoulade", "package.py" +) +with open(PACKAGE_FILENAME, encoding="utf-8") as f: + exec(f.read(), PACKAGE_INFO) + +# Mark any instruments/runtime dependencies as test dependencies as well. +extras_require["instruments"] = PACKAGE_INFO["_instruments"] +test_deps = extras_require.get("test", []) +for dep in extras_require["instruments"]: + test_deps.append(dep) + +extras_require["test"] = test_deps + + +class JSONMetadataCommand(distutils.cmd.Command): + + description = ( + "print out package metadata as JSON. This is used by OpenTelemetry dev scripts to ", + "auto-generate code in other places", + ) + user_options = [] + + def initialize_options(self): + pass + + def finalize_options(self): + pass + + def run(self): + metadata = { + "name": config["metadata"]["name"], + "version": PACKAGE_INFO["__version__"], + "instruments": PACKAGE_INFO["_instruments"], + } + print(json.dumps(metadata)) + + +setuptools.setup( + cmdclass={"meta": JSONMetadataCommand}, + version=PACKAGE_INFO["__version__"], + extras_require=extras_require, +) diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py new file mode 100644 index 0000000000..65a1335f4f --- /dev/null +++ b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py @@ -0,0 +1,83 @@ +import logging +from typing import Collection + +from remoulade import Middleware, broker + +from opentelemetry import trace +from opentelemetry.instrumentation.remoulade import utils +from opentelemetry.instrumentation.remoulade.version import __version__ +from opentelemetry.instrumentation.remoulade.package import _instruments +from opentelemetry.instrumentation.instrumentor import BaseInstrumentor +from opentelemetry.propagate import extract, inject + + +class InstrumentationMiddleware(Middleware): + def __init__(self, _tracer): + self._tracer = _tracer + self._span_registry = {} + + def before_process_message(self, _broker, message): + trace_ctx = extract(message.options) # FIXME: extract/inject in message.option["trace_ctx"] + operation_name = "remoulade/process" + + span = self._tracer.start_span(operation_name, kind=trace.SpanKind.CONSUMER, context=trace_ctx) + + activation = trace.use_span(span, end_on_exit=True) + activation.__enter__() + + utils.attach_span(self._span_registry, message.message_id, (span, activation)) + + def after_process_message(self, _broker, message, *, result=None, exception=None): + span, activation = utils.retrieve_span(self._span_registry, message.message_id) + + if span is None: + # no existing span found for message_id + return + + if span.is_recording(): + pass + + activation.__exit__(None, None, None) + utils.detach_span(self._span_registry, message.message_id) + + def before_enqueue(self, _broker, message, delay): + operation_name = "remoulade/send" + + span = self._tracer.start_span(operation_name, kind=trace.SpanKind.PRODUCER) + + if span.is_recording(): + # span.set_attribute("TEST_ATTRIBUTE", "TEST_VALUE") + pass + + activation = trace.use_span(span, end_on_exit=True) + activation.__enter__() + + utils.attach_span(self._span_registry, message.message_id, (span, activation), is_publish=True) + + inject(message.options) # FIXME: extract/inject in message.option["trace_ctx"] + + def after_enqueue(self, _broker, message, delay, exception=None): + _, activation = utils.retrieve_span(self._span_registry, message.message_id, is_publish=True) + + if activation is None: + # no existing span found for message_id + return + + activation.__exit__(None, None, None) + utils.detach_span(self._span_registry, message.message_id, is_publish=True) + + +class RemouladeInstrumentor(BaseInstrumentor): + def instrumentation_dependencies(self) -> Collection[str]: + return _instruments + + def _instrument(self, **kwargs): + tracer_provider = kwargs.get("tracer_provider") + + self._tracer = trace.get_tracer(__name__, __version__, tracer_provider) + + instrumentation_middleware = InstrumentationMiddleware(self._tracer) + broker.get_broker().add_middleware(instrumentation_middleware) + + def _uninstrument(self, **kwargs): + return \ No newline at end of file diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/package.py b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/package.py new file mode 100644 index 0000000000..fcf32742d4 --- /dev/null +++ b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/package.py @@ -0,0 +1,16 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +_instruments = ("remoulade >= 0.48",) diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/utils.py b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/utils.py new file mode 100644 index 0000000000..a0cdc2b06b --- /dev/null +++ b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/utils.py @@ -0,0 +1,10 @@ +def attach_span(span_registry, message_id, span, is_publish=False): + span_registry[(message_id, is_publish)] = span + + +def detach_span(span_registry, message_id, is_publish=False): + span_registry.pop((message_id, is_publish)) + + +def retrieve_span(span_registry, message_id, is_publish=False): + return span_registry.get((message_id, is_publish), (None, None)) diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/version.py b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/version.py new file mode 100644 index 0000000000..75e49aa583 --- /dev/null +++ b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/version.py @@ -0,0 +1,15 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +__version__ = "0.30b0" diff --git a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py index 967d3265d1..bbc95c647a 100644 --- a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py +++ b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py @@ -112,6 +112,10 @@ "library": "redis >= 2.6", "instrumentation": "opentelemetry-instrumentation-redis==0.30b0", }, + "remoulade": { + "library": "remoulade >= 0.48", + "instrumentation": "opentelemetry-instrumentation-remoulade==0.30b0", + }, "requests": { "library": "requests ~= 2.0", "instrumentation": "opentelemetry-instrumentation-requests==0.30b0", diff --git a/tox.ini b/tox.ini index ed3ad86413..5dcc10cd83 100644 --- a/tox.ini +++ b/tox.ini @@ -156,6 +156,10 @@ envlist = py3{6,7,8,9,10}-test-instrumentation-redis pypy3-test-instrumentation-redis + ; opentelemetry-instrumentation-remoulade + py3{6,7,8,9,10}-test-instrumentation-remoualde + pypy3-test-instrumentation-remoulade + ; opentelemetry-instrumentation-celery py3{6,7,8,9,10}-test-instrumentation-celery pypy3-test-instrumentation-celery From 73da3550bb33bf68ebf8717183c563ea90a05b4a Mon Sep 17 00:00:00 2001 From: Adrien Bennatan Date: Wed, 20 Apr 2022 17:32:23 +0200 Subject: [PATCH 02/31] feat: add basic test --- .../tests/__init__.py | 0 .../tests/test_messages.py | 47 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 instrumentation/opentelemetry-instrumentation-remoulade/tests/__init__.py create mode 100644 instrumentation/opentelemetry-instrumentation-remoulade/tests/test_messages.py diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/tests/__init__.py b/instrumentation/opentelemetry-instrumentation-remoulade/tests/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_messages.py b/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_messages.py new file mode 100644 index 0000000000..e812694f5c --- /dev/null +++ b/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_messages.py @@ -0,0 +1,47 @@ +import remoulade +from remoulade.brokers.local import LocalBroker +from remoulade.results import Results +from remoulade.results.backends import LocalBackend +from opentelemetry.instrumentation.remoulade import RemouladeInstrumentor +from opentelemetry.test.test_base import TestBase +from opentelemetry.trace import SpanKind + + + +@remoulade.actor +def actor_multiply(x, y): + return x * y + + +class TestRemouladeInstrumentation(TestBase): + def setUp(self): + super().setUp() + + broker = LocalBroker() + + # Should a backend be added to wait for the result ? + # result_backend = LocalBackend() + # broker.add_middleware(Results(backend=result_backend)) + remoulade.set_broker(broker) + RemouladeInstrumentor().instrument() + + broker.declare_actor(actor_multiply) + + def test_message(self): + message = actor_multiply.send(1, 2) + # result = message.result.get(block=True) + + spans = self.sorted_spans(self.memory_exporter.get_finished_spans()) + self.assertEqual(len(spans), 2) + + consumer, producer = spans + + self.assertEqual(consumer.name, "remoulade/process") + self.assertEqual(consumer.kind, SpanKind.CONSUMER) + + self.assertEqual(producer.name, "remoulade/send") + self.assertEqual(producer.kind, SpanKind.PRODUCER) + + self.assertNotEqual(consumer.parent, producer.context) + self.assertEqual(consumer.parent.span_id, producer.context.span_id) + self.assertEqual(consumer.context.trace_id, producer.context.trace_id) \ No newline at end of file From 9cc3e2c551e880501cb740842d8629f37a0e17df Mon Sep 17 00:00:00 2001 From: Adrien Bennatan Date: Wed, 27 Apr 2022 15:42:32 +0200 Subject: [PATCH 03/31] feat: add basic tests --- .../tests/test_falcon.py | 419 ------------------ .../README.rst | 36 ++ .../tests/remoulade_test_messages.py | 29 ++ 3 files changed, 65 insertions(+), 419 deletions(-) delete mode 100644 instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py create mode 100644 instrumentation/opentelemetry-instrumentation-remoulade/tests/remoulade_test_messages.py diff --git a/instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py b/instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py deleted file mode 100644 index 5098937b2a..0000000000 --- a/instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py +++ /dev/null @@ -1,419 +0,0 @@ -# Copyright The OpenTelemetry Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from unittest.mock import Mock, patch - -import pytest -from falcon import __version__ as _falcon_verison -from falcon import testing -from packaging import version as package_version - -from opentelemetry import trace -from opentelemetry.instrumentation.falcon import FalconInstrumentor -from opentelemetry.instrumentation.propagators import ( - TraceResponsePropagator, - get_global_response_propagator, - set_global_response_propagator, -) -from opentelemetry.sdk.resources import Resource -from opentelemetry.semconv.trace import SpanAttributes -from opentelemetry.test.test_base import TestBase -from opentelemetry.test.wsgitestutil import WsgiTestBase -from opentelemetry.trace import StatusCode -from opentelemetry.util.http import ( - OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST, - OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE, -) - -from .app import make_app - - -class TestFalconBase(TestBase): - def setUp(self): - super().setUp() - self.env_patch = patch.dict( - "os.environ", - { - "OTEL_PYTHON_FALCON_EXCLUDED_URLS": "ping", - "OTEL_PYTHON_FALCON_TRACED_REQUEST_ATTRS": "query_string", - }, - ) - self.env_patch.start() - - FalconInstrumentor().instrument( - request_hook=getattr(self, "request_hook", None), - response_hook=getattr(self, "response_hook", None), - ) - self.app = make_app() - - def client(self): - return testing.TestClient(self.app) - - def tearDown(self): - super().tearDown() - with self.disable_logging(): - FalconInstrumentor().uninstrument() - self.env_patch.stop() - - -class TestFalconInstrumentation(TestFalconBase, WsgiTestBase): - def test_get(self): - self._test_method("GET") - - def test_post(self): - self._test_method("POST") - - def test_patch(self): - self._test_method("PATCH") - - def test_put(self): - self._test_method("PUT") - - def test_delete(self): - self._test_method("DELETE") - - def test_head(self): - self._test_method("HEAD") - - def _test_method(self, method): - self.client().simulate_request(method=method, path="/hello") - spans = self.memory_exporter.get_finished_spans() - self.assertEqual(len(spans), 1) - span = spans[0] - self.assertEqual(span.name, f"HelloWorldResource.on_{method.lower()}") - self.assertEqual(span.status.status_code, StatusCode.UNSET) - self.assertEqual( - span.status.description, - None, - ) - self.assertSpanHasAttributes( - span, - { - SpanAttributes.HTTP_METHOD: method, - SpanAttributes.HTTP_SERVER_NAME: "falconframework.org", - SpanAttributes.HTTP_SCHEME: "http", - SpanAttributes.NET_HOST_PORT: 80, - SpanAttributes.HTTP_HOST: "falconframework.org", - SpanAttributes.HTTP_TARGET: "/", - SpanAttributes.NET_PEER_PORT: "65133", - SpanAttributes.HTTP_FLAVOR: "1.1", - "falcon.resource": "HelloWorldResource", - SpanAttributes.HTTP_STATUS_CODE: 201, - }, - ) - # In falcon<3, NET_PEER_IP is always set by default to 127.0.0.1 - # In falcon>3, NET_PEER_IP is not set to anything by default to - # https://github.com/falconry/falcon/blob/5233d0abed977d9dab78ebadf305f5abe2eef07c/falcon/testing/helpers.py#L1168-L1172 # noqa - if SpanAttributes.NET_PEER_IP in span.attributes: - self.assertEqual( - span.attributes[SpanAttributes.NET_PEER_IP], "127.0.0.1" - ) - self.memory_exporter.clear() - - def test_404(self): - self.client().simulate_get("/does-not-exist") - spans = self.memory_exporter.get_finished_spans() - self.assertEqual(len(spans), 1) - span = spans[0] - self.assertEqual(span.name, "HTTP GET") - self.assertEqual(span.status.status_code, StatusCode.UNSET) - self.assertSpanHasAttributes( - span, - { - SpanAttributes.HTTP_METHOD: "GET", - SpanAttributes.HTTP_SERVER_NAME: "falconframework.org", - SpanAttributes.HTTP_SCHEME: "http", - SpanAttributes.NET_HOST_PORT: 80, - SpanAttributes.HTTP_HOST: "falconframework.org", - SpanAttributes.HTTP_TARGET: "/", - SpanAttributes.NET_PEER_PORT: "65133", - SpanAttributes.HTTP_FLAVOR: "1.1", - SpanAttributes.HTTP_STATUS_CODE: 404, - }, - ) - # In falcon<3, NET_PEER_IP is always set by default to 127.0.0.1 - # In falcon>3, NET_PEER_IP is not set to anything by default to - # https://github.com/falconry/falcon/blob/5233d0abed977d9dab78ebadf305f5abe2eef07c/falcon/testing/helpers.py#L1168-L1172 # noqa - if SpanAttributes.NET_PEER_IP in span.attributes: - self.assertEqual( - span.attributes[SpanAttributes.NET_PEER_IP], "127.0.0.1" - ) - - def test_500(self): - try: - self.client().simulate_get("/error") - except NameError: - pass - spans = self.memory_exporter.get_finished_spans() - self.assertEqual(len(spans), 1) - span = spans[0] - self.assertEqual(span.name, "ErrorResource.on_get") - self.assertFalse(span.status.is_ok) - self.assertEqual(span.status.status_code, StatusCode.ERROR) - self.assertEqual( - span.status.description, - "NameError: name 'non_existent_var' is not defined", - ) - self.assertSpanHasAttributes( - span, - { - SpanAttributes.HTTP_METHOD: "GET", - SpanAttributes.HTTP_SERVER_NAME: "falconframework.org", - SpanAttributes.HTTP_SCHEME: "http", - SpanAttributes.NET_HOST_PORT: 80, - SpanAttributes.HTTP_HOST: "falconframework.org", - SpanAttributes.HTTP_TARGET: "/", - SpanAttributes.NET_PEER_PORT: "65133", - SpanAttributes.HTTP_FLAVOR: "1.1", - SpanAttributes.HTTP_STATUS_CODE: 500, - }, - ) - # In falcon<3, NET_PEER_IP is always set by default to 127.0.0.1 - # In falcon>3, NET_PEER_IP is not set to anything by default to - # https://github.com/falconry/falcon/blob/5233d0abed977d9dab78ebadf305f5abe2eef07c/falcon/testing/helpers.py#L1168-L1172 # noqa - if SpanAttributes.NET_PEER_IP in span.attributes: - self.assertEqual( - span.attributes[SpanAttributes.NET_PEER_IP], "127.0.0.1" - ) - - def test_uninstrument(self): - self.client().simulate_get(path="/hello") - spans = self.memory_exporter.get_finished_spans() - self.assertEqual(len(spans), 1) - - self.memory_exporter.clear() - - FalconInstrumentor().uninstrument() - self.app = make_app() - self.client().simulate_get(path="/hello") - spans = self.memory_exporter.get_finished_spans() - self.assertEqual(len(spans), 0) - - def test_exclude_lists(self): - self.client().simulate_get(path="/ping") - span_list = self.memory_exporter.get_finished_spans() - self.assertEqual(len(span_list), 0) - - self.client().simulate_get(path="/hello") - span_list = self.memory_exporter.get_finished_spans() - self.assertEqual(len(span_list), 1) - - def test_traced_request_attributes(self): - self.client().simulate_get(path="/hello", query_string="q=abc") - span = self.memory_exporter.get_finished_spans()[0] - self.assertIn("query_string", span.attributes) - self.assertEqual(span.attributes["query_string"], "q=abc") - self.assertNotIn("not_available_attr", span.attributes) - - def test_trace_response(self): - orig = get_global_response_propagator() - set_global_response_propagator(TraceResponsePropagator()) - - response = self.client().simulate_get( - path="/hello", query_string="q=abc" - ) - self.assertTraceResponseHeaderMatchesSpan( - response.headers, self.memory_exporter.get_finished_spans()[0] - ) - - set_global_response_propagator(orig) - - def test_traced_not_recording(self): - mock_tracer = Mock() - mock_span = Mock() - mock_span.is_recording.return_value = False - mock_tracer.start_span.return_value = mock_span - with patch("opentelemetry.trace.get_tracer") as tracer: - tracer.return_value = mock_tracer - self.client().simulate_get(path="/hello", query_string="q=abc") - self.assertFalse(mock_span.is_recording()) - self.assertTrue(mock_span.is_recording.called) - self.assertFalse(mock_span.set_attribute.called) - self.assertFalse(mock_span.set_status.called) - - -class TestFalconInstrumentationWithTracerProvider(TestBase): - def setUp(self): - super().setUp() - resource = Resource.create({"resource-key": "resource-value"}) - result = self.create_tracer_provider(resource=resource) - tracer_provider, exporter = result - self.exporter = exporter - - FalconInstrumentor().instrument(tracer_provider=tracer_provider) - self.app = make_app() - - def client(self): - return testing.TestClient(self.app) - - def tearDown(self): - super().tearDown() - with self.disable_logging(): - FalconInstrumentor().uninstrument() - - def test_traced_request(self): - self.client().simulate_request(method="GET", path="/hello") - spans = self.exporter.get_finished_spans() - self.assertEqual(len(spans), 1) - span = spans[0] - self.assertEqual( - span.resource.attributes["resource-key"], "resource-value" - ) - self.exporter.clear() - - -class TestFalconInstrumentationHooks(TestFalconBase): - # pylint: disable=no-self-use - def request_hook(self, span, req): - span.set_attribute("request_hook_attr", "value from hook") - - def response_hook(self, span, req, resp): - span.update_name("set from hook") - - def test_hooks(self): - self.client().simulate_get(path="/hello", query_string="q=abc") - span = self.memory_exporter.get_finished_spans()[0] - - self.assertEqual(span.name, "set from hook") - self.assertIn("request_hook_attr", span.attributes) - self.assertEqual( - span.attributes["request_hook_attr"], "value from hook" - ) - - -class TestFalconInstrumentationWrappedWithOtherFramework(TestFalconBase): - def test_mark_span_internal_in_presence_of_span_from_other_framework(self): - tracer = trace.get_tracer(__name__) - with tracer.start_as_current_span( - "test", kind=trace.SpanKind.SERVER - ) as parent_span: - self.client().simulate_request(method="GET", path="/hello") - span = self.memory_exporter.get_finished_spans()[0] - assert span.status.is_ok - self.assertEqual(trace.SpanKind.INTERNAL, span.kind) - self.assertEqual( - span.parent.span_id, parent_span.get_span_context().span_id - ) - - -@patch.dict( - "os.environ", - { - OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST: "Custom-Test-Header-1,Custom-Test-Header-2,invalid-header", - OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE: "content-type,content-length,my-custom-header,invalid-header", - }, -) -class TestCustomRequestResponseHeaders(TestFalconBase): - def test_custom_request_header_added_in_server_span(self): - headers = { - "Custom-Test-Header-1": "Test Value 1", - "Custom-Test-Header-2": "TestValue2,TestValue3", - "Custom-Test-Header-3": "TestValue4", - } - self.client().simulate_request( - method="GET", path="/hello", headers=headers - ) - span = self.memory_exporter.get_finished_spans()[0] - assert span.status.is_ok - - expected = { - "http.request.header.custom_test_header_1": ("Test Value 1",), - "http.request.header.custom_test_header_2": ( - "TestValue2,TestValue3", - ), - } - not_expected = { - "http.request.header.custom_test_header_3": ("TestValue4",), - } - - self.assertEqual(span.kind, trace.SpanKind.SERVER) - self.assertSpanHasAttributes(span, expected) - for key, _ in not_expected.items(): - self.assertNotIn(key, span.attributes) - - def test_custom_request_header_not_added_in_internal_span(self): - tracer = trace.get_tracer(__name__) - with tracer.start_as_current_span("test", kind=trace.SpanKind.SERVER): - headers = { - "Custom-Test-Header-1": "Test Value 1", - "Custom-Test-Header-2": "TestValue2,TestValue3", - } - self.client().simulate_request( - method="GET", path="/hello", headers=headers - ) - span = self.memory_exporter.get_finished_spans()[0] - assert span.status.is_ok - not_expected = { - "http.request.header.custom_test_header_1": ("Test Value 1",), - "http.request.header.custom_test_header_2": ( - "TestValue2,TestValue3", - ), - } - self.assertEqual(span.kind, trace.SpanKind.INTERNAL) - for key, _ in not_expected.items(): - self.assertNotIn(key, span.attributes) - - @pytest.mark.skipif( - condition=package_version.parse(_falcon_verison) - < package_version.parse("2.0.0"), - reason="falcon<2 does not implement custom response headers", - ) - def test_custom_response_header_added_in_server_span(self): - self.client().simulate_request( - method="GET", path="/test_custom_response_headers" - ) - span = self.memory_exporter.get_finished_spans()[0] - assert span.status.is_ok - expected = { - "http.response.header.content_type": ( - "text/plain; charset=utf-8", - ), - "http.response.header.content_length": ("0",), - "http.response.header.my_custom_header": ( - "my-custom-value-1,my-custom-header-2", - ), - } - not_expected = { - "http.response.header.dont_capture_me": ("test-value",) - } - self.assertEqual(span.kind, trace.SpanKind.SERVER) - self.assertSpanHasAttributes(span, expected) - for key, _ in not_expected.items(): - self.assertNotIn(key, span.attributes) - - @pytest.mark.skipif( - condition=package_version.parse(_falcon_verison) - < package_version.parse("2.0.0"), - reason="falcon<2 does not implement custom response headers", - ) - def test_custom_response_header_not_added_in_internal_span(self): - tracer = trace.get_tracer(__name__) - with tracer.start_as_current_span("test", kind=trace.SpanKind.SERVER): - self.client().simulate_request( - method="GET", path="/test_custom_response_headers" - ) - span = self.memory_exporter.get_finished_spans()[0] - assert span.status.is_ok - not_expected = { - "http.response.header.content_type": ( - "text/plain; charset=utf-8", - ), - "http.response.header.content_length": ("0",), - "http.response.header.my_custom_header": ( - "my-custom-value-1,my-custom-header-2", - ), - } - self.assertEqual(span.kind, trace.SpanKind.INTERNAL) - for key, _ in not_expected.items(): - self.assertNotIn(key, span.attributes) diff --git a/instrumentation/opentelemetry-instrumentation-redis/README.rst b/instrumentation/opentelemetry-instrumentation-redis/README.rst index d7f4fa7aaa..2de1da31bc 100644 --- a/instrumentation/opentelemetry-instrumentation-redis/README.rst +++ b/instrumentation/opentelemetry-instrumentation-redis/README.rst @@ -15,6 +15,42 @@ Installation pip install opentelemetry-instrumentation-redis +Usage +----- + +* Start broker backend + +:: + + docker run -p 5672:5672 rabbitmq + +* Run instrumented actor + +.. code-block:: python + + from remoulade.brokers.rabbitmq import RabbitmqBroker + import remoulade + + broker = RabbitmqBroker() + remoulade.set_broker(broker) + + RemouladeInstrumentor().instrument() + + @remoulade.actor + def multiply(x, y): + return x * y + + broker.declare_actor(count_words) + + multiply.send(43, 51) + + +Setting up tracing +-------------------- + The ``instrument()`` method of the RemouladeInstrumentor should always be called after the broker is set, because the instrumentation is attached to the broker. + + + References ---------- diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/tests/remoulade_test_messages.py b/instrumentation/opentelemetry-instrumentation-remoulade/tests/remoulade_test_messages.py new file mode 100644 index 0000000000..d9660412f0 --- /dev/null +++ b/instrumentation/opentelemetry-instrumentation-remoulade/tests/remoulade_test_messages.py @@ -0,0 +1,29 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from celery import Celery + + +class Config: + result_backend = "rpc" + broker_backend = "memory" + + +app = Celery(broker="memory:///") +app.config_from_object(Config) + + +@app.task +def task_add(num_a, num_b): + return num_a + num_b From fc79f80031ac27a336803174de6140581796e977 Mon Sep 17 00:00:00 2001 From: Adrien Bennatan Date: Wed, 27 Apr 2022 16:09:44 +0200 Subject: [PATCH 04/31] feat: add basic attributes --- .../instrumentation/remoulade/__init__.py | 17 ++++++++++++- .../tests/test_messages.py | 24 ++++++++++++------- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py index 65a1335f4f..4814375d37 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py @@ -9,6 +9,14 @@ from opentelemetry.instrumentation.remoulade.package import _instruments from opentelemetry.instrumentation.instrumentor import BaseInstrumentor from opentelemetry.propagate import extract, inject +from opentelemetry.semconv.trace import SpanAttributes + + +_MESSAGE_TAG_KEY = "remoulade.action" +_MESSAGE_SEND = "send" +_MESSAGE_RUN = "run" + +_MESSAGE_NAME_KEY = "remoulade.actor_name" class InstrumentationMiddleware(Middleware): @@ -35,6 +43,10 @@ def after_process_message(self, _broker, message, *, result=None, exception=None return if span.is_recording(): + span.set_attribute(_MESSAGE_TAG_KEY, _MESSAGE_RUN) + # utils.set_attributes_from_context(span, kwargs) + # utils.set_attributes_from_context(span, task.request) + span.set_attribute(_MESSAGE_NAME_KEY, message.actor_name) pass activation.__exit__(None, None, None) @@ -46,7 +58,10 @@ def before_enqueue(self, _broker, message, delay): span = self._tracer.start_span(operation_name, kind=trace.SpanKind.PRODUCER) if span.is_recording(): - # span.set_attribute("TEST_ATTRIBUTE", "TEST_VALUE") + span.set_attribute(_MESSAGE_TAG_KEY, _MESSAGE_SEND) + span.set_attribute(SpanAttributes.MESSAGING_MESSAGE_ID, message.message_id) + span.set_attribute(_MESSAGE_NAME_KEY, message.actor_name) + # utils.set_attributes_from_context(span, kwargs) pass activation = trace.use_span(span, end_on_exit=True) diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_messages.py b/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_messages.py index e812694f5c..05c739d9b5 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_messages.py +++ b/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_messages.py @@ -1,11 +1,9 @@ import remoulade from remoulade.brokers.local import LocalBroker -from remoulade.results import Results -from remoulade.results.backends import LocalBackend from opentelemetry.instrumentation.remoulade import RemouladeInstrumentor from opentelemetry.test.test_base import TestBase from opentelemetry.trace import SpanKind - +from opentelemetry.semconv.trace import SpanAttributes @remoulade.actor @@ -19,17 +17,13 @@ def setUp(self): broker = LocalBroker() - # Should a backend be added to wait for the result ? - # result_backend = LocalBackend() - # broker.add_middleware(Results(backend=result_backend)) remoulade.set_broker(broker) RemouladeInstrumentor().instrument() broker.declare_actor(actor_multiply) def test_message(self): - message = actor_multiply.send(1, 2) - # result = message.result.get(block=True) + actor_multiply.send(1, 2) spans = self.sorted_spans(self.memory_exporter.get_finished_spans()) self.assertEqual(len(spans), 2) @@ -38,9 +32,23 @@ def test_message(self): self.assertEqual(consumer.name, "remoulade/process") self.assertEqual(consumer.kind, SpanKind.CONSUMER) + self.assertSpanHasAttributes( + consumer, + { + "remoulade.action": "run", + "remoulade.actor_name": "actor_multiply", + }, + ) self.assertEqual(producer.name, "remoulade/send") self.assertEqual(producer.kind, SpanKind.PRODUCER) + self.assertSpanHasAttributes( + producer, + { + "remoulade.action": "send", + "remoulade.actor_name": "actor_multiply", + }, + ) self.assertNotEqual(consumer.parent, producer.context) self.assertEqual(consumer.parent.span_id, producer.context.span_id) From 8eab9171d689ac1a625fc68650cbbe9c3322750c Mon Sep 17 00:00:00 2001 From: Adrien Bennatan Date: Wed, 27 Apr 2022 16:20:10 +0200 Subject: [PATCH 05/31] feat: pass context in options["trace_ctx"] instead of options --- .../src/opentelemetry/instrumentation/remoulade/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py index 4814375d37..e93a96057c 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py @@ -25,7 +25,7 @@ def __init__(self, _tracer): self._span_registry = {} def before_process_message(self, _broker, message): - trace_ctx = extract(message.options) # FIXME: extract/inject in message.option["trace_ctx"] + trace_ctx = extract(message.options["trace_ctx"]) operation_name = "remoulade/process" span = self._tracer.start_span(operation_name, kind=trace.SpanKind.CONSUMER, context=trace_ctx) @@ -69,7 +69,9 @@ def before_enqueue(self, _broker, message, delay): utils.attach_span(self._span_registry, message.message_id, (span, activation), is_publish=True) - inject(message.options) # FIXME: extract/inject in message.option["trace_ctx"] + if "trace_ctx" not in message.options: + message.options["trace_ctx"] = {} + inject(message.options["trace_ctx"]) def after_enqueue(self, _broker, message, delay, exception=None): _, activation = utils.retrieve_span(self._span_registry, message.message_id, is_publish=True) From 53698aad3e762f737480a22ed631501fc4edd0f2 Mon Sep 17 00:00:00 2001 From: Adrien Bennatan Date: Wed, 27 Apr 2022 17:45:43 +0200 Subject: [PATCH 06/31] feat: add retries and retries tests --- .../instrumentation/remoulade/__init__.py | 17 +++++-- .../tests/test_messages.py | 48 ++++++++++++++++--- 2 files changed, 54 insertions(+), 11 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py index e93a96057c..a28e7f8254 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py @@ -26,10 +26,15 @@ def __init__(self, _tracer): def before_process_message(self, _broker, message): trace_ctx = extract(message.options["trace_ctx"]) - operation_name = "remoulade/process" + retry_count = message.options.get("retries") + + operation_name = "remoulade/process" if retry_count is None else f"remoulade/process(retry-{retry_count})" span = self._tracer.start_span(operation_name, kind=trace.SpanKind.CONSUMER, context=trace_ctx) + if retry_count is not None: + span.set_attribute("retry_count", retry_count) + activation = trace.use_span(span, end_on_exit=True) activation.__enter__() @@ -44,8 +49,6 @@ def after_process_message(self, _broker, message, *, result=None, exception=None if span.is_recording(): span.set_attribute(_MESSAGE_TAG_KEY, _MESSAGE_RUN) - # utils.set_attributes_from_context(span, kwargs) - # utils.set_attributes_from_context(span, task.request) span.set_attribute(_MESSAGE_NAME_KEY, message.actor_name) pass @@ -53,15 +56,19 @@ def after_process_message(self, _broker, message, *, result=None, exception=None utils.detach_span(self._span_registry, message.message_id) def before_enqueue(self, _broker, message, delay): - operation_name = "remoulade/send" + retry_count = message.options.get("retries") + + operation_name = "remoulade/send" if retry_count is None else f"remoulade/send(retry-{retry_count})" span = self._tracer.start_span(operation_name, kind=trace.SpanKind.PRODUCER) + if retry_count is not None: + span.set_attribute("retry_count", retry_count) + if span.is_recording(): span.set_attribute(_MESSAGE_TAG_KEY, _MESSAGE_SEND) span.set_attribute(SpanAttributes.MESSAGING_MESSAGE_ID, message.message_id) span.set_attribute(_MESSAGE_NAME_KEY, message.actor_name) - # utils.set_attributes_from_context(span, kwargs) pass activation = trace.use_span(span, end_on_exit=True) diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_messages.py b/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_messages.py index 05c739d9b5..21d8a36f5b 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_messages.py +++ b/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_messages.py @@ -6,9 +6,9 @@ from opentelemetry.semconv.trace import SpanAttributes -@remoulade.actor -def actor_multiply(x, y): - return x * y +@remoulade.actor(max_retries=3) +def actor_div(x, y): + return x / y class TestRemouladeInstrumentation(TestBase): @@ -20,10 +20,10 @@ def setUp(self): remoulade.set_broker(broker) RemouladeInstrumentor().instrument() - broker.declare_actor(actor_multiply) + broker.declare_actor(actor_div) def test_message(self): - actor_multiply.send(1, 2) + actor_div.send(2, 3) spans = self.sorted_spans(self.memory_exporter.get_finished_spans()) self.assertEqual(len(spans), 2) @@ -52,4 +52,40 @@ def test_message(self): self.assertNotEqual(consumer.parent, producer.context) self.assertEqual(consumer.parent.span_id, producer.context.span_id) - self.assertEqual(consumer.context.trace_id, producer.context.trace_id) \ No newline at end of file + self.assertEqual(consumer.context.trace_id, producer.context.trace_id) + + def test_retries(self): + try: + actor_div.send(1, 0) + except ZeroDivisionError: + pass + + spans = self.sorted_spans(self.memory_exporter.get_finished_spans()) + self.assertEqual(len(spans), 8) + + consumer_spans = spans[::2] + producer_spans = spans[1::2] + + self.assertEqual(consumer_spans[0].name, "remoulade/process(retry-3)") + self.assertSpanHasAttributes( + consumer_spans[0], + { "retry_count": 3 } + ) + self.assertEqual(consumer_spans[1].name, "remoulade/process(retry-2)") + self.assertSpanHasAttributes( + consumer_spans[1], + {"retry_count": 2} + ) + self.assertEqual(consumer_spans[3].name, "remoulade/process") + + self.assertEqual(producer_spans[0].name, "remoulade/send(retry-3)") + self.assertSpanHasAttributes( + producer_spans[0], + {"retry_count": 3} + ) + self.assertEqual(producer_spans[1].name, "remoulade/send(retry-2)") + self.assertSpanHasAttributes( + producer_spans[1], + {"retry_count": 2} + ) + self.assertEqual(producer_spans[3].name, "remoulade/send") From b5ca442e4d29f78675a5eb8e6cd758b71111cf25 Mon Sep 17 00:00:00 2001 From: Adrien Bennatan Date: Thu, 28 Apr 2022 11:06:11 +0200 Subject: [PATCH 07/31] fix: copy pasta --- instrumentation/opentelemetry-instrumentation-redis/README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation/opentelemetry-instrumentation-redis/README.rst b/instrumentation/opentelemetry-instrumentation-redis/README.rst index 2de1da31bc..f69d783f5a 100644 --- a/instrumentation/opentelemetry-instrumentation-redis/README.rst +++ b/instrumentation/opentelemetry-instrumentation-redis/README.rst @@ -54,6 +54,6 @@ Setting up tracing References ---------- -* `OpenTelemetry Redis Instrumentation `_ +* `OpenTelemetry Redis Instrumentation `_ * `OpenTelemetry Project `_ * `OpenTelemetry Python Examples `_ From 918405b24281e0e06a75e033b21a04486f1231d2 Mon Sep 17 00:00:00 2001 From: Adrien Bennatan Date: Fri, 29 Apr 2022 10:18:21 +0200 Subject: [PATCH 08/31] feat: add uninstrument logic (wait for remoulade release) --- .../src/opentelemetry/instrumentation/remoulade/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py index a28e7f8254..212821c91e 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py @@ -104,4 +104,6 @@ def _instrument(self, **kwargs): broker.get_broker().add_middleware(instrumentation_middleware) def _uninstrument(self, **kwargs): + # Wait for remoulade==0.49.0 release + # broker.get_broker().remove_middleware(InstrumentationMiddleware) return \ No newline at end of file From 5e4e3e15242db208649c58350051787d3a53e046 Mon Sep 17 00:00:00 2001 From: Adrien Bennatan Date: Tue, 3 May 2022 12:18:28 +0200 Subject: [PATCH 09/31] feat: add uninstrument --- .../setup.cfg | 3 +- .../instrumentation/remoulade/__init__.py | 4 +-- .../instrumentation/remoulade/package.py | 2 +- .../tests/remoulade_test_messages.py | 29 ------------------- .../tests/test_messages.py | 7 ++--- 5 files changed, 6 insertions(+), 39 deletions(-) delete mode 100644 instrumentation/opentelemetry-instrumentation-remoulade/tests/remoulade_test_messages.py diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/setup.cfg b/instrumentation/opentelemetry-instrumentation-remoulade/setup.cfg index 7271cbb295..e054b339ad 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-remoulade/setup.cfg @@ -43,7 +43,6 @@ install_requires = opentelemetry-api ~= 1.3 opentelemetry-semantic-conventions == 0.30b0 opentelemetry-instrumentation == 0.30b0 - wrapt >= 1.12.1 [options.extras_require] test = @@ -55,4 +54,4 @@ where = src [options.entry_points] opentelemetry_instrumentor = - redis = opentelemetry.instrumentation.remoulade:RemouladeInstrumentor + remoulade = opentelemetry.instrumentation.remoulade:RemouladeInstrumentor diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py index 212821c91e..8202614470 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py @@ -104,6 +104,4 @@ def _instrument(self, **kwargs): broker.get_broker().add_middleware(instrumentation_middleware) def _uninstrument(self, **kwargs): - # Wait for remoulade==0.49.0 release - # broker.get_broker().remove_middleware(InstrumentationMiddleware) - return \ No newline at end of file + broker.get_broker().remove_middleware(InstrumentationMiddleware) diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/package.py b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/package.py index fcf32742d4..4952c29f84 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/package.py +++ b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/package.py @@ -13,4 +13,4 @@ # limitations under the License. -_instruments = ("remoulade >= 0.48",) +_instruments = ("remoulade >= 0.49",) diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/tests/remoulade_test_messages.py b/instrumentation/opentelemetry-instrumentation-remoulade/tests/remoulade_test_messages.py deleted file mode 100644 index d9660412f0..0000000000 --- a/instrumentation/opentelemetry-instrumentation-remoulade/tests/remoulade_test_messages.py +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright The OpenTelemetry Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from celery import Celery - - -class Config: - result_backend = "rpc" - broker_backend = "memory" - - -app = Celery(broker="memory:///") -app.config_from_object(Config) - - -@app.task -def task_add(num_a, num_b): - return num_a + num_b diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_messages.py b/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_messages.py index 21d8a36f5b..8642dd28bb 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_messages.py +++ b/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_messages.py @@ -3,7 +3,6 @@ from opentelemetry.instrumentation.remoulade import RemouladeInstrumentor from opentelemetry.test.test_base import TestBase from opentelemetry.trace import SpanKind -from opentelemetry.semconv.trace import SpanAttributes @remoulade.actor(max_retries=3) @@ -36,7 +35,7 @@ def test_message(self): consumer, { "remoulade.action": "run", - "remoulade.actor_name": "actor_multiply", + "remoulade.actor_name": "actor_div", }, ) @@ -46,7 +45,7 @@ def test_message(self): producer, { "remoulade.action": "send", - "remoulade.actor_name": "actor_multiply", + "remoulade.actor_name": "actor_div", }, ) @@ -69,7 +68,7 @@ def test_retries(self): self.assertEqual(consumer_spans[0].name, "remoulade/process(retry-3)") self.assertSpanHasAttributes( consumer_spans[0], - { "retry_count": 3 } + {"retry_count": 3} ) self.assertEqual(consumer_spans[1].name, "remoulade/process(retry-2)") self.assertSpanHasAttributes( From 51b932eb033410161c6ebd2887f8bb6293097acf Mon Sep 17 00:00:00 2001 From: Adrien Bennatan Date: Tue, 3 May 2022 12:27:26 +0200 Subject: [PATCH 10/31] chore: clean --- .../tests/test_falcon.py | 419 ++++++++++++++++++ .../README.rst | 38 +- .../README.rst | 12 +- .../setup.cfg | 2 +- 4 files changed, 427 insertions(+), 44 deletions(-) create mode 100644 instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py diff --git a/instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py b/instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py new file mode 100644 index 0000000000..5098937b2a --- /dev/null +++ b/instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py @@ -0,0 +1,419 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from unittest.mock import Mock, patch + +import pytest +from falcon import __version__ as _falcon_verison +from falcon import testing +from packaging import version as package_version + +from opentelemetry import trace +from opentelemetry.instrumentation.falcon import FalconInstrumentor +from opentelemetry.instrumentation.propagators import ( + TraceResponsePropagator, + get_global_response_propagator, + set_global_response_propagator, +) +from opentelemetry.sdk.resources import Resource +from opentelemetry.semconv.trace import SpanAttributes +from opentelemetry.test.test_base import TestBase +from opentelemetry.test.wsgitestutil import WsgiTestBase +from opentelemetry.trace import StatusCode +from opentelemetry.util.http import ( + OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST, + OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE, +) + +from .app import make_app + + +class TestFalconBase(TestBase): + def setUp(self): + super().setUp() + self.env_patch = patch.dict( + "os.environ", + { + "OTEL_PYTHON_FALCON_EXCLUDED_URLS": "ping", + "OTEL_PYTHON_FALCON_TRACED_REQUEST_ATTRS": "query_string", + }, + ) + self.env_patch.start() + + FalconInstrumentor().instrument( + request_hook=getattr(self, "request_hook", None), + response_hook=getattr(self, "response_hook", None), + ) + self.app = make_app() + + def client(self): + return testing.TestClient(self.app) + + def tearDown(self): + super().tearDown() + with self.disable_logging(): + FalconInstrumentor().uninstrument() + self.env_patch.stop() + + +class TestFalconInstrumentation(TestFalconBase, WsgiTestBase): + def test_get(self): + self._test_method("GET") + + def test_post(self): + self._test_method("POST") + + def test_patch(self): + self._test_method("PATCH") + + def test_put(self): + self._test_method("PUT") + + def test_delete(self): + self._test_method("DELETE") + + def test_head(self): + self._test_method("HEAD") + + def _test_method(self, method): + self.client().simulate_request(method=method, path="/hello") + spans = self.memory_exporter.get_finished_spans() + self.assertEqual(len(spans), 1) + span = spans[0] + self.assertEqual(span.name, f"HelloWorldResource.on_{method.lower()}") + self.assertEqual(span.status.status_code, StatusCode.UNSET) + self.assertEqual( + span.status.description, + None, + ) + self.assertSpanHasAttributes( + span, + { + SpanAttributes.HTTP_METHOD: method, + SpanAttributes.HTTP_SERVER_NAME: "falconframework.org", + SpanAttributes.HTTP_SCHEME: "http", + SpanAttributes.NET_HOST_PORT: 80, + SpanAttributes.HTTP_HOST: "falconframework.org", + SpanAttributes.HTTP_TARGET: "/", + SpanAttributes.NET_PEER_PORT: "65133", + SpanAttributes.HTTP_FLAVOR: "1.1", + "falcon.resource": "HelloWorldResource", + SpanAttributes.HTTP_STATUS_CODE: 201, + }, + ) + # In falcon<3, NET_PEER_IP is always set by default to 127.0.0.1 + # In falcon>3, NET_PEER_IP is not set to anything by default to + # https://github.com/falconry/falcon/blob/5233d0abed977d9dab78ebadf305f5abe2eef07c/falcon/testing/helpers.py#L1168-L1172 # noqa + if SpanAttributes.NET_PEER_IP in span.attributes: + self.assertEqual( + span.attributes[SpanAttributes.NET_PEER_IP], "127.0.0.1" + ) + self.memory_exporter.clear() + + def test_404(self): + self.client().simulate_get("/does-not-exist") + spans = self.memory_exporter.get_finished_spans() + self.assertEqual(len(spans), 1) + span = spans[0] + self.assertEqual(span.name, "HTTP GET") + self.assertEqual(span.status.status_code, StatusCode.UNSET) + self.assertSpanHasAttributes( + span, + { + SpanAttributes.HTTP_METHOD: "GET", + SpanAttributes.HTTP_SERVER_NAME: "falconframework.org", + SpanAttributes.HTTP_SCHEME: "http", + SpanAttributes.NET_HOST_PORT: 80, + SpanAttributes.HTTP_HOST: "falconframework.org", + SpanAttributes.HTTP_TARGET: "/", + SpanAttributes.NET_PEER_PORT: "65133", + SpanAttributes.HTTP_FLAVOR: "1.1", + SpanAttributes.HTTP_STATUS_CODE: 404, + }, + ) + # In falcon<3, NET_PEER_IP is always set by default to 127.0.0.1 + # In falcon>3, NET_PEER_IP is not set to anything by default to + # https://github.com/falconry/falcon/blob/5233d0abed977d9dab78ebadf305f5abe2eef07c/falcon/testing/helpers.py#L1168-L1172 # noqa + if SpanAttributes.NET_PEER_IP in span.attributes: + self.assertEqual( + span.attributes[SpanAttributes.NET_PEER_IP], "127.0.0.1" + ) + + def test_500(self): + try: + self.client().simulate_get("/error") + except NameError: + pass + spans = self.memory_exporter.get_finished_spans() + self.assertEqual(len(spans), 1) + span = spans[0] + self.assertEqual(span.name, "ErrorResource.on_get") + self.assertFalse(span.status.is_ok) + self.assertEqual(span.status.status_code, StatusCode.ERROR) + self.assertEqual( + span.status.description, + "NameError: name 'non_existent_var' is not defined", + ) + self.assertSpanHasAttributes( + span, + { + SpanAttributes.HTTP_METHOD: "GET", + SpanAttributes.HTTP_SERVER_NAME: "falconframework.org", + SpanAttributes.HTTP_SCHEME: "http", + SpanAttributes.NET_HOST_PORT: 80, + SpanAttributes.HTTP_HOST: "falconframework.org", + SpanAttributes.HTTP_TARGET: "/", + SpanAttributes.NET_PEER_PORT: "65133", + SpanAttributes.HTTP_FLAVOR: "1.1", + SpanAttributes.HTTP_STATUS_CODE: 500, + }, + ) + # In falcon<3, NET_PEER_IP is always set by default to 127.0.0.1 + # In falcon>3, NET_PEER_IP is not set to anything by default to + # https://github.com/falconry/falcon/blob/5233d0abed977d9dab78ebadf305f5abe2eef07c/falcon/testing/helpers.py#L1168-L1172 # noqa + if SpanAttributes.NET_PEER_IP in span.attributes: + self.assertEqual( + span.attributes[SpanAttributes.NET_PEER_IP], "127.0.0.1" + ) + + def test_uninstrument(self): + self.client().simulate_get(path="/hello") + spans = self.memory_exporter.get_finished_spans() + self.assertEqual(len(spans), 1) + + self.memory_exporter.clear() + + FalconInstrumentor().uninstrument() + self.app = make_app() + self.client().simulate_get(path="/hello") + spans = self.memory_exporter.get_finished_spans() + self.assertEqual(len(spans), 0) + + def test_exclude_lists(self): + self.client().simulate_get(path="/ping") + span_list = self.memory_exporter.get_finished_spans() + self.assertEqual(len(span_list), 0) + + self.client().simulate_get(path="/hello") + span_list = self.memory_exporter.get_finished_spans() + self.assertEqual(len(span_list), 1) + + def test_traced_request_attributes(self): + self.client().simulate_get(path="/hello", query_string="q=abc") + span = self.memory_exporter.get_finished_spans()[0] + self.assertIn("query_string", span.attributes) + self.assertEqual(span.attributes["query_string"], "q=abc") + self.assertNotIn("not_available_attr", span.attributes) + + def test_trace_response(self): + orig = get_global_response_propagator() + set_global_response_propagator(TraceResponsePropagator()) + + response = self.client().simulate_get( + path="/hello", query_string="q=abc" + ) + self.assertTraceResponseHeaderMatchesSpan( + response.headers, self.memory_exporter.get_finished_spans()[0] + ) + + set_global_response_propagator(orig) + + def test_traced_not_recording(self): + mock_tracer = Mock() + mock_span = Mock() + mock_span.is_recording.return_value = False + mock_tracer.start_span.return_value = mock_span + with patch("opentelemetry.trace.get_tracer") as tracer: + tracer.return_value = mock_tracer + self.client().simulate_get(path="/hello", query_string="q=abc") + self.assertFalse(mock_span.is_recording()) + self.assertTrue(mock_span.is_recording.called) + self.assertFalse(mock_span.set_attribute.called) + self.assertFalse(mock_span.set_status.called) + + +class TestFalconInstrumentationWithTracerProvider(TestBase): + def setUp(self): + super().setUp() + resource = Resource.create({"resource-key": "resource-value"}) + result = self.create_tracer_provider(resource=resource) + tracer_provider, exporter = result + self.exporter = exporter + + FalconInstrumentor().instrument(tracer_provider=tracer_provider) + self.app = make_app() + + def client(self): + return testing.TestClient(self.app) + + def tearDown(self): + super().tearDown() + with self.disable_logging(): + FalconInstrumentor().uninstrument() + + def test_traced_request(self): + self.client().simulate_request(method="GET", path="/hello") + spans = self.exporter.get_finished_spans() + self.assertEqual(len(spans), 1) + span = spans[0] + self.assertEqual( + span.resource.attributes["resource-key"], "resource-value" + ) + self.exporter.clear() + + +class TestFalconInstrumentationHooks(TestFalconBase): + # pylint: disable=no-self-use + def request_hook(self, span, req): + span.set_attribute("request_hook_attr", "value from hook") + + def response_hook(self, span, req, resp): + span.update_name("set from hook") + + def test_hooks(self): + self.client().simulate_get(path="/hello", query_string="q=abc") + span = self.memory_exporter.get_finished_spans()[0] + + self.assertEqual(span.name, "set from hook") + self.assertIn("request_hook_attr", span.attributes) + self.assertEqual( + span.attributes["request_hook_attr"], "value from hook" + ) + + +class TestFalconInstrumentationWrappedWithOtherFramework(TestFalconBase): + def test_mark_span_internal_in_presence_of_span_from_other_framework(self): + tracer = trace.get_tracer(__name__) + with tracer.start_as_current_span( + "test", kind=trace.SpanKind.SERVER + ) as parent_span: + self.client().simulate_request(method="GET", path="/hello") + span = self.memory_exporter.get_finished_spans()[0] + assert span.status.is_ok + self.assertEqual(trace.SpanKind.INTERNAL, span.kind) + self.assertEqual( + span.parent.span_id, parent_span.get_span_context().span_id + ) + + +@patch.dict( + "os.environ", + { + OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST: "Custom-Test-Header-1,Custom-Test-Header-2,invalid-header", + OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE: "content-type,content-length,my-custom-header,invalid-header", + }, +) +class TestCustomRequestResponseHeaders(TestFalconBase): + def test_custom_request_header_added_in_server_span(self): + headers = { + "Custom-Test-Header-1": "Test Value 1", + "Custom-Test-Header-2": "TestValue2,TestValue3", + "Custom-Test-Header-3": "TestValue4", + } + self.client().simulate_request( + method="GET", path="/hello", headers=headers + ) + span = self.memory_exporter.get_finished_spans()[0] + assert span.status.is_ok + + expected = { + "http.request.header.custom_test_header_1": ("Test Value 1",), + "http.request.header.custom_test_header_2": ( + "TestValue2,TestValue3", + ), + } + not_expected = { + "http.request.header.custom_test_header_3": ("TestValue4",), + } + + self.assertEqual(span.kind, trace.SpanKind.SERVER) + self.assertSpanHasAttributes(span, expected) + for key, _ in not_expected.items(): + self.assertNotIn(key, span.attributes) + + def test_custom_request_header_not_added_in_internal_span(self): + tracer = trace.get_tracer(__name__) + with tracer.start_as_current_span("test", kind=trace.SpanKind.SERVER): + headers = { + "Custom-Test-Header-1": "Test Value 1", + "Custom-Test-Header-2": "TestValue2,TestValue3", + } + self.client().simulate_request( + method="GET", path="/hello", headers=headers + ) + span = self.memory_exporter.get_finished_spans()[0] + assert span.status.is_ok + not_expected = { + "http.request.header.custom_test_header_1": ("Test Value 1",), + "http.request.header.custom_test_header_2": ( + "TestValue2,TestValue3", + ), + } + self.assertEqual(span.kind, trace.SpanKind.INTERNAL) + for key, _ in not_expected.items(): + self.assertNotIn(key, span.attributes) + + @pytest.mark.skipif( + condition=package_version.parse(_falcon_verison) + < package_version.parse("2.0.0"), + reason="falcon<2 does not implement custom response headers", + ) + def test_custom_response_header_added_in_server_span(self): + self.client().simulate_request( + method="GET", path="/test_custom_response_headers" + ) + span = self.memory_exporter.get_finished_spans()[0] + assert span.status.is_ok + expected = { + "http.response.header.content_type": ( + "text/plain; charset=utf-8", + ), + "http.response.header.content_length": ("0",), + "http.response.header.my_custom_header": ( + "my-custom-value-1,my-custom-header-2", + ), + } + not_expected = { + "http.response.header.dont_capture_me": ("test-value",) + } + self.assertEqual(span.kind, trace.SpanKind.SERVER) + self.assertSpanHasAttributes(span, expected) + for key, _ in not_expected.items(): + self.assertNotIn(key, span.attributes) + + @pytest.mark.skipif( + condition=package_version.parse(_falcon_verison) + < package_version.parse("2.0.0"), + reason="falcon<2 does not implement custom response headers", + ) + def test_custom_response_header_not_added_in_internal_span(self): + tracer = trace.get_tracer(__name__) + with tracer.start_as_current_span("test", kind=trace.SpanKind.SERVER): + self.client().simulate_request( + method="GET", path="/test_custom_response_headers" + ) + span = self.memory_exporter.get_finished_spans()[0] + assert span.status.is_ok + not_expected = { + "http.response.header.content_type": ( + "text/plain; charset=utf-8", + ), + "http.response.header.content_length": ("0",), + "http.response.header.my_custom_header": ( + "my-custom-value-1,my-custom-header-2", + ), + } + self.assertEqual(span.kind, trace.SpanKind.INTERNAL) + for key, _ in not_expected.items(): + self.assertNotIn(key, span.attributes) diff --git a/instrumentation/opentelemetry-instrumentation-redis/README.rst b/instrumentation/opentelemetry-instrumentation-redis/README.rst index f69d783f5a..d7f4fa7aaa 100644 --- a/instrumentation/opentelemetry-instrumentation-redis/README.rst +++ b/instrumentation/opentelemetry-instrumentation-redis/README.rst @@ -15,45 +15,9 @@ Installation pip install opentelemetry-instrumentation-redis -Usage ------ - -* Start broker backend - -:: - - docker run -p 5672:5672 rabbitmq - -* Run instrumented actor - -.. code-block:: python - - from remoulade.brokers.rabbitmq import RabbitmqBroker - import remoulade - - broker = RabbitmqBroker() - remoulade.set_broker(broker) - - RemouladeInstrumentor().instrument() - - @remoulade.actor - def multiply(x, y): - return x * y - - broker.declare_actor(count_words) - - multiply.send(43, 51) - - -Setting up tracing --------------------- - The ``instrument()`` method of the RemouladeInstrumentor should always be called after the broker is set, because the instrumentation is attached to the broker. - - - References ---------- -* `OpenTelemetry Redis Instrumentation `_ +* `OpenTelemetry Redis Instrumentation `_ * `OpenTelemetry Project `_ * `OpenTelemetry Python Examples `_ diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/README.rst b/instrumentation/opentelemetry-instrumentation-remoulade/README.rst index 2de1da31bc..428e50bb3e 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/README.rst +++ b/instrumentation/opentelemetry-instrumentation-remoulade/README.rst @@ -1,19 +1,19 @@ -OpenTelemetry Redis Instrumentation +OpenTelemetry Remoulade Instrumentation =================================== |pypi| -.. |pypi| image:: https://badge.fury.io/py/opentelemetry-instrumentation-redis.svg - :target: https://pypi.org/project/opentelemetry-instrumentation-redis/ +.. |pypi| image:: https://badge.fury.io/py/opentelemetry-instrumentation-remoulade.svg + :target: https://pypi.org/project/opentelemetry-instrumentation-remoulade/ -This library allows tracing requests made by the Redis library. +This library allows tracing requests made by the Remoulade library. Installation ------------ :: - pip install opentelemetry-instrumentation-redis + pip install opentelemetry-instrumentation-remoulade Usage ----- @@ -54,6 +54,6 @@ Setting up tracing References ---------- -* `OpenTelemetry Redis Instrumentation `_ +* `OpenTelemetry Remoulade Instrumentation `_ * `OpenTelemetry Project `_ * `OpenTelemetry Python Examples `_ diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/setup.cfg b/instrumentation/opentelemetry-instrumentation-remoulade/setup.cfg index e054b339ad..fadd8ed9ee 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-remoulade/setup.cfg @@ -14,7 +14,7 @@ # [metadata] name = opentelemetry-instrumentation-remoulade -description = OpenTelemetry remoulade instrumentation +description = OpenTelemetry Remoulade instrumentation long_description = file: README.rst long_description_content_type = text/x-rst author = OpenTelemetry Authors From 8bcadcd91f803e4d57647a04ff3f7982bb01234c Mon Sep 17 00:00:00 2001 From: Adrien Bennatan Date: Tue, 3 May 2022 15:40:54 +0200 Subject: [PATCH 11/31] fix: typo and run tox --- instrumentation/README.md | 1 + .../setup.py | 14 ++++- .../instrumentation/remoulade/__init__.py | 56 ++++++++++++++----- .../tests/test_messages.py | 21 ++----- .../setup.cfg | 1 + .../instrumentation/bootstrap_gen.py | 2 +- tox.ini | 3 +- 7 files changed, 64 insertions(+), 34 deletions(-) diff --git a/instrumentation/README.md b/instrumentation/README.md index 20caa144bb..08c80880e5 100644 --- a/instrumentation/README.md +++ b/instrumentation/README.md @@ -28,6 +28,7 @@ | [opentelemetry-instrumentation-pymysql](./opentelemetry-instrumentation-pymysql) | PyMySQL < 2 | | [opentelemetry-instrumentation-pyramid](./opentelemetry-instrumentation-pyramid) | pyramid >= 1.7 | | [opentelemetry-instrumentation-redis](./opentelemetry-instrumentation-redis) | redis >= 2.6 | +| [opentelemetry-instrumentation-remoulade](./opentelemetry-instrumentation-remoulade) | remoulade >= 0.49 | | [opentelemetry-instrumentation-requests](./opentelemetry-instrumentation-requests) | requests ~= 2.0 | | [opentelemetry-instrumentation-sklearn](./opentelemetry-instrumentation-sklearn) | scikit-learn ~= 0.24.0 | | [opentelemetry-instrumentation-sqlalchemy](./opentelemetry-instrumentation-sqlalchemy) | sqlalchemy | diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/setup.py b/instrumentation/opentelemetry-instrumentation-remoulade/setup.py index f969faf71f..4df9c5a2e5 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/setup.py +++ b/instrumentation/opentelemetry-instrumentation-remoulade/setup.py @@ -39,13 +39,23 @@ PACKAGE_INFO = {} VERSION_FILENAME = os.path.join( - BASE_DIR, "src", "opentelemetry", "instrumentation", "remoulade", "version.py" + BASE_DIR, + "src", + "opentelemetry", + "instrumentation", + "remoulade", + "version.py", ) with open(VERSION_FILENAME, encoding="utf-8") as f: exec(f.read(), PACKAGE_INFO) PACKAGE_FILENAME = os.path.join( - BASE_DIR, "src", "opentelemetry", "instrumentation", "remoulade", "package.py" + BASE_DIR, + "src", + "opentelemetry", + "instrumentation", + "remoulade", + "package.py", ) with open(PACKAGE_FILENAME, encoding="utf-8") as f: exec(f.read(), PACKAGE_INFO) diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py index 8202614470..60733fc99f 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py @@ -4,14 +4,13 @@ from remoulade import Middleware, broker from opentelemetry import trace +from opentelemetry.instrumentation.instrumentor import BaseInstrumentor from opentelemetry.instrumentation.remoulade import utils -from opentelemetry.instrumentation.remoulade.version import __version__ from opentelemetry.instrumentation.remoulade.package import _instruments -from opentelemetry.instrumentation.instrumentor import BaseInstrumentor +from opentelemetry.instrumentation.remoulade.version import __version__ from opentelemetry.propagate import extract, inject from opentelemetry.semconv.trace import SpanAttributes - _MESSAGE_TAG_KEY = "remoulade.action" _MESSAGE_SEND = "send" _MESSAGE_RUN = "run" @@ -28,9 +27,15 @@ def before_process_message(self, _broker, message): trace_ctx = extract(message.options["trace_ctx"]) retry_count = message.options.get("retries") - operation_name = "remoulade/process" if retry_count is None else f"remoulade/process(retry-{retry_count})" + operation_name = ( + "remoulade/process" + if retry_count is None + else f"remoulade/process(retry-{retry_count})" + ) - span = self._tracer.start_span(operation_name, kind=trace.SpanKind.CONSUMER, context=trace_ctx) + span = self._tracer.start_span( + operation_name, kind=trace.SpanKind.CONSUMER, context=trace_ctx + ) if retry_count is not None: span.set_attribute("retry_count", retry_count) @@ -38,10 +43,16 @@ def before_process_message(self, _broker, message): activation = trace.use_span(span, end_on_exit=True) activation.__enter__() - utils.attach_span(self._span_registry, message.message_id, (span, activation)) + utils.attach_span( + self._span_registry, message.message_id, (span, activation) + ) - def after_process_message(self, _broker, message, *, result=None, exception=None): - span, activation = utils.retrieve_span(self._span_registry, message.message_id) + def after_process_message( + self, _broker, message, *, result=None, exception=None + ): + span, activation = utils.retrieve_span( + self._span_registry, message.message_id + ) if span is None: # no existing span found for message_id @@ -58,37 +69,54 @@ def after_process_message(self, _broker, message, *, result=None, exception=None def before_enqueue(self, _broker, message, delay): retry_count = message.options.get("retries") - operation_name = "remoulade/send" if retry_count is None else f"remoulade/send(retry-{retry_count})" + operation_name = ( + "remoulade/send" + if retry_count is None + else f"remoulade/send(retry-{retry_count})" + ) - span = self._tracer.start_span(operation_name, kind=trace.SpanKind.PRODUCER) + span = self._tracer.start_span( + operation_name, kind=trace.SpanKind.PRODUCER + ) if retry_count is not None: span.set_attribute("retry_count", retry_count) if span.is_recording(): span.set_attribute(_MESSAGE_TAG_KEY, _MESSAGE_SEND) - span.set_attribute(SpanAttributes.MESSAGING_MESSAGE_ID, message.message_id) + span.set_attribute( + SpanAttributes.MESSAGING_MESSAGE_ID, message.message_id + ) span.set_attribute(_MESSAGE_NAME_KEY, message.actor_name) pass activation = trace.use_span(span, end_on_exit=True) activation.__enter__() - utils.attach_span(self._span_registry, message.message_id, (span, activation), is_publish=True) + utils.attach_span( + self._span_registry, + message.message_id, + (span, activation), + is_publish=True, + ) if "trace_ctx" not in message.options: message.options["trace_ctx"] = {} inject(message.options["trace_ctx"]) def after_enqueue(self, _broker, message, delay, exception=None): - _, activation = utils.retrieve_span(self._span_registry, message.message_id, is_publish=True) + _, activation = utils.retrieve_span( + self._span_registry, message.message_id, is_publish=True + ) if activation is None: # no existing span found for message_id return activation.__exit__(None, None, None) - utils.detach_span(self._span_registry, message.message_id, is_publish=True) + utils.detach_span( + self._span_registry, message.message_id, is_publish=True + ) class RemouladeInstrumentor(BaseInstrumentor): diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_messages.py b/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_messages.py index 8642dd28bb..8066952b0b 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_messages.py +++ b/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_messages.py @@ -1,5 +1,6 @@ import remoulade from remoulade.brokers.local import LocalBroker + from opentelemetry.instrumentation.remoulade import RemouladeInstrumentor from opentelemetry.test.test_base import TestBase from opentelemetry.trace import SpanKind @@ -66,25 +67,13 @@ def test_retries(self): producer_spans = spans[1::2] self.assertEqual(consumer_spans[0].name, "remoulade/process(retry-3)") - self.assertSpanHasAttributes( - consumer_spans[0], - {"retry_count": 3} - ) + self.assertSpanHasAttributes(consumer_spans[0], {"retry_count": 3}) self.assertEqual(consumer_spans[1].name, "remoulade/process(retry-2)") - self.assertSpanHasAttributes( - consumer_spans[1], - {"retry_count": 2} - ) + self.assertSpanHasAttributes(consumer_spans[1], {"retry_count": 2}) self.assertEqual(consumer_spans[3].name, "remoulade/process") self.assertEqual(producer_spans[0].name, "remoulade/send(retry-3)") - self.assertSpanHasAttributes( - producer_spans[0], - {"retry_count": 3} - ) + self.assertSpanHasAttributes(producer_spans[0], {"retry_count": 3}) self.assertEqual(producer_spans[1].name, "remoulade/send(retry-2)") - self.assertSpanHasAttributes( - producer_spans[1], - {"retry_count": 2} - ) + self.assertSpanHasAttributes(producer_spans[1], {"retry_count": 2}) self.assertEqual(producer_spans[3].name, "remoulade/send") diff --git a/opentelemetry-contrib-instrumentations/setup.cfg b/opentelemetry-contrib-instrumentations/setup.cfg index 6e6d0924b0..cdeee071f6 100644 --- a/opentelemetry-contrib-instrumentations/setup.cfg +++ b/opentelemetry-contrib-instrumentations/setup.cfg @@ -55,6 +55,7 @@ install_requires = opentelemetry-instrumentation-pymysql==0.30b0 opentelemetry-instrumentation-pyramid==0.30b0 opentelemetry-instrumentation-redis==0.30b0 + opentelemetry-instrumentation-remoulade==0.30b0 opentelemetry-instrumentation-requests==0.30b0 opentelemetry-instrumentation-sklearn==0.30b0 opentelemetry-instrumentation-sqlalchemy==0.30b0 diff --git a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py index bbc95c647a..ddb42872bd 100644 --- a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py +++ b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py @@ -113,7 +113,7 @@ "instrumentation": "opentelemetry-instrumentation-redis==0.30b0", }, "remoulade": { - "library": "remoulade >= 0.48", + "library": "remoulade >= 0.49", "instrumentation": "opentelemetry-instrumentation-remoulade==0.30b0", }, "requests": { diff --git a/tox.ini b/tox.ini index 5dcc10cd83..ebecb2285f 100644 --- a/tox.ini +++ b/tox.ini @@ -157,7 +157,7 @@ envlist = pypy3-test-instrumentation-redis ; opentelemetry-instrumentation-remoulade - py3{6,7,8,9,10}-test-instrumentation-remoualde + py3{6,7,8,9,10}-test-instrumentation-remoulade pypy3-test-instrumentation-remoulade ; opentelemetry-instrumentation-celery @@ -282,6 +282,7 @@ changedir = test-instrumentation-pymysql: instrumentation/opentelemetry-instrumentation-pymysql/tests test-instrumentation-pyramid: instrumentation/opentelemetry-instrumentation-pyramid/tests test-instrumentation-redis: instrumentation/opentelemetry-instrumentation-redis/tests + test-instrumentation-remoulade: instrumentation/opentelemetry-instrumentation-remoulade/tests test-instrumentation-requests: instrumentation/opentelemetry-instrumentation-requests/tests test-instrumentation-sklearn: instrumentation/opentelemetry-instrumentation-sklearn/tests test-instrumentation-sqlalchemy{11,14}: instrumentation/opentelemetry-instrumentation-sqlalchemy/tests From ebf30665baf92d79cf5e664a1fafcfef18e73582 Mon Sep 17 00:00:00 2001 From: Adrien Bennatan Date: Tue, 3 May 2022 16:54:54 +0200 Subject: [PATCH 12/31] fix: add docs-requirements.txt --- docs-requirements.txt | 1 + tox.ini | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/docs-requirements.txt b/docs-requirements.txt index 4efc0ca46e..60f10dabdc 100644 --- a/docs-requirements.txt +++ b/docs-requirements.txt @@ -33,6 +33,7 @@ pymongo~=3.1 PyMySQL~=0.9.3 pyramid>=1.7 redis>=2.6 +remoulade>=0.49 sqlalchemy>=1.0 tornado>=5.1.1 ddtrace>=0.34.0 diff --git a/tox.ini b/tox.ini index ebecb2285f..8d38c2eb8c 100644 --- a/tox.ini +++ b/tox.ini @@ -363,6 +363,8 @@ commands_pre = redis: pip install {toxinidir}/instrumentation/opentelemetry-instrumentation-redis[test] + remoulade: pip install {toxinidir}/instrumentation/opentelemetry-instrumentation-remoulade[test] + requests: pip install {toxinidir}/instrumentation/opentelemetry-instrumentation-requests[test] starlette: pip install {toxinidir}/instrumentation/opentelemetry-instrumentation-starlette[test] @@ -459,6 +461,7 @@ commands_pre = python -m pip install -e {toxinidir}/instrumentation/opentelemetry-instrumentation-pika[test] python -m pip install -e {toxinidir}/instrumentation/opentelemetry-instrumentation-sklearn[test] python -m pip install -e {toxinidir}/instrumentation/opentelemetry-instrumentation-redis[test] + python -m pip install -e {toxinidir}/instrumentation/opentelemetry-instrumentation-remoulade[test] python -m pip install -e {toxinidir}/instrumentation/opentelemetry-instrumentation-fastapi[test] python -m pip install -e {toxinidir}/instrumentation/opentelemetry-instrumentation-jinja2[test] python -m pip install -e {toxinidir}/instrumentation/opentelemetry-instrumentation-kafka-python[test] @@ -509,6 +512,7 @@ deps = requests==2.25.0 pyodbc~=4.0.30 flaky==3.7.0 + remoulade >= 0.49 changedir = tests/opentelemetry-docker-tests/tests @@ -531,6 +535,7 @@ commands_pre = -e {toxinidir}/instrumentation/opentelemetry-instrumentation-sqlalchemy \ -e {toxinidir}/instrumentation/opentelemetry-instrumentation-aiopg \ -e {toxinidir}/instrumentation/opentelemetry-instrumentation-redis \ + -e {toxinidir}/instrumentation/opentelemetry-instrumentation-remoulade \ "{env:CORE_REPO}#egg=opentelemetry-exporter-opencensus&subdirectory=exporter/opentelemetry-exporter-opencensus" docker-compose up -d python check_availability.py From d1f7ed4265aeeed938353092571b7c8c86c3ff10 Mon Sep 17 00:00:00 2001 From: Adrien Bennatan Date: Tue, 3 May 2022 17:31:57 +0200 Subject: [PATCH 13/31] chore: set version to 0.30b1 --- .../opentelemetry-instrumentation-remoulade/setup.cfg | 6 +++--- .../src/opentelemetry/instrumentation/remoulade/version.py | 2 +- .../src/opentelemetry/instrumentation/bootstrap_gen.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/setup.cfg b/instrumentation/opentelemetry-instrumentation-remoulade/setup.cfg index fadd8ed9ee..6c69f6e1dd 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-remoulade/setup.cfg @@ -41,12 +41,12 @@ package_dir= packages=find_namespace: install_requires = opentelemetry-api ~= 1.3 - opentelemetry-semantic-conventions == 0.30b0 - opentelemetry-instrumentation == 0.30b0 + opentelemetry-semantic-conventions == 0.30b1 + opentelemetry-instrumentation == 0.30b1 [options.extras_require] test = - opentelemetry-test-utils == 0.30b0 + opentelemetry-test-utils == 0.30b1 opentelemetry-sdk ~= 1.3 [options.packages.find] diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/version.py b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/version.py index 75e49aa583..88015aae34 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/version.py +++ b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.30b0" +__version__ = "0.30b1" diff --git a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py index 5b130fb96a..c99b342927 100644 --- a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py +++ b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py @@ -114,7 +114,7 @@ }, "remoulade": { "library": "remoulade >= 0.49", - "instrumentation": "opentelemetry-instrumentation-remoulade==0.30b0", + "instrumentation": "opentelemetry-instrumentation-remoulade==0.30b1", }, "requests": { "library": "requests ~= 2.0", From 94ab40a180d7171fb870919b426f707ea2a8bff4 Mon Sep 17 00:00:00 2001 From: Adrien Bennatan Date: Tue, 3 May 2022 17:35:49 +0200 Subject: [PATCH 14/31] docs: changelog update --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c892e6af8..956e5cd9e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased](https://github.com/open-telemetry/opentelemetry-python/compare/v1.11.1-0.30b1...HEAD) ### Fixed -- `opentelemetry-instrumentation-aiohttp-client` make span attributes available to sampler +- `opentelemetry-instrumentation-aiohttp-clientopentelemetry-instrumentation-aiohttp-client` make span attributes available to sampler ([1072](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1072)) - `opentelemetry-instrumentation-aws-lambda` Fixed an issue - in some rare cases (API GW proxy integration test) headers are set to None, breaking context propagators. @@ -19,6 +19,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - `opentelemetry-instrument` and `opentelemetry-bootstrap` now include a `--version` flag ([#1065](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1065)) +- `opentelemetry-instrumentation-remoulade` Initial release + ([#1082](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1082)) + ## [1.11.1-0.30b1](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.11.1-0.30b1) - 2022-04-21 From 236002b0a3761b94eabf31476306c888de04a6c1 Mon Sep 17 00:00:00 2001 From: Adrien Bennatan Date: Fri, 6 May 2022 15:26:24 +0200 Subject: [PATCH 15/31] feat: add auto-instrumentation --- .../README.rst | 9 +--- .../instrumentation/remoulade/__init__.py | 6 +-- .../instrumentation/remoulade/package.py | 2 +- .../tests/test_messages.py | 3 +- .../tests/test_uninstrument.py | 43 +++++++++++++++++++ .../setup.cfg | 2 +- 6 files changed, 51 insertions(+), 14 deletions(-) create mode 100644 instrumentation/opentelemetry-instrumentation-remoulade/tests/test_uninstrument.py diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/README.rst b/instrumentation/opentelemetry-instrumentation-remoulade/README.rst index 428e50bb3e..0146a8bac4 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/README.rst +++ b/instrumentation/opentelemetry-instrumentation-remoulade/README.rst @@ -31,11 +31,11 @@ Usage from remoulade.brokers.rabbitmq import RabbitmqBroker import remoulade + RemouladeInstrumentor().instrument() + broker = RabbitmqBroker() remoulade.set_broker(broker) - RemouladeInstrumentor().instrument() - @remoulade.actor def multiply(x, y): return x * y @@ -45,11 +45,6 @@ Usage multiply.send(43, 51) -Setting up tracing --------------------- - The ``instrument()`` method of the RemouladeInstrumentor should always be called after the broker is set, because the instrumentation is attached to the broker. - - References ---------- diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py index 60733fc99f..fba485d868 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py @@ -127,9 +127,9 @@ def _instrument(self, **kwargs): tracer_provider = kwargs.get("tracer_provider") self._tracer = trace.get_tracer(__name__, __version__, tracer_provider) - instrumentation_middleware = InstrumentationMiddleware(self._tracer) - broker.get_broker().add_middleware(instrumentation_middleware) + + broker.add_extra_default_middleware(instrumentation_middleware) def _uninstrument(self, **kwargs): - broker.get_broker().remove_middleware(InstrumentationMiddleware) + broker.remove_extra_default_middleware(InstrumentationMiddleware) diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/package.py b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/package.py index 4952c29f84..aff56a4b6c 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/package.py +++ b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/package.py @@ -13,4 +13,4 @@ # limitations under the License. -_instruments = ("remoulade >= 0.49",) +_instruments = ("remoulade >= 0.50",) diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_messages.py b/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_messages.py index 8066952b0b..2028194517 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_messages.py +++ b/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_messages.py @@ -14,11 +14,10 @@ def actor_div(x, y): class TestRemouladeInstrumentation(TestBase): def setUp(self): super().setUp() + RemouladeInstrumentor().instrument() broker = LocalBroker() - remoulade.set_broker(broker) - RemouladeInstrumentor().instrument() broker.declare_actor(actor_div) diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_uninstrument.py b/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_uninstrument.py new file mode 100644 index 0000000000..b5f687fe58 --- /dev/null +++ b/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_uninstrument.py @@ -0,0 +1,43 @@ +import remoulade +from remoulade.brokers.local import LocalBroker + +from opentelemetry.instrumentation.remoulade import RemouladeInstrumentor +from opentelemetry.test.test_base import TestBase + + +@remoulade.actor(max_retries=3) +def actor_div(x, y): + return x / y + + +class TestRemouladeUninstrumentation(TestBase): + def setUp(self): + super().setUp() + RemouladeInstrumentor().instrument() + + broker = LocalBroker() + remoulade.set_broker(broker) + broker.declare_actor(actor_div) + + RemouladeInstrumentor().uninstrument() + + def test_uninstrument_existing_broker(self): + actor_div.send(1, 1) + spans = self.sorted_spans(self.memory_exporter.get_finished_spans()) + self.assertEqual(len(spans), 0) + + def test_uninstrument_new_brokers(self): + new_broker = LocalBroker() + remoulade.set_broker(new_broker) + new_broker.declare_actor(actor_div) + + actor_div.send(1, 1) + spans = self.sorted_spans(self.memory_exporter.get_finished_spans()) + self.assertEqual(len(spans), 0) + + def test_reinstrument_existing_broker(self): + RemouladeInstrumentor().instrument() + + actor_div.send(1, 1) + spans = self.sorted_spans(self.memory_exporter.get_finished_spans()) + self.assertEqual(len(spans), 2) diff --git a/opentelemetry-contrib-instrumentations/setup.cfg b/opentelemetry-contrib-instrumentations/setup.cfg index f44aed9437..ec0a13380a 100644 --- a/opentelemetry-contrib-instrumentations/setup.cfg +++ b/opentelemetry-contrib-instrumentations/setup.cfg @@ -54,8 +54,8 @@ install_requires = opentelemetry-instrumentation-pymongo==0.30b1 opentelemetry-instrumentation-pymysql==0.30b1 opentelemetry-instrumentation-pyramid==0.30b1 - opentelemetry-instrumentation-remoulade==0.30b1 opentelemetry-instrumentation-redis==0.30b1 + opentelemetry-instrumentation-remoulade==0.30b1 opentelemetry-instrumentation-requests==0.30b1 opentelemetry-instrumentation-sklearn==0.30b1 opentelemetry-instrumentation-sqlalchemy==0.30b1 From 9d5abd3cfc2eea40a0e81c5e8501511215058540 Mon Sep 17 00:00:00 2001 From: Adrien Bennatan Date: Fri, 6 May 2022 16:10:12 +0200 Subject: [PATCH 16/31] feat: add RemouladeGetter --- .../instrumentation/remoulade/__init__.py | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py index fba485d868..1dd26366ea 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py @@ -1,5 +1,4 @@ -import logging -from typing import Collection +from typing import Collection, Optional, List, Iterable from remoulade import Middleware, broker @@ -8,6 +7,7 @@ from opentelemetry.instrumentation.remoulade import utils from opentelemetry.instrumentation.remoulade.package import _instruments from opentelemetry.instrumentation.remoulade.version import __version__ +from opentelemetry.propagators.textmap import CarrierT, Getter from opentelemetry.propagate import extract, inject from opentelemetry.semconv.trace import SpanAttributes @@ -18,14 +18,33 @@ _MESSAGE_NAME_KEY = "remoulade.actor_name" +class RemouladeGetter(Getter): + def get(self, carrier: CarrierT, key: str) -> Optional[str]: + value = carrier.get(key, None) + if value is None: + return None + if isinstance(value, str) or not isinstance(value, Iterable): + value = (value,) + return value + + def keys(self, carrier: CarrierT) -> List[str]: + return [] + + +remoulade_getter = RemouladeGetter() + + class InstrumentationMiddleware(Middleware): def __init__(self, _tracer): self._tracer = _tracer self._span_registry = {} def before_process_message(self, _broker, message): - trace_ctx = extract(message.options["trace_ctx"]) - retry_count = message.options.get("retries") + if "trace_ctx" not in message.options: + return + + trace_ctx = extract(message.options["trace_ctx"], getter=remoulade_getter) + retry_count = message.options.get("retries", None) operation_name = ( "remoulade/process" @@ -67,7 +86,7 @@ def after_process_message( utils.detach_span(self._span_registry, message.message_id) def before_enqueue(self, _broker, message, delay): - retry_count = message.options.get("retries") + retry_count = message.options.get("retries", None) operation_name = ( "remoulade/send" From acd7884c1c730cd60166d49fd93ec38fe7f984e3 Mon Sep 17 00:00:00 2001 From: Adrien Bennatan Date: Fri, 6 May 2022 16:21:20 +0200 Subject: [PATCH 17/31] test: add test_getter.py --- .../tests/test_getter.py | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 instrumentation/opentelemetry-instrumentation-remoulade/tests/test_getter.py diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_getter.py b/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_getter.py new file mode 100644 index 0000000000..67618caae4 --- /dev/null +++ b/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_getter.py @@ -0,0 +1,45 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from unittest import TestCase + +from opentelemetry.instrumentation.remoulade import RemouladeGetter + + +class TestRemouladeGetter(TestCase): + def setUp(self): + self.getter = RemouladeGetter() + + def test_get_none(self): + carrier = {} + val = self.getter.get(carrier, "test") + self.assertIsNone(val) + + def test_get_str(self): + key = "test" + value = "value" + carrier = {key: value} + val = self.getter.get(carrier, key) + self.assertEqual(val, (value,)) + + def test_get_iter(self): + key = "test" + value = ["value"] + carrier = {key: value} + val = self.getter.get(carrier, key) + self.assertEqual(val, value) + + def test_keys(self): + keys = self.getter.keys({}) + self.assertEqual(keys, []) From 75d2efe2885a1b311e6ac3b985275a6cc56f0a31 Mon Sep 17 00:00:00 2001 From: Adrien Bennatan Date: Fri, 6 May 2022 16:27:17 +0200 Subject: [PATCH 18/31] chore: add copyright --- .../README.rst | 31 ------------- .../instrumentation/remoulade/__init__.py | 45 +++++++++++++++++++ .../instrumentation/remoulade/package.py | 1 - .../instrumentation/remoulade/utils.py | 14 ++++++ .../tests/test_messages.py | 14 ++++++ .../tests/test_uninstrument.py | 14 ++++++ 6 files changed, 87 insertions(+), 32 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/README.rst b/instrumentation/opentelemetry-instrumentation-remoulade/README.rst index 0146a8bac4..0b812262ea 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/README.rst +++ b/instrumentation/opentelemetry-instrumentation-remoulade/README.rst @@ -15,37 +15,6 @@ Installation pip install opentelemetry-instrumentation-remoulade -Usage ------ - -* Start broker backend - -:: - - docker run -p 5672:5672 rabbitmq - -* Run instrumented actor - -.. code-block:: python - - from remoulade.brokers.rabbitmq import RabbitmqBroker - import remoulade - - RemouladeInstrumentor().instrument() - - broker = RabbitmqBroker() - remoulade.set_broker(broker) - - @remoulade.actor - def multiply(x, y): - return x * y - - broker.declare_actor(count_words) - - multiply.send(43, 51) - - - References ---------- diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py index 1dd26366ea..926872d02e 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py @@ -1,3 +1,48 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +Usage +----- + +* Start broker backend + +:: + + docker run -p 5672:5672 rabbitmq + +* Run instrumented actor + +.. code-block:: python + + from remoulade.brokers.rabbitmq import RabbitmqBroker + import remoulade + + RemouladeInstrumentor().instrument() + + broker = RabbitmqBroker() + remoulade.set_broker(broker) + + @remoulade.actor + def multiply(x, y): + return x * y + + broker.declare_actor(count_words) + + multiply.send(43, 51) + +""" from typing import Collection, Optional, List, Iterable from remoulade import Middleware, broker diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/package.py b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/package.py index aff56a4b6c..db37739bb7 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/package.py +++ b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/package.py @@ -12,5 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. - _instruments = ("remoulade >= 0.50",) diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/utils.py b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/utils.py index a0cdc2b06b..594eed7865 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/utils.py +++ b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/utils.py @@ -1,3 +1,17 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + def attach_span(span_registry, message_id, span, is_publish=False): span_registry[(message_id, is_publish)] = span diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_messages.py b/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_messages.py index 2028194517..61953f14ac 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_messages.py +++ b/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_messages.py @@ -1,3 +1,17 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import remoulade from remoulade.brokers.local import LocalBroker diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_uninstrument.py b/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_uninstrument.py index b5f687fe58..6a72a35506 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_uninstrument.py +++ b/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_uninstrument.py @@ -1,3 +1,17 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import remoulade from remoulade.brokers.local import LocalBroker From 4e2f1c6718c1399a67f3c066f37376191957a8e5 Mon Sep 17 00:00:00 2001 From: Adrien Bennatan Date: Fri, 6 May 2022 16:31:11 +0200 Subject: [PATCH 19/31] fix: remoulade version --- CHANGELOG.md | 2 +- docs-requirements.txt | 2 +- instrumentation/README.md | 78 +++++++++---------- .../instrumentation/bootstrap_gen.py | 2 +- tox.ini | 2 +- 5 files changed, 43 insertions(+), 43 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 59db32131d..a69b6f7869 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased](https://github.com/open-telemetry/opentelemetry-python/compare/v1.11.1-0.30b1...HEAD) ### Fixed -- `opentelemetry-instrumentation-aiohttp-clientopentelemetry-instrumentation-aiohttp-client` make span attributes available to sampler +- `opentelemetry-instrumentation-aiohttp-client` make span attributes available to sampler ([1072](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1072)) - `opentelemetry-instrumentation-aws-lambda` Fixed an issue - in some rare cases (API GW proxy integration test) headers are set to None, breaking context propagators. diff --git a/docs-requirements.txt b/docs-requirements.txt index 60f10dabdc..3e09c15112 100644 --- a/docs-requirements.txt +++ b/docs-requirements.txt @@ -33,7 +33,7 @@ pymongo~=3.1 PyMySQL~=0.9.3 pyramid>=1.7 redis>=2.6 -remoulade>=0.49 +remoulade>=0.50 sqlalchemy>=1.0 tornado>=5.1.1 ddtrace>=0.34.0 diff --git a/instrumentation/README.md b/instrumentation/README.md index 08c80880e5..64187e17c3 100644 --- a/instrumentation/README.md +++ b/instrumentation/README.md @@ -1,41 +1,41 @@ -| Instrumentation | Supported Packages | -| --------------- | ------------------ | -| [opentelemetry-instrumentation-aiohttp-client](./opentelemetry-instrumentation-aiohttp-client) | aiohttp ~= 3.0 | -| [opentelemetry-instrumentation-aiopg](./opentelemetry-instrumentation-aiopg) | aiopg >= 0.13.0, < 1.3.0 | -| [opentelemetry-instrumentation-asgi](./opentelemetry-instrumentation-asgi) | asgiref ~= 3.0 | -| [opentelemetry-instrumentation-asyncpg](./opentelemetry-instrumentation-asyncpg) | asyncpg >= 0.12.0 | -| [opentelemetry-instrumentation-aws-lambda](./opentelemetry-instrumentation-aws-lambda) | aws_lambda | -| [opentelemetry-instrumentation-boto](./opentelemetry-instrumentation-boto) | boto~=2.0 | -| [opentelemetry-instrumentation-botocore](./opentelemetry-instrumentation-botocore) | botocore ~= 1.0 | -| [opentelemetry-instrumentation-celery](./opentelemetry-instrumentation-celery) | celery >= 4.0, < 6.0 | -| [opentelemetry-instrumentation-dbapi](./opentelemetry-instrumentation-dbapi) | dbapi | -| [opentelemetry-instrumentation-django](./opentelemetry-instrumentation-django) | django >= 1.10 | -| [opentelemetry-instrumentation-elasticsearch](./opentelemetry-instrumentation-elasticsearch) | elasticsearch >= 2.0 | -| [opentelemetry-instrumentation-falcon](./opentelemetry-instrumentation-falcon) | falcon >= 1.4.1, < 4.0.0 | -| [opentelemetry-instrumentation-fastapi](./opentelemetry-instrumentation-fastapi) | fastapi ~= 0.58 | -| [opentelemetry-instrumentation-flask](./opentelemetry-instrumentation-flask) | flask >= 1.0, < 3.0 | -| [opentelemetry-instrumentation-grpc](./opentelemetry-instrumentation-grpc) | grpcio ~= 1.27 | -| [opentelemetry-instrumentation-httpx](./opentelemetry-instrumentation-httpx) | httpx >= 0.18.0 | -| [opentelemetry-instrumentation-jinja2](./opentelemetry-instrumentation-jinja2) | jinja2 >= 2.7, < 4.0 | -| [opentelemetry-instrumentation-kafka-python](./opentelemetry-instrumentation-kafka-python) | kafka-python >= 2.0 | -| [opentelemetry-instrumentation-logging](./opentelemetry-instrumentation-logging) | logging | +| Instrumentation | Supported Packages | +| --------------- |-------------------------------| +| [opentelemetry-instrumentation-aiohttp-client](./opentelemetry-instrumentation-aiohttp-client) | aiohttp ~= 3.0 | +| [opentelemetry-instrumentation-aiopg](./opentelemetry-instrumentation-aiopg) | aiopg >= 0.13.0, < 1.3.0 | +| [opentelemetry-instrumentation-asgi](./opentelemetry-instrumentation-asgi) | asgiref ~= 3.0 | +| [opentelemetry-instrumentation-asyncpg](./opentelemetry-instrumentation-asyncpg) | asyncpg >= 0.12.0 | +| [opentelemetry-instrumentation-aws-lambda](./opentelemetry-instrumentation-aws-lambda) | aws_lambda | +| [opentelemetry-instrumentation-boto](./opentelemetry-instrumentation-boto) | boto~=2.0 | +| [opentelemetry-instrumentation-botocore](./opentelemetry-instrumentation-botocore) | botocore ~= 1.0 | +| [opentelemetry-instrumentation-celery](./opentelemetry-instrumentation-celery) | celery >= 4.0, < 6.0 | +| [opentelemetry-instrumentation-dbapi](./opentelemetry-instrumentation-dbapi) | dbapi | +| [opentelemetry-instrumentation-django](./opentelemetry-instrumentation-django) | django >= 1.10 | +| [opentelemetry-instrumentation-elasticsearch](./opentelemetry-instrumentation-elasticsearch) | elasticsearch >= 2.0 | +| [opentelemetry-instrumentation-falcon](./opentelemetry-instrumentation-falcon) | falcon >= 1.4.1, < 4.0.0 | +| [opentelemetry-instrumentation-fastapi](./opentelemetry-instrumentation-fastapi) | fastapi ~= 0.58 | +| [opentelemetry-instrumentation-flask](./opentelemetry-instrumentation-flask) | flask >= 1.0, < 3.0 | +| [opentelemetry-instrumentation-grpc](./opentelemetry-instrumentation-grpc) | grpcio ~= 1.27 | +| [opentelemetry-instrumentation-httpx](./opentelemetry-instrumentation-httpx) | httpx >= 0.18.0 | +| [opentelemetry-instrumentation-jinja2](./opentelemetry-instrumentation-jinja2) | jinja2 >= 2.7, < 4.0 | +| [opentelemetry-instrumentation-kafka-python](./opentelemetry-instrumentation-kafka-python) | kafka-python >= 2.0 | +| [opentelemetry-instrumentation-logging](./opentelemetry-instrumentation-logging) | logging | | [opentelemetry-instrumentation-mysql](./opentelemetry-instrumentation-mysql) | mysql-connector-python ~= 8.0 | -| [opentelemetry-instrumentation-pika](./opentelemetry-instrumentation-pika) | pika >= 0.12.0 | -| [opentelemetry-instrumentation-psycopg2](./opentelemetry-instrumentation-psycopg2) | psycopg2 >= 2.7.3.1 | -| [opentelemetry-instrumentation-pymemcache](./opentelemetry-instrumentation-pymemcache) | pymemcache >= 1.3.5, < 4 | -| [opentelemetry-instrumentation-pymongo](./opentelemetry-instrumentation-pymongo) | pymongo >= 3.1, < 5.0 | -| [opentelemetry-instrumentation-pymysql](./opentelemetry-instrumentation-pymysql) | PyMySQL < 2 | -| [opentelemetry-instrumentation-pyramid](./opentelemetry-instrumentation-pyramid) | pyramid >= 1.7 | -| [opentelemetry-instrumentation-redis](./opentelemetry-instrumentation-redis) | redis >= 2.6 | -| [opentelemetry-instrumentation-remoulade](./opentelemetry-instrumentation-remoulade) | remoulade >= 0.49 | -| [opentelemetry-instrumentation-requests](./opentelemetry-instrumentation-requests) | requests ~= 2.0 | -| [opentelemetry-instrumentation-sklearn](./opentelemetry-instrumentation-sklearn) | scikit-learn ~= 0.24.0 | -| [opentelemetry-instrumentation-sqlalchemy](./opentelemetry-instrumentation-sqlalchemy) | sqlalchemy | -| [opentelemetry-instrumentation-sqlite3](./opentelemetry-instrumentation-sqlite3) | sqlite3 | -| [opentelemetry-instrumentation-starlette](./opentelemetry-instrumentation-starlette) | starlette ~= 0.13.0 | -| [opentelemetry-instrumentation-system-metrics](./opentelemetry-instrumentation-system-metrics) | psutil >= 5 | -| [opentelemetry-instrumentation-tornado](./opentelemetry-instrumentation-tornado) | tornado >= 5.1.1 | -| [opentelemetry-instrumentation-urllib](./opentelemetry-instrumentation-urllib) | urllib | -| [opentelemetry-instrumentation-urllib3](./opentelemetry-instrumentation-urllib3) | urllib3 >= 1.0.0, < 2.0.0 | -| [opentelemetry-instrumentation-wsgi](./opentelemetry-instrumentation-wsgi) | wsgi | \ No newline at end of file +| [opentelemetry-instrumentation-pika](./opentelemetry-instrumentation-pika) | pika >= 0.12.0 | +| [opentelemetry-instrumentation-psycopg2](./opentelemetry-instrumentation-psycopg2) | psycopg2 >= 2.7.3.1 | +| [opentelemetry-instrumentation-pymemcache](./opentelemetry-instrumentation-pymemcache) | pymemcache >= 1.3.5, < 4 | +| [opentelemetry-instrumentation-pymongo](./opentelemetry-instrumentation-pymongo) | pymongo >= 3.1, < 5.0 | +| [opentelemetry-instrumentation-pymysql](./opentelemetry-instrumentation-pymysql) | PyMySQL < 2 | +| [opentelemetry-instrumentation-pyramid](./opentelemetry-instrumentation-pyramid) | pyramid >= 1.7 | +| [opentelemetry-instrumentation-redis](./opentelemetry-instrumentation-redis) | redis >= 2.6 | +| [opentelemetry-instrumentation-remoulade](./opentelemetry-instrumentation-remoulade) | remoulade >= 0.50 | +| [opentelemetry-instrumentation-requests](./opentelemetry-instrumentation-requests) | requests ~= 2.0 | +| [opentelemetry-instrumentation-sklearn](./opentelemetry-instrumentation-sklearn) | scikit-learn ~= 0.24.0 | +| [opentelemetry-instrumentation-sqlalchemy](./opentelemetry-instrumentation-sqlalchemy) | sqlalchemy | +| [opentelemetry-instrumentation-sqlite3](./opentelemetry-instrumentation-sqlite3) | sqlite3 | +| [opentelemetry-instrumentation-starlette](./opentelemetry-instrumentation-starlette) | starlette ~= 0.13.0 | +| [opentelemetry-instrumentation-system-metrics](./opentelemetry-instrumentation-system-metrics) | psutil >= 5 | +| [opentelemetry-instrumentation-tornado](./opentelemetry-instrumentation-tornado) | tornado >= 5.1.1 | +| [opentelemetry-instrumentation-urllib](./opentelemetry-instrumentation-urllib) | urllib | +| [opentelemetry-instrumentation-urllib3](./opentelemetry-instrumentation-urllib3) | urllib3 >= 1.0.0, < 2.0.0 | +| [opentelemetry-instrumentation-wsgi](./opentelemetry-instrumentation-wsgi) | wsgi | \ No newline at end of file diff --git a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py index c99b342927..26041b578a 100644 --- a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py +++ b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py @@ -113,7 +113,7 @@ "instrumentation": "opentelemetry-instrumentation-redis==0.30b1", }, "remoulade": { - "library": "remoulade >= 0.49", + "library": "remoulade >= 0.50", "instrumentation": "opentelemetry-instrumentation-remoulade==0.30b1", }, "requests": { diff --git a/tox.ini b/tox.ini index 615c4e843e..3d46bdced7 100644 --- a/tox.ini +++ b/tox.ini @@ -505,7 +505,7 @@ deps = requests==2.25.0 pyodbc~=4.0.30 flaky==3.7.0 - remoulade >= 0.49 + remoulade >= 0.50 changedir = tests/opentelemetry-docker-tests/tests From 8507a74014763e7225026d646a365fbfe5dd039f Mon Sep 17 00:00:00 2001 From: Adrien Bennatan Date: Fri, 6 May 2022 16:36:38 +0200 Subject: [PATCH 20/31] fix: readme spaces --- instrumentation/README.md | 78 +++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/instrumentation/README.md b/instrumentation/README.md index 64187e17c3..8869203bd1 100644 --- a/instrumentation/README.md +++ b/instrumentation/README.md @@ -1,41 +1,41 @@ -| Instrumentation | Supported Packages | -| --------------- |-------------------------------| -| [opentelemetry-instrumentation-aiohttp-client](./opentelemetry-instrumentation-aiohttp-client) | aiohttp ~= 3.0 | -| [opentelemetry-instrumentation-aiopg](./opentelemetry-instrumentation-aiopg) | aiopg >= 0.13.0, < 1.3.0 | -| [opentelemetry-instrumentation-asgi](./opentelemetry-instrumentation-asgi) | asgiref ~= 3.0 | -| [opentelemetry-instrumentation-asyncpg](./opentelemetry-instrumentation-asyncpg) | asyncpg >= 0.12.0 | -| [opentelemetry-instrumentation-aws-lambda](./opentelemetry-instrumentation-aws-lambda) | aws_lambda | -| [opentelemetry-instrumentation-boto](./opentelemetry-instrumentation-boto) | boto~=2.0 | -| [opentelemetry-instrumentation-botocore](./opentelemetry-instrumentation-botocore) | botocore ~= 1.0 | -| [opentelemetry-instrumentation-celery](./opentelemetry-instrumentation-celery) | celery >= 4.0, < 6.0 | -| [opentelemetry-instrumentation-dbapi](./opentelemetry-instrumentation-dbapi) | dbapi | -| [opentelemetry-instrumentation-django](./opentelemetry-instrumentation-django) | django >= 1.10 | -| [opentelemetry-instrumentation-elasticsearch](./opentelemetry-instrumentation-elasticsearch) | elasticsearch >= 2.0 | -| [opentelemetry-instrumentation-falcon](./opentelemetry-instrumentation-falcon) | falcon >= 1.4.1, < 4.0.0 | -| [opentelemetry-instrumentation-fastapi](./opentelemetry-instrumentation-fastapi) | fastapi ~= 0.58 | -| [opentelemetry-instrumentation-flask](./opentelemetry-instrumentation-flask) | flask >= 1.0, < 3.0 | -| [opentelemetry-instrumentation-grpc](./opentelemetry-instrumentation-grpc) | grpcio ~= 1.27 | -| [opentelemetry-instrumentation-httpx](./opentelemetry-instrumentation-httpx) | httpx >= 0.18.0 | -| [opentelemetry-instrumentation-jinja2](./opentelemetry-instrumentation-jinja2) | jinja2 >= 2.7, < 4.0 | -| [opentelemetry-instrumentation-kafka-python](./opentelemetry-instrumentation-kafka-python) | kafka-python >= 2.0 | -| [opentelemetry-instrumentation-logging](./opentelemetry-instrumentation-logging) | logging | +| Instrumentation | Supported Packages | +| --------------- | ------------------ | +| [opentelemetry-instrumentation-aiohttp-client](./opentelemetry-instrumentation-aiohttp-client) | aiohttp ~= 3.0 | +| [opentelemetry-instrumentation-aiopg](./opentelemetry-instrumentation-aiopg) | aiopg >= 0.13.0, < 1.3.0 | +| [opentelemetry-instrumentation-asgi](./opentelemetry-instrumentation-asgi) | asgiref ~= 3.0 | +| [opentelemetry-instrumentation-asyncpg](./opentelemetry-instrumentation-asyncpg) | asyncpg >= 0.12.0 | +| [opentelemetry-instrumentation-aws-lambda](./opentelemetry-instrumentation-aws-lambda) | aws_lambda | +| [opentelemetry-instrumentation-boto](./opentelemetry-instrumentation-boto) | boto~=2.0 | +| [opentelemetry-instrumentation-botocore](./opentelemetry-instrumentation-botocore) | botocore ~= 1.0 | +| [opentelemetry-instrumentation-celery](./opentelemetry-instrumentation-celery) | celery >= 4.0, < 6.0 | +| [opentelemetry-instrumentation-dbapi](./opentelemetry-instrumentation-dbapi) | dbapi | +| [opentelemetry-instrumentation-django](./opentelemetry-instrumentation-django) | django >= 1.10 | +| [opentelemetry-instrumentation-elasticsearch](./opentelemetry-instrumentation-elasticsearch) | elasticsearch >= 2.0 | +| [opentelemetry-instrumentation-falcon](./opentelemetry-instrumentation-falcon) | falcon >= 1.4.1, < 4.0.0 | +| [opentelemetry-instrumentation-fastapi](./opentelemetry-instrumentation-fastapi) | fastapi ~= 0.58 | +| [opentelemetry-instrumentation-flask](./opentelemetry-instrumentation-flask) | flask >= 1.0, < 3.0 | +| [opentelemetry-instrumentation-grpc](./opentelemetry-instrumentation-grpc) | grpcio ~= 1.27 | +| [opentelemetry-instrumentation-httpx](./opentelemetry-instrumentation-httpx) | httpx >= 0.18.0 | +| [opentelemetry-instrumentation-jinja2](./opentelemetry-instrumentation-jinja2) | jinja2 >= 2.7, < 4.0 | +| [opentelemetry-instrumentation-kafka-python](./opentelemetry-instrumentation-kafka-python) | kafka-python >= 2.0 | +| [opentelemetry-instrumentation-logging](./opentelemetry-instrumentation-logging) | logging | | [opentelemetry-instrumentation-mysql](./opentelemetry-instrumentation-mysql) | mysql-connector-python ~= 8.0 | -| [opentelemetry-instrumentation-pika](./opentelemetry-instrumentation-pika) | pika >= 0.12.0 | -| [opentelemetry-instrumentation-psycopg2](./opentelemetry-instrumentation-psycopg2) | psycopg2 >= 2.7.3.1 | -| [opentelemetry-instrumentation-pymemcache](./opentelemetry-instrumentation-pymemcache) | pymemcache >= 1.3.5, < 4 | -| [opentelemetry-instrumentation-pymongo](./opentelemetry-instrumentation-pymongo) | pymongo >= 3.1, < 5.0 | -| [opentelemetry-instrumentation-pymysql](./opentelemetry-instrumentation-pymysql) | PyMySQL < 2 | -| [opentelemetry-instrumentation-pyramid](./opentelemetry-instrumentation-pyramid) | pyramid >= 1.7 | -| [opentelemetry-instrumentation-redis](./opentelemetry-instrumentation-redis) | redis >= 2.6 | -| [opentelemetry-instrumentation-remoulade](./opentelemetry-instrumentation-remoulade) | remoulade >= 0.50 | -| [opentelemetry-instrumentation-requests](./opentelemetry-instrumentation-requests) | requests ~= 2.0 | -| [opentelemetry-instrumentation-sklearn](./opentelemetry-instrumentation-sklearn) | scikit-learn ~= 0.24.0 | -| [opentelemetry-instrumentation-sqlalchemy](./opentelemetry-instrumentation-sqlalchemy) | sqlalchemy | -| [opentelemetry-instrumentation-sqlite3](./opentelemetry-instrumentation-sqlite3) | sqlite3 | -| [opentelemetry-instrumentation-starlette](./opentelemetry-instrumentation-starlette) | starlette ~= 0.13.0 | -| [opentelemetry-instrumentation-system-metrics](./opentelemetry-instrumentation-system-metrics) | psutil >= 5 | -| [opentelemetry-instrumentation-tornado](./opentelemetry-instrumentation-tornado) | tornado >= 5.1.1 | -| [opentelemetry-instrumentation-urllib](./opentelemetry-instrumentation-urllib) | urllib | -| [opentelemetry-instrumentation-urllib3](./opentelemetry-instrumentation-urllib3) | urllib3 >= 1.0.0, < 2.0.0 | -| [opentelemetry-instrumentation-wsgi](./opentelemetry-instrumentation-wsgi) | wsgi | \ No newline at end of file +| [opentelemetry-instrumentation-pika](./opentelemetry-instrumentation-pika) | pika >= 0.12.0 | +| [opentelemetry-instrumentation-psycopg2](./opentelemetry-instrumentation-psycopg2) | psycopg2 >= 2.7.3.1 | +| [opentelemetry-instrumentation-pymemcache](./opentelemetry-instrumentation-pymemcache) | pymemcache >= 1.3.5, < 4 | +| [opentelemetry-instrumentation-pymongo](./opentelemetry-instrumentation-pymongo) | pymongo >= 3.1, < 5.0 | +| [opentelemetry-instrumentation-pymysql](./opentelemetry-instrumentation-pymysql) | PyMySQL < 2 | +| [opentelemetry-instrumentation-pyramid](./opentelemetry-instrumentation-pyramid) | pyramid >= 1.7 | +| [opentelemetry-instrumentation-redis](./opentelemetry-instrumentation-redis) | redis >= 2.6 | +| [opentelemetry-instrumentation-remoulade](./opentelemetry-instrumentation-remoulade) | remoulade >= 0.50 | +| [opentelemetry-instrumentation-requests](./opentelemetry-instrumentation-requests) | requests ~= 2.0 | +| [opentelemetry-instrumentation-sklearn](./opentelemetry-instrumentation-sklearn) | scikit-learn ~= 0.24.0 | +| [opentelemetry-instrumentation-sqlalchemy](./opentelemetry-instrumentation-sqlalchemy) | sqlalchemy | +| [opentelemetry-instrumentation-sqlite3](./opentelemetry-instrumentation-sqlite3) | sqlite3 | +| [opentelemetry-instrumentation-starlette](./opentelemetry-instrumentation-starlette) | starlette ~= 0.13.0 | +| [opentelemetry-instrumentation-system-metrics](./opentelemetry-instrumentation-system-metrics) | psutil >= 5 | +| [opentelemetry-instrumentation-tornado](./opentelemetry-instrumentation-tornado) | tornado >= 5.1.1 | +| [opentelemetry-instrumentation-urllib](./opentelemetry-instrumentation-urllib) | urllib | +| [opentelemetry-instrumentation-urllib3](./opentelemetry-instrumentation-urllib3) | urllib3 >= 1.0.0, < 2.0.0 | +| [opentelemetry-instrumentation-wsgi](./opentelemetry-instrumentation-wsgi) | wsgi | \ No newline at end of file From dc67bcc0943be4ba23169bff57fc599680f5a649 Mon Sep 17 00:00:00 2001 From: Adrien Bennatan Date: Wed, 11 May 2022 11:49:28 +0200 Subject: [PATCH 21/31] fix: lint and opentelemetry-api version --- .../opentelemetry-instrumentation-remoulade/setup.cfg | 4 ++-- .../opentelemetry/instrumentation/remoulade/__init__.py | 8 +++++--- .../src/opentelemetry/instrumentation/remoulade/utils.py | 1 + 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/setup.cfg b/instrumentation/opentelemetry-instrumentation-remoulade/setup.cfg index 6c69f6e1dd..c72fd0932d 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-remoulade/setup.cfg @@ -40,14 +40,14 @@ package_dir= =src packages=find_namespace: install_requires = - opentelemetry-api ~= 1.3 + opentelemetry-api ~= 1.10 opentelemetry-semantic-conventions == 0.30b1 opentelemetry-instrumentation == 0.30b1 [options.extras_require] test = opentelemetry-test-utils == 0.30b1 - opentelemetry-sdk ~= 1.3 + opentelemetry-sdk ~= 1.10 [options.packages.find] where = src diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py index 926872d02e..5f5f9246ca 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py @@ -43,7 +43,7 @@ def multiply(x, y): multiply.send(43, 51) """ -from typing import Collection, Optional, List, Iterable +from typing import Collection, Iterable, List, Optional from remoulade import Middleware, broker @@ -52,8 +52,8 @@ def multiply(x, y): from opentelemetry.instrumentation.remoulade import utils from opentelemetry.instrumentation.remoulade.package import _instruments from opentelemetry.instrumentation.remoulade.version import __version__ -from opentelemetry.propagators.textmap import CarrierT, Getter from opentelemetry.propagate import extract, inject +from opentelemetry.propagators.textmap import CarrierT, Getter from opentelemetry.semconv.trace import SpanAttributes _MESSAGE_TAG_KEY = "remoulade.action" @@ -88,7 +88,9 @@ def before_process_message(self, _broker, message): if "trace_ctx" not in message.options: return - trace_ctx = extract(message.options["trace_ctx"], getter=remoulade_getter) + trace_ctx = extract( + message.options["trace_ctx"], getter=remoulade_getter + ) retry_count = message.options.get("retries", None) operation_name = ( diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/utils.py b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/utils.py index 594eed7865..d4fdb2b2d2 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/utils.py +++ b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/utils.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + def attach_span(span_registry, message_id, span, is_publish=False): span_registry[(message_id, is_publish)] = span From 18f487eeb90604d55e11a6b297f52406613092c0 Mon Sep 17 00:00:00 2001 From: Adrien Bennatan Date: Mon, 16 May 2022 12:41:34 +0200 Subject: [PATCH 22/31] fix: typo in remoulade version --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 3d46bdced7..9c7c2cfaac 100644 --- a/tox.ini +++ b/tox.ini @@ -505,7 +505,7 @@ deps = requests==2.25.0 pyodbc~=4.0.30 flaky==3.7.0 - remoulade >= 0.50 + remoulade>=0.50 changedir = tests/opentelemetry-docker-tests/tests From b745608df57afd9d2bfdfcb45946f20f7ce1a36c Mon Sep 17 00:00:00 2001 From: Adrien Bennatan Date: Wed, 18 May 2022 12:07:07 +0200 Subject: [PATCH 23/31] fix: python >= 3.7 --- .../opentelemetry-instrumentation-remoulade/setup.cfg | 3 +-- tox.ini | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/setup.cfg b/instrumentation/opentelemetry-instrumentation-remoulade/setup.cfg index c72fd0932d..77532102bb 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-remoulade/setup.cfg @@ -28,14 +28,13 @@ classifiers = License :: OSI Approved :: Apache Software License Programming Language :: Python Programming Language :: Python :: 3 - Programming Language :: Python :: 3.6 Programming Language :: Python :: 3.7 Programming Language :: Python :: 3.8 Programming Language :: Python :: 3.9 Programming Language :: Python :: 3.10 [options] -python_requires = >=3.6 +python_requires = >=3.7 package_dir= =src packages=find_namespace: diff --git a/tox.ini b/tox.ini index 9c7c2cfaac..9b64988103 100644 --- a/tox.ini +++ b/tox.ini @@ -154,7 +154,8 @@ envlist = pypy3-test-instrumentation-redis ; opentelemetry-instrumentation-remoulade - py3{6,7,8,9,10}-test-instrumentation-remoulade + ; remoulade only supports 3.7 and above + py3{7,8,9,10}-test-instrumentation-remoulade pypy3-test-instrumentation-remoulade ; opentelemetry-instrumentation-celery From 6b3718eb0ab558a94c276d5dc84ee33aa58aef29 Mon Sep 17 00:00:00 2001 From: Adrien Bennatan Date: Wed, 18 May 2022 13:27:10 +0200 Subject: [PATCH 24/31] chore: bump to 31b0 --- .../opentelemetry-instrumentation-remoulade/setup.cfg | 6 +++--- .../src/opentelemetry/instrumentation/bootstrap_gen.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/setup.cfg b/instrumentation/opentelemetry-instrumentation-remoulade/setup.cfg index 77532102bb..e4fe1fe000 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-remoulade/setup.cfg @@ -40,12 +40,12 @@ package_dir= packages=find_namespace: install_requires = opentelemetry-api ~= 1.10 - opentelemetry-semantic-conventions == 0.30b1 - opentelemetry-instrumentation == 0.30b1 + opentelemetry-semantic-conventions == 0.31b0 + opentelemetry-instrumentation == 0.31b0 [options.extras_require] test = - opentelemetry-test-utils == 0.30b1 + opentelemetry-test-utils == 0.31b0 opentelemetry-sdk ~= 1.10 [options.packages.find] diff --git a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py index c8493e8e87..fcb5dd716f 100644 --- a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py +++ b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py @@ -114,7 +114,7 @@ }, "remoulade": { "library": "remoulade >= 0.50", - "instrumentation": "opentelemetry-instrumentation-remoulade==0.30b1", + "instrumentation": "opentelemetry-instrumentation-remoulade==0.31b0", }, "requests": { "library": "requests ~= 2.0", From 4c2b4c018e77d34704eed6b4c4069b37317dde0b Mon Sep 17 00:00:00 2001 From: Adrien Bennatan Date: Wed, 18 May 2022 13:30:13 +0200 Subject: [PATCH 25/31] docs: update CHANGELOG.md --- CHANGELOG.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1eb44799ab..2931ef0be4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased](https://github.com/open-telemetry/opentelemetry-python/compare/v1.12.0rc1-0.31b0...HEAD) +### Added +- `opentelemetry-instrumentation-remoulade` Initial release + ([#1082](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1082)) + ## [1.12.0rc1-0.31b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.12.0rc1-0.31b0) - 2022-05-17 @@ -25,8 +29,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - `opentelemetry-instrument` and `opentelemetry-bootstrap` now include a `--version` flag ([#1065](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1065)) -- `opentelemetry-instrumentation-remoulade` Initial release - ([#1082](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1082)) - `opentelemetry-instrumentation-redis` now instruments asynchronous Redis clients, if the installed redis-py includes async support (>=4.2.0). ([#1076](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1076)) From 911c142eb29d2b4295301bcb220f485eab4e9e51 Mon Sep 17 00:00:00 2001 From: Adrien Bennatan Date: Wed, 18 May 2022 14:31:50 +0200 Subject: [PATCH 26/31] run tox -e generate --- opentelemetry-contrib-instrumentations/setup.cfg | 2 +- .../src/opentelemetry/instrumentation/bootstrap_gen.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/opentelemetry-contrib-instrumentations/setup.cfg b/opentelemetry-contrib-instrumentations/setup.cfg index eb65e39a50..02500f28bb 100644 --- a/opentelemetry-contrib-instrumentations/setup.cfg +++ b/opentelemetry-contrib-instrumentations/setup.cfg @@ -55,7 +55,7 @@ install_requires = opentelemetry-instrumentation-pymysql==0.31b0 opentelemetry-instrumentation-pyramid==0.31b0 opentelemetry-instrumentation-redis==0.31b0 - opentelemetry-instrumentation-remoulade==0.31b0 + opentelemetry-instrumentation-remoulade==0.30b1 opentelemetry-instrumentation-requests==0.31b0 opentelemetry-instrumentation-sklearn==0.31b0 opentelemetry-instrumentation-sqlalchemy==0.31b0 diff --git a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py index fcb5dd716f..c8493e8e87 100644 --- a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py +++ b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py @@ -114,7 +114,7 @@ }, "remoulade": { "library": "remoulade >= 0.50", - "instrumentation": "opentelemetry-instrumentation-remoulade==0.31b0", + "instrumentation": "opentelemetry-instrumentation-remoulade==0.30b1", }, "requests": { "library": "requests ~= 2.0", From 4c2c478aed4fe872ca078461b2a1d25b439175c3 Mon Sep 17 00:00:00 2001 From: Adrien Bennatan Date: Wed, 18 May 2022 15:18:05 +0200 Subject: [PATCH 27/31] lint --- .../opentelemetry/instrumentation/remoulade/__init__.py | 7 +++---- .../tests/test_messages.py | 4 ++-- .../tests/test_uninstrument.py | 4 ++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py index 5f5f9246ca..23978bc0a0 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py @@ -107,7 +107,7 @@ def before_process_message(self, _broker, message): span.set_attribute("retry_count", retry_count) activation = trace.use_span(span, end_on_exit=True) - activation.__enter__() + activation.__enter__() # pylint: disable=E1101 utils.attach_span( self._span_registry, message.message_id, (span, activation) @@ -127,7 +127,6 @@ def after_process_message( if span.is_recording(): span.set_attribute(_MESSAGE_TAG_KEY, _MESSAGE_RUN) span.set_attribute(_MESSAGE_NAME_KEY, message.actor_name) - pass activation.__exit__(None, None, None) utils.detach_span(self._span_registry, message.message_id) @@ -154,10 +153,9 @@ def before_enqueue(self, _broker, message, delay): SpanAttributes.MESSAGING_MESSAGE_ID, message.message_id ) span.set_attribute(_MESSAGE_NAME_KEY, message.actor_name) - pass activation = trace.use_span(span, end_on_exit=True) - activation.__enter__() + activation.__enter__() # pylint: disable=E1101 utils.attach_span( self._span_registry, @@ -192,6 +190,7 @@ def instrumentation_dependencies(self) -> Collection[str]: def _instrument(self, **kwargs): tracer_provider = kwargs.get("tracer_provider") + # pylint: disable=attribute-defined-outside-init self._tracer = trace.get_tracer(__name__, __version__, tracer_provider) instrumentation_middleware = InstrumentationMiddleware(self._tracer) diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_messages.py b/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_messages.py index 61953f14ac..14c83a2bed 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_messages.py +++ b/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_messages.py @@ -21,8 +21,8 @@ @remoulade.actor(max_retries=3) -def actor_div(x, y): - return x / y +def actor_div(dividend, divisor): + return dividend / divisor class TestRemouladeInstrumentation(TestBase): diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_uninstrument.py b/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_uninstrument.py index 6a72a35506..b2b00c3cf1 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_uninstrument.py +++ b/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_uninstrument.py @@ -20,8 +20,8 @@ @remoulade.actor(max_retries=3) -def actor_div(x, y): - return x / y +def actor_div(dividend, divisor): + return dividend / divisor class TestRemouladeUninstrumentation(TestBase): From 94713340e7110110aae349e5a635b705268522bd Mon Sep 17 00:00:00 2001 From: Adrien Bennatan Date: Thu, 19 May 2022 15:02:25 +0200 Subject: [PATCH 28/31] Izchen code review --- .../README.rst | 2 +- .../instrumentation/remoulade/__init__.py | 61 +++++++++---------- .../instrumentation/remoulade/utils.py | 22 ++++++- 3 files changed, 51 insertions(+), 34 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/README.rst b/instrumentation/opentelemetry-instrumentation-remoulade/README.rst index 0b812262ea..46effe07f0 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/README.rst +++ b/instrumentation/opentelemetry-instrumentation-remoulade/README.rst @@ -1,5 +1,5 @@ OpenTelemetry Remoulade Instrumentation -=================================== +======================================= |pypi| diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py index 23978bc0a0..4ccf78fa6f 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py @@ -56,11 +56,11 @@ def multiply(x, y): from opentelemetry.propagators.textmap import CarrierT, Getter from opentelemetry.semconv.trace import SpanAttributes -_MESSAGE_TAG_KEY = "remoulade.action" -_MESSAGE_SEND = "send" -_MESSAGE_RUN = "run" +_REMOULADE_MESSAGE_TAG_KEY = "remoulade.action" +_REMOULADE_MESSAGE_SEND = "send" +_REMOULADE_MESSAGE_RUN = "run" -_MESSAGE_NAME_KEY = "remoulade.actor_name" +_REMOULADE_MESSAGE_NAME_KEY = "remoulade.actor_name" class RemouladeGetter(Getter): @@ -79,7 +79,7 @@ def keys(self, carrier: CarrierT) -> List[str]: remoulade_getter = RemouladeGetter() -class InstrumentationMiddleware(Middleware): +class _InstrumentationMiddleware(Middleware): def __init__(self, _tracer): self._tracer = _tracer self._span_registry = {} @@ -91,21 +91,19 @@ def before_process_message(self, _broker, message): trace_ctx = extract( message.options["trace_ctx"], getter=remoulade_getter ) - retry_count = message.options.get("retries", None) - - operation_name = ( - "remoulade/process" - if retry_count is None - else f"remoulade/process(retry-{retry_count})" + retry_count = message.options.get("retries", 0) + operation_name = utils.get_operation_name( + "before_process_message", retry_count ) + span_attributes = {"retry_count": retry_count} span = self._tracer.start_span( - operation_name, kind=trace.SpanKind.CONSUMER, context=trace_ctx + operation_name, + kind=trace.SpanKind.CONSUMER, + context=trace_ctx, + attributes=span_attributes, ) - if retry_count is not None: - span.set_attribute("retry_count", retry_count) - activation = trace.use_span(span, end_on_exit=True) activation.__enter__() # pylint: disable=E1101 @@ -125,34 +123,35 @@ def after_process_message( return if span.is_recording(): - span.set_attribute(_MESSAGE_TAG_KEY, _MESSAGE_RUN) - span.set_attribute(_MESSAGE_NAME_KEY, message.actor_name) + span.set_attribute( + _REMOULADE_MESSAGE_TAG_KEY, _REMOULADE_MESSAGE_RUN + ) + span.set_attribute(_REMOULADE_MESSAGE_NAME_KEY, message.actor_name) activation.__exit__(None, None, None) utils.detach_span(self._span_registry, message.message_id) def before_enqueue(self, _broker, message, delay): - retry_count = message.options.get("retries", None) - - operation_name = ( - "remoulade/send" - if retry_count is None - else f"remoulade/send(retry-{retry_count})" + retry_count = message.options.get("retries", 0) + operation_name = utils.get_operation_name( + "before_enqueue", retry_count ) + span_attributes = {"retry_count": retry_count} span = self._tracer.start_span( - operation_name, kind=trace.SpanKind.PRODUCER + operation_name, + kind=trace.SpanKind.PRODUCER, + attributes=span_attributes, ) - if retry_count is not None: - span.set_attribute("retry_count", retry_count) - if span.is_recording(): - span.set_attribute(_MESSAGE_TAG_KEY, _MESSAGE_SEND) + span.set_attribute( + _REMOULADE_MESSAGE_TAG_KEY, _REMOULADE_MESSAGE_SEND + ) span.set_attribute( SpanAttributes.MESSAGING_MESSAGE_ID, message.message_id ) - span.set_attribute(_MESSAGE_NAME_KEY, message.actor_name) + span.set_attribute(_REMOULADE_MESSAGE_NAME_KEY, message.actor_name) activation = trace.use_span(span, end_on_exit=True) activation.__enter__() # pylint: disable=E1101 @@ -192,9 +191,9 @@ def _instrument(self, **kwargs): # pylint: disable=attribute-defined-outside-init self._tracer = trace.get_tracer(__name__, __version__, tracer_provider) - instrumentation_middleware = InstrumentationMiddleware(self._tracer) + instrumentation_middleware = _InstrumentationMiddleware(self._tracer) broker.add_extra_default_middleware(instrumentation_middleware) def _uninstrument(self, **kwargs): - broker.remove_extra_default_middleware(InstrumentationMiddleware) + broker.remove_extra_default_middleware(_InstrumentationMiddleware) diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/utils.py b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/utils.py index d4fdb2b2d2..c6d602019f 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/utils.py +++ b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/utils.py @@ -13,8 +13,10 @@ # limitations under the License. -def attach_span(span_registry, message_id, span, is_publish=False): - span_registry[(message_id, is_publish)] = span +def attach_span( + span_registry, message_id, span_and_activation, is_publish=False +): + span_registry[(message_id, is_publish)] = span_and_activation def detach_span(span_registry, message_id, is_publish=False): @@ -23,3 +25,19 @@ def detach_span(span_registry, message_id, is_publish=False): def retrieve_span(span_registry, message_id, is_publish=False): return span_registry.get((message_id, is_publish), (None, None)) + + +def get_operation_name(hook_name, retry_count): + if hook_name == "before_process_message": + return ( + "remoulade/process" + if retry_count == 0 + else f"remoulade/process(retry-{retry_count})" + ) + elif hook_name == "before_enqueue": + return ( + "remoulade/send" + if retry_count == 0 + else f"remoulade/send(retry-{retry_count})" + ) + return "" From 0fc6b65094c9f94062308d0f446f87be56d4c374 Mon Sep 17 00:00:00 2001 From: Adrien Bennatan Date: Thu, 19 May 2022 16:50:21 +0200 Subject: [PATCH 29/31] srikanthccv code review --- .../instrumentation/remoulade/__init__.py | 45 +++++++------------ .../instrumentation/remoulade/version.py | 2 +- .../tests/test_getter.py | 45 ------------------- .../tests/test_messages.py | 16 +++++-- .../setup.cfg | 2 +- .../instrumentation/bootstrap_gen.py | 2 +- 6 files changed, 30 insertions(+), 82 deletions(-) delete mode 100644 instrumentation/opentelemetry-instrumentation-remoulade/tests/test_getter.py diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py index 4ccf78fa6f..80f1625dd3 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py @@ -63,22 +63,6 @@ def multiply(x, y): _REMOULADE_MESSAGE_NAME_KEY = "remoulade.actor_name" -class RemouladeGetter(Getter): - def get(self, carrier: CarrierT, key: str) -> Optional[str]: - value = carrier.get(key, None) - if value is None: - return None - if isinstance(value, str) or not isinstance(value, Iterable): - value = (value,) - return value - - def keys(self, carrier: CarrierT) -> List[str]: - return [] - - -remoulade_getter = RemouladeGetter() - - class _InstrumentationMiddleware(Middleware): def __init__(self, _tracer): self._tracer = _tracer @@ -88,14 +72,12 @@ def before_process_message(self, _broker, message): if "trace_ctx" not in message.options: return - trace_ctx = extract( - message.options["trace_ctx"], getter=remoulade_getter - ) + trace_ctx = extract(message.options["trace_ctx"]) retry_count = message.options.get("retries", 0) operation_name = utils.get_operation_name( "before_process_message", retry_count ) - span_attributes = {"retry_count": retry_count} + span_attributes = {"remoulade.retry_count": retry_count} span = self._tracer.start_span( operation_name, @@ -123,10 +105,13 @@ def after_process_message( return if span.is_recording(): - span.set_attribute( - _REMOULADE_MESSAGE_TAG_KEY, _REMOULADE_MESSAGE_RUN + span.set_attributes( + { + _REMOULADE_MESSAGE_TAG_KEY: _REMOULADE_MESSAGE_RUN, + _REMOULADE_MESSAGE_NAME_KEY: message.actor_name, + SpanAttributes.MESSAGING_MESSAGE_ID: message.message_id, + } ) - span.set_attribute(_REMOULADE_MESSAGE_NAME_KEY, message.actor_name) activation.__exit__(None, None, None) utils.detach_span(self._span_registry, message.message_id) @@ -136,7 +121,7 @@ def before_enqueue(self, _broker, message, delay): operation_name = utils.get_operation_name( "before_enqueue", retry_count ) - span_attributes = {"retry_count": retry_count} + span_attributes = {"remoulade.retry_count": retry_count} span = self._tracer.start_span( operation_name, @@ -145,13 +130,13 @@ def before_enqueue(self, _broker, message, delay): ) if span.is_recording(): - span.set_attribute( - _REMOULADE_MESSAGE_TAG_KEY, _REMOULADE_MESSAGE_SEND - ) - span.set_attribute( - SpanAttributes.MESSAGING_MESSAGE_ID, message.message_id + span.set_attributes( + { + _REMOULADE_MESSAGE_TAG_KEY: _REMOULADE_MESSAGE_SEND, + _REMOULADE_MESSAGE_NAME_KEY: message.actor_name, + SpanAttributes.MESSAGING_MESSAGE_ID: message.message_id, + } ) - span.set_attribute(_REMOULADE_MESSAGE_NAME_KEY, message.actor_name) activation = trace.use_span(span, end_on_exit=True) activation.__enter__() # pylint: disable=E1101 diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/version.py b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/version.py index 88015aae34..268a795344 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/version.py +++ b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.30b1" +__version__ = "0.32b0" diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_getter.py b/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_getter.py deleted file mode 100644 index 67618caae4..0000000000 --- a/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_getter.py +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright The OpenTelemetry Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from unittest import TestCase - -from opentelemetry.instrumentation.remoulade import RemouladeGetter - - -class TestRemouladeGetter(TestCase): - def setUp(self): - self.getter = RemouladeGetter() - - def test_get_none(self): - carrier = {} - val = self.getter.get(carrier, "test") - self.assertIsNone(val) - - def test_get_str(self): - key = "test" - value = "value" - carrier = {key: value} - val = self.getter.get(carrier, key) - self.assertEqual(val, (value,)) - - def test_get_iter(self): - key = "test" - value = ["value"] - carrier = {key: value} - val = self.getter.get(carrier, key) - self.assertEqual(val, value) - - def test_keys(self): - keys = self.getter.keys({}) - self.assertEqual(keys, []) diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_messages.py b/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_messages.py index 14c83a2bed..4704111bdd 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_messages.py +++ b/instrumentation/opentelemetry-instrumentation-remoulade/tests/test_messages.py @@ -80,13 +80,21 @@ def test_retries(self): producer_spans = spans[1::2] self.assertEqual(consumer_spans[0].name, "remoulade/process(retry-3)") - self.assertSpanHasAttributes(consumer_spans[0], {"retry_count": 3}) + self.assertSpanHasAttributes( + consumer_spans[0], {"remoulade.retry_count": 3} + ) self.assertEqual(consumer_spans[1].name, "remoulade/process(retry-2)") - self.assertSpanHasAttributes(consumer_spans[1], {"retry_count": 2}) + self.assertSpanHasAttributes( + consumer_spans[1], {"remoulade.retry_count": 2} + ) self.assertEqual(consumer_spans[3].name, "remoulade/process") self.assertEqual(producer_spans[0].name, "remoulade/send(retry-3)") - self.assertSpanHasAttributes(producer_spans[0], {"retry_count": 3}) + self.assertSpanHasAttributes( + producer_spans[0], {"remoulade.retry_count": 3} + ) self.assertEqual(producer_spans[1].name, "remoulade/send(retry-2)") - self.assertSpanHasAttributes(producer_spans[1], {"retry_count": 2}) + self.assertSpanHasAttributes( + producer_spans[1], {"remoulade.retry_count": 2} + ) self.assertEqual(producer_spans[3].name, "remoulade/send") diff --git a/opentelemetry-contrib-instrumentations/setup.cfg b/opentelemetry-contrib-instrumentations/setup.cfg index 02500f28bb..45e32a8645 100644 --- a/opentelemetry-contrib-instrumentations/setup.cfg +++ b/opentelemetry-contrib-instrumentations/setup.cfg @@ -55,7 +55,7 @@ install_requires = opentelemetry-instrumentation-pymysql==0.31b0 opentelemetry-instrumentation-pyramid==0.31b0 opentelemetry-instrumentation-redis==0.31b0 - opentelemetry-instrumentation-remoulade==0.30b1 + opentelemetry-instrumentation-remoulade==0.32b0 opentelemetry-instrumentation-requests==0.31b0 opentelemetry-instrumentation-sklearn==0.31b0 opentelemetry-instrumentation-sqlalchemy==0.31b0 diff --git a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py index c8493e8e87..6fe5fe1230 100644 --- a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py +++ b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py @@ -114,7 +114,7 @@ }, "remoulade": { "library": "remoulade >= 0.50", - "instrumentation": "opentelemetry-instrumentation-remoulade==0.30b1", + "instrumentation": "opentelemetry-instrumentation-remoulade==0.32b0", }, "requests": { "library": "requests ~= 2.0", From b18e951c5ac63ae382636bc535ba3c95eea31584 Mon Sep 17 00:00:00 2001 From: Adrien Bennatan Date: Fri, 20 May 2022 10:47:11 +0200 Subject: [PATCH 30/31] remove pypy3 test --- .github/component_owners.yml | 4 ++++ .../opentelemetry/instrumentation/remoulade/__init__.py | 9 +++++---- tox.ini | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/component_owners.yml b/.github/component_owners.yml index 669ce38751..b6d1930eff 100644 --- a/.github/component_owners.yml +++ b/.github/component_owners.yml @@ -7,6 +7,10 @@ components: - oxeye-nikolay - nikosokolik + instrumentation/opentelemetry-instrumentation-remoulade: + - ben-natan + - machine424 + propagator/opentelemetry-propagator-aws-xray: - NathanielRN diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py index 80f1625dd3..c9e53d92df 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/__init__.py @@ -43,7 +43,7 @@ def multiply(x, y): multiply.send(43, 51) """ -from typing import Collection, Iterable, List, Optional +from typing import Collection from remoulade import Middleware, broker @@ -53,7 +53,6 @@ def multiply(x, y): from opentelemetry.instrumentation.remoulade.package import _instruments from opentelemetry.instrumentation.remoulade.version import __version__ from opentelemetry.propagate import extract, inject -from opentelemetry.propagators.textmap import CarrierT, Getter from opentelemetry.semconv.trace import SpanAttributes _REMOULADE_MESSAGE_TAG_KEY = "remoulade.action" @@ -62,6 +61,8 @@ def multiply(x, y): _REMOULADE_MESSAGE_NAME_KEY = "remoulade.actor_name" +_REMOULADE_MESSAGE_RETRY_COUNT_KEY = "remoulade.retry_count" + class _InstrumentationMiddleware(Middleware): def __init__(self, _tracer): @@ -77,7 +78,7 @@ def before_process_message(self, _broker, message): operation_name = utils.get_operation_name( "before_process_message", retry_count ) - span_attributes = {"remoulade.retry_count": retry_count} + span_attributes = {_REMOULADE_MESSAGE_RETRY_COUNT_KEY: retry_count} span = self._tracer.start_span( operation_name, @@ -121,7 +122,7 @@ def before_enqueue(self, _broker, message, delay): operation_name = utils.get_operation_name( "before_enqueue", retry_count ) - span_attributes = {"remoulade.retry_count": retry_count} + span_attributes = {_REMOULADE_MESSAGE_RETRY_COUNT_KEY: retry_count} span = self._tracer.start_span( operation_name, diff --git a/tox.ini b/tox.ini index 9b64988103..0f484f71bb 100644 --- a/tox.ini +++ b/tox.ini @@ -156,7 +156,7 @@ envlist = ; opentelemetry-instrumentation-remoulade ; remoulade only supports 3.7 and above py3{7,8,9,10}-test-instrumentation-remoulade - pypy3-test-instrumentation-remoulade + ; instrumentation-remoulade intentionally excluded from pypy3 ; opentelemetry-instrumentation-celery py3{6,7,8,9,10}-test-instrumentation-celery From 314ee1a913a81e5c15a1b8b28b4865ceb739f377 Mon Sep 17 00:00:00 2001 From: Adrien Bennatan Date: Mon, 30 May 2022 09:51:29 +0200 Subject: [PATCH 31/31] 31b0 --- .../src/opentelemetry/instrumentation/remoulade/utils.py | 2 +- .../src/opentelemetry/instrumentation/remoulade/version.py | 2 +- opentelemetry-contrib-instrumentations/setup.cfg | 2 +- .../src/opentelemetry/instrumentation/bootstrap_gen.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/utils.py b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/utils.py index c6d602019f..9237f29883 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/utils.py +++ b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/utils.py @@ -34,7 +34,7 @@ def get_operation_name(hook_name, retry_count): if retry_count == 0 else f"remoulade/process(retry-{retry_count})" ) - elif hook_name == "before_enqueue": + if hook_name == "before_enqueue": return ( "remoulade/send" if retry_count == 0 diff --git a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/version.py b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/version.py index 268a795344..d8dc1e1ed7 100644 --- a/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/version.py +++ b/instrumentation/opentelemetry-instrumentation-remoulade/src/opentelemetry/instrumentation/remoulade/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.32b0" +__version__ = "0.31b0" diff --git a/opentelemetry-contrib-instrumentations/setup.cfg b/opentelemetry-contrib-instrumentations/setup.cfg index 8b2c91f0b7..42c1ba3481 100644 --- a/opentelemetry-contrib-instrumentations/setup.cfg +++ b/opentelemetry-contrib-instrumentations/setup.cfg @@ -56,7 +56,7 @@ install_requires = opentelemetry-instrumentation-pymysql==0.31b0 opentelemetry-instrumentation-pyramid==0.31b0 opentelemetry-instrumentation-redis==0.31b0 - opentelemetry-instrumentation-remoulade==0.32b0 + opentelemetry-instrumentation-remoulade==0.31b0 opentelemetry-instrumentation-requests==0.31b0 opentelemetry-instrumentation-sklearn==0.31b0 opentelemetry-instrumentation-sqlalchemy==0.31b0 diff --git a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py index 158930c02c..93d06d3295 100644 --- a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py +++ b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py @@ -118,7 +118,7 @@ }, "remoulade": { "library": "remoulade >= 0.50", - "instrumentation": "opentelemetry-instrumentation-remoulade==0.32b0", + "instrumentation": "opentelemetry-instrumentation-remoulade==0.31b0", }, "requests": { "library": "requests ~= 2.0",