Skip to content

Commit daa7238

Browse files
authored
Instrumentation runtime checks (#475)
1 parent 9fe7838 commit daa7238

File tree

139 files changed

+2005
-156
lines changed

Some content is hidden

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

139 files changed

+2005
-156
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
@@ -21,6 +21,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121
## [0.21b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.2.0-0.21b0) - 2021-05-11
2222

2323
### Changed
24+
- Instrumentation packages don't specify the libraries they instrument as dependencies
25+
anymore. Instead, they verify the correct version of libraries are installed at runtime.
26+
([#475](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/475))
2427
- `opentelemetry-propagator-ot-trace` Use `TraceFlags` object in `extract`
2528
([#472](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/472))
2629
- Set the `traced_request_attrs` of FalconInstrumentor by an argument correctly.

exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/spanprocessor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def export(self) -> None:
186186
self.flush_condition.notify()
187187

188188
def _drain_queue(self):
189-
""""Export all elements until queue is empty.
189+
"""Export all elements until queue is empty.
190190
191191
Can only be called from the worker thread context because it invokes
192192
`export` that is not thread safe.

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.3.0.dev0
4242
opentelemetry-semantic-conventions == 0.22.dev0
4343
opentelemetry-instrumentation == 0.22.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

+36-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,24 @@
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+
# We provide extras_require parameter to setuptools.setup later which
29+
# overwrites the extra_require section from setup.cfg. To support extra_require
30+
# secion in setup.cfg, we load it here and merge it with the extra_require param.
31+
extras_require = {}
32+
if "options.extras_require" in config:
33+
for key, value in config["options.extras_require"].items():
34+
extras_require[key] = [v for v in value.split("\n") if v.strip()]
35+
2436
BASE_DIR = os.path.dirname(__file__)
37+
PACKAGE_INFO = {}
38+
2539
VERSION_FILENAME = os.path.join(
2640
BASE_DIR,
2741
"src",
@@ -30,8 +44,28 @@
3044
"aiohttp_client",
3145
"version.py",
3246
)
33-
PACKAGE_INFO = {}
3447
with open(VERSION_FILENAME) as f:
3548
exec(f.read(), PACKAGE_INFO)
3649

37-
setuptools.setup(version=PACKAGE_INFO["__version__"])
50+
PACKAGE_FILENAME = os.path.join(
51+
BASE_DIR,
52+
"src",
53+
"opentelemetry",
54+
"instrumentation",
55+
"aiohttp_client",
56+
"package.py",
57+
)
58+
with open(PACKAGE_FILENAME) as f:
59+
exec(f.read(), PACKAGE_INFO)
60+
61+
# Mark any instruments/runtime dependencies as test dependencies as well.
62+
extras_require["instruments"] = PACKAGE_INFO["_instruments"]
63+
test_deps = extras_require.get("test", [])
64+
for dep in extras_require["instruments"]:
65+
test_deps.append(dep)
66+
67+
extras_require["test"] = test_deps
68+
69+
setuptools.setup(
70+
version=PACKAGE_INFO["__version__"], extras_require=extras_require
71+
)

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

+5
Original file line numberDiff line numberDiff line change
@@ -64,12 +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
74+
from opentelemetry.instrumentation.aiohttp_client.package import _instruments
7375
from opentelemetry.instrumentation.aiohttp_client.version import __version__
7476
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
7577
from opentelemetry.instrumentation.utils import (
@@ -288,6 +290,9 @@ class AioHttpClientInstrumentor(BaseInstrumentor):
288290
See `BaseInstrumentor`
289291
"""
290292

293+
def instrumentation_dependencies(self) -> Collection[str]:
294+
return _instruments
295+
291296
def _instrument(self, **kwargs):
292297
"""Instruments aiohttp ClientSession
293298
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright 2020, 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+
16+
_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.22.dev0
4343
opentelemetry-instrumentation-dbapi == 0.22.dev0
4444
opentelemetry-instrumentation == 0.22.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

+31-2
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,44 @@
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+
# We provide extras_require parameter to setuptools.setup later which
29+
# overwrites the extra_require section from setup.cfg. To support extra_require
30+
# secion in setup.cfg, we load it here and merge it with the extra_require param.
31+
extras_require = {}
32+
if "options.extras_require" in config:
33+
for key, value in config["options.extras_require"].items():
34+
extras_require[key] = [v for v in value.split("\n") if v.strip()]
35+
2436
BASE_DIR = os.path.dirname(__file__)
37+
PACKAGE_INFO = {}
38+
2539
VERSION_FILENAME = os.path.join(
2640
BASE_DIR, "src", "opentelemetry", "instrumentation", "aiopg", "version.py"
2741
)
28-
PACKAGE_INFO = {}
2942
with open(VERSION_FILENAME) as f:
3043
exec(f.read(), PACKAGE_INFO)
3144

32-
setuptools.setup(version=PACKAGE_INFO["__version__"])
45+
PACKAGE_FILENAME = os.path.join(
46+
BASE_DIR, "src", "opentelemetry", "instrumentation", "aiopg", "package.py"
47+
)
48+
with open(PACKAGE_FILENAME) as f:
49+
exec(f.read(), PACKAGE_INFO)
50+
51+
# Mark any instruments/runtime dependencies as test dependencies as well.
52+
extras_require["instruments"] = PACKAGE_INFO["_instruments"]
53+
test_deps = extras_require.get("test", [])
54+
for dep in extras_require["instruments"]:
55+
test_deps.append(dep)
56+
57+
extras_require["test"] = test_deps
58+
59+
setuptools.setup(
60+
version=PACKAGE_INFO["__version__"], extras_require=extras_require
61+
)

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

+6
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@
4545
---
4646
"""
4747

48+
from typing import Collection
49+
4850
from opentelemetry.instrumentation.aiopg import wrappers
51+
from opentelemetry.instrumentation.aiopg.package import _instruments
4952
from opentelemetry.instrumentation.aiopg.version import __version__
5053
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
5154

@@ -60,6 +63,9 @@ class AiopgInstrumentor(BaseInstrumentor):
6063

6164
_DATABASE_SYSTEM = "postgresql"
6265

66+
def instrumentation_dependencies(self) -> Collection[str]:
67+
return _instruments
68+
6369
def _instrument(self, **kwargs):
6470
"""Integrate with PostgreSQL aiopg library.
6571
aiopg: https://github.com/aio-libs/aiopg
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
16+
_instruments = ("aiopg >= 0.13.0",)

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.3.0.dev0
4242
opentelemetry-semantic-conventions == 0.22.dev0
4343
opentelemetry-instrumentation == 0.22.dev0
44-
asgiref ~= 3.0
4544

4645
[options.extras_require]
4746
test =

instrumentation/opentelemetry-instrumentation-asgi/setup.py

+31-2
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,44 @@
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+
# We provide extras_require parameter to setuptools.setup later which
29+
# overwrites the extra_require section from setup.cfg. To support extra_require
30+
# secion in setup.cfg, we load it here and merge it with the extra_require param.
31+
extras_require = {}
32+
if "options.extras_require" in config:
33+
for key, value in config["options.extras_require"].items():
34+
extras_require[key] = [v for v in value.split("\n") if v.strip()]
35+
2436
BASE_DIR = os.path.dirname(__file__)
37+
PACKAGE_INFO = {}
38+
2539
VERSION_FILENAME = os.path.join(
2640
BASE_DIR, "src", "opentelemetry", "instrumentation", "asgi", "version.py"
2741
)
28-
PACKAGE_INFO = {}
2942
with open(VERSION_FILENAME) as f:
3043
exec(f.read(), PACKAGE_INFO)
3144

32-
setuptools.setup(version=PACKAGE_INFO["__version__"])
45+
PACKAGE_FILENAME = os.path.join(
46+
BASE_DIR, "src", "opentelemetry", "instrumentation", "asgi", "package.py"
47+
)
48+
with open(PACKAGE_FILENAME) as f:
49+
exec(f.read(), PACKAGE_INFO)
50+
51+
# Mark any instruments/runtime dependencies as test dependencies as well.
52+
extras_require["instruments"] = PACKAGE_INFO["_instruments"]
53+
test_deps = extras_require.get("test", [])
54+
for dep in extras_require["instruments"]:
55+
test_deps.append(dep)
56+
57+
extras_require["test"] = test_deps
58+
59+
setuptools.setup(
60+
version=PACKAGE_INFO["__version__"], extras_require=extras_require
61+
)

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ def collect_request_attributes(scope):
112112

113113

114114
def get_host_port_url_tuple(scope):
115-
"""Returns (host, port, full_url) tuple.
116-
"""
115+
"""Returns (host, port, full_url) tuple."""
117116
server = scope.get("server") or ["0.0.0.0", 80]
118117
port = server[1]
119118
server_host = server[0] + (":" + str(port) if port != 80 else "")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
16+
_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.3.0.dev0
4242
opentelemetry-semantic-conventions == 0.22.dev0
4343
opentelemetry-instrumentation == 0.22.dev0
44-
asyncpg >= 0.12.0
4544

4645
[options.extras_require]
4746
test =

instrumentation/opentelemetry-instrumentation-asyncpg/setup.py

+36-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,24 @@
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+
# We provide extras_require parameter to setuptools.setup later which
29+
# overwrites the extra_require section from setup.cfg. To support extra_require
30+
# secion in setup.cfg, we load it here and merge it with the extra_require param.
31+
extras_require = {}
32+
if "options.extras_require" in config:
33+
for key, value in config["options.extras_require"].items():
34+
extras_require[key] = [v for v in value.split("\n") if v.strip()]
35+
2436
BASE_DIR = os.path.dirname(__file__)
37+
PACKAGE_INFO = {}
38+
2539
VERSION_FILENAME = os.path.join(
2640
BASE_DIR,
2741
"src",
@@ -30,8 +44,28 @@
3044
"asyncpg",
3145
"version.py",
3246
)
33-
PACKAGE_INFO = {}
3447
with open(VERSION_FILENAME) as f:
3548
exec(f.read(), PACKAGE_INFO)
3649

37-
setuptools.setup(version=PACKAGE_INFO["__version__"])
50+
PACKAGE_FILENAME = os.path.join(
51+
BASE_DIR,
52+
"src",
53+
"opentelemetry",
54+
"instrumentation",
55+
"asyncpg",
56+
"package.py",
57+
)
58+
with open(PACKAGE_FILENAME) as f:
59+
exec(f.read(), PACKAGE_INFO)
60+
61+
# Mark any instruments/runtime dependencies as test dependencies as well.
62+
extras_require["instruments"] = PACKAGE_INFO["_instruments"]
63+
test_deps = extras_require.get("test", [])
64+
for dep in extras_require["instruments"]:
65+
test_deps.append(dep)
66+
67+
extras_require["test"] = test_deps
68+
69+
setuptools.setup(
70+
version=PACKAGE_INFO["__version__"], extras_require=extras_require
71+
)

0 commit comments

Comments
 (0)