Skip to content

Commit 5b811ae

Browse files
committed
Instrumentation: Use runtime dependency checks
1 parent ab36898 commit 5b811ae

File tree

159 files changed

+1525
-647
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

159 files changed

+1525
-647
lines changed

.github/workflows/test.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
uses: actions/cache@v2
4646
with:
4747
path: .tox
48-
key: tox-cache-${{ env.RUN_MATRIX_COMBINATION }}-${{ hashFiles('tox.ini', 'dev-requirements.txt') }}
48+
key: v2-build-tox-cache-${{ env.RUN_MATRIX_COMBINATION }}-${{ hashFiles('tox.ini', 'dev-requirements.txt') }}
4949
- name: run tox
5050
run: tox -f ${{ matrix.python-version }}-${{ matrix.package }} -- --benchmark-json=${{ env.RUN_MATRIX_COMBINATION }}-benchmark.json
5151
- name: Find and merge benchmarks
@@ -99,6 +99,6 @@ jobs:
9999
uses: actions/cache@v2
100100
with:
101101
path: .tox
102-
key: v2-tox-cache-${{ matrix.tox-environment }}-${{ hashFiles('tox.ini', 'dev-requirements.txt', 'docs-requirements.txt') }}
102+
key: v2-misc-tox-cache-${{ matrix.tox-environment }}-${{ hashFiles('tox.ini', 'dev-requirements.txt', 'docs-requirements.txt') }}
103103
- name: run tox
104104
run: tox -e ${{ matrix.tox-environment }}

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
## [Unreleased](https://github.com/open-telemetry/opentelemetry-python-contrib/compare/v0.200...HEAD)
88

