Skip to content

Commit

Permalink
Update tooling (open-telemetry#1330)
Browse files Browse the repository at this point in the history
  • Loading branch information
srikanthccv committed Sep 15, 2022
1 parent 273ae3c commit 6753c87
Show file tree
Hide file tree
Showing 20 changed files with 112 additions and 277 deletions.
1 change: 0 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[run]
omit =
*/tests/*
*/setup.py
*/gen/*
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ exclude =
docs/examples/opentelemetry-example-app/build/*
opentelemetry-proto/build/*
opentelemetry-proto/src/opentelemetry/proto/
scripts/*
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extension-pkg-whitelist=

# Add list of files or directories to be excluded. They should be base names, not
# paths.
ignore=CVS,gen,Dockerfile,docker-compose.yml,README.md,requirements.txt
ignore=CVS,gen,Dockerfile,docker-compose.yml,README.md,requirements.txt,docs

# Add files or directories matching the regex patterns to be excluded. The
# regex matches against base names, not paths.
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ Below is a checklist of things to be mindful of when implementing a new instrume
- The instrumentation should follow the semantic conventions defined [here](https://github.com/open-telemetry/opentelemetry-specification/tree/main/semantic_conventions)
- Extends from [BaseInstrumentor](https://github.com/open-telemetry/opentelemetry-python-contrib/blob/main/opentelemetry-instrumentation/src/opentelemetry/instrumentation/instrumentor.py#L26)
- Supports auto-instrumentation
- Add an entry point (ex. https://github.com/open-telemetry/opentelemetry-python-contrib/blob/main/instrumentation/opentelemetry-instrumentation-requests/setup.cfg#L56)
- Run `python scripts/setup.py` followed by `python scripts/generate_instrumentation_bootstrap.py` after adding a new instrumentation package.
- Add an entry point (ex. https://github.com/open-telemetry/opentelemetry-python-contrib/blob/f045c43affff6ff1af8fa2f7514a4fdaca97dacf/instrumentation/opentelemetry-instrumentation-requests/pyproject.toml#L44)
- Run `python scripts/generate_instrumentation_bootstrap.py` after adding a new instrumentation package.
- Functionality that is common amongst other instrumentation and can be abstracted [here](https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/opentelemetry-instrumentation/src/opentelemetry/instrumentation)
- Request/response [hooks](https://github.com/open-telemetry/opentelemetry-python-contrib/issues/408) for http instrumentations
- `suppress_instrumentation` functionality
Expand Down
12 changes: 5 additions & 7 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,11 @@ def getlistcfg(strval):
scm_web = "https://github.com/" + REPO + "blob/" + branch

# Store variables in the epilogue so they are globally available.
rst_epilog = """
.. |SCM_WEB| replace:: {s}
.. |SCM_RAW_WEB| replace:: {sr}
.. |SCM_BRANCH| replace:: {b}
""".format(
s=scm_web, sr=scm_raw_web, b=branch
)
rst_epilog = f"""
.. |SCM_WEB| replace:: {scm_web}
.. |SCM_RAW_WEB| replace:: {scm_raw_web}
.. |SCM_BRANCH| replace:: {branch}
"""

# used to have links to repo files
extlinks = {
Expand Down
3 changes: 3 additions & 0 deletions gen-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ markupsafe==2.0.1
isort
black
requests
tomli
tomli_w
hatch
116 changes: 61 additions & 55 deletions opentelemetry-contrib-instrumentations/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,70 +1,74 @@
[build-system]
requires = ["hatchling"]
requires = [
"hatchling",
]
build-backend = "hatchling.build"

[project]
name = "opentelemetry-contrib-instrumentations"
dynamic = ["version"]
dynamic = [
"version",
]
description = "OpenTelemetry Contrib Instrumentation Packages"
readme = "README.rst"
license = "Apache-2.0"
requires-python = ">=3.7"
authors = [
{ name = "OpenTelemetry Authors", email = "cncf-opentelemetry-contributors@lists.cncf.io" },
{ 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",
"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-instrumentation-aio-pika==0.33b0",
"opentelemetry-instrumentation-aiohttp-client==0.33b0",
"opentelemetry-instrumentation-aiopg==0.33b0",
"opentelemetry-instrumentation-asgi==0.33b0",
"opentelemetry-instrumentation-asyncpg==0.33b0",
"opentelemetry-instrumentation-aws-lambda==0.33b0",
"opentelemetry-instrumentation-boto3sqs==0.33b0",
"opentelemetry-instrumentation-boto==0.33b0",
"opentelemetry-instrumentation-botocore==0.33b0",
"opentelemetry-instrumentation-celery==0.33b0",
"opentelemetry-instrumentation-confluent-kafka==0.33b0",
"opentelemetry-instrumentation-dbapi==0.33b0",
"opentelemetry-instrumentation-django==0.33b0",
"opentelemetry-instrumentation-elasticsearch==0.33b0",
"opentelemetry-instrumentation-falcon==0.33b0",
"opentelemetry-instrumentation-fastapi==0.33b0",
"opentelemetry-instrumentation-flask==0.33b0",
"opentelemetry-instrumentation-grpc==0.33b0",
"opentelemetry-instrumentation-httpx==0.33b0",
"opentelemetry-instrumentation-jinja2==0.33b0",
"opentelemetry-instrumentation-kafka-python==0.33b0",
"opentelemetry-instrumentation-logging==0.33b0",
"opentelemetry-instrumentation-mysql==0.33b0",
"opentelemetry-instrumentation-pika==0.33b0",
"opentelemetry-instrumentation-psycopg2==0.33b0",
"opentelemetry-instrumentation-pymemcache==0.33b0",
"opentelemetry-instrumentation-pymongo==0.33b0",
"opentelemetry-instrumentation-pymysql==0.33b0",
"opentelemetry-instrumentation-pyramid==0.33b0",
"opentelemetry-instrumentation-redis==0.33b0",
"opentelemetry-instrumentation-remoulade==0.33b0",
"opentelemetry-instrumentation-requests==0.33b0",
"opentelemetry-instrumentation-sklearn==0.33b0",
"opentelemetry-instrumentation-sqlalchemy==0.33b0",
"opentelemetry-instrumentation-sqlite3==0.33b0",
"opentelemetry-instrumentation-starlette==0.33b0",
"opentelemetry-instrumentation-system-metrics==0.33b0",
"opentelemetry-instrumentation-tornado==0.33b0",
"opentelemetry-instrumentation-urllib3==0.33b0",
"opentelemetry-instrumentation-urllib==0.33b0",
"opentelemetry-instrumentation-wsgi==0.33b0",
"opentelemetry-instrumentation-aio-pika==0.33b0",
"opentelemetry-instrumentation-aiohttp-client==0.33b0",
"opentelemetry-instrumentation-aiopg==0.33b0",
"opentelemetry-instrumentation-asgi==0.33b0",
"opentelemetry-instrumentation-asyncpg==0.33b0",
"opentelemetry-instrumentation-aws-lambda==0.33b0",
"opentelemetry-instrumentation-boto==0.33b0",
"opentelemetry-instrumentation-boto3sqs==0.33b0",
"opentelemetry-instrumentation-botocore==0.33b0",
"opentelemetry-instrumentation-celery==0.33b0",
"opentelemetry-instrumentation-confluent-kafka==0.33b0",
"opentelemetry-instrumentation-dbapi==0.33b0",
"opentelemetry-instrumentation-django==0.33b0",
"opentelemetry-instrumentation-elasticsearch==0.33b0",
"opentelemetry-instrumentation-falcon==0.33b0",
"opentelemetry-instrumentation-fastapi==0.33b0",
"opentelemetry-instrumentation-flask==0.33b0",
"opentelemetry-instrumentation-grpc==0.33b0",
"opentelemetry-instrumentation-httpx==0.33b0",
"opentelemetry-instrumentation-jinja2==0.33b0",
"opentelemetry-instrumentation-kafka-python==0.33b0",
"opentelemetry-instrumentation-logging==0.33b0",
"opentelemetry-instrumentation-mysql==0.33b0",
"opentelemetry-instrumentation-pika==0.33b0",
"opentelemetry-instrumentation-psycopg2==0.33b0",
"opentelemetry-instrumentation-pymemcache==0.33b0",
"opentelemetry-instrumentation-pymongo==0.33b0",
"opentelemetry-instrumentation-pymysql==0.33b0",
"opentelemetry-instrumentation-pyramid==0.33b0",
"opentelemetry-instrumentation-redis==0.33b0",
"opentelemetry-instrumentation-remoulade==0.33b0",
"opentelemetry-instrumentation-requests==0.33b0",
"opentelemetry-instrumentation-sklearn==0.33b0",
"opentelemetry-instrumentation-sqlalchemy==0.33b0",
"opentelemetry-instrumentation-sqlite3==0.33b0",
"opentelemetry-instrumentation-starlette==0.33b0",
"opentelemetry-instrumentation-system-metrics==0.33b0",
"opentelemetry-instrumentation-tornado==0.33b0",
"opentelemetry-instrumentation-urllib==0.33b0",
"opentelemetry-instrumentation-urllib3==0.33b0",
"opentelemetry-instrumentation-wsgi==0.33b0",
]

[project.optional-dependencies]
Expand All @@ -78,8 +82,10 @@ path = "src/opentelemetry/contrib-instrumentations/version.py"

[tool.hatch.build.targets.sdist]
include = [
"/src",
"/src",
]

[tool.hatch.build.targets.wheel]
packages = ["src/opentelemetry"]
packages = [
"src/opentelemetry",
]
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def is_instrumented_by_opentelemetry(self):
def instrumentation_dependencies(self) -> Collection[str]:
"""Return a list of python packages with versions that the will be instrumented.
The format should be the same as used in requirements.txt or setup.py.
The format should be the same as used in requirements.txt or pyproject.toml.
For example, if an instrumentation instruments requests 1.x, this method should look
like:
Expand Down
8 changes: 4 additions & 4 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
set -ev

# Get the latest versions of packaging tools
python3 -m pip install --upgrade pip setuptools wheel
python3 -m pip install --upgrade pip build setuptools wheel

BASEDIR=$(dirname $(readlink -f $(dirname $0)))
DISTDIR=dist
Expand All @@ -21,9 +21,9 @@ DISTDIR=dist
echo "building $d"
cd "$d"
# Some ext directories (such as docker tests) are not intended to be
# packaged. Verify the intent by looking for a setup.py.
if [ -f setup.py ]; then
python3 setup.py sdist --dist-dir "$BASEDIR/dist/" clean --all
# packaged. Verify the intent by looking for a pyproject.toml.
if [ -f pyproject.toml ]; then
python3 -m build --outdir "$BASEDIR/dist/"
fi
)
done
Expand Down
10 changes: 5 additions & 5 deletions scripts/build_a_package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ distdir=${basedir}/dist
mkdir -p $distdir
rm -rf $distdir/*

setup_py_file_path=$(ls **/$pkg_name/setup.py)
pyproject_toml_file_path=$(ls **/$pkg_name/pyproject.toml)

