Skip to content

Commit

Permalink
Instrumentation: Use runtime dependency checks
Browse files Browse the repository at this point in the history
  • Loading branch information
owais committed Apr 28, 2021
1 parent ab36898 commit 5b811ae
Show file tree
Hide file tree
Showing 159 changed files with 1,525 additions and 647 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
uses: actions/cache@v2
with:
path: .tox
key: tox-cache-${{ env.RUN_MATRIX_COMBINATION }}-${{ hashFiles('tox.ini', 'dev-requirements.txt') }}
key: v2-build-tox-cache-${{ env.RUN_MATRIX_COMBINATION }}-${{ hashFiles('tox.ini', 'dev-requirements.txt') }}
- name: run tox
run: tox -f ${{ matrix.python-version }}-${{ matrix.package }} -- --benchmark-json=${{ env.RUN_MATRIX_COMBINATION }}-benchmark.json
- name: Find and merge benchmarks
Expand Down Expand Up @@ -99,6 +99,6 @@ jobs:
uses: actions/cache@v2
with:
path: .tox
key: v2-tox-cache-${{ matrix.tox-environment }}-${{ hashFiles('tox.ini', 'dev-requirements.txt', 'docs-requirements.txt') }}
key: v2-misc-tox-cache-${{ matrix.tox-environment }}-${{ hashFiles('tox.ini', 'dev-requirements.txt', 'docs-requirements.txt') }}
- name: run tox
run: tox -e ${{ matrix.tox-environment }}
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased](https://github.com/open-telemetry/opentelemetry-python-contrib/compare/v0.200...HEAD)

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ install_requires =
opentelemetry-api == 1.2.0.dev0
opentelemetry-semantic-conventions == 0.21.dev0
opentelemetry-instrumentation == 0.21.dev0
aiohttp ~= 3.0
wrapt >= 1.0.0, < 2.0.0

[options.packages.find]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,43 @@
# limitations under the License.


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


import os
from configparser import ConfigParser

import setuptools

config = ConfigParser()
config.read("setup.cfg")

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__)
VERSION_FILENAME = os.path.join(
PACKAGE_FILENAME = os.path.join(
BASE_DIR,
"src",
"opentelemetry",
"instrumentation",
"aiohttp_client",
"version.py",
"package.py",
)
PACKAGE_INFO = {}
with open(VERSION_FILENAME) as f:
with open(PACKAGE_FILENAME) as f:
exec(f.read(), PACKAGE_INFO)

setuptools.setup(version=PACKAGE_INFO["__version__"])
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

setuptools.setup(
version=PACKAGE_INFO["__version__"], extras_require=extras_require
)
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,14 @@ def strip_query_params(url: yarl.URL) -> str:

import types
import typing
from typing import Collection

import aiohttp
import wrapt

from opentelemetry import context as context_api
from opentelemetry import trace
from opentelemetry.instrumentation.aiohttp_client.version import __version__
from opentelemetry.instrumentation.aiohttp_client.package import __version__
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
from opentelemetry.instrumentation.utils import (
http_status_to_status_code,
Expand All @@ -81,6 +82,8 @@ def strip_query_params(url: yarl.URL) -> str:
from opentelemetry.trace import SpanKind, TracerProvider, get_tracer
from opentelemetry.trace.status import Status, StatusCode

from . import package as pkg

_UrlFilterT = typing.Optional[typing.Callable[[str], str]]
_SpanNameT = typing.Optional[
typing.Union[typing.Callable[[aiohttp.TraceRequestStartParams], str], str]
Expand Down Expand Up @@ -288,6 +291,9 @@ class AioHttpClientInstrumentor(BaseInstrumentor):
See `BaseInstrumentor`
"""

def instrumentation_dependencies(self) -> Collection[str]:
return pkg._instruments

def _instrument(self, **kwargs):
"""Instruments aiohttp ClientSession
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@
# limitations under the License.

__version__ = "0.21.dev0"

_instruments = ("aiohttp ~= 3.0",)
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ install_requires =
opentelemetry-semantic-conventions == 0.21.dev0
opentelemetry-instrumentation-dbapi == 0.21.dev0
opentelemetry-instrumentation == 0.21.dev0
aiopg >= 0.13.0
wrapt >= 1.0.0, < 2.0.0

[options.extras_require]
Expand Down
28 changes: 23 additions & 5 deletions instrumentation/opentelemetry-instrumentation-aiopg/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,38 @@
# limitations under the License.


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


import os
from configparser import ConfigParser

import setuptools

config = ConfigParser()
config.read("setup.cfg")

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__)
VERSION_FILENAME = os.path.join(
BASE_DIR, "src", "opentelemetry", "instrumentation", "aiopg", "version.py"
PACKAGE_FILENAME = os.path.join(
BASE_DIR, "src", "opentelemetry", "instrumentation", "aiopg", "package.py"
)
PACKAGE_INFO = {}
with open(VERSION_FILENAME) as f:
with open(PACKAGE_FILENAME) as f:
exec(f.read(), PACKAGE_INFO)

setuptools.setup(version=PACKAGE_INFO["__version__"])
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

setuptools.setup(
version=PACKAGE_INFO["__version__"], extras_require=extras_require
)
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,14 @@
---
"""

from typing import Collection

from opentelemetry.instrumentation.aiopg import wrappers
from opentelemetry.instrumentation.aiopg.version import __version__
from opentelemetry.instrumentation.aiopg.package import __version__
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor

from . import package as pkg


class AiopgInstrumentor(BaseInstrumentor):
_CONNECTION_ATTRIBUTES = {
Expand All @@ -60,6 +64,9 @@ class AiopgInstrumentor(BaseInstrumentor):

_DATABASE_SYSTEM = "postgresql"

def instrumentation_dependencies(self) -> Collection[str]:
return pkg._instruments

def _instrument(self, **kwargs):
"""Integrate with PostgreSQL aiopg library.
aiopg: https://github.com/aio-libs/aiopg
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +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.

__version__ = "0.21.dev0"

_instruments = ("aiopg >= 0.13.0",)
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
AiopgIntegration,
get_traced_connection_proxy,
)
from opentelemetry.instrumentation.aiopg.version import __version__
from opentelemetry.instrumentation.aiopg.package import __version__
from opentelemetry.instrumentation.utils import unwrap
from opentelemetry.trace import TracerProvider

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ install_requires =
opentelemetry-api == 1.2.0.dev0
opentelemetry-semantic-conventions == 0.21.dev0
opentelemetry-instrumentation == 0.21.dev0
asgiref ~= 3.0

[options.extras_require]
test =
Expand Down
28 changes: 23 additions & 5 deletions instrumentation/opentelemetry-instrumentation-asgi/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,38 @@
# limitations under the License.


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


import os
from configparser import ConfigParser

import setuptools

config = ConfigParser()
config.read("setup.cfg")

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__)
VERSION_FILENAME = os.path.join(
BASE_DIR, "src", "opentelemetry", "instrumentation", "asgi", "version.py"
PACKAGE_FILENAME = os.path.join(
BASE_DIR, "src", "opentelemetry", "instrumentation", "asgi", "package.py"
)
PACKAGE_INFO = {}
with open(VERSION_FILENAME) as f:
with open(PACKAGE_FILENAME) as f:
exec(f.read(), PACKAGE_INFO)

setuptools.setup(version=PACKAGE_INFO["__version__"])
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

setuptools.setup(
version=PACKAGE_INFO["__version__"], extras_require=extras_require
)
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from asgiref.compatibility import guarantee_single_callable

from opentelemetry import context, trace
from opentelemetry.instrumentation.asgi.version import __version__ # noqa
from opentelemetry.instrumentation.asgi.package import __version__ # noqa
from opentelemetry.instrumentation.utils import http_status_to_status_code
from opentelemetry.propagate import extract
from opentelemetry.propagators.textmap import Getter
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +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.

__version__ = "0.21.dev0"

_instruments = ("asgiref ~= 3.0",)
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ install_requires =
opentelemetry-api == 1.2.0.dev0
opentelemetry-semantic-conventions == 0.21.dev0
opentelemetry-instrumentation == 0.21.dev0
asyncpg >= 0.12.0

[options.extras_require]
test =
Expand Down
28 changes: 23 additions & 5 deletions instrumentation/opentelemetry-instrumentation-asyncpg/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,43 @@
# limitations under the License.


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


import os
from configparser import ConfigParser

import setuptools

config = ConfigParser()
config.read("setup.cfg")

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__)
VERSION_FILENAME = os.path.join(
PACKAGE_FILENAME = os.path.join(
BASE_DIR,
"src",
"opentelemetry",
"instrumentation",
"asyncpg",
"version.py",
"package.py",
)
PACKAGE_INFO = {}
with open(VERSION_FILENAME) as f:
with open(PACKAGE_FILENAME) as f:
exec(f.read(), PACKAGE_INFO)

setuptools.setup(version=PACKAGE_INFO["__version__"])
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

setuptools.setup(
version=PACKAGE_INFO["__version__"], extras_require=extras_require
)
Loading

0 comments on commit 5b811ae

Please sign in to comment.