99
### Changed
10+
- Instrumentation packages don't specify the libraries they instrument as dependencies
11+
anymore. Instead, they verify the correct version of libraries are installed at runtime.
12+
([#475](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/475))
1013
- `opentelemetry-propagator-ot-trace` Use `TraceFlags` object in `extract`
1114
([#472](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/472))
1215

instrumentation/opentelemetry-instrumentation-aiohttp-client/setup.cfg

-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ install_requires =
4141
opentelemetry-api == 1.2.0.dev0
4242
opentelemetry-semantic-conventions == 0.21.dev0
4343
opentelemetry-instrumentation == 0.21.dev0
44-
aiohttp ~= 3.0
4544
wrapt >= 1.0.0, < 2.0.0
4645

4746
[options.packages.find]

instrumentation/opentelemetry-instrumentation-aiohttp-client/setup.py

+23-5
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,43 @@
1313
# limitations under the License.
1414

1515

16-
# DO NOT EDIT. THIS FILE WAS AUTOGENERATED FROM templaes/aiohttp_client.
16+
# DO NOT EDIT. THIS FILE WAS AUTOGENERATED FROM templates/aiohttp_client.
1717
# Run `python scripts/generate_setuppy.py` to regenerate.
1818

1919

2020
import os
21+
from configparser import ConfigParser
2122

2223
import setuptools
2324

25+
config = ConfigParser()
26+
config.read("setup.cfg")
27+
28+
extras_require = {}
29+
if "options.extras_require" in config:
30+
for key, value in config["options.extras_require"].items():
31+
extras_require[key] = [v for v in value.split("\n") if v.strip()]
32+
2433
BASE_DIR = os.path.dirname(__file__)
25-
VERSION_FILENAME = os.path.join(
34+
PACKAGE_FILENAME = os.path.join(
2635
BASE_DIR,
2736
"src",
2837
"opentelemetry",
2938
"instrumentation",
3039
"aiohttp_client",
31-
"version.py",
40+
"package.py",
3241
)
3342
PACKAGE_INFO = {}
34-
with open(VERSION_FILENAME) as f:
43+
with open(PACKAGE_FILENAME) as f:
3544
exec(f.read(), PACKAGE_INFO)
3645

37-
setuptools.setup(version=PACKAGE_INFO["__version__"])
46+
extras_require["instruments"] = PACKAGE_INFO["_instruments"]
47+
test_deps = extras_require.get("test", [])
48+
for dep in extras_require["instruments"]:
49+
test_deps.append(dep)
50+
51+
extras_require["test"] = test_deps
52+
53+
setuptools.setup(
54+
version=PACKAGE_INFO["__version__"], extras_require=extras_require
55+
)

instrumentation/opentelemetry-instrumentation-aiohttp-client/src/opentelemetry/instrumentation/aiohttp_client/__init__.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,14 @@ def strip_query_params(url: yarl.URL) -> str:
6464

6565
import types
6666
import typing
67+
from typing import Collection
6768

6869
import aiohttp
6970
import wrapt
7071

7172
from opentelemetry import context as context_api
7273
from opentelemetry import trace
73-
from opentelemetry.instrumentation.aiohttp_client.version import __version__
74+
from opentelemetry.instrumentation.aiohttp_client.package import __version__
7475
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
7576
from opentelemetry.instrumentation.utils import (
7677
http_status_to_status_code,
@@ -81,6 +82,8 @@ def strip_query_params(url: yarl.URL) -> str:
8182
from opentelemetry.trace import SpanKind, TracerProvider, get_tracer
8283
from opentelemetry.trace.status import Status, StatusCode
8384

85+
from . import package as pkg
86+
8487
_UrlFilterT = typing.Optional[typing.Callable[[str], str]]
8588
_SpanNameT = typing.Optional[
8689
typing.Union[typing.Callable[[aiohttp.TraceRequestStartParams], str], str]
@@ -288,6 +291,9 @@ class AioHttpClientInstrumentor(BaseInstrumentor):
288291
See `BaseInstrumentor`
289292
"""
290293

294+
def instrumentation_dependencies(self) -> Collection[str]:
295+
return pkg._instruments
296+
291297
def _instrument(self, **kwargs):
292298
"""Instruments aiohttp ClientSession
293299

instrumentation/opentelemetry-instrumentation-aiohttp-client/src/opentelemetry/instrumentation/aiohttp_client/version.py instrumentation/opentelemetry-instrumentation-aiohttp-client/src/opentelemetry/instrumentation/aiohttp_client/package.py

+2
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@
1313
# limitations under the License.
1414

1515
__version__ = "0.21.dev0"
16+
17+
_instruments = ("aiohttp ~= 3.0",)

instrumentation/opentelemetry-instrumentation-aiopg/setup.cfg

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ install_requires =
4242
opentelemetry-semantic-conventions == 0.21.dev0
4343
opentelemetry-instrumentation-dbapi == 0.21.dev0
4444
opentelemetry-instrumentation == 0.21.dev0
45-
aiopg >= 0.13.0
4645
wrapt >= 1.0.0, < 2.0.0
4746

4847
[options.extras_require]

instrumentation/opentelemetry-instrumentation-aiopg/setup.py

+23-5
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,38 @@
1313
# limitations under the License.
1414

1515

16-
# DO NOT EDIT. THIS FILE WAS AUTOGENERATED FROM templaes/aiopg.
16+
# DO NOT EDIT. THIS FILE WAS AUTOGENERATED FROM templates/aiopg.
1717
# Run `python scripts/generate_setuppy.py` to regenerate.
1818

1919

2020
import os
21+
from configparser import ConfigParser
2122

2223
import setuptools
2324

25+
config = ConfigParser()
26+
config.read("setup.cfg")
27+
28+
extras_require = {}
29+
if "options.extras_require" in config:
30+
for key, value in config["options.extras_require"].items():
31+
extras_require[key] = [v for v in value.split("\n") if v.strip()]
32+
2433
BASE_DIR = os.path.dirname(__file__)
25-
VERSION_FILENAME = os.path.join(
26-
BASE_DIR, "src", "opentelemetry", "instrumentation", "aiopg", "version.py"
34+
PACKAGE_FILENAME = os.path.join(
35+
BASE_DIR, "src", "opentelemetry", "instrumentation", "aiopg", "package.py"
2736
)
2837
PACKAGE_INFO = {}
29-
with open(VERSION_FILENAME) as f:
38+
with open(PACKAGE_FILENAME) as f:
3039
exec(f.read(), PACKAGE_INFO)
3140

32-
setuptools.setup(version=PACKAGE_INFO["__version__"])
41+
extras_require["instruments"] = PACKAGE_INFO["_instruments"]
42+
test_deps = extras_require.get("test", [])
43+
for dep in extras_require["instruments"]:
44+
test_deps.append(dep)
45+
46+
extras_require["test"] = test_deps
47+
48+
setuptools.setup(
49+
version=PACKAGE_INFO["__version__"], extras_require=extras_require
50+
)

instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/__init__.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,14 @@
4545
---
4646
"""
4747

48+
from typing import Collection
49+
4850
from opentelemetry.instrumentation.aiopg import wrappers
49-
from opentelemetry.instrumentation.aiopg.version import __version__
51+
from opentelemetry.instrumentation.aiopg.package import __version__
5052
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
5153

54+
from . import package as pkg
55+
5256

5357
class AiopgInstrumentor(BaseInstrumentor):
5458
_CONNECTION_ATTRIBUTES = {
@@ -60,6 +64,9 @@ class AiopgInstrumentor(BaseInstrumentor):
6064

6165
_DATABASE_SYSTEM = "postgresql"
6266

67+
def instrumentation_dependencies(self) -> Collection[str]:
68+
return pkg._instruments
69+
6370
def _instrument(self, **kwargs):
6471
"""Integrate with PostgreSQL aiopg library.
6572
aiopg: https://github.com/aio-libs/aiopg
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright The OpenTelemetry Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
__version__ = "0.21.dev0"
16+
17+
_instruments = ("aiopg >= 0.13.0",)

instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/wrappers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
AiopgIntegration,
4141
get_traced_connection_proxy,
4242
)
43-
from opentelemetry.instrumentation.aiopg.version import __version__
43+
from opentelemetry.instrumentation.aiopg.package import __version__
4444
from opentelemetry.instrumentation.utils import unwrap
4545
from opentelemetry.trace import TracerProvider
4646

instrumentation/opentelemetry-instrumentation-asgi/setup.cfg

-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ install_requires =
4141
opentelemetry-api == 1.2.0.dev0
4242
opentelemetry-semantic-conventions == 0.21.dev0
4343
opentelemetry-instrumentation == 0.21.dev0
44-
asgiref ~= 3.0
4544

4645
[options.extras_require]
4746
test =

instrumentation/opentelemetry-instrumentation-asgi/setup.py

+23-5
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,38 @@
1313
# limitations under the License.
1414

1515

16-
# DO NOT EDIT. THIS FILE WAS AUTOGENERATED FROM templaes/asgi.
16+
# DO NOT EDIT. THIS FILE WAS AUTOGENERATED FROM templates/asgi.
1717
# Run `python scripts/generate_setuppy.py` to regenerate.
1818

1919

2020
import os
21+
from configparser import ConfigParser
2122

2223
import setuptools
2324

25+
config = ConfigParser()
26+
config.read("setup.cfg")
27+
28+
extras_require = {}
29+
if "options.extras_require" in config:
30+
for key, value in config["options.extras_require"].items():
31+
extras_require[key] = [v for v in value.split("\n") if v.strip()]
32+
2433
BASE_DIR = os.path.dirname(__file__)
25-
VERSION_FILENAME = os.path.join(
26-
BASE_DIR, "src", "opentelemetry", "instrumentation", "asgi", "version.py"
34+
PACKAGE_FILENAME = os.path.join(
35+
BASE_DIR, "src", "opentelemetry", "instrumentation", "asgi", "package.py"
2736
)
2837
PACKAGE_INFO = {}
29-
with open(VERSION_FILENAME) as f:
38+
with open(PACKAGE_FILENAME) as f:
3039
exec(f.read(), PACKAGE_INFO)
3140

32-
setuptools.setup(version=PACKAGE_INFO["__version__"])
41+
extras_require["instruments"] = PACKAGE_INFO["_instruments"]
42+
test_deps = extras_require.get("test", [])
43+
for dep in extras_require["instruments"]:
44+
test_deps.append(dep)
45+
46+
extras_require["test"] = test_deps
47+
48+
setuptools.setup(
49+
version=PACKAGE_INFO["__version__"], extras_require=extras_require
50+
)

instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from asgiref.compatibility import guarantee_single_callable
2727

2828
from opentelemetry import context, trace
29-
from opentelemetry.instrumentation.asgi.version import __version__ # noqa
29+
from opentelemetry.instrumentation.asgi.package import __version__ # noqa
3030
from opentelemetry.instrumentation.utils import http_status_to_status_code
3131
from opentelemetry.propagate import extract
3232
from opentelemetry.propagators.textmap import Getter
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright The OpenTelemetry Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
__version__ = "0.21.dev0"
16+
17+
_instruments = ("asgiref ~= 3.0",)

instrumentation/opentelemetry-instrumentation-asyncpg/setup.cfg

-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ install_requires =
4141
opentelemetry-api == 1.2.0.dev0
4242
opentelemetry-semantic-conventions == 0.21.dev0
4343
opentelemetry-instrumentation == 0.21.dev0
44-
asyncpg >= 0.12.0
4544

4645
[options.extras_require]
4746
test =

instrumentation/opentelemetry-instrumentation-asyncpg/setup.py

+23-5
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,43 @@
1313
# limitations under the License.
1414

1515

16-
# DO NOT EDIT. THIS FILE WAS AUTOGENERATED FROM templaes/asyncpg.
16+
# DO NOT EDIT. THIS FILE WAS AUTOGENERATED FROM templates/asyncpg.
1717
# Run `python scripts/generate_setuppy.py` to regenerate.
1818

1919

2020
import os
21+
from configparser import ConfigParser
2122

2223
import setuptools
2324

25+
config = ConfigParser()
26+
config.read("setup.cfg")
27+
28+
extras_require = {}
29+
if "options.extras_require" in config:
30+
for key, value in config["options.extras_require"].items():
31+
extras_require[key] = [v for v in value.split("\n") if v.strip()]
32+
2433
BASE_DIR = os.path.dirname(__file__)
25-
VERSION_FILENAME = os.path.join(
34+
PACKAGE_FILENAME = os.path.join(
2635
BASE_DIR,
2736
"src",
2837
"opentelemetry",
2938
"instrumentation",
3039
"asyncpg",
31-
"version.py",
40+
"package.py",
3241
)
3342
PACKAGE_INFO = {}
34-
with open(VERSION_FILENAME) as f:
43+
with open(PACKAGE_FILENAME) as f:
3544
exec(f.read(), PACKAGE_INFO)
3645

37-
setuptools.setup(version=PACKAGE_INFO["__version__"])
46+
extras_require["instruments"] = PACKAGE_INFO["_instruments"]
47+
test_deps = extras_require.get("test", [])
48+
for dep in extras_require["instruments"]:
49+
test_deps.append(dep)
50+
51+
extras_require["test"] = test_deps
52+
53+
setuptools.setup(
54+
version=PACKAGE_INFO["__version__"], extras_require=extras_require
55+
)

0 commit comments

Comments
 (0)