diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a8c77df06..3eafcfbf02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,11 +16,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - `opentelemetry-instrumentation-boto3sqs` Make propagation compatible with other SQS instrumentations, add 'messaging.url' span attribute, and fix missing package dependencies. - ([#1234](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1234)) + ([#1234](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1234)) +- `opentelemetry-instrumentation-pymongo` Change span names to not contain queries but only database name and command name + ([#1247](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1247)) - restoring metrics in django framework ([#1208](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1208)) - `opentelemetry-instrumentation-aiohttp-client` Fix producing additional spans with each newly created ClientSession - ([#1246](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1246)) +- Add _is_openetlemetry_instrumented check in _InstrumentedFastAPI class + ([#1313](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1313)) ## [1.12.0-0.33b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.12.0-0.33b0) - 2022-08-08 diff --git a/instrumentation/opentelemetry-instrumentation-fastapi/src/opentelemetry/instrumentation/fastapi/__init__.py b/instrumentation/opentelemetry-instrumentation-fastapi/src/opentelemetry/instrumentation/fastapi/__init__.py index 1c76c8bb50..4fd4947418 100644 --- a/instrumentation/opentelemetry-instrumentation-fastapi/src/opentelemetry/instrumentation/fastapi/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-fastapi/src/opentelemetry/instrumentation/fastapi/__init__.py @@ -247,6 +247,7 @@ def __init__(self, *args, **kwargs): client_response_hook=_InstrumentedFastAPI._client_response_hook, tracer_provider=_InstrumentedFastAPI._tracer_provider, ) + self._is_instrumented_by_opentelemetry = True def _get_route_details(scope): diff --git a/instrumentation/opentelemetry-instrumentation-fastapi/tests/test_fastapi_instrumentation.py b/instrumentation/opentelemetry-instrumentation-fastapi/tests/test_fastapi_instrumentation.py index 0d42e7533c..4cd3cbee29 100644 --- a/instrumentation/opentelemetry-instrumentation-fastapi/tests/test_fastapi_instrumentation.py +++ b/instrumentation/opentelemetry-instrumentation-fastapi/tests/test_fastapi_instrumentation.py @@ -274,6 +274,14 @@ def test_request(self): self.assertEqual(span.resource.attributes["key1"], "value1") self.assertEqual(span.resource.attributes["key2"], "value2") + def test_mulitple_way_instrumentation(self): + self._instrumentor.instrument_app(self._app) + count = 0 + for middleware in self._app.user_middleware: + if middleware.cls is OpenTelemetryMiddleware: + count += 1 + self.assertEqual(count, 1) + def tearDown(self): self._instrumentor.uninstrument() super().tearDown() diff --git a/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/__init__.py b/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/__init__.py index ba3afae11f..91cd81aab3 100644 --- a/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/__init__.py @@ -121,10 +121,10 @@ def started(self, event: monitoring.CommandStartedEvent): ): return command = event.command.get(event.command_name, "") - name = event.command_name + name = event.database_name + name += "." + event.command_name statement = event.command_name if command: - name += "." + str(command) statement += " " + str(command) try: diff --git a/instrumentation/opentelemetry-instrumentation-pymongo/tests/test_pymongo.py b/instrumentation/opentelemetry-instrumentation-pymongo/tests/test_pymongo.py index ef3734c596..15a5a0be0b 100644 --- a/instrumentation/opentelemetry-instrumentation-pymongo/tests/test_pymongo.py +++ b/instrumentation/opentelemetry-instrumentation-pymongo/tests/test_pymongo.py @@ -40,7 +40,6 @@ def test_pymongo_instrumentor(self): ) with patch: PymongoInstrumentor().instrument() - self.assertTrue(mock_register.called) def test_started(self): @@ -59,7 +58,7 @@ def test_started(self): # pylint: disable=protected-access span = command_tracer._pop_span(mock_event) self.assertIs(span.kind, trace_api.SpanKind.CLIENT) - self.assertEqual(span.name, "command_name.find") + self.assertEqual(span.name, "database_name.command_name") self.assertEqual(span.attributes[SpanAttributes.DB_SYSTEM], "mongodb") self.assertEqual( span.attributes[SpanAttributes.DB_NAME], "database_name" @@ -189,8 +188,7 @@ def test_int_command(self): self.assertEqual(len(spans_list), 1) span = spans_list[0] - - self.assertEqual(span.name, "command_name.123") + self.assertEqual(span.name, "database_name.command_name") class MockCommand: diff --git a/opentelemetry-distro/MANIFEST.in b/opentelemetry-distro/MANIFEST.in deleted file mode 100644 index 191b7d1959..0000000000 --- a/opentelemetry-distro/MANIFEST.in +++ /dev/null @@ -1,7 +0,0 @@ -prune tests -graft src -global-exclude *.pyc -global-exclude *.pyo -global-exclude __pycache__/* -include MANIFEST.in -include README.rst diff --git a/opentelemetry-distro/pyproject.toml b/opentelemetry-distro/pyproject.toml new file mode 100644 index 0000000000..6707fc5c29 --- /dev/null +++ b/opentelemetry-distro/pyproject.toml @@ -0,0 +1,56 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +name = "opentelemetry-distro" +dynamic = ["version"] +description = "OpenTelemetry Python Distro" +readme = "README.rst" +license = "Apache-2.0" +requires-python = ">=3.7" +authors = [ + { name = "OpenTelemetry Authors", email = "cncf-opentelemetry-contributors@lists.cncf.io" }, +] +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.7", + "Programming Language :: Python :: 3.8", + "Typing :: Typed", +] +dependencies = [ + "opentelemetry-api ~= 1.12", + "opentelemetry-instrumentation == 0.33b0", + "opentelemetry-sdk == 1.12.0", +] + +[project.optional-dependencies] +otlp = [ + "opentelemetry-exporter-otlp == 1.12.0", +] +test = [] + +[project.entry-points.opentelemetry_configurator] +configurator = "opentelemetry.distro:OpenTelemetryConfigurator" + +[project.entry-points.opentelemetry_distro] +distro = "opentelemetry.distro:OpenTelemetryDistro" + +[project.urls] +Homepage = "https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/opentelemetry-distro" + +[tool.hatch.version] +path = "src/opentelemetry/distro/version.py" + +[tool.hatch.build.targets.sdist] +include = [ + "/src", + "/tests", +] + +[tool.hatch.build.targets.wheel] +packages = ["src/opentelemetry"] diff --git a/opentelemetry-distro/setup.cfg b/opentelemetry-distro/setup.cfg deleted file mode 100644 index 59f199a07e..0000000000 --- a/opentelemetry-distro/setup.cfg +++ /dev/null @@ -1,59 +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. -# -[metadata] -name = opentelemetry-distro -description = OpenTelemetry Python Distro -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/opentelemetry-distro -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.7 - Programming Language :: Python :: 3.8 - Typing :: Typed - -[options] -python_requires = >=3.7 -package_dir= - =src -packages=find_namespace: -zip_safe = False -include_package_data = True -install_requires = - opentelemetry-api ~= 1.12 - opentelemetry-instrumentation == 0.33b0 - opentelemetry-sdk == 1.12.0 - -[options.packages.find] -where = src - -[options.entry_points] -opentelemetry_distro = - distro = opentelemetry.distro:OpenTelemetryDistro -opentelemetry_configurator = - configurator = opentelemetry.distro:OpenTelemetryConfigurator - -[options.extras_require] -test = -otlp = - opentelemetry-exporter-otlp == 1.12.0 diff --git a/opentelemetry-distro/setup.py b/opentelemetry-distro/setup.py deleted file mode 100644 index ddf6de91aa..0000000000 --- a/opentelemetry-distro/setup.py +++ /dev/null @@ -1,27 +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. - -import os - -import setuptools - -BASE_DIR = os.path.dirname(__file__) -VERSION_FILENAME = os.path.join( - BASE_DIR, "src", "opentelemetry", "distro", "version.py" -) -PACKAGE_INFO = {} -with open(VERSION_FILENAME, encoding="utf-8") as f: - exec(f.read(), PACKAGE_INFO) - -setuptools.setup(version=PACKAGE_INFO["__version__"],) diff --git a/opentelemetry-instrumentation/MANIFEST.in b/opentelemetry-instrumentation/MANIFEST.in deleted file mode 100644 index faee277146..0000000000 --- a/opentelemetry-instrumentation/MANIFEST.in +++ /dev/null @@ -1,8 +0,0 @@ -graft src -graft tests -global-exclude *.pyc -global-exclude *.pyo -global-exclude __pycache__/* -include MANIFEST.in -include README.rst -include LICENSE diff --git a/opentelemetry-instrumentation/pyproject.toml b/opentelemetry-instrumentation/pyproject.toml new file mode 100644 index 0000000000..6d219f6428 --- /dev/null +++ b/opentelemetry-instrumentation/pyproject.toml @@ -0,0 +1,55 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +name = "opentelemetry-instrumentation" +dynamic = ["version"] +description = "Instrumentation Tools & Auto Instrumentation for OpenTelemetry Python" +readme = "README.rst" +license = "Apache-2.0" +requires-python = ">=3.7" +authors = [ + { name = "OpenTelemetry Authors", email = "cncf-opentelemetry-contributors@lists.cncf.io" }, +] +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.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", +] +dependencies = [ + "opentelemetry-api ~= 1.4", + "setuptools >= 16.0", + "wrapt >= 1.0.0, < 2.0.0", +] + +[project.optional-dependencies] +test = [] + +[project.scripts] +opentelemetry-bootstrap = "opentelemetry.instrumentation.bootstrap:run" +opentelemetry-instrument = "opentelemetry.instrumentation.auto_instrumentation:run" + +[project.entry-points.opentelemetry_environment_variables] +instrumentation = "opentelemetry.instrumentation.environment_variables" + +[project.urls] +Homepage = "https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/opentelemetry-instrumentation" + +[tool.hatch.version] +path = "src/opentelemetry/instrumentation/version.py" + +[tool.hatch.build.targets.sdist] +include = [ + "/src", + "/tests", +] + +[tool.hatch.build.targets.wheel] +packages = ["src/opentelemetry"] diff --git a/opentelemetry-instrumentation/setup.cfg b/opentelemetry-instrumentation/setup.cfg deleted file mode 100644 index fcbde9b507..0000000000 --- a/opentelemetry-instrumentation/setup.cfg +++ /dev/null @@ -1,59 +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. -# -[metadata] -name = opentelemetry-instrumentation -description = Instrumentation Tools & Auto Instrumentation for OpenTelemetry Python -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/opentelemetry-instrumentation -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.7 - Programming Language :: Python :: 3.8 - Programming Language :: Python :: 3.9 - Programming Language :: Python :: 3.10 - -[options] -python_requires = >=3.7 -package_dir= - =src -packages=find_namespace: -zip_safe = False -include_package_data = True -install_requires = - opentelemetry-api ~= 1.4 - setuptools >= 16.0 - wrapt >= 1.0.0, < 2.0.0 - -[options.packages.find] -where = src - -[options.entry_points] -console_scripts = - opentelemetry-instrument = opentelemetry.instrumentation.auto_instrumentation:run - opentelemetry-bootstrap = opentelemetry.instrumentation.bootstrap:run -opentelemetry_environment_variables = - instrumentation = opentelemetry.instrumentation.environment_variables - -[options.extras_require] -test = diff --git a/opentelemetry-instrumentation/setup.py b/opentelemetry-instrumentation/setup.py deleted file mode 100644 index 9d1d5b7b06..0000000000 --- a/opentelemetry-instrumentation/setup.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. - -import os - -import setuptools - -BASE_DIR = os.path.dirname(__file__) -VERSION_FILENAME = os.path.join( - BASE_DIR, "src", "opentelemetry", "instrumentation", "version.py" -) -PACKAGE_INFO = {} -with open(VERSION_FILENAME, encoding="utf-8") as f: - exec(f.read(), PACKAGE_INFO) - -setuptools.setup( - version=PACKAGE_INFO["__version__"], -) diff --git a/scripts/eachdist.py b/scripts/eachdist.py index 103a63de88..7b1359226a 100755 --- a/scripts/eachdist.py +++ b/scripts/eachdist.py @@ -518,18 +518,19 @@ def lint_args(args): runsubprocess( args.dry_run, - ("black", ".") + (("--diff", "--check") if args.check_only else ()), + ("black", "--config", f"{rootdir}/pyproject.toml", ".") + + (("--diff", "--check") if args.check_only else ()), cwd=rootdir, check=True, ) runsubprocess( args.dry_run, - ("isort", ".") + ("isort", "--settings-path", f"{rootdir}/.isort.cfg", ".") + (("--diff", "--check-only") if args.check_only else ()), cwd=rootdir, check=True, ) - runsubprocess(args.dry_run, ("flake8", rootdir), check=True) + runsubprocess(args.dry_run, ("flake8", "--config", f"{rootdir}/.flake8", rootdir), check=True) execute_args( parse_subargs( args, ("exec", "pylint {}", "--all", "--mode", "lintroots") @@ -644,7 +645,7 @@ def update_dependencies(targets, version, packages): update_files( targets, - "setup.cfg", + "pyproject.toml", fr"({package_name}.*)==(.*)", r"\1== " + version, ) @@ -717,13 +718,16 @@ def format_args(args): format_dir = str(find_projectroot()) if args.path: format_dir = os.path.join(format_dir, args.path) - + root_dir = str(find_projectroot()) runsubprocess( - args.dry_run, ("black", "."), cwd=format_dir, check=True, + args.dry_run, + ("black", "--config", f"{root_dir}/pyproject.toml", "."), + cwd=format_dir, + check=True, ) runsubprocess( args.dry_run, - ("isort", "--profile", "black", "."), + ("isort", "--settings-path", f"{root_dir}/.isort.cfg", "--profile", "black", "."), cwd=format_dir, check=True, )