if [ -z $setup_py_file_path ]; then
echo "Error! setup.py not found for $pkg_name, can't build."
if [ -z $pyproject_toml_file_path ]; then
echo "Error! pyproject.toml not found for $pkg_name, can't build."
exit -1
fi

directory_with_package=$(dirname $setup_py_file_path)
directory_with_package=$(dirname $pyproject_toml_file_path)

cd $directory_with_package

python3 setup.py sdist --dist-dir ${distdir} clean --all
python3 -m build --outdir ${distdir}

cd $distdir

Expand Down
1 change: 0 additions & 1 deletion scripts/check_for_valid_readme.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def main():
print("FAILED: RST syntax errors in", readme)
continue
except FileNotFoundError:
error = True
print("FAILED: README.rst not found in", path)
continue
if args.verbose:
Expand Down
1 change: 0 additions & 1 deletion scripts/coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ set -e

function cov {
pytest \
--ignore-glob=*/setup.py \
--cov ${1} \
--cov-append \
--cov-branch \
Expand Down
4 changes: 2 additions & 2 deletions scripts/eachdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def parse_args(args=None):
commands according to `format` and `--all`.
Target paths are initially all Python distribution root paths
(as determined by the existence of setup.py, etc. files).
(as determined by the existence of pyproject.toml, etc. files).
They are then augmented according to the section of the
`PROJECT_ROOT/eachdist.ini` config file specified by the `--mode` option.
Expand Down Expand Up @@ -282,7 +282,7 @@ def find_targets_unordered(rootpath):
continue
if any(
(subdir / marker).exists()
for marker in ("setup.py", "pyproject.toml")
for marker in ("pyproject.toml")
):
yield subdir
else:
Expand Down
5 changes: 0 additions & 5 deletions scripts/generate_instrumentation_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("instrumentation_list_generator")

_auto_generation_msg = """
# DO NOT EDIT. THIS FILE WAS AUTOGENERATED FROM templates/{source}.
# RUN `python scripts/generate_setup.py` TO REGENERATE.
"""

_template = """
{header}
Expand Down
20 changes: 11 additions & 9 deletions scripts/generate_instrumentation_metapackage.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

import logging
import os
from configparser import ConfigParser

import tomli
import tomli_w

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("instrumentation_metapackage_generator")
Expand Down Expand Up @@ -65,17 +67,17 @@ def get_instrumentation_packages():
def main():
dependencies = get_instrumentation_packages()

setup_cfg_path = os.path.join(
root_path, "opentelemetry-contrib-instrumentations", "setup.cfg"
pyproject_toml_path = os.path.join(
root_path, "opentelemetry-contrib-instrumentations", "pyproject.toml"
)
config = ConfigParser()
config.read(setup_cfg_path)

deps = "\n".join(f"{pkg}=={version}" for pkg, version in dependencies)
deps = [f"{pkg}=={version}" for pkg, version in dependencies]
with open(pyproject_toml_path, "rb") as file:
pyproject_toml = tomli.load(file)

config["options"]["install_requires"] = "\n" + deps
with open(setup_cfg_path, "w", encoding="utf-8") as fh:
config.write(fh)
pyproject_toml["project"]["dependencies"] = deps
with open(pyproject_toml_path, "wb") as fh:
tomli_w.dump(pyproject_toml, fh)


if __name__ == "__main__":
Expand Down
Loading

0 comments on commit 6753c87

Please sign in to comment.