diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 832b294a94..2597b185d0 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -4,7 +4,7 @@ about: Create a report to help us improve labels: bug --- -**Describe your environment** Describe any aspect of your environment relevant to the problem, including your Python version, [platform](https://docs.python.org/3/library/platform.html), version numbers of installed dependencies, information about your cloud hosting provider, etc. If you're reporting a problem with a specific version of a library in this repo, please check whether the problem has been fixed on master. +**Describe your environment** Describe any aspect of your environment relevant to the problem, including your Python version, [platform](https://docs.python.org/3/library/platform.html), version numbers of installed dependencies, information about your cloud hosting provider, etc. If you're reporting a problem with a specific version of a library in this repo, please check whether the problem has been fixed on main. **Steps to reproduce** Describe exactly how to reproduce the error. Include a code sample if applicable. diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 47b8396378..b5b5de4610 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -26,7 +26,7 @@ Please describe the tests that you ran to verify your changes. Provide instructi # Checklist: -See [contributing.md](https://github.com/open-telemetry/opentelemetry-python-contrib/blob/master/CONTRIBUTING.md) for styleguide, changelog guidelines, and more. +See [contributing.md](https://github.com/open-telemetry/opentelemetry-python-contrib/blob/main/CONTRIBUTING.md) for styleguide, changelog guidelines, and more. - [ ] Followed the style guidelines of this project - [ ] Changelogs have been updated diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml index 7e4b1032a7..11e1a61fc5 100644 --- a/.github/workflows/changelog.yml +++ b/.github/workflows/changelog.yml @@ -1,4 +1,4 @@ -# This action requires that any PR targeting the master branch should touch at +# This action requires that any PR targeting the main branch should touch at # least one CHANGELOG file. If a CHANGELOG entry is not required, add the "Skip # Changelog" label to disable this action. @@ -8,7 +8,7 @@ on: pull_request: types: [opened, synchronize, reopened, labeled, unlabeled] branches: - - master + - main jobs: changelog: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 02406343a7..5c42f4a4e4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,7 +6,7 @@ on: - 'release/*' pull_request: env: - CORE_REPO_SHA: 2b188b9a43dfaa74c1a0a4514b91d1cb07d3075d + CORE_REPO_SHA: f3ee81243b4266729ba5196a7883ce897549aaba jobs: build: @@ -78,14 +78,14 @@ jobs: alert-threshold: 200% fail-on-alert: true # Make a commit on `gh-pages` with benchmarks from previous step - auto-push: ${{ github.ref == 'refs/heads/master' }} + auto-push: ${{ github.ref == 'refs/heads/main' }} gh-pages-branch: gh-pages benchmark-data-dir-path: benchmarks misc: strategy: fail-fast: false matrix: - tox-environment: [ "docker-tests", "lint" ] + tox-environment: [ "docker-tests", "lint", "docs" ] name: ${{ matrix.tox-environment }} runs-on: ubuntu-latest steps: diff --git a/.pylintrc b/.pylintrc index 9f767af293..2a2ad87040 100644 --- a/.pylintrc +++ b/.pylintrc @@ -78,7 +78,7 @@ disable=missing-docstring, protected-access, # temp-pylint-upgrade super-init-not-called, # temp-pylint-upgrade invalid-overridden-method, # temp-pylint-upgrade - missing-module-docstring, # temp-pylint-upgrad, # temp-pylint-upgradee + missing-module-docstring, # temp-pylint-upgrade # Enable the message, report, category or checker with the given id(s). You can # either give multiple identifier separated by comma (,) or put this option diff --git a/.readthedocs.yml b/.readthedocs.yml new file mode 100644 index 0000000000..3dcf0e5cf6 --- /dev/null +++ b/.readthedocs.yml @@ -0,0 +1,14 @@ +# Read the Docs configuration file +# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details +version: 2 + +sphinx: + configuration: docs/conf.py + +build: + image: latest + +python: + version: 3.8 + install: + - requirements: docs-requirements.txt diff --git a/CHANGELOG.md b/CHANGELOG.md index f3fa3bbbf7..e986fb2cde 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,16 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [Unreleased](https://github.com/open-telemetry/opentelemetry-python-contrib/compare/v0.16b1...HEAD) +## [Unreleased](https://github.com/open-telemetry/opentelemetry-python-contrib/compare/v0.17b0...HEAD) + +### Changed +- Remove `component` span attribute in instrumentations. + `opentelemetry-instrumentation-aiopg`, `opentelemetry-instrumentation-dbapi` Remove unused `database_type` parameter from `trace_integration` function. + ([#301](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/301)) +- `opentelemetry-instrumentation-grpc` Updated client attributes, added tests, fixed examples, docs + ([#269](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/269)) + +## [0.17b0](https://github.com/open-telemetry/opentelemetry-python-contrib/releases/tag/v0.17b0) - 2021-01-20 ### Added - `opentelemetry-instrumentation-sqlalchemy` Ensure spans have kind set to "CLIENT" @@ -42,7 +51,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - `opentelemetry-instrumentation-asgi`, `opentelemetry-instrumentation-wsgi` Return `None` for `CarrierGetter` if key not found - ([#1374](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/233)) + ([#233](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/233)) - `opentelemetry-instrumentation-grpc` Comply with updated spec, rework tests ([#236](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/236)) - `opentelemetry-instrumentation-asgi`, `opentelemetry-instrumentation-falcon`, `opentelemetry-instrumentation-flask`, `opentelemetry-instrumentation-pyramid`, `opentelemetry-instrumentation-wsgi` Renamed `host.port` attribute to `net.host.port` @@ -56,9 +65,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `opentelemetry-instrumentation-aiopg` Fix AttributeError `__aexit__` when `aiopg.connect` and `aio[g].create_pool` used with async context manager ([#235](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/235)) - `opentelemetry-exporter-datadog` `opentelemetry-sdk-extension-aws` Fix reference to ids_generator in sdk - ([#235](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/235)) -- `opentelemetry-instrumentation-grpc` Updated client attributes, added tests, fixed examples, docs - ([#269](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/269)) + ([#283](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/283)) +- `opentelemetry-instrumentation-sqlalchemy` Use SQL operation and DB name as span name. + ([#254](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/254)) +- `opentelemetry-instrumentation-dbapi`, `TracedCursor` replaced by `CursorTracer` + ([#246](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/246)) +- `opentelemetry-instrumentation-psycopg2`, Added support for psycopg2 registered types. + ([#246](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/246)) +- `opentelemetry-instrumentation-dbapi`, `opentelemetry-instrumentation-psycopg2`, `opentelemetry-instrumentation-mysql`, `opentelemetry-instrumentation-pymysql`, `opentelemetry-instrumentation-aiopg` Use SQL command name as the span operation name instead of the entire query. + ([#246](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/246)) +- Update TraceState to adhere to specs + ([#276](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/276)) ## [0.16b1](https://github.com/open-telemetry/opentelemetry-python-contrib/releases/tag/v0.16b1) - 2020-11-26 diff --git a/CODEOWNERS b/CODEOWNERS index 84b53a4f48..0bc82ac181 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -5,7 +5,7 @@ ##################################################### # # Learn about membership in OpenTelemetry community: -# https://github.com/open-telemetry/community/blob/master/community-membership.md +# https://github.com/open-telemetry/community/blob/main/community-membership.md # # # Learn about CODEOWNERS file format: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ddb72dcaf3..6d3c2d9cec 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -8,10 +8,10 @@ See the [public meeting notes](https://docs.google.com/document/d/1CIMGoIOZ-c3-i for a summary description of past meetings. To request edit access, join the meeting or get in touch on [Gitter](https://gitter.im/open-telemetry/opentelemetry-python). -See to the [community membership document](https://github.com/open-telemetry/community/blob/master/community-membership.md) -on how to become a [**Member**](https://github.com/open-telemetry/community/blob/master/community-membership.md#member), -[**Approver**](https://github.com/open-telemetry/community/blob/master/community-membership.md#approver) -and [**Maintainer**](https://github.com/open-telemetry/community/blob/master/community-membership.md#maintainer). +See to the [community membership document](https://github.com/open-telemetry/community/blob/main/community-membership.md) +on how to become a [**Member**](https://github.com/open-telemetry/community/blob/main/community-membership.md#member), +[**Approver**](https://github.com/open-telemetry/community/blob/main/community-membership.md#approver) +and [**Maintainer**](https://github.com/open-telemetry/community/blob/main/community-membership.md#maintainer). ## Find a Buddy and get Started Quickly! @@ -46,7 +46,7 @@ You can run: - `tox -e lint` to run lint checks on all code See -[`tox.ini`](https://github.com/open-telemetry/opentelemetry-python-contrib/blob/master/tox.ini) +[`tox.ini`](https://github.com/open-telemetry/opentelemetry-python-contrib/blob/main/tox.ini) for more detail on available tox commands. ### Benchmarks @@ -121,8 +121,8 @@ Open a pull request against the main `opentelemetry-python-contrib` repo. ### How to Get PRs Merged A PR is considered to be **ready to merge** when: -* It has received two approvals from [Approvers](https://github.com/open-telemetry/community/blob/master/community-membership.md#approver) - / [Maintainers](https://github.com/open-telemetry/community/blob/master/community-membership.md#maintainer) +* It has received two approvals from [Approvers](https://github.com/open-telemetry/community/blob/main/community-membership.md#approver) + / [Maintainers](https://github.com/open-telemetry/community/blob/main/community-membership.md#maintainer) (at different companies). * Major feedbacks are resolved. * It has been open for review for at least one working day. This gives people @@ -138,7 +138,7 @@ Any Approver / Maintainer can merge the PR once it is **ready to merge**. As with other OpenTelemetry clients, opentelemetry-python follows the [opentelemetry-specification](https://github.com/open-telemetry/opentelemetry-specification). -It's especially valuable to read through the [library guidelines](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/library-guidelines.md). +It's especially valuable to read through the [library guidelines](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/library-guidelines.md). ### Focus on Capabilities, Not Structure Compliance diff --git a/README.md b/README.md index 420345f3da..6357d203a0 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,44 @@ -# opentelemetry-python-contrib -[![Gitter chat](https://img.shields.io/gitter/room/opentelemetry/opentelemetry-python)](https://gitter.im/open-telemetry/opentelemetry-python)[![Build status](https://travis-ci.org/open-telemetry/opentelemetry-python-contrib.svg?branch=master)](https://travis-ci.org/open-telemetry/opentelemetry-python-contrib) - -The Python auto-instrumentation libraries for [OpenTelemetry](https://opentelemetry.io/) (per [OTEP 0001](https://github.com/open-telemetry/oteps/blob/master/text/0001-telemetry-without-manual-instrumentation.md)) +--- +

+ + Getting Started +   •   + API Documentation +   •   + Getting In Touch (Gitter) + +

+ +

+ + GitHub release (latest by date including pre-releases) + + + Codecov Status + + + license + +
+ + Build Status + + Beta +

+ +

+ + Contributing +   •   + Examples + +

+ +--- + +## OpenTelemetry Python Contrib + +The Python auto-instrumentation libraries for [OpenTelemetry](https://opentelemetry.io/) (per [OTEP 0001](https://github.com/open-telemetry/oteps/blob/main/text/0001-telemetry-without-manual-instrumentation.md)) ### Installation @@ -13,7 +50,7 @@ depend on `opentelemetry-sdk` or another package that implements the API. generally be used in production environments. The -[`instrumentation/`](https://github.com/open-telemetry/opentelemetry-python-contrib/tree/master/instrumentation) +[`instrumentation/`](https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation) directory includes OpenTelemetry instrumentation packages, which can be installed separately as: @@ -35,7 +72,7 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) We meet weekly on Thursday, and the time of the meeting alternates between 9AM PT and 4PM PT. The meeting is subject to change depending on contributors' availability. Check the [OpenTelemetry community calendar](https://calendar.google.com/calendar/embed?src=google.com_b79e3e90j7bbsa2n2p5an5lf60%40group.calendar.google.com) for specific dates. -Meetings take place via [Zoom video conference](https://zoom.us/j/6729396170). +Meetings take place via [Zoom video conference](https://zoom.us/j/6729396170). The passcode is _77777_. Meeting notes are available as a public [Google doc](https://docs.google.com/document/d/1CIMGoIOZ-c3-igzbd6_Pnxx1SjAkjwqoYSUWxPY8XIs/edit). For edit access, get in touch on [Gitter](https://gitter.im/open-telemetry/opentelemetry-python). @@ -47,14 +84,14 @@ Approvers ([@open-telemetry/python-approvers](https://github.com/orgs/open-telem - [Owais Lone](https://github.com/owais), Splunk - [Yusuke Tsutsumi](https://github.com/toumorokoshi), Google -*Find more about the approver role in [community repository](https://github.com/open-telemetry/community/blob/master/community-membership.md#approver).* +*Find more about the approver role in [community repository](https://github.com/open-telemetry/community/blob/main/community-membership.md#approver).* Maintainers ([@open-telemetry/python-maintainers](https://github.com/orgs/open-telemetry/teams/python-maintainers)): - [Alex Boten](https://github.com/codeboten), Lightstep - [Leighton Chen](https://github.com/lzchen), Microsoft -*Find more about the maintainer role in [community repository](https://github.com/open-telemetry/community/blob/master/community-membership.md#maintainer).* +*Find more about the maintainer role in [community repository](https://github.com/open-telemetry/community/blob/main/community-membership.md#maintainer).* ## Running Tests Locally diff --git a/_template/setup.cfg b/_template/setup.cfg index c330e91cbd..39d624c4fb 100644 --- a/_template/setup.cfg +++ b/_template/setup.cfg @@ -46,7 +46,7 @@ package_dir= packages=find_namespace: install_requires = - opentelemetry-api == 0.17.dev0 + opentelemetry-api == 0.18.dev0 [options.extras_require] test = diff --git a/_template/version.py b/_template/version.py index 86e1dbb17a..ebb75f6c11 100644 --- a/_template/version.py +++ b/_template/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.17.dev0" +__version__ = "0.18.dev0" diff --git a/docs-requirements.txt b/docs-requirements.txt new file mode 100644 index 0000000000..dc1cbc7790 --- /dev/null +++ b/docs-requirements.txt @@ -0,0 +1,35 @@ +sphinx~=2.4 +sphinx-rtd-theme~=0.4 +sphinx-autodoc-typehints~=1.10.2 + +# Need to install the api/sdk in the venv for autodoc. Modifying sys.path +# doesn't work for pkg_resources. +-e "git+https://github.com/open-telemetry/opentelemetry-python.git#egg=opentelemetry-api&subdirectory=opentelemetry-api" +-e "git+https://github.com/open-telemetry/opentelemetry-python.git#egg=opentelemetry-sdk&subdirectory=opentelemetry-sdk" + +# Required by opentelemetry-instrumentation +fastapi~=0.58.1 +psutil~=5.7.0 +pymemcache~=1.3 + +-e "git+https://github.com/open-telemetry/opentelemetry-python.git#egg=opentelemetry-instrumentation&subdirectory=opentelemetry-instrumentation" + +# Required by conf +django>=2.2 + +# Required by instrumentation packages +aiohttp~=3.0 +aiopg>=0.13.0 +asyncpg>=0.12.0 +boto~=2.0 +botocore~=1.0 +celery>=4.0 +flask~=1.0 +grpcio~=1.27 +mysql-connector-python~=8.0 +pymongo~=3.1 +PyMySQL~=0.9.3 +pyramid>=1.7 +redis>=2.6 +sqlalchemy>=1.0 +ddtrace>=0.34.0 diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000000..51285967a7 --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,19 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +SOURCEDIR = . +BUILDDIR = _build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000000..8db08c2211 --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,179 @@ +# Configuration file for the Sphinx documentation builder. +# +# This file only contains a selection of the most common options. For a full +# list see the documentation: +# http://www.sphinx-doc.org/en/master/config + +# -- Path setup -------------------------------------------------------------- + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. + +import os +import sys +from configparser import ConfigParser +from os import listdir +from os.path import isdir, join + +# configure django to avoid the following exception: +# django.core.exceptions.ImproperlyConfigured: Requested settings, but settings +# are not configured. You must either define the environment variable +# DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings. +from django.conf import settings + +settings.configure() + +exp = "../exporter" +exp_dirs = [ + os.path.abspath("/".join(["../exporter", f, "src"])) + for f in listdir(exp) + if isdir(join(exp, f)) +] + +instr = "../instrumentation" +instr_dirs = [ + os.path.abspath("/".join(["../instrumentation", f, "src"])) + for f in listdir(instr) + if isdir(join(instr, f)) +] + +sdk_ext = "../sdk-extension" +sdk_ext_dirs = [ + os.path.abspath("/".join(["../sdk-extension", f, "src"])) + for f in listdir(sdk_ext) + if isdir(join(sdk_ext, f)) +] + +sys.path[:0] = exp_dirs + instr_dirs + sdk_ext_dirs + +# -- Project information ----------------------------------------------------- + +project = "OpenTelemetry Python Contrib" +copyright = "OpenTelemetry Authors" # pylint: disable=redefined-builtin +author = "OpenTelemetry Authors" + + +# -- General configuration --------------------------------------------------- + +# Easy automatic cross-references for `code in backticks` +default_role = "any" + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ + # API doc generation + "sphinx.ext.autodoc", + # Support for google-style docstrings + "sphinx.ext.napoleon", + # Infer types from hints instead of docstrings + "sphinx_autodoc_typehints", + # Add links to source from generated docs + "sphinx.ext.viewcode", + # Link to other sphinx docs + "sphinx.ext.intersphinx", + # Add a .nojekyll file to the generated HTML docs + # https://help.github.com/en/articles/files-that-start-with-an-underscore-are-missing + "sphinx.ext.githubpages", + # Support external links to different versions in the Github repo + "sphinx.ext.extlinks", +] + +intersphinx_mapping = { + "python": ("https://docs.python.org/3/", None), + "opentracing": ( + "https://opentracing-python.readthedocs.io/en/latest/", + None, + ), + "aiohttp": ("https://aiohttp.readthedocs.io/en/stable/", None), + "wrapt": ("https://wrapt.readthedocs.io/en/latest/", None), + "pymongo": ("https://pymongo.readthedocs.io/en/stable/", None), + "opentelemetry": ( + "https://opentelemetry-python.readthedocs.io/en/latest/", + None, + ), +} + +# http://www.sphinx-doc.org/en/master/config.html#confval-nitpicky +# Sphinx will warn about all references where the target cannot be found. +nitpicky = True +# Sphinx does not recognize generic type TypeVars +# Container supposedly were fixed, but does not work +# https://github.com/sphinx-doc/sphinx/pull/3744 +nitpick_ignore = [] + +cfg = ConfigParser() +cfg.read("./nitpick-exceptions.ini") +mcfg = cfg["default"] + + +def getlistcfg(strval): + return [ + val.strip() + for line in strval.split("\n") + for val in line.split(",") + if val.strip() + ] + + +if "class_references" in mcfg: + class_references = getlistcfg(mcfg["class_references"]) + for class_reference in class_references: + nitpick_ignore.append(("py:class", class_reference,)) + +if "anys" in mcfg: + anys = getlistcfg(mcfg["anys"]) + for any in anys: + nitpick_ignore.append(("any", any,)) + +# Add any paths that contain templates here, relative to this directory. +templates_path = ["_templates"] + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This pattern also affects html_static_path and html_extra_path. +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] + +autodoc_default_options = { + "members": True, + "undoc-members": True, + "show-inheritance": True, + "member-order": "bysource", +} + +# -- Options for HTML output ------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +html_theme = "sphinx_rtd_theme" + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = [] + +# Support external links to specific versions of the files in the Github repo +branch = os.environ.get("READTHEDOCS_VERSION") +if branch is None or branch == "latest": + branch = "main" + +REPO = "open-telemetry/opentelemetry-python-contrib/" +scm_raw_web = "https://raw.githubusercontent.com/" + REPO + branch +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 +) + +# used to have links to repo files +extlinks = { + "scm_raw_web": (scm_raw_web + "/%s", "scm_raw_web"), + "scm_web": (scm_web + "/%s", "scm_web"), +} diff --git a/docs/exporter/datadog/datadog.rst b/docs/exporter/datadog/datadog.rst new file mode 100644 index 0000000000..3b43c2bdf7 --- /dev/null +++ b/docs/exporter/datadog/datadog.rst @@ -0,0 +1,7 @@ +OpenTelemetry Datadog Exporter +============================== + +.. automodule:: opentelemetry.exporter.datadog + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 0000000000..47c4466c4c --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,93 @@ +OpenTelemetry-Python-Contrib +============================ + +Complimentary instrumentation and vendor-specific packages for use with the +Python `OpenTelemetry `_ client. + +.. image:: https://img.shields.io/gitter/room/opentelemetry/opentelemetry-python + :target: https://gitter.im/open-telemetry/opentelemetry-python + :alt: Gitter Chat + + +**Please note** that this library is currently in _beta_, and shouldn't +generally be used in production environments. + +Installation +------------ + +There are several complimentary packages available on PyPI which can be +installed separately via pip: + +.. code-block:: sh + + pip install opentelemetry-exporter-{exporter} + pip install opentelemetry-instrumentation-{instrumentation} + pip install opentelemetry-sdk-extension-{sdkextension} + +A complete list of packages can be found at the +`Contrib repo instrumentation `_ +and `Contrib repo exporter `_ directories. + +Extensions +---------- + +Visit `OpenTelemetry Registry `_ to +find a lit of related projects like exporters, instrumentation libraries, tracer +implementations, etc. + +Installing Cutting Edge Packages +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +While the project is pre-1.0, there may be significant functionality that +has not yet been released to PyPI. In that situation, you may want to +install the packages directly from the repo. This can be done by cloning the +repository and doing an `editable +install `_: + +.. code-block:: sh + + git clone https://github.com/open-telemetry/opentelemetry-python-contrib.git + cd opentelemetry-python-contrib + pip install -e ./instrumentation/opentelemetry-instrumentation-flask + pip install -e ./instrumentation/opentelemetry-instrumentation-botocore + pip install -e ./sdk-extension/opentelemetry-sdk-extension-aws + + +.. toctree:: + :maxdepth: 2 + :caption: OpenTelemetry Exporters + :name: exporters + :glob: + + exporter/** + +.. toctree:: + :maxdepth: 2 + :caption: OpenTelemetry Instrumentations + :name: Instrumentations + :glob: + + instrumentation/** + +.. toctree:: + :maxdepth: 2 + :caption: OpenTelemetry Performance + :name: Performance + :glob: + + performance/** + +.. toctree:: + :maxdepth: 2 + :caption: OpenTelemetry SDK Extensions + :name: SDK Extensions + :glob: + + sdk-extension/** + +Indices and tables +------------------ + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff --git a/docs/instrumentation/aiohttp_client/aiohttp_client.rst b/docs/instrumentation/aiohttp_client/aiohttp_client.rst new file mode 100644 index 0000000000..f8549f07fa --- /dev/null +++ b/docs/instrumentation/aiohttp_client/aiohttp_client.rst @@ -0,0 +1,7 @@ +OpenTelemetry aiohttp client Instrumentation +============================================ + +.. automodule:: opentelemetry.instrumentation.aiohttp_client + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/instrumentation/aiopg/aiopg.rst b/docs/instrumentation/aiopg/aiopg.rst new file mode 100644 index 0000000000..9da450c4e7 --- /dev/null +++ b/docs/instrumentation/aiopg/aiopg.rst @@ -0,0 +1,7 @@ +OpenTelemetry aiopg Instrumentation +=================================== + +.. automodule:: opentelemetry.instrumentation.aiopg + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/instrumentation/asgi/asgi.rst b/docs/instrumentation/asgi/asgi.rst new file mode 100644 index 0000000000..b988e4de43 --- /dev/null +++ b/docs/instrumentation/asgi/asgi.rst @@ -0,0 +1,9 @@ +.. include:: ../../../instrumentation/opentelemetry-instrumentation-asgi/README.rst + +API +--- + +.. automodule:: opentelemetry.instrumentation.asgi + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/instrumentation/asyncpg/asyncpg.rst b/docs/instrumentation/asyncpg/asyncpg.rst new file mode 100644 index 0000000000..d4ee9b4abb --- /dev/null +++ b/docs/instrumentation/asyncpg/asyncpg.rst @@ -0,0 +1,10 @@ +OpenTelemetry asyncpg Instrumentation +===================================== + +Module contents +--------------- + +.. automodule:: opentelemetry.instrumentation.asyncpg + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/instrumentation/boto/boto.rst b/docs/instrumentation/boto/boto.rst new file mode 100644 index 0000000000..c438c2466c --- /dev/null +++ b/docs/instrumentation/boto/boto.rst @@ -0,0 +1,7 @@ +OpenTelemetry Boto Instrumentation +================================== + +.. automodule:: opentelemetry.instrumentation.boto + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/instrumentation/botocore/botocore.rst b/docs/instrumentation/botocore/botocore.rst new file mode 100644 index 0000000000..eb8ea6bcf7 --- /dev/null +++ b/docs/instrumentation/botocore/botocore.rst @@ -0,0 +1,7 @@ +OpenTelemetry Botocore Instrumentation +====================================== + +.. automodule:: opentelemetry.instrumentation.botocore + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/instrumentation/celery/celery.rst b/docs/instrumentation/celery/celery.rst new file mode 100644 index 0000000000..c85f3adb59 --- /dev/null +++ b/docs/instrumentation/celery/celery.rst @@ -0,0 +1,7 @@ +OpenTelemetry Celery Instrumentation +==================================== + +.. automodule:: opentelemetry.instrumentation.celery + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/instrumentation/dbapi/dbapi.rst b/docs/instrumentation/dbapi/dbapi.rst new file mode 100644 index 0000000000..a20be63097 --- /dev/null +++ b/docs/instrumentation/dbapi/dbapi.rst @@ -0,0 +1,7 @@ +OpenTelemetry Database API Instrumentation +========================================== + +.. automodule:: opentelemetry.instrumentation.dbapi + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/instrumentation/django/django.rst b/docs/instrumentation/django/django.rst new file mode 100644 index 0000000000..8076730843 --- /dev/null +++ b/docs/instrumentation/django/django.rst @@ -0,0 +1,7 @@ +OpenTelemetry Django Instrumentation +==================================== + +.. automodule:: opentelemetry.instrumentation.django + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/instrumentation/fastapi/fastapi.rst b/docs/instrumentation/fastapi/fastapi.rst new file mode 100644 index 0000000000..09eb8a828b --- /dev/null +++ b/docs/instrumentation/fastapi/fastapi.rst @@ -0,0 +1,9 @@ +.. include:: ../../../instrumentation/opentelemetry-instrumentation-fastapi/README.rst + +API +--- + +.. automodule:: opentelemetry.instrumentation.fastapi + :members: + :undoc-members: + :show-inheritance: \ No newline at end of file diff --git a/docs/instrumentation/flask/flask.rst b/docs/instrumentation/flask/flask.rst new file mode 100644 index 0000000000..ac8932acd4 --- /dev/null +++ b/docs/instrumentation/flask/flask.rst @@ -0,0 +1,7 @@ +OpenTelemetry Flask Instrumentation +=================================== + +.. automodule:: opentelemetry.instrumentation.flask + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/instrumentation/grpc/grpc.rst b/docs/instrumentation/grpc/grpc.rst new file mode 100644 index 0000000000..243f696143 --- /dev/null +++ b/docs/instrumentation/grpc/grpc.rst @@ -0,0 +1,10 @@ +OpenTelemetry gRPC Instrumentation +================================== + +Module contents +--------------- + +.. automodule:: opentelemetry.instrumentation.grpc + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/instrumentation/jinja2/jinja2.rst b/docs/instrumentation/jinja2/jinja2.rst new file mode 100644 index 0000000000..5c7143724c --- /dev/null +++ b/docs/instrumentation/jinja2/jinja2.rst @@ -0,0 +1,7 @@ +OpenTelemetry Jinja2 Instrumentation +==================================== + +.. automodule:: opentelemetry.instrumentation.jinja2 + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/instrumentation/mysql/mysql.rst b/docs/instrumentation/mysql/mysql.rst new file mode 100644 index 0000000000..3a4a41542a --- /dev/null +++ b/docs/instrumentation/mysql/mysql.rst @@ -0,0 +1,7 @@ +OpenTelemetry MySQL Instrumentation +=================================== + +.. automodule:: opentelemetry.instrumentation.mysql + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/instrumentation/psycopg2/psycopg2.rst b/docs/instrumentation/psycopg2/psycopg2.rst new file mode 100644 index 0000000000..69be31b2d1 --- /dev/null +++ b/docs/instrumentation/psycopg2/psycopg2.rst @@ -0,0 +1,7 @@ +OpenTelemetry Psycopg Instrumentation +===================================== + +.. automodule:: opentelemetry.instrumentation.psycopg2 + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/instrumentation/pymemcache/pymemcache.rst b/docs/instrumentation/pymemcache/pymemcache.rst new file mode 100644 index 0000000000..2a77b829d9 --- /dev/null +++ b/docs/instrumentation/pymemcache/pymemcache.rst @@ -0,0 +1,7 @@ +OpenTelemetry pymemcache Instrumentation +======================================== + +.. automodule:: opentelemetry.instrumentation.pymemcache + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/instrumentation/pymongo/pymongo.rst b/docs/instrumentation/pymongo/pymongo.rst new file mode 100644 index 0000000000..4eb68be27b --- /dev/null +++ b/docs/instrumentation/pymongo/pymongo.rst @@ -0,0 +1,7 @@ +OpenTelemetry pymongo Instrumentation +===================================== + +.. automodule:: opentelemetry.instrumentation.pymongo + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/instrumentation/pymysql/pymysql.rst b/docs/instrumentation/pymysql/pymysql.rst new file mode 100644 index 0000000000..26482292fe --- /dev/null +++ b/docs/instrumentation/pymysql/pymysql.rst @@ -0,0 +1,7 @@ +OpenTelemetry PyMySQL Instrumentation +===================================== + +.. automodule:: opentelemetry.instrumentation.pymysql + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/instrumentation/pyramid/pyramid.rst b/docs/instrumentation/pyramid/pyramid.rst new file mode 100644 index 0000000000..56abd2800b --- /dev/null +++ b/docs/instrumentation/pyramid/pyramid.rst @@ -0,0 +1,7 @@ +OpenTelemetry Pyramid Instrumentation +===================================== + +.. automodule:: opentelemetry.instrumentation.pyramid + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/instrumentation/redis/redis.rst b/docs/instrumentation/redis/redis.rst new file mode 100644 index 0000000000..4e21bce24b --- /dev/null +++ b/docs/instrumentation/redis/redis.rst @@ -0,0 +1,7 @@ +OpenTelemetry Redis Instrumentation +=================================== + +.. automodule:: opentelemetry.instrumentation.redis + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/instrumentation/requests/requests.rst b/docs/instrumentation/requests/requests.rst new file mode 100644 index 0000000000..7a0665cd99 --- /dev/null +++ b/docs/instrumentation/requests/requests.rst @@ -0,0 +1,7 @@ +OpenTelemetry requests Instrumentation +====================================== + +.. automodule:: opentelemetry.instrumentation.requests + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/instrumentation/sqlalchemy/sqlalchemy.rst b/docs/instrumentation/sqlalchemy/sqlalchemy.rst new file mode 100644 index 0000000000..1a1895ea6b --- /dev/null +++ b/docs/instrumentation/sqlalchemy/sqlalchemy.rst @@ -0,0 +1,7 @@ +OpenTelemetry SQLAlchemy Instrumentation +======================================== + +.. automodule:: opentelemetry.instrumentation.sqlalchemy + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/instrumentation/sqlite3/sqlite3.rst b/docs/instrumentation/sqlite3/sqlite3.rst new file mode 100644 index 0000000000..36b541ccd1 --- /dev/null +++ b/docs/instrumentation/sqlite3/sqlite3.rst @@ -0,0 +1,7 @@ +OpenTelemetry SQLite3 Instrumentation +===================================== + +.. automodule:: opentelemetry.instrumentation.sqlite3 + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/instrumentation/starlette/starlette.rst b/docs/instrumentation/starlette/starlette.rst new file mode 100644 index 0000000000..0efa8cce83 --- /dev/null +++ b/docs/instrumentation/starlette/starlette.rst @@ -0,0 +1,9 @@ +.. include:: ../../../instrumentation/opentelemetry-instrumentation-starlette/README.rst + +API +--- + +.. automodule:: opentelemetry.instrumentation.starlette + :members: + :undoc-members: + :show-inheritance: \ No newline at end of file diff --git a/docs/instrumentation/system_metrics/system_metrics.rst b/docs/instrumentation/system_metrics/system_metrics.rst new file mode 100644 index 0000000000..96b39d9267 --- /dev/null +++ b/docs/instrumentation/system_metrics/system_metrics.rst @@ -0,0 +1,7 @@ +OpenTelemetry System Metrics Instrumentation +============================================ + +.. automodule:: opentelemetry.instrumentation.system_metrics + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/instrumentation/wsgi/wsgi.rst b/docs/instrumentation/wsgi/wsgi.rst new file mode 100644 index 0000000000..39ad5ffd58 --- /dev/null +++ b/docs/instrumentation/wsgi/wsgi.rst @@ -0,0 +1,7 @@ +OpenTelemetry WSGI Instrumentation +================================== + +.. automodule:: opentelemetry.instrumentation.wsgi + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/make.bat b/docs/make.bat new file mode 100644 index 0000000000..27f573b87a --- /dev/null +++ b/docs/make.bat @@ -0,0 +1,35 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=. +set BUILDDIR=_build + +if "%1" == "" goto help + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.http://sphinx-doc.org/ + exit /b 1 +) + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% + +:end +popd diff --git a/docs/nitpick-exceptions.ini b/docs/nitpick-exceptions.ini new file mode 100644 index 0000000000..3143b9cd75 --- /dev/null +++ b/docs/nitpick-exceptions.ini @@ -0,0 +1,30 @@ +[default] +class_references= + ; TODO: Understand why sphinx is not able to find this local class + opentelemetry.trace.propagation.textmap.TextMapPropagator + ; - AwsXRayFormat + opentelemetry.trace.propagation.textmap.DictGetter + ; - instrumentation.asgi.CarrierGetter + ; API + opentelemetry.trace.propagation.textmap.Getter + ; - DatadogFormat + ; - AWSXRayFormat + TextMapPropagatorT + ; - AwsXRayFormat.extract + +anys= + ; API + opentelemetry.trace.propagation.textmap.TextMapPropagator.fields + ; - AWSXRayFormat + TraceId + ; - AwsXRayIdsGenerator + TraceIdRatioBased + ; - AwsXRayIdsGenerator + ; SDK + SpanProcessor + ; - DatadogExportSpanProcessor + TracerProvider + ; - AwsXRayIdsGenerator + ; Instrumentation + BaseInstrumentor + ; - instrumentation.* diff --git a/docs/performance/benchmarks.rst b/docs/performance/benchmarks.rst index 428d5acbbb..99859a27d8 100644 --- a/docs/performance/benchmarks.rst +++ b/docs/performance/benchmarks.rst @@ -1,4 +1,4 @@ Performance Tests - Benchmarks ============================== -Click `here _` to view the latest performance benchmarks for packages in this repo. +Click `here `_ to view the latest performance benchmarks for packages in this repo. diff --git a/docs/sdk-extension/aws/aws.rst b/docs/sdk-extension/aws/aws.rst new file mode 100644 index 0000000000..1306e45665 --- /dev/null +++ b/docs/sdk-extension/aws/aws.rst @@ -0,0 +1,12 @@ +OpenTelemetry Python - AWS SDK Extension +======================================== + +.. automodule:: opentelemetry.sdk.extension.aws.trace.aws_xray_ids_generator + :members: + :undoc-members: + :show-inheritance: + +.. automodule:: opentelemetry.sdk.extension.aws.trace.propagation.aws_xray_format + :members: + :undoc-members: + :show-inheritance: diff --git a/exporter/opentelemetry-exporter-datadog/setup.cfg b/exporter/opentelemetry-exporter-datadog/setup.cfg index b958e774dd..66057f211c 100644 --- a/exporter/opentelemetry-exporter-datadog/setup.cfg +++ b/exporter/opentelemetry-exporter-datadog/setup.cfg @@ -40,8 +40,8 @@ package_dir= packages=find_namespace: install_requires = ddtrace>=0.34.0 - opentelemetry-api == 0.17.dev0 - opentelemetry-sdk == 0.17.dev0 + opentelemetry-api == 0.18.dev0 + opentelemetry-sdk == 0.18.dev0 [options.packages.find] where = src diff --git a/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/__init__.py b/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/__init__.py index 3294ba4e4e..089883da40 100644 --- a/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/__init__.py +++ b/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/__init__.py @@ -66,7 +66,7 @@ --- .. _Datadog: https://www.datadoghq.com/ .. _OpenTelemetry: https://github.com/open-telemetry/opentelemetry-python/ -.. _docs/examples/datadog_exporter: https://github.com/open-telemetry/opentelemetry-python/tree/master/docs/examples/datadog_exporter +.. _docs/examples/datadog_exporter: https://github.com/open-telemetry/opentelemetry-python/tree/main/docs/examples/datadog_exporter """ # pylint: disable=import-error diff --git a/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/constants.py b/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/constants.py index 2ae5386e84..90f15a7ffc 100644 --- a/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/constants.py +++ b/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/constants.py @@ -1,4 +1,4 @@ -DD_ORIGIN = "_dd_origin" +DD_ORIGIN = "dd_origin" AUTO_REJECT = 0 AUTO_KEEP = 1 USER_KEEP = 2 diff --git a/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/propagator.py b/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/propagator.py index 66c833174e..d5f14011be 100644 --- a/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/propagator.py +++ b/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/propagator.py @@ -70,7 +70,7 @@ def extract( span_id=int(span_id), is_remote=True, trace_flags=trace_flags, - trace_state=trace.TraceState({constants.DD_ORIGIN: origin}), + trace_state=trace.TraceState([(constants.DD_ORIGIN, origin)]), ) return set_span_in_context(trace.DefaultSpan(span_context), context) diff --git a/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/version.py b/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/version.py index 86e1dbb17a..ebb75f6c11 100644 --- a/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/version.py +++ b/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.17.dev0" +__version__ = "0.18.dev0" diff --git a/exporter/opentelemetry-exporter-datadog/tests/test_datadog_exporter.py b/exporter/opentelemetry-exporter-datadog/tests/test_datadog_exporter.py index 3ef5d226b9..4a576c5de1 100644 --- a/exporter/opentelemetry-exporter-datadog/tests/test_datadog_exporter.py +++ b/exporter/opentelemetry-exporter-datadog/tests/test_datadog_exporter.py @@ -542,7 +542,7 @@ def test_origin(self): span_id=trace_api.INVALID_SPAN, is_remote=True, trace_state=trace_api.TraceState( - {datadog.constants.DD_ORIGIN: "origin-service"} + [(datadog.constants.DD_ORIGIN, "origin-service")] ), ) diff --git a/exporter/opentelemetry-exporter-prometheus-remote-write/README.rst b/exporter/opentelemetry-exporter-prometheus-remote-write/README.rst index 94f4b61686..1f5dc01404 100644 --- a/exporter/opentelemetry-exporter-prometheus-remote-write/README.rst +++ b/exporter/opentelemetry-exporter-prometheus-remote-write/README.rst @@ -232,10 +232,10 @@ and key files in the ``tls_config`` parameter. Supported Aggregators --------------------- -Behaviour of these aggregators is outlined in the `OpenTelemetry Specification `_. +Behaviour of these aggregators is outlined in the `OpenTelemetry Specification `_. All aggregators are converted into the `timeseries`_ data format. However, method in -which they are converted `differs `_ from aggregator to aggregator. A -map of the conversion methods can be found `here `_. +which they are converted `differs `_ from aggregator to aggregator. A +map of the conversion methods can be found `here `_. +------------------------------+-------------------------------------+------------------------------------------------------------------------------------------------------------+ | **OpenTelemetry Aggregator** | **Equivalent Prometheus Data Type** | **Behaviour** | @@ -308,13 +308,13 @@ significantly increase the size of this repo. .. _RFC 7617: https://tools.ietf.org/html/rfc7617 .. _RFC 6750: https://tools.ietf.org/html/rfc6750 .. _Design Document: https://github.com/open-o11y/docs/blob/master/python-prometheus-remote-write/design-doc.md -.. _OTLP: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/protocol/otlp.md +.. _OTLP: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/otlp.md .. _OpenTelemetry Python SDK: https://github.com/open-telemetry/opentelemetry-python -.. _Prometheus "pull" exporter: https://github.com/open-telemetry/opentelemetry-python/tree/master/exporter/opentelemetry-exporter-prometheus +.. _Prometheus "pull" exporter: https://github.com/open-telemetry/opentelemetry-python/tree/main/exporter/opentelemetry-exporter-prometheus .. _Prometheus Remote Write integrated backend: https://prometheus.io/docs/operating/integrations/ .. _types.proto: https://github.com/prometheus/prometheus/blob/master/prompb/types.proto .. _remote.proto: https://github.com/prometheus/prometheus/blob/master/prompb/remote.proto -.. _push controller: https://github.com/open-telemetry/opentelemetry-python/blob/master/opentelemetry-sdk/src/opentelemetry/sdk/metrics/export/controller.py#L22 +.. _push controller: https://github.com/open-telemetry/opentelemetry-python/blob/main/opentelemetry-sdk/src/opentelemetry/sdk/metrics/export/controller.py#L22 .. _timeseries: https://prometheus.io/docs/concepts/data_model/ .. _Docker Compose: https://docs.docker.com/compose/ .. _Cortex: https://cortexmetrics.io/ diff --git a/exporter/opentelemetry-exporter-prometheus-remote-write/setup.cfg b/exporter/opentelemetry-exporter-prometheus-remote-write/setup.cfg index 9bec805791..53afd484df 100644 --- a/exporter/opentelemetry-exporter-prometheus-remote-write/setup.cfg +++ b/exporter/opentelemetry-exporter-prometheus-remote-write/setup.cfg @@ -19,7 +19,7 @@ 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/master/exporter/opentelemetry-exporter-prometheus-remote-write +url = https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/exporter/opentelemetry-exporter-prometheus-remote-write platforms = any license = Apache-2.0 classifiers = @@ -42,8 +42,8 @@ install_requires = snappy >= 2.8 protobuf >= 3.13.0 requests == 2.25.0 - opentelemetry-api == 0.17.dev0 - opentelemetry-sdk == 0.17.dev0 + opentelemetry-api == 0.18.dev0 + opentelemetry-sdk == 0.18.dev0 python-snappy >= 0.5.4 [options.packages.find] diff --git a/exporter/opentelemetry-exporter-prometheus-remote-write/src/opentelemetry/exporter/prometheus_remote_write/version.py b/exporter/opentelemetry-exporter-prometheus-remote-write/src/opentelemetry/exporter/prometheus_remote_write/version.py index 86e1dbb17a..ebb75f6c11 100644 --- a/exporter/opentelemetry-exporter-prometheus-remote-write/src/opentelemetry/exporter/prometheus_remote_write/version.py +++ b/exporter/opentelemetry-exporter-prometheus-remote-write/src/opentelemetry/exporter/prometheus_remote_write/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.17.dev0" +__version__ = "0.18.dev0" diff --git a/instrumentation/opentelemetry-instrumentation-aiohttp-client/README.rst b/instrumentation/opentelemetry-instrumentation-aiohttp-client/README.rst index bc44e0e262..e129b9f5f8 100644 --- a/instrumentation/opentelemetry-instrumentation-aiohttp-client/README.rst +++ b/instrumentation/opentelemetry-instrumentation-aiohttp-client/README.rst @@ -17,6 +17,44 @@ Installation pip install opentelemetry-instrumentation-aiohttp-client +Example +------- + +.. code:: python + + import asyncio + + import aiohttp + + from opentelemetry.instrumentation.aiohttp_client import AioHttpClientInstrumentor + from opentelemetry import trace + from opentelemetry.exporter import jaeger + from opentelemetry.sdk.trace import TracerProvider + from opentelemetry.sdk.trace.export import BatchExportSpanProcessor + + + _JAEGER_EXPORTER = jaeger.JaegerSpanExporter( + service_name="example-xxx", + agent_host_name="localhost", + agent_port=6831, + ) + + _TRACE_PROVIDER = TracerProvider() + _TRACE_PROVIDER.add_span_processor(BatchExportSpanProcessor(_JAEGER_EXPORTER)) + trace.set_tracer_provider(_TRACE_PROVIDER) + + AioHttpClientInstrumentor().instrument() + + + async def span_emitter(): + async with aiohttp.ClientSession() as session: + async with session.get("https://example.com") as resp: + print(resp.status) + + + asyncio.run(span_emitter()) + + References ---------- diff --git a/instrumentation/opentelemetry-instrumentation-aiohttp-client/setup.cfg b/instrumentation/opentelemetry-instrumentation-aiohttp-client/setup.cfg index 92f1d317ef..d65c92887d 100644 --- a/instrumentation/opentelemetry-instrumentation-aiohttp-client/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-aiohttp-client/setup.cfg @@ -39,8 +39,8 @@ package_dir= =src packages=find_namespace: install_requires = - opentelemetry-api == 0.17.dev0 - opentelemetry-instrumentation == 0.17.dev0 + opentelemetry-api == 0.18.dev0 + opentelemetry-instrumentation == 0.18.dev0 aiohttp ~= 3.0 wrapt >= 1.0.0, < 2.0.0 diff --git a/instrumentation/opentelemetry-instrumentation-aiohttp-client/src/opentelemetry/instrumentation/aiohttp_client/__init__.py b/instrumentation/opentelemetry-instrumentation-aiohttp-client/src/opentelemetry/instrumentation/aiohttp_client/__init__.py index c708802a92..1ff76e96da 100644 --- a/instrumentation/opentelemetry-instrumentation-aiohttp-client/src/opentelemetry/instrumentation/aiohttp_client/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-aiohttp-client/src/opentelemetry/instrumentation/aiohttp_client/__init__.py @@ -169,7 +169,6 @@ async def on_request_start( if trace_config_ctx.span.is_recording(): attributes = { - "component": "http", "http.method": http_method, "http.url": trace_config_ctx.url_filter(params.url) if callable(trace_config_ctx.url_filter) diff --git a/instrumentation/opentelemetry-instrumentation-aiohttp-client/src/opentelemetry/instrumentation/aiohttp_client/version.py b/instrumentation/opentelemetry-instrumentation-aiohttp-client/src/opentelemetry/instrumentation/aiohttp_client/version.py index 1dfb1884f4..98df029ba4 100644 --- a/instrumentation/opentelemetry-instrumentation-aiohttp-client/src/opentelemetry/instrumentation/aiohttp_client/version.py +++ b/instrumentation/opentelemetry-instrumentation-aiohttp-client/src/opentelemetry/instrumentation/aiohttp_client/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.17.dev0" +__version__ = "0.18.dev0" diff --git a/instrumentation/opentelemetry-instrumentation-aiohttp-client/tests/test_aiohttp_client_integration.py b/instrumentation/opentelemetry-instrumentation-aiohttp-client/tests/test_aiohttp_client_integration.py index f073465348..363b0356d4 100644 --- a/instrumentation/opentelemetry-instrumentation-aiohttp-client/tests/test_aiohttp_client_integration.py +++ b/instrumentation/opentelemetry-instrumentation-aiohttp-client/tests/test_aiohttp_client_integration.py @@ -129,7 +129,6 @@ def test_status_codes(self): "HTTP GET", (span_status, None), { - "component": "http", "http.method": "GET", "http.url": "http://{}:{}/test-path?query=param#foobar".format( host, port @@ -187,7 +186,6 @@ def test_span_name_option(self): expected, (StatusCode.UNSET, None), { - "component": "http", "http.method": method, "http.url": "http://{}:{}{}".format( host, port, path @@ -219,7 +217,6 @@ def strip_query_params(url: yarl.URL) -> str: "HTTP GET", (StatusCode.UNSET, None), { - "component": "http", "http.method": "GET", "http.url": "http://{}:{}/some/path".format( host, port @@ -256,11 +253,7 @@ async def do_request(url): ( "HTTP GET", (expected_status, None), - { - "component": "http", - "http.method": "GET", - "http.url": url, - }, + {"http.method": "GET", "http.url": url}, ) ] ) @@ -285,7 +278,6 @@ async def request_handler(request): "HTTP GET", (StatusCode.ERROR, None), { - "component": "http", "http.method": "GET", "http.url": "http://{}:{}/test_timeout".format( host, port @@ -315,7 +307,6 @@ async def request_handler(request): "HTTP GET", (StatusCode.ERROR, None), { - "component": "http", "http.method": "GET", "http.url": "http://{}:{}/test_too_many_redirects".format( host, port @@ -364,7 +355,6 @@ def test_instrument(self): self.get_default_request(), self.URL, self.default_handler ) span = self.assert_spans(1) - self.assertEqual("http", span.attributes["component"]) self.assertEqual("GET", span.attributes["http.method"]) self.assertEqual( "http://{}:{}/test-path".format(host, port), diff --git a/instrumentation/opentelemetry-instrumentation-aiopg/setup.cfg b/instrumentation/opentelemetry-instrumentation-aiopg/setup.cfg index 345ea713c4..aeb82b4d9f 100644 --- a/instrumentation/opentelemetry-instrumentation-aiopg/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-aiopg/setup.cfg @@ -19,7 +19,7 @@ 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/master/instrumentation/opentelemetry-instrumentation-aiopg +url = https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-aiopg platforms = any license = Apache-2.0 classifiers = @@ -39,15 +39,15 @@ package_dir= =src packages=find_namespace: install_requires = - opentelemetry-api == 0.17.dev0 - opentelemetry-instrumentation-dbapi == 0.17.dev0 - opentelemetry-instrumentation == 0.17.dev0 + opentelemetry-api == 0.18.dev0 + opentelemetry-instrumentation-dbapi == 0.18.dev0 + opentelemetry-instrumentation == 0.18.dev0 aiopg >= 0.13.0 wrapt >= 1.0.0, < 2.0.0 [options.extras_require] test = - opentelemetry-test == 0.17.dev0 + opentelemetry-test == 0.18.dev0 [options.packages.find] where = src diff --git a/instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/__init__.py b/instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/__init__.py index 176fc82b40..ffae8df5cc 100644 --- a/instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/__init__.py @@ -58,8 +58,7 @@ class AiopgInstrumentor(BaseInstrumentor): "user": "info.user", } - _DATABASE_COMPONENT = "postgresql" - _DATABASE_TYPE = "sql" + _DATABASE_SYSTEM = "postgresql" def _instrument(self, **kwargs): """Integrate with PostgreSQL aiopg library. @@ -70,8 +69,7 @@ def _instrument(self, **kwargs): wrappers.wrap_connect( __name__, - self._DATABASE_COMPONENT, - self._DATABASE_TYPE, + self._DATABASE_SYSTEM, self._CONNECTION_ATTRIBUTES, version=__version__, tracer_provider=tracer_provider, @@ -79,8 +77,7 @@ def _instrument(self, **kwargs): wrappers.wrap_create_pool( __name__, - self._DATABASE_COMPONENT, - self._DATABASE_TYPE, + self._DATABASE_SYSTEM, self._CONNECTION_ATTRIBUTES, version=__version__, tracer_provider=tracer_provider, @@ -104,8 +101,7 @@ def instrument_connection(self, connection): return wrappers.instrument_connection( __name__, connection, - self._DATABASE_COMPONENT, - self._DATABASE_TYPE, + self._DATABASE_SYSTEM, self._CONNECTION_ATTRIBUTES, ) diff --git a/instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/aiopg_integration.py b/instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/aiopg_integration.py index 9824237565..b130ef2b51 100644 --- a/instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/aiopg_integration.py +++ b/instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/aiopg_integration.py @@ -4,8 +4,8 @@ from aiopg.utils import _ContextManager, _PoolAcquireContextManager from opentelemetry.instrumentation.dbapi import ( + CursorTracer, DatabaseApiIntegration, - TracedCursor, ) from opentelemetry.trace import SpanKind from opentelemetry.trace.status import Status, StatusCode @@ -94,25 +94,29 @@ async def _acquire(self): return TracedPoolProxy(pool, *args, **kwargs) -class AsyncTracedCursor(TracedCursor): +class AsyncCursorTracer(CursorTracer): async def traced_execution( self, + cursor, query_method: typing.Callable[..., typing.Any], *args: typing.Tuple[typing.Any, typing.Any], **kwargs: typing.Dict[typing.Any, typing.Any] ): name = "" - if len(args) > 0 and args[0]: - name = args[0] - elif self._db_api_integration.database: - name = self._db_api_integration.database - else: - name = self._db_api_integration.name + if args: + name = self.get_operation_name(cursor, args) + + if not name: + name = ( + self._db_api_integration.database + if self._db_api_integration.database + else self._db_api_integration.name + ) with self._db_api_integration.get_tracer().start_as_current_span( name, kind=SpanKind.CLIENT ) as span: - self._populate_span(span, *args) + self._populate_span(span, cursor, *args) try: result = await query_method(*args, **kwargs) return result @@ -123,10 +127,10 @@ async def traced_execution( def get_traced_cursor_proxy(cursor, db_api_integration, *args, **kwargs): - _traced_cursor = AsyncTracedCursor(db_api_integration) + _traced_cursor = AsyncCursorTracer(db_api_integration) # pylint: disable=abstract-method - class AsyncTracedCursorProxy(AsyncProxyObject): + class AsyncCursorTracerProxy(AsyncProxyObject): # pylint: disable=unused-argument def __init__(self, cursor, *args, **kwargs): @@ -134,20 +138,20 @@ def __init__(self, cursor, *args, **kwargs): async def execute(self, *args, **kwargs): result = await _traced_cursor.traced_execution( - self.__wrapped__.execute, *args, **kwargs + self, self.__wrapped__.execute, *args, **kwargs ) return result async def executemany(self, *args, **kwargs): result = await _traced_cursor.traced_execution( - self.__wrapped__.executemany, *args, **kwargs + self, self.__wrapped__.executemany, *args, **kwargs ) return result async def callproc(self, *args, **kwargs): result = await _traced_cursor.traced_execution( - self.__wrapped__.callproc, *args, **kwargs + self, self.__wrapped__.callproc, *args, **kwargs ) return result - return AsyncTracedCursorProxy(cursor, *args, **kwargs) + return AsyncCursorTracerProxy(cursor, *args, **kwargs) diff --git a/instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/version.py b/instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/version.py index 86e1dbb17a..ebb75f6c11 100644 --- a/instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/version.py +++ b/instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.17.dev0" +__version__ = "0.18.dev0" diff --git a/instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/wrappers.py b/instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/wrappers.py index 63a5d17514..706648d643 100644 --- a/instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/wrappers.py +++ b/instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/wrappers.py @@ -24,7 +24,7 @@ from opentelemetry import trace from opentelemetry.instrumentation.aiopg import trace_integration - trace_integration(aiopg.connection, "_connect", "postgresql", "sql") + trace_integration(aiopg.connection, "_connect", "postgresql") API --- @@ -48,8 +48,7 @@ def trace_integration( - database_component: str, - database_type: str = "", + database_system: str, connection_attributes: typing.Dict = None, tracer_provider: typing.Optional[TracerProvider] = None, ): @@ -57,19 +56,17 @@ def trace_integration( based on dbapi integration, where replaced sync wrap methods to async Args: - database_component: Database driver name or - database name "postgreSQL". - database_type: The Database type. For any SQL database, "sql". + database_system: An identifier for the database management system (DBMS) + product being used. connection_attributes: Attribute names for database, port, host and user in Connection object. tracer_provider: The :class:`opentelemetry.trace.TracerProvider` to - use. If ommited the current configured one is used. + use. If omitted the current configured one is used. """ wrap_connect( __name__, - database_component, - database_type, + database_system, connection_attributes, __version__, tracer_provider, @@ -78,8 +75,7 @@ def trace_integration( def wrap_connect( name: str, - database_component: str, - database_type: str = "", + database_system: str, connection_attributes: typing.Dict = None, version: str = "", tracer_provider: typing.Optional[TracerProvider] = None, @@ -89,14 +85,13 @@ def wrap_connect( Args: name: Name of opentelemetry extension for aiopg. - database_component: Database driver name - or database name "postgreSQL". - database_type: The Database type. For any SQL database, "sql". + database_system: An identifier for the database management system (DBMS) + product being used. connection_attributes: Attribute names for database, port, host and user in Connection object. version: Version of opentelemetry extension for aiopg. tracer_provider: The :class:`opentelemetry.trace.TracerProvider` to - use. If ommited the current configured one is used. + use. If omitted the current configured one is used. """ # pylint: disable=unused-argument @@ -108,8 +103,7 @@ def wrap_connect_( ): db_integration = AiopgIntegration( name, - database_component, - database_type=database_type, + database_system, connection_attributes=connection_attributes, version=version, tracer_provider=tracer_provider, @@ -135,8 +129,7 @@ def unwrap_connect(): def instrument_connection( name: str, connection, - database_component: str, - database_type: str = "", + database_system: str, connection_attributes: typing.Dict = None, version: str = "", tracer_provider: typing.Optional[TracerProvider] = None, @@ -146,21 +139,20 @@ def instrument_connection( Args: name: Name of opentelemetry extension for aiopg. connection: The connection to instrument. - database_component: Database driver name or database name "postgreSQL". - database_type: The Database type. For any SQL database, "sql". + database_system: An identifier for the database management system (DBMS) + product being used. connection_attributes: Attribute names for database, port, host and user in a connection object. version: Version of opentelemetry extension for aiopg. tracer_provider: The :class:`opentelemetry.trace.TracerProvider` to - use. If ommited the current configured one is used. + use. If omitted the current configured one is used. Returns: An instrumented connection. """ db_integration = AiopgIntegration( name, - database_component, - database_type, + database_system, connection_attributes=connection_attributes, version=version, tracer_provider=tracer_provider, @@ -187,8 +179,7 @@ def uninstrument_connection(connection): def wrap_create_pool( name: str, - database_component: str, - database_type: str = "", + database_system: str, connection_attributes: typing.Dict = None, version: str = "", tracer_provider: typing.Optional[TracerProvider] = None, @@ -202,8 +193,7 @@ def wrap_create_pool_( ): db_integration = AiopgIntegration( name, - database_component, - database_type, + database_system, connection_attributes=connection_attributes, version=version, tracer_provider=tracer_provider, diff --git a/instrumentation/opentelemetry-instrumentation-aiopg/tests/test_aiopg_integration.py b/instrumentation/opentelemetry-instrumentation-aiopg/tests/test_aiopg_integration.py index ad935cfdfd..27d47ca415 100644 --- a/instrumentation/opentelemetry-instrumentation-aiopg/tests/test_aiopg_integration.py +++ b/instrumentation/opentelemetry-instrumentation-aiopg/tests/test_aiopg_integration.py @@ -242,7 +242,6 @@ def test_span_succeeded(self): db_integration = AiopgIntegration( self.tracer, "testcomponent", - "testtype", connection_attributes, capture_parameters=True, ) @@ -256,10 +255,9 @@ def test_span_succeeded(self): spans_list = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans_list), 1) span = spans_list[0] - self.assertEqual(span.name, "Test query") + self.assertEqual(span.name, "Test") self.assertIs(span.kind, trace_api.SpanKind.CLIENT) - self.assertEqual(span.attributes["component"], "testcomponent") self.assertEqual(span.attributes["db.system"], "testcomponent") self.assertEqual(span.attributes["db.name"], "testdatabase") self.assertEqual(span.attributes["db.statement"], "Test query") @@ -294,7 +292,7 @@ def test_span_not_recording(self): mock_tracer.use_span.return_value.__enter__ = mock_span mock_tracer.use_span.return_value.__exit__ = True db_integration = AiopgIntegration( - mock_tracer, "testcomponent", "testtype", connection_attributes + mock_tracer, "testcomponent", connection_attributes ) mock_connection = async_call( db_integration.wrapped_connection( diff --git a/instrumentation/opentelemetry-instrumentation-asgi/setup.cfg b/instrumentation/opentelemetry-instrumentation-asgi/setup.cfg index 649d17ff8e..ee9969f3b7 100644 --- a/instrumentation/opentelemetry-instrumentation-asgi/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-asgi/setup.cfg @@ -39,8 +39,8 @@ package_dir= =src packages=find_namespace: install_requires = - opentelemetry-api == 0.17.dev0 - opentelemetry-instrumentation == 0.17.dev0 + opentelemetry-api == 0.18.dev0 + opentelemetry-instrumentation == 0.18.dev0 asgiref ~= 3.0 [options.extras_require] diff --git a/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py b/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py index 0947eadf08..b81b8b77f7 100644 --- a/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py @@ -72,7 +72,6 @@ def collect_request_attributes(scope): http_url = http_url + ("?" + urllib.parse.unquote(query_string)) result = { - "component": scope["type"], "http.scheme": scope.get("scheme"), "http.host": server_host, "net.host.port": port, diff --git a/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/version.py b/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/version.py index 86e1dbb17a..ebb75f6c11 100644 --- a/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/version.py +++ b/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.17.dev0" +__version__ = "0.18.dev0" diff --git a/instrumentation/opentelemetry-instrumentation-asgi/tests/test_asgi_middleware.py b/instrumentation/opentelemetry-instrumentation-asgi/tests/test_asgi_middleware.py index aecc06b082..7c4ae20a77 100644 --- a/instrumentation/opentelemetry-instrumentation-asgi/tests/test_asgi_middleware.py +++ b/instrumentation/opentelemetry-instrumentation-asgi/tests/test_asgi_middleware.py @@ -134,7 +134,6 @@ def validate_outputs(self, outputs, error=None, modifiers=None): "name": "GET asgi", "kind": trace_api.SpanKind.SERVER, "attributes": { - "component": "http", "http.method": "GET", "http.scheme": "http", "net.host.port": 80, @@ -321,7 +320,6 @@ def test_request_attributes(self): self.assertDictEqual( attrs, { - "component": "http", "http.method": "GET", "http.host": "127.0.0.1", "http.target": "/", diff --git a/instrumentation/opentelemetry-instrumentation-asyncpg/setup.cfg b/instrumentation/opentelemetry-instrumentation-asyncpg/setup.cfg index b22f9b60a2..f99c4b59e3 100644 --- a/instrumentation/opentelemetry-instrumentation-asyncpg/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-asyncpg/setup.cfg @@ -39,13 +39,13 @@ package_dir= =src packages=find_namespace: install_requires = - opentelemetry-api == 0.17.dev0 - opentelemetry-instrumentation == 0.17.dev0 + opentelemetry-api == 0.18.dev0 + opentelemetry-instrumentation == 0.18.dev0 asyncpg >= 0.12.0 [options.extras_require] test = - opentelemetry-test == 0.17.dev0 + opentelemetry-test == 0.18.dev0 [options.packages.find] where = src diff --git a/instrumentation/opentelemetry-instrumentation-asyncpg/src/opentelemetry/instrumentation/asyncpg/version.py b/instrumentation/opentelemetry-instrumentation-asyncpg/src/opentelemetry/instrumentation/asyncpg/version.py index 86e1dbb17a..ebb75f6c11 100644 --- a/instrumentation/opentelemetry-instrumentation-asyncpg/src/opentelemetry/instrumentation/asyncpg/version.py +++ b/instrumentation/opentelemetry-instrumentation-asyncpg/src/opentelemetry/instrumentation/asyncpg/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.17.dev0" +__version__ = "0.18.dev0" diff --git a/instrumentation/opentelemetry-instrumentation-boto/setup.cfg b/instrumentation/opentelemetry-instrumentation-boto/setup.cfg index c99153a5bf..b3b65ea632 100644 --- a/instrumentation/opentelemetry-instrumentation-boto/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-boto/setup.cfg @@ -19,7 +19,7 @@ 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/master/instrumentation/opentelemetry-instrumentation-boto +url = https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-boto platforms = any license = Apache-2.0 classifiers = @@ -40,15 +40,15 @@ package_dir= packages=find_namespace: install_requires = boto ~= 2.0 - opentelemetry-api == 0.17.dev0 - opentelemetry-instrumentation == 0.17.dev0 - opentelemetry-instrumentation-botocore == 0.17.dev0 + opentelemetry-api == 0.18.dev0 + opentelemetry-instrumentation == 0.18.dev0 + opentelemetry-instrumentation-botocore == 0.18.dev0 [options.extras_require] test = boto~=2.0 moto~=1.0 - opentelemetry-test == 0.17.dev0 + opentelemetry-test == 0.18.dev0 [options.packages.find] where = src diff --git a/instrumentation/opentelemetry-instrumentation-boto/src/opentelemetry/instrumentation/boto/version.py b/instrumentation/opentelemetry-instrumentation-boto/src/opentelemetry/instrumentation/boto/version.py index 86e1dbb17a..ebb75f6c11 100644 --- a/instrumentation/opentelemetry-instrumentation-boto/src/opentelemetry/instrumentation/boto/version.py +++ b/instrumentation/opentelemetry-instrumentation-boto/src/opentelemetry/instrumentation/boto/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.17.dev0" +__version__ = "0.18.dev0" diff --git a/instrumentation/opentelemetry-instrumentation-botocore/setup.cfg b/instrumentation/opentelemetry-instrumentation-botocore/setup.cfg index ed4954adbe..082f274aef 100644 --- a/instrumentation/opentelemetry-instrumentation-botocore/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-botocore/setup.cfg @@ -19,7 +19,7 @@ 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/master/instrumentation/opentelemetry-instrumentation-botocore +url = https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-botocore platforms = any license = Apache-2.0 classifiers = @@ -40,13 +40,13 @@ package_dir= packages=find_namespace: install_requires = botocore ~= 1.0 - opentelemetry-api == 0.17.dev0 - opentelemetry-instrumentation == 0.17.dev0 + opentelemetry-api == 0.18.dev0 + opentelemetry-instrumentation == 0.18.dev0 [options.extras_require] test = moto ~= 1.0 - opentelemetry-test == 0.17.dev0 + opentelemetry-test == 0.18.dev0 [options.packages.find] where = src diff --git a/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/version.py b/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/version.py index 86e1dbb17a..ebb75f6c11 100644 --- a/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/version.py +++ b/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.17.dev0" +__version__ = "0.18.dev0" diff --git a/instrumentation/opentelemetry-instrumentation-celery/setup.cfg b/instrumentation/opentelemetry-instrumentation-celery/setup.cfg index b12587fd7e..15f4cff569 100644 --- a/instrumentation/opentelemetry-instrumentation-celery/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-celery/setup.cfg @@ -19,7 +19,7 @@ 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/master/instrumentation/opentelemetry-instrumentation-celery +url = https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-celery platforms = any license = Apache-2.0 classifiers = @@ -40,14 +40,14 @@ package_dir= packages=find_namespace: install_requires = celery >= 4.0, < 6.0 - opentelemetry-api == 0.17.dev0 - opentelemetry-instrumentation == 0.17.dev0 + opentelemetry-api == 0.18.dev0 + opentelemetry-instrumentation == 0.18.dev0 [options.extras_require] test = pytest celery >= 4.0, < 6.0 - opentelemetry-test == 0.17.dev0 + opentelemetry-test == 0.18.dev0 [options.packages.find] where = src diff --git a/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/version.py b/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/version.py index 86e1dbb17a..ebb75f6c11 100644 --- a/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/version.py +++ b/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.17.dev0" +__version__ = "0.18.dev0" diff --git a/instrumentation/opentelemetry-instrumentation-dbapi/setup.cfg b/instrumentation/opentelemetry-instrumentation-dbapi/setup.cfg index f14776a2b3..4856a98c94 100644 --- a/instrumentation/opentelemetry-instrumentation-dbapi/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-dbapi/setup.cfg @@ -19,7 +19,7 @@ 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/master/instrumentation/opentelemetry-instrumentation-dbapi +url = https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-dbapi platforms = any license = Apache-2.0 classifiers = @@ -39,13 +39,13 @@ package_dir= =src packages=find_namespace: install_requires = - opentelemetry-api == 0.17.dev0 - opentelemetry-instrumentation == 0.17.dev0 + opentelemetry-api == 0.18.dev0 + opentelemetry-instrumentation == 0.18.dev0 wrapt >= 1.0.0, < 2.0.0 [options.extras_require] test = - opentelemetry-test == 0.17.dev0 + opentelemetry-test == 0.18.dev0 [options.packages.find] where = src diff --git a/instrumentation/opentelemetry-instrumentation-dbapi/src/opentelemetry/instrumentation/dbapi/__init__.py b/instrumentation/opentelemetry-instrumentation-dbapi/src/opentelemetry/instrumentation/dbapi/__init__.py index 197f4ade44..6a20e3dbfc 100644 --- a/instrumentation/opentelemetry-instrumentation-dbapi/src/opentelemetry/instrumentation/dbapi/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-dbapi/src/opentelemetry/instrumentation/dbapi/__init__.py @@ -29,9 +29,9 @@ # Ex: mysql.connector - trace_integration(mysql.connector, "connect", "mysql", "sql") + trace_integration(mysql.connector, "connect", "mysql") # Ex: pyodbc - trace_integration(pyodbc, "Connection", "odbc", "sql") + trace_integration(pyodbc, "Connection", "odbc") API --- @@ -55,11 +55,11 @@ def trace_integration( connect_module: typing.Callable[..., typing.Any], connect_method_name: str, - database_component: str, - database_type: str = "", + database_system: str, connection_attributes: typing.Dict = None, tracer_provider: typing.Optional[TracerProvider] = None, capture_parameters: bool = False, + db_api_integration_factory=None, ): """Integrate with DB API library. https://www.python.org/dev/peps/pep-0249/ @@ -67,25 +67,24 @@ def trace_integration( Args: connect_module: Module name where connect method is available. connect_method_name: The connect method name. - database_component: Database driver name or database name "JDBI", - "jdbc", "odbc", "postgreSQL". - database_type: The Database type. For any SQL database, "sql". + database_system: An identifier for the database management system (DBMS) + product being used. connection_attributes: Attribute names for database, port, host and user in Connection object. tracer_provider: The :class:`opentelemetry.trace.TracerProvider` to - use. If ommited the current configured one is used. + use. If omitted the current configured one is used. capture_parameters: Configure if db.statement.parameters should be captured. """ wrap_connect( __name__, connect_module, connect_method_name, - database_component, - database_type, + database_system, connection_attributes, version=__version__, tracer_provider=tracer_provider, capture_parameters=capture_parameters, + db_api_integration_factory=db_api_integration_factory, ) @@ -93,28 +92,31 @@ def wrap_connect( name: str, connect_module: typing.Callable[..., typing.Any], connect_method_name: str, - database_component: str, - database_type: str = "", + database_system: str, connection_attributes: typing.Dict = None, version: str = "", tracer_provider: typing.Optional[TracerProvider] = None, capture_parameters: bool = False, + db_api_integration_factory=None, ): """Integrate with DB API library. https://www.python.org/dev/peps/pep-0249/ Args: - tracer: The :class:`opentelemetry.trace.Tracer` to use. connect_module: Module name where connect method is available. connect_method_name: The connect method name. - database_component: Database driver name or database name "JDBI", - "jdbc", "odbc", "postgreSQL". - database_type: The Database type. For any SQL database, "sql". + database_system: An identifier for the database management system (DBMS) + product being used. connection_attributes: Attribute names for database, port, host and user in Connection object. + tracer_provider: The :class:`opentelemetry.trace.TracerProvider` to + use. If omitted the current configured one is used. capture_parameters: Configure if db.statement.parameters should be captured. """ + db_api_integration_factory = ( + db_api_integration_factory or DatabaseApiIntegration + ) # pylint: disable=unused-argument def wrap_connect_( @@ -123,10 +125,9 @@ def wrap_connect_( args: typing.Tuple[typing.Any, typing.Any], kwargs: typing.Dict[typing.Any, typing.Any], ): - db_integration = DatabaseApiIntegration( + db_integration = db_api_integration_factory( name, - database_component, - database_type=database_type, + database_system, connection_attributes=connection_attributes, version=version, tracer_provider=tracer_provider, @@ -158,8 +159,7 @@ def unwrap_connect( def instrument_connection( name: str, connection, - database_component: str, - database_type: str = "", + database_system: str, connection_attributes: typing.Dict = None, version: str = "", tracer_provider: typing.Optional[TracerProvider] = None, @@ -168,21 +168,20 @@ def instrument_connection( """Enable instrumentation in a database connection. Args: - tracer: The :class:`opentelemetry.trace.Tracer` to use. connection: The connection to instrument. - database_component: Database driver name or database name "JDBI", - "jdbc", "odbc", "postgreSQL". - database_type: The Database type. For any SQL database, "sql". + database_system: An identifier for the database management system (DBMS) + product being used. connection_attributes: Attribute names for database, port, host and user in a connection object. + tracer_provider: The :class:`opentelemetry.trace.TracerProvider` to + use. If omitted the current configured one is used. capture_parameters: Configure if db.statement.parameters should be captured. Returns: An instrumented connection. """ db_integration = DatabaseApiIntegration( name, - database_component, - database_type, + database_system, connection_attributes=connection_attributes, version=version, tracer_provider=tracer_provider, @@ -212,8 +211,7 @@ class DatabaseApiIntegration: def __init__( self, name: str, - database_component: str, - database_type: str = "sql", + database_system: str, connection_attributes=None, version: str = "", tracer_provider: typing.Optional[TracerProvider] = None, @@ -231,8 +229,7 @@ def __init__( self._version = version self._tracer_provider = tracer_provider self.capture_parameters = capture_parameters - self.database_component = database_component - self.database_type = database_type + self.database_system = database_system self.connection_props = {} self.span_attributes = {} self.name = "" @@ -269,7 +266,7 @@ def get_connection_attributes(self, connection): ) if attribute: self.connection_props[key] = attribute - self.name = self.database_component + self.name = self.database_system self.database = self.connection_props.get("database", "") if self.database: # PyMySQL encodes names with utf-8 @@ -314,21 +311,21 @@ def __exit__(self, *args, **kwargs): return TracedConnectionProxy(connection, *args, **kwargs) -class TracedCursor: +class CursorTracer: def __init__(self, db_api_integration: DatabaseApiIntegration): self._db_api_integration = db_api_integration def _populate_span( - self, span: trace_api.Span, *args: typing.Tuple[typing.Any, typing.Any] + self, + span: trace_api.Span, + cursor, + *args: typing.Tuple[typing.Any, typing.Any] ): if not span.is_recording(): return - statement = args[0] if args else "" + statement = self.get_statement(cursor, args) span.set_attribute( - "component", self._db_api_integration.database_component - ) - span.set_attribute( - "db.system", self._db_api_integration.database_component + "db.system", self._db_api_integration.database_system ) span.set_attribute("db.name", self._db_api_integration.database) span.set_attribute("db.statement", statement) @@ -342,24 +339,38 @@ def _populate_span( if self._db_api_integration.capture_parameters and len(args) > 1: span.set_attribute("db.statement.parameters", str(args[1])) + def get_operation_name(self, cursor, args): # pylint: disable=no-self-use + if args and isinstance(args[0], str): + return args[0].split()[0] + return "" + + def get_statement(self, cursor, args): # pylint: disable=no-self-use + if not args: + return "" + statement = args[0] + if isinstance(statement, bytes): + return statement.decode("utf8", "replace") + return statement + def traced_execution( self, + cursor, query_method: typing.Callable[..., typing.Any], *args: typing.Tuple[typing.Any, typing.Any], **kwargs: typing.Dict[typing.Any, typing.Any] ): - name = "" - if args: - name = args[0] - elif self._db_api_integration.database: - name = self._db_api_integration.database - else: - name = self._db_api_integration.name + name = self.get_operation_name(cursor, args) + if not name: + name = ( + self._db_api_integration.database + if self._db_api_integration.database + else self._db_api_integration.name + ) with self._db_api_integration.get_tracer().start_as_current_span( name, kind=SpanKind.CLIENT ) as span: - self._populate_span(span, *args) + self._populate_span(span, cursor, *args) try: result = query_method(*args, **kwargs) return result @@ -370,7 +381,7 @@ def traced_execution( def get_traced_cursor_proxy(cursor, db_api_integration, *args, **kwargs): - _traced_cursor = TracedCursor(db_api_integration) + _cursor_tracer = CursorTracer(db_api_integration) # pylint: disable=abstract-method class TracedCursorProxy(wrapt.ObjectProxy): @@ -380,18 +391,18 @@ def __init__(self, cursor, *args, **kwargs): wrapt.ObjectProxy.__init__(self, cursor) def execute(self, *args, **kwargs): - return _traced_cursor.traced_execution( - self.__wrapped__.execute, *args, **kwargs + return _cursor_tracer.traced_execution( + self.__wrapped__, self.__wrapped__.execute, *args, **kwargs ) def executemany(self, *args, **kwargs): - return _traced_cursor.traced_execution( - self.__wrapped__.executemany, *args, **kwargs + return _cursor_tracer.traced_execution( + self.__wrapped__, self.__wrapped__.executemany, *args, **kwargs ) def callproc(self, *args, **kwargs): - return _traced_cursor.traced_execution( - self.__wrapped__.callproc, *args, **kwargs + return _cursor_tracer.traced_execution( + self.__wrapped__, self.__wrapped__.callproc, *args, **kwargs ) def __enter__(self): diff --git a/instrumentation/opentelemetry-instrumentation-dbapi/src/opentelemetry/instrumentation/dbapi/version.py b/instrumentation/opentelemetry-instrumentation-dbapi/src/opentelemetry/instrumentation/dbapi/version.py index 86e1dbb17a..ebb75f6c11 100644 --- a/instrumentation/opentelemetry-instrumentation-dbapi/src/opentelemetry/instrumentation/dbapi/version.py +++ b/instrumentation/opentelemetry-instrumentation-dbapi/src/opentelemetry/instrumentation/dbapi/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.17.dev0" +__version__ = "0.18.dev0" diff --git a/instrumentation/opentelemetry-instrumentation-dbapi/tests/test_dbapi_integration.py b/instrumentation/opentelemetry-instrumentation-dbapi/tests/test_dbapi_integration.py index e69bf60c9d..5a8b34530e 100644 --- a/instrumentation/opentelemetry-instrumentation-dbapi/tests/test_dbapi_integration.py +++ b/instrumentation/opentelemetry-instrumentation-dbapi/tests/test_dbapi_integration.py @@ -40,7 +40,7 @@ def test_span_succeeded(self): "user": "user", } db_integration = dbapi.DatabaseApiIntegration( - self.tracer, "testcomponent", "testtype", connection_attributes + self.tracer, "testcomponent", connection_attributes ) mock_connection = db_integration.wrapped_connection( mock_connect, {}, connection_props @@ -50,10 +50,9 @@ def test_span_succeeded(self): spans_list = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans_list), 1) span = spans_list[0] - self.assertEqual(span.name, "Test query") + self.assertEqual(span.name, "Test") self.assertIs(span.kind, trace_api.SpanKind.CLIENT) - self.assertEqual(span.attributes["component"], "testcomponent") self.assertEqual(span.attributes["db.system"], "testcomponent") self.assertEqual(span.attributes["db.name"], "testdatabase") self.assertEqual(span.attributes["db.statement"], "Test query") @@ -65,6 +64,27 @@ def test_span_succeeded(self): span.status.status_code, trace_api.status.StatusCode.UNSET ) + def test_span_name(self): + db_integration = dbapi.DatabaseApiIntegration( + self.tracer, "testcomponent", {} + ) + mock_connection = db_integration.wrapped_connection( + mock_connect, {}, {} + ) + cursor = mock_connection.cursor() + cursor.execute("Test query", ("param1Value", False)) + cursor.execute( + """multi + line + query""" + ) + cursor.execute("tab\tseparated query") + spans_list = self.memory_exporter.get_finished_spans() + self.assertEqual(len(spans_list), 3) + self.assertEqual(spans_list[0].name, "Test") + self.assertEqual(spans_list[1].name, "multi") + self.assertEqual(spans_list[2].name, "tab") + def test_span_succeeded_with_capture_of_statement_parameters(self): connection_props = { "database": "testdatabase", @@ -81,7 +101,6 @@ def test_span_succeeded_with_capture_of_statement_parameters(self): db_integration = dbapi.DatabaseApiIntegration( self.tracer, "testcomponent", - "testtype", connection_attributes, capture_parameters=True, ) @@ -93,10 +112,9 @@ def test_span_succeeded_with_capture_of_statement_parameters(self): spans_list = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans_list), 1) span = spans_list[0] - self.assertEqual(span.name, "Test query") + self.assertEqual(span.name, "Test") self.assertIs(span.kind, trace_api.SpanKind.CLIENT) - self.assertEqual(span.attributes["component"], "testcomponent") self.assertEqual(span.attributes["db.system"], "testcomponent") self.assertEqual(span.attributes["db.name"], "testdatabase") self.assertEqual(span.attributes["db.statement"], "Test query") @@ -131,7 +149,7 @@ def test_span_not_recording(self): mock_tracer.use_span.return_value.__enter__ = mock_span mock_tracer.use_span.return_value.__exit__ = True db_integration = dbapi.DatabaseApiIntegration( - mock_tracer, "testcomponent", "testtype", connection_attributes + mock_tracer, "testcomponent", connection_attributes ) mock_connection = db_integration.wrapped_connection( mock_connect, {}, connection_props diff --git a/instrumentation/opentelemetry-instrumentation-django/setup.cfg b/instrumentation/opentelemetry-instrumentation-django/setup.cfg index 2f5483f779..6bb8d05ede 100644 --- a/instrumentation/opentelemetry-instrumentation-django/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-django/setup.cfg @@ -19,7 +19,7 @@ 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/master/instrumentation/opentelemetry-instrumentation-django +url = https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-django platforms = any license = Apache-2.0 classifiers = @@ -40,13 +40,13 @@ package_dir= packages=find_namespace: install_requires = django >= 1.10 - opentelemetry-instrumentation-wsgi == 0.17.dev0 - opentelemetry-instrumentation == 0.17.dev0 - opentelemetry-api == 0.17.dev0 + opentelemetry-instrumentation-wsgi == 0.18.dev0 + opentelemetry-instrumentation == 0.18.dev0 + opentelemetry-api == 0.18.dev0 [options.extras_require] test = - opentelemetry-test == 0.17.dev0 + opentelemetry-test == 0.18.dev0 [options.packages.find] where = src diff --git a/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/version.py b/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/version.py index 86e1dbb17a..ebb75f6c11 100644 --- a/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/version.py +++ b/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.17.dev0" +__version__ = "0.18.dev0" diff --git a/instrumentation/opentelemetry-instrumentation-elasticsearch/setup.cfg b/instrumentation/opentelemetry-instrumentation-elasticsearch/setup.cfg index 4bcd9f2de6..167a3bbd6a 100644 --- a/instrumentation/opentelemetry-instrumentation-elasticsearch/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-elasticsearch/setup.cfg @@ -19,7 +19,7 @@ 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/master/instrumentation/opentelemetry-instrumentation-elasticsearch +url = https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-elasticsearch platforms = any license = Apache-2.0 classifiers = @@ -39,14 +39,14 @@ package_dir= =src packages=find_namespace: install_requires = - opentelemetry-api == 0.17.dev0 - opentelemetry-instrumentation == 0.17.dev0 + opentelemetry-api == 0.18.dev0 + opentelemetry-instrumentation == 0.18.dev0 wrapt >= 1.0.0, < 2.0.0 elasticsearch >= 2.0 [options.extras_require] test = - opentelemetry-test == 0.17.dev0 + opentelemetry-test == 0.18.dev0 elasticsearch-dsl >= 2.0 [options.packages.find] diff --git a/instrumentation/opentelemetry-instrumentation-elasticsearch/src/opentelemetry/instrumentation/elasticsearch/__init__.py b/instrumentation/opentelemetry-instrumentation-elasticsearch/src/opentelemetry/instrumentation/elasticsearch/__init__.py index 5df7f6a807..848ec135a8 100644 --- a/instrumentation/opentelemetry-instrumentation-elasticsearch/src/opentelemetry/instrumentation/elasticsearch/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-elasticsearch/src/opentelemetry/instrumentation/elasticsearch/__init__.py @@ -128,8 +128,7 @@ def wrapper(wrapped, _, args, kwargs): ) as span: if span.is_recording(): attributes = { - "component": "elasticsearch-py", - "db.type": "elasticsearch", + "db.system": "elasticsearch", } if url: attributes["elasticsearch.url"] = url diff --git a/instrumentation/opentelemetry-instrumentation-elasticsearch/src/opentelemetry/instrumentation/elasticsearch/version.py b/instrumentation/opentelemetry-instrumentation-elasticsearch/src/opentelemetry/instrumentation/elasticsearch/version.py index 86e1dbb17a..ebb75f6c11 100644 --- a/instrumentation/opentelemetry-instrumentation-elasticsearch/src/opentelemetry/instrumentation/elasticsearch/version.py +++ b/instrumentation/opentelemetry-instrumentation-elasticsearch/src/opentelemetry/instrumentation/elasticsearch/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.17.dev0" +__version__ = "0.18.dev0" diff --git a/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py b/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py index ea0e6ce2fb..fbdf5f3952 100644 --- a/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py +++ b/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py @@ -248,8 +248,7 @@ def test_dsl_search(self, request_mock): self.assertEqual( span.attributes, { - "component": "elasticsearch-py", - "db.type": "elasticsearch", + "db.system": "elasticsearch", "elasticsearch.url": "/test-index/_search", "elasticsearch.method": helpers.dsl_search_method, "db.statement": str( @@ -276,8 +275,7 @@ def test_dsl_create(self, request_mock): self.assertEqual( span1.attributes, { - "component": "elasticsearch-py", - "db.type": "elasticsearch", + "db.system": "elasticsearch", "elasticsearch.url": "/test-index", "elasticsearch.method": "HEAD", }, @@ -285,8 +283,7 @@ def test_dsl_create(self, request_mock): self.assertEqual(span2.name, "Elasticsearch/test-index") attributes = { - "component": "elasticsearch-py", - "db.type": "elasticsearch", + "db.system": "elasticsearch", "elasticsearch.url": "/test-index", "elasticsearch.method": "PUT", } @@ -312,8 +309,7 @@ def test_dsl_index(self, request_mock): span = spans[0] self.assertEqual(span.name, helpers.dsl_index_span_name) attributes = { - "component": "elasticsearch-py", - "db.type": "elasticsearch", + "db.system": "elasticsearch", "elasticsearch.url": helpers.dsl_index_url, "elasticsearch.method": "PUT", } diff --git a/instrumentation/opentelemetry-instrumentation-falcon/setup.cfg b/instrumentation/opentelemetry-instrumentation-falcon/setup.cfg index 3f312f6a8e..bbc9268b9b 100644 --- a/instrumentation/opentelemetry-instrumentation-falcon/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-falcon/setup.cfg @@ -19,7 +19,7 @@ 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/master/instrumentation/opentelemetry-instrumentation-falcon +url = https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-falcon platforms = any license = Apache-2.0 classifiers = @@ -41,14 +41,14 @@ package_dir= packages=find_namespace: install_requires = falcon ~= 2.0 - opentelemetry-instrumentation-wsgi == 0.17.dev0 - opentelemetry-instrumentation == 0.17.dev0 - opentelemetry-api == 0.17.dev0 + opentelemetry-instrumentation-wsgi == 0.18.dev0 + opentelemetry-instrumentation == 0.18.dev0 + opentelemetry-api == 0.18.dev0 [options.extras_require] test = falcon ~= 2.0 - opentelemetry-test == 0.17.dev0 + opentelemetry-test == 0.18.dev0 parameterized == 0.7.4 [options.packages.find] diff --git a/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/version.py b/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/version.py index 86e1dbb17a..ebb75f6c11 100644 --- a/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/version.py +++ b/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.17.dev0" +__version__ = "0.18.dev0" diff --git a/instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py b/instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py index 616db2837f..73088d7611 100644 --- a/instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py +++ b/instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py @@ -95,7 +95,6 @@ def _test_method(self, method): self.assert_span_has_attributes( span, { - "component": "http", "http.method": method, "http.server_name": "falconframework.org", "http.scheme": "http", @@ -122,7 +121,6 @@ def test_404(self): self.assert_span_has_attributes( span, { - "component": "http", "http.method": "GET", "http.server_name": "falconframework.org", "http.scheme": "http", @@ -155,7 +153,6 @@ def test_500(self): self.assert_span_has_attributes( span, { - "component": "http", "http.method": "GET", "http.server_name": "falconframework.org", "http.scheme": "http", diff --git a/instrumentation/opentelemetry-instrumentation-fastapi/setup.cfg b/instrumentation/opentelemetry-instrumentation-fastapi/setup.cfg index cc737148a0..6828ea1af4 100644 --- a/instrumentation/opentelemetry-instrumentation-fastapi/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-fastapi/setup.cfg @@ -19,7 +19,7 @@ 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/master/instrumentation/opentelemetry-instrumentation-fastapi +url = https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-fastapi platforms = any license = Apache-2.0 classifiers = @@ -38,8 +38,8 @@ package_dir= =src packages=find_namespace: install_requires = - opentelemetry-api == 0.17.dev0 - opentelemetry-instrumentation-asgi == 0.17.dev0 + opentelemetry-api == 0.18.dev0 + opentelemetry-instrumentation-asgi == 0.18.dev0 [options.entry_points] opentelemetry_instrumentor = @@ -47,7 +47,7 @@ opentelemetry_instrumentor = [options.extras_require] test = - opentelemetry-test == 0.17.dev0 + opentelemetry-test == 0.18.dev0 fastapi ~= 0.58.1 requests ~= 2.23.0 # needed for testclient diff --git a/instrumentation/opentelemetry-instrumentation-fastapi/src/opentelemetry/instrumentation/fastapi/version.py b/instrumentation/opentelemetry-instrumentation-fastapi/src/opentelemetry/instrumentation/fastapi/version.py index 86e1dbb17a..ebb75f6c11 100644 --- a/instrumentation/opentelemetry-instrumentation-fastapi/src/opentelemetry/instrumentation/fastapi/version.py +++ b/instrumentation/opentelemetry-instrumentation-fastapi/src/opentelemetry/instrumentation/fastapi/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.17.dev0" +__version__ = "0.18.dev0" diff --git a/instrumentation/opentelemetry-instrumentation-flask/setup.cfg b/instrumentation/opentelemetry-instrumentation-flask/setup.cfg index 2e6191a95d..bf98fb7880 100644 --- a/instrumentation/opentelemetry-instrumentation-flask/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-flask/setup.cfg @@ -19,7 +19,7 @@ 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/master/instrumentation/opentelemetry-instrumentation-flask +url = https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-flask platforms = any license = Apache-2.0 classifiers = @@ -40,14 +40,14 @@ package_dir= packages=find_namespace: install_requires = flask ~= 1.0 - opentelemetry-instrumentation-wsgi == 0.17.dev0 - opentelemetry-instrumentation == 0.17.dev0 - opentelemetry-api == 0.17.dev0 + opentelemetry-instrumentation-wsgi == 0.18.dev0 + opentelemetry-instrumentation == 0.18.dev0 + opentelemetry-api == 0.18.dev0 [options.extras_require] test = flask~=1.0 - opentelemetry-test == 0.17.dev0 + opentelemetry-test == 0.18.dev0 [options.packages.find] where = src diff --git a/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/version.py b/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/version.py index 86e1dbb17a..ebb75f6c11 100644 --- a/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/version.py +++ b/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.17.dev0" +__version__ = "0.18.dev0" diff --git a/instrumentation/opentelemetry-instrumentation-flask/tests/test_programmatic.py b/instrumentation/opentelemetry-instrumentation-flask/tests/test_programmatic.py index 495b4a739a..377ce88842 100644 --- a/instrumentation/opentelemetry-instrumentation-flask/tests/test_programmatic.py +++ b/instrumentation/opentelemetry-instrumentation-flask/tests/test_programmatic.py @@ -28,7 +28,6 @@ def expected_attributes(override_attributes): default_attributes = { - "component": "http", "http.method": "GET", "http.server_name": "localhost", "http.scheme": "http", diff --git a/instrumentation/opentelemetry-instrumentation-grpc/setup.cfg b/instrumentation/opentelemetry-instrumentation-grpc/setup.cfg index 268a326562..aa767bd3d8 100644 --- a/instrumentation/opentelemetry-instrumentation-grpc/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-grpc/setup.cfg @@ -19,7 +19,7 @@ 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/master/instrumentation/opentelemetry-instrumentation-grpc +url = https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-grpc platforms = any license = Apache-2.0 classifiers = @@ -39,14 +39,14 @@ package_dir= =src packages=find_namespace: install_requires = - opentelemetry-api == 0.17.dev0 - opentelemetry-sdk == 0.17.dev0 + opentelemetry-api == 0.18.dev0 + opentelemetry-sdk == 0.18.dev0 grpcio ~= 1.27 [options.extras_require] test = - opentelemetry-test == 0.17.dev0 - opentelemetry-sdk == 0.17.dev0 + opentelemetry-test == 0.18.dev0 + opentelemetry-sdk == 0.18.dev0 protobuf >= 3.13.0 [options.packages.find] diff --git a/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/version.py b/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/version.py index 86e1dbb17a..ebb75f6c11 100644 --- a/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/version.py +++ b/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.17.dev0" +__version__ = "0.18.dev0" diff --git a/instrumentation/opentelemetry-instrumentation-jinja2/setup.cfg b/instrumentation/opentelemetry-instrumentation-jinja2/setup.cfg index ca5e3bcf3e..1ec718f6ae 100644 --- a/instrumentation/opentelemetry-instrumentation-jinja2/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-jinja2/setup.cfg @@ -19,7 +19,7 @@ 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/master/instrumentation/opentelemetry-instrumentation-jinja2 +url = https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-jinja2 platforms = any license = Apache-2.0 classifiers = @@ -38,14 +38,14 @@ package_dir= =src packages=find_namespace: install_requires = - opentelemetry-api == 0.17.dev0 - opentelemetry-instrumentation == 0.17.dev0 + opentelemetry-api == 0.18.dev0 + opentelemetry-instrumentation == 0.18.dev0 jinja2~=2.7 wrapt >= 1.0.0, < 2.0.0 [options.extras_require] test = - opentelemetry-test == 0.17.dev0 + opentelemetry-test == 0.18.dev0 [options.packages.find] where = src diff --git a/instrumentation/opentelemetry-instrumentation-jinja2/src/opentelemetry/instrumentation/jinja2/version.py b/instrumentation/opentelemetry-instrumentation-jinja2/src/opentelemetry/instrumentation/jinja2/version.py index 86e1dbb17a..ebb75f6c11 100644 --- a/instrumentation/opentelemetry-instrumentation-jinja2/src/opentelemetry/instrumentation/jinja2/version.py +++ b/instrumentation/opentelemetry-instrumentation-jinja2/src/opentelemetry/instrumentation/jinja2/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.17.dev0" +__version__ = "0.18.dev0" diff --git a/instrumentation/opentelemetry-instrumentation-mysql/setup.cfg b/instrumentation/opentelemetry-instrumentation-mysql/setup.cfg index 4f5d4ad1c5..b35a11485c 100644 --- a/instrumentation/opentelemetry-instrumentation-mysql/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-mysql/setup.cfg @@ -19,7 +19,7 @@ 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/master/instrumentation/opentelemetry-instrumentation-mysql +url = https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-mysql platforms = any license = Apache-2.0 classifiers = @@ -39,15 +39,15 @@ package_dir= =src packages=find_namespace: install_requires = - opentelemetry-api == 0.17.dev0 - opentelemetry-instrumentation-dbapi == 0.17.dev0 - opentelemetry-instrumentation == 0.17.dev0 + opentelemetry-api == 0.18.dev0 + opentelemetry-instrumentation-dbapi == 0.18.dev0 + opentelemetry-instrumentation == 0.18.dev0 mysql-connector-python ~= 8.0 wrapt >= 1.0.0, < 2.0.0 [options.extras_require] test = - opentelemetry-test == 0.17.dev0 + opentelemetry-test == 0.18.dev0 [options.packages.find] where = src diff --git a/instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql/__init__.py b/instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql/__init__.py index 7440ee8bc2..9fdf594c56 100644 --- a/instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql/__init__.py @@ -54,8 +54,7 @@ class MySQLInstrumentor(BaseInstrumentor): "user": "user", } - _DATABASE_COMPONENT = "mysql" - _DATABASE_TYPE = "sql" + _DATABASE_SYSTEM = "mysql" def _instrument(self, **kwargs): """Integrate with MySQL Connector/Python library. @@ -67,8 +66,7 @@ def _instrument(self, **kwargs): __name__, mysql.connector, "connect", - self._DATABASE_COMPONENT, - self._DATABASE_TYPE, + self._DATABASE_SYSTEM, self._CONNECTION_ATTRIBUTES, version=__version__, tracer_provider=tracer_provider, @@ -93,8 +91,7 @@ def instrument_connection(self, connection): return dbapi.instrument_connection( tracer, connection, - self._DATABASE_COMPONENT, - self._DATABASE_TYPE, + self._DATABASE_SYSTEM, self._CONNECTION_ATTRIBUTES, ) diff --git a/instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql/version.py b/instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql/version.py index 86e1dbb17a..ebb75f6c11 100644 --- a/instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql/version.py +++ b/instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.17.dev0" +__version__ = "0.18.dev0" diff --git a/instrumentation/opentelemetry-instrumentation-psycopg2/setup.cfg b/instrumentation/opentelemetry-instrumentation-psycopg2/setup.cfg index d5f281fcb7..569da90885 100644 --- a/instrumentation/opentelemetry-instrumentation-psycopg2/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-psycopg2/setup.cfg @@ -19,7 +19,7 @@ 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/master/instrumentation/opentelemetry-instrumentation-psycopg2 +url = https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-psycopg2 platforms = any license = Apache-2.0 classifiers = @@ -39,15 +39,15 @@ package_dir= =src packages=find_namespace: install_requires = - opentelemetry-api == 0.17.dev0 - opentelemetry-instrumentation-dbapi == 0.17.dev0 - opentelemetry-instrumentation == 0.17.dev0 + opentelemetry-api == 0.18.dev0 + opentelemetry-instrumentation-dbapi == 0.18.dev0 + opentelemetry-instrumentation == 0.18.dev0 psycopg2-binary >= 2.7.3.1 wrapt >= 1.0.0, < 2.0.0 [options.extras_require] test = - opentelemetry-test == 0.17.dev0 + opentelemetry-test == 0.18.dev0 [options.packages.find] where = src diff --git a/instrumentation/opentelemetry-instrumentation-psycopg2/src/opentelemetry/instrumentation/psycopg2/__init__.py b/instrumentation/opentelemetry-instrumentation-psycopg2/src/opentelemetry/instrumentation/psycopg2/__init__.py index 4b8799402e..1190d1c083 100644 --- a/instrumentation/opentelemetry-instrumentation-psycopg2/src/opentelemetry/instrumentation/psycopg2/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-psycopg2/src/opentelemetry/instrumentation/psycopg2/__init__.py @@ -39,12 +39,19 @@ --- """ +import typing + import psycopg2 +from psycopg2.extensions import ( + cursor as pg_cursor, # pylint: disable=no-name-in-module +) +from psycopg2.sql import Composed # pylint: disable=no-name-in-module from opentelemetry.instrumentation import dbapi from opentelemetry.instrumentation.instrumentor import BaseInstrumentor from opentelemetry.instrumentation.psycopg2.version import __version__ -from opentelemetry.trace import get_tracer + +_OTEL_CURSOR_FACTORY_KEY = "_otel_orig_cursor_factory" class Psycopg2Instrumentor(BaseInstrumentor): @@ -55,58 +62,116 @@ class Psycopg2Instrumentor(BaseInstrumentor): "user": "info.user", } - _DATABASE_COMPONENT = "postgresql" - _DATABASE_TYPE = "sql" + _DATABASE_SYSTEM = "postgresql" def _instrument(self, **kwargs): """Integrate with PostgreSQL Psycopg library. Psycopg: http://initd.org/psycopg/ """ - tracer_provider = kwargs.get("tracer_provider") dbapi.wrap_connect( __name__, psycopg2, "connect", - self._DATABASE_COMPONENT, - self._DATABASE_TYPE, + self._DATABASE_SYSTEM, self._CONNECTION_ATTRIBUTES, version=__version__, tracer_provider=tracer_provider, + db_api_integration_factory=DatabaseApiIntegration, ) def _uninstrument(self, **kwargs): """"Disable Psycopg2 instrumentation""" dbapi.unwrap_connect(psycopg2, "connect") - # pylint:disable=no-self-use - def instrument_connection(self, connection): - """Enable instrumentation in a Psycopg2 connection. - - Args: - connection: The connection to instrument. + # TODO(owais): check if core dbapi can do this for all dbapi implementations e.g, pymysql and mysql + def instrument_connection(self, connection): # pylint: disable=no-self-use + setattr( + connection, _OTEL_CURSOR_FACTORY_KEY, connection.cursor_factory + ) + connection.cursor_factory = _new_cursor_factory() + return connection + + # TODO(owais): check if core dbapi can do this for all dbapi implementations e.g, pymysql and mysql + def uninstrument_connection( + self, connection + ): # pylint: disable=no-self-use + connection.cursor_factory = getattr( + connection, _OTEL_CURSOR_FACTORY_KEY, None + ) + return connection + + +# TODO(owais): check if core dbapi can do this for all dbapi implementations e.g, pymysql and mysql +class DatabaseApiIntegration(dbapi.DatabaseApiIntegration): + def wrapped_connection( + self, + connect_method: typing.Callable[..., typing.Any], + args: typing.Tuple[typing.Any, typing.Any], + kwargs: typing.Dict[typing.Any, typing.Any], + ): + """Add object proxy to connection object.""" + base_cursor_factory = kwargs.pop("cursor_factory", None) + new_factory_kwargs = {"db_api": self} + if base_cursor_factory: + new_factory_kwargs["base_factory"] = base_cursor_factory + kwargs["cursor_factory"] = _new_cursor_factory(**new_factory_kwargs) + connection = connect_method(*args, **kwargs) + self.get_connection_attributes(connection) + return connection + + +class CursorTracer(dbapi.CursorTracer): + def get_operation_name(self, cursor, args): + if not args: + return "" + + statement = args[0] + if isinstance(statement, Composed): + statement = statement.as_string(cursor) + + if isinstance(statement, str): + return statement.split()[0] + + return "" + + def get_statement(self, cursor, args): + if not args: + return "" + + statement = args[0] + if isinstance(statement, Composed): + statement = statement.as_string(cursor) + return statement + + +def _new_cursor_factory(db_api=None, base_factory=None): + if not db_api: + db_api = DatabaseApiIntegration( + __name__, + Psycopg2Instrumentor._DATABASE_SYSTEM, + connection_attributes=Psycopg2Instrumentor._CONNECTION_ATTRIBUTES, + version=__version__, + ) - Returns: - An instrumented connection. - """ - tracer = get_tracer(__name__, __version__) + base_factory = base_factory or pg_cursor + _cursor_tracer = CursorTracer(db_api) - return dbapi.instrument_connection( - tracer, - connection, - self._DATABASE_COMPONENT, - self._DATABASE_TYPE, - self._CONNECTION_ATTRIBUTES, - ) + class TracedCursorFactory(base_factory): + def execute(self, *args, **kwargs): + return _cursor_tracer.traced_execution( + self, super().execute, *args, **kwargs + ) - def uninstrument_connection(self, connection): - """Disable instrumentation in a Psycopg2 connection. + def executemany(self, *args, **kwargs): + return _cursor_tracer.traced_execution( + self, super().executemany, *args, **kwargs + ) - Args: - connection: The connection to uninstrument. + def callproc(self, *args, **kwargs): + return _cursor_tracer.traced_execution( + self, super().callproc, *args, **kwargs + ) - Returns: - An uninstrumented connection. - """ - return dbapi.uninstrument_connection(connection) + return TracedCursorFactory diff --git a/instrumentation/opentelemetry-instrumentation-psycopg2/src/opentelemetry/instrumentation/psycopg2/version.py b/instrumentation/opentelemetry-instrumentation-psycopg2/src/opentelemetry/instrumentation/psycopg2/version.py index 86e1dbb17a..ebb75f6c11 100644 --- a/instrumentation/opentelemetry-instrumentation-psycopg2/src/opentelemetry/instrumentation/psycopg2/version.py +++ b/instrumentation/opentelemetry-instrumentation-psycopg2/src/opentelemetry/instrumentation/psycopg2/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.17.dev0" +__version__ = "0.18.dev0" diff --git a/instrumentation/opentelemetry-instrumentation-psycopg2/tests/test_psycopg2_integration.py b/instrumentation/opentelemetry-instrumentation-psycopg2/tests/test_psycopg2_integration.py index cb127c7a5e..e25fd7a934 100644 --- a/instrumentation/opentelemetry-instrumentation-psycopg2/tests/test_psycopg2_integration.py +++ b/instrumentation/opentelemetry-instrumentation-psycopg2/tests/test_psycopg2_integration.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import types from unittest import mock import psycopg2 @@ -22,15 +23,69 @@ from opentelemetry.test.test_base import TestBase +class MockCursor: + + execute = mock.MagicMock(spec=types.MethodType) + execute.__name__ = "execute" + + executemany = mock.MagicMock(spec=types.MethodType) + executemany.__name__ = "executemany" + + callproc = mock.MagicMock(spec=types.MethodType) + callproc.__name__ = "callproc" + + rowcount = "SomeRowCount" + + def __init__(self, *args, **kwargs): + pass + + def __enter__(self): + return self + + def __exit__(self, *args): + return self + + +class MockConnection: + + commit = mock.MagicMock(spec=types.MethodType) + commit.__name__ = "commit" + + rollback = mock.MagicMock(spec=types.MethodType) + rollback.__name__ = "rollback" + + def __init__(self, *args, **kwargs): + self.cursor_factory = kwargs.pop("cursor_factory", None) + + def cursor(self): + if self.cursor_factory: + return self.cursor_factory(self) + return MockCursor() + + def get_dsn_parameters(self): # pylint: disable=no-self-use + return dict(dbname="test") + + class TestPostgresqlIntegration(TestBase): + def setUp(self): + self.cursor_mock = mock.patch( + "opentelemetry.instrumentation.psycopg2.pg_cursor", MockCursor + ) + self.connection_mock = mock.patch("psycopg2.connect", MockConnection) + + self.cursor_mock.start() + self.connection_mock.start() + def tearDown(self): super().tearDown() + self.memory_exporter.clear() + self.cursor_mock.stop() + self.connection_mock.stop() with self.disable_logging(): Psycopg2Instrumentor().uninstrument() - @mock.patch("psycopg2.connect") # pylint: disable=unused-argument - def test_instrumentor(self, mock_connect): + def test_instrumentor(self): Psycopg2Instrumentor().instrument() cnx = psycopg2.connect(database="test") @@ -60,9 +115,8 @@ def test_instrumentor(self, mock_connect): spans_list = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans_list), 1) - @mock.patch("psycopg2.connect") # pylint: disable=unused-argument - def test_not_recording(self, mock_connect): + def test_not_recording(self): mock_tracer = mock.Mock() mock_span = mock.Mock() mock_span.is_recording.return_value = False @@ -83,9 +137,8 @@ def test_not_recording(self, mock_connect): Psycopg2Instrumentor().uninstrument() - @mock.patch("psycopg2.connect") # pylint: disable=unused-argument - def test_custom_tracer_provider(self, mock_connect): + def test_custom_tracer_provider(self): resource = resources.Resource.create({}) result = self.create_tracer_provider(resource=resource) tracer_provider, exporter = result @@ -103,9 +156,8 @@ def test_custom_tracer_provider(self, mock_connect): self.assertIs(span.resource, resource) - @mock.patch("psycopg2.connect") # pylint: disable=unused-argument - def test_instrument_connection(self, mock_connect): + def test_instrument_connection(self): cnx = psycopg2.connect(database="test") query = "SELECT * FROM test" cursor = cnx.cursor() @@ -121,9 +173,8 @@ def test_instrument_connection(self, mock_connect): spans_list = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans_list), 1) - @mock.patch("psycopg2.connect") # pylint: disable=unused-argument - def test_uninstrument_connection(self, mock_connect): + def test_uninstrument_connection(self): Psycopg2Instrumentor().instrument() cnx = psycopg2.connect(database="test") query = "SELECT * FROM test" diff --git a/instrumentation/opentelemetry-instrumentation-pymemcache/setup.cfg b/instrumentation/opentelemetry-instrumentation-pymemcache/setup.cfg index d92f767c8a..c32eee7993 100644 --- a/instrumentation/opentelemetry-instrumentation-pymemcache/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-pymemcache/setup.cfg @@ -39,14 +39,14 @@ package_dir= =src packages=find_namespace: install_requires = - opentelemetry-api == 0.17.dev0 - opentelemetry-instrumentation == 0.17.dev0 + opentelemetry-api == 0.18.dev0 + opentelemetry-instrumentation == 0.18.dev0 pymemcache ~= 1.3 wrapt >= 1.0.0, < 2.0.0 [options.extras_require] test = - opentelemetry-test == 0.17.dev0 + opentelemetry-test == 0.18.dev0 [options.packages.find] where = src diff --git a/instrumentation/opentelemetry-instrumentation-pymemcache/src/opentelemetry/instrumentation/pymemcache/__init__.py b/instrumentation/opentelemetry-instrumentation-pymemcache/src/opentelemetry/instrumentation/pymemcache/__init__.py index 5fa9c04b9f..7e1b597ef8 100644 --- a/instrumentation/opentelemetry-instrumentation-pymemcache/src/opentelemetry/instrumentation/pymemcache/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-pymemcache/src/opentelemetry/instrumentation/pymemcache/__init__.py @@ -51,12 +51,12 @@ logger = logging.getLogger(__name__) # Network attribute semantic convention here: -# https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/span-general.md#general-network-connection-attributes +# https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/span-general.md#general-network-connection-attributes _HOST = "net.peer.name" _PORT = "net.peer.port" _TRANSPORT = "net.transport" # Database semantic conventions here: -# https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/database.md +# https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/database.md _DB = "db.system" _DEFAULT_SERVICE = "memcached" diff --git a/instrumentation/opentelemetry-instrumentation-pymemcache/src/opentelemetry/instrumentation/pymemcache/version.py b/instrumentation/opentelemetry-instrumentation-pymemcache/src/opentelemetry/instrumentation/pymemcache/version.py index 86e1dbb17a..ebb75f6c11 100644 --- a/instrumentation/opentelemetry-instrumentation-pymemcache/src/opentelemetry/instrumentation/pymemcache/version.py +++ b/instrumentation/opentelemetry-instrumentation-pymemcache/src/opentelemetry/instrumentation/pymemcache/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.17.dev0" +__version__ = "0.18.dev0" diff --git a/instrumentation/opentelemetry-instrumentation-pymongo/setup.cfg b/instrumentation/opentelemetry-instrumentation-pymongo/setup.cfg index e320c32455..6e653fa39c 100644 --- a/instrumentation/opentelemetry-instrumentation-pymongo/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-pymongo/setup.cfg @@ -19,7 +19,7 @@ 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/master/instrumentation/opentelemetry-instrumentation-pymongo +url = https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-pymongo platforms = any license = Apache-2.0 classifiers = @@ -39,13 +39,13 @@ package_dir= =src packages=find_namespace: install_requires = - opentelemetry-api == 0.17.dev0 - opentelemetry-instrumentation == 0.17.dev0 + opentelemetry-api == 0.18.dev0 + opentelemetry-instrumentation == 0.18.dev0 pymongo ~= 3.1 [options.extras_require] test = - opentelemetry-test == 0.17.dev0 + opentelemetry-test == 0.18.dev0 [options.packages.find] where = src 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 abcbe0d633..39de8e32c5 100644 --- a/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/__init__.py @@ -45,7 +45,7 @@ from opentelemetry.trace import SpanKind, get_tracer from opentelemetry.trace.status import Status, StatusCode -DATABASE_TYPE = "mongodb" +DATABASE_SYSTEM = "mongodb" class CommandTracer(monitoring.CommandListener): @@ -68,7 +68,7 @@ def started(self, event: monitoring.CommandStartedEvent): try: span = self._tracer.start_span(name, kind=SpanKind.CLIENT) if span.is_recording(): - span.set_attribute("db.system", DATABASE_TYPE) + span.set_attribute("db.system", DATABASE_SYSTEM) span.set_attribute("db.name", event.database_name) span.set_attribute("db.statement", statement) if event.connection_id is not None: diff --git a/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/version.py b/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/version.py index 86e1dbb17a..ebb75f6c11 100644 --- a/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/version.py +++ b/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.17.dev0" +__version__ = "0.18.dev0" diff --git a/instrumentation/opentelemetry-instrumentation-pymysql/setup.cfg b/instrumentation/opentelemetry-instrumentation-pymysql/setup.cfg index a9387f7320..9acca8d708 100644 --- a/instrumentation/opentelemetry-instrumentation-pymysql/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-pymysql/setup.cfg @@ -19,7 +19,7 @@ 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/master/instrumentation/opentelemetry-instrumentation-pymysql +url = https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-pymysql platforms = any license = Apache-2.0 classifiers = @@ -39,14 +39,14 @@ package_dir= =src packages=find_namespace: install_requires = - opentelemetry-api == 0.17.dev0 - opentelemetry-instrumentation-dbapi == 0.17.dev0 - opentelemetry-instrumentation == 0.17.dev0 + opentelemetry-api == 0.18.dev0 + opentelemetry-instrumentation-dbapi == 0.18.dev0 + opentelemetry-instrumentation == 0.18.dev0 PyMySQL ~= 0.10.1 [options.extras_require] test = - opentelemetry-test == 0.17.dev0 + opentelemetry-test == 0.18.dev0 [options.packages.find] where = src diff --git a/instrumentation/opentelemetry-instrumentation-pymysql/src/opentelemetry/instrumentation/pymysql/__init__.py b/instrumentation/opentelemetry-instrumentation-pymysql/src/opentelemetry/instrumentation/pymysql/__init__.py index afceefafed..5e9952bc47 100644 --- a/instrumentation/opentelemetry-instrumentation-pymysql/src/opentelemetry/instrumentation/pymysql/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-pymysql/src/opentelemetry/instrumentation/pymysql/__init__.py @@ -55,8 +55,7 @@ class PyMySQLInstrumentor(BaseInstrumentor): "user": "user", } - _DATABASE_COMPONENT = "mysql" - _DATABASE_TYPE = "sql" + _DATABASE_SYSTEM = "mysql" def _instrument(self, **kwargs): """Integrate with the PyMySQL library. @@ -68,8 +67,7 @@ def _instrument(self, **kwargs): __name__, pymysql, "connect", - self._DATABASE_COMPONENT, - self._DATABASE_TYPE, + self._DATABASE_SYSTEM, self._CONNECTION_ATTRIBUTES, version=__version__, tracer_provider=tracer_provider, @@ -93,8 +91,7 @@ def instrument_connection(self, connection): return dbapi.instrument_connection( __name__, connection, - self._DATABASE_COMPONENT, - self._DATABASE_TYPE, + self._DATABASE_SYSTEM, self._CONNECTION_ATTRIBUTES, version=__version__, ) diff --git a/instrumentation/opentelemetry-instrumentation-pymysql/src/opentelemetry/instrumentation/pymysql/version.py b/instrumentation/opentelemetry-instrumentation-pymysql/src/opentelemetry/instrumentation/pymysql/version.py index 86e1dbb17a..ebb75f6c11 100644 --- a/instrumentation/opentelemetry-instrumentation-pymysql/src/opentelemetry/instrumentation/pymysql/version.py +++ b/instrumentation/opentelemetry-instrumentation-pymysql/src/opentelemetry/instrumentation/pymysql/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.17.dev0" +__version__ = "0.18.dev0" diff --git a/instrumentation/opentelemetry-instrumentation-pyramid/setup.cfg b/instrumentation/opentelemetry-instrumentation-pyramid/setup.cfg index a4599fcca5..b449fb34f5 100644 --- a/instrumentation/opentelemetry-instrumentation-pyramid/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-pyramid/setup.cfg @@ -19,7 +19,7 @@ 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/master/instrumentation/opentelemetry-instrumentation-pyramid +url = https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-pyramid platforms = any license = Apache-2.0 classifiers = @@ -40,15 +40,15 @@ package_dir= packages=find_namespace: install_requires = pyramid >= 1.7 - opentelemetry-instrumentation == 0.17.dev0 - opentelemetry-api == 0.17.dev0 - opentelemetry-instrumentation-wsgi == 0.17.dev0 + opentelemetry-instrumentation == 0.18.dev0 + opentelemetry-api == 0.18.dev0 + opentelemetry-instrumentation-wsgi == 0.18.dev0 wrapt >= 1.0.0, < 2.0.0 [options.extras_require] test = werkzeug == 0.16.1 - opentelemetry-test == 0.17.dev0 + opentelemetry-test == 0.18.dev0 [options.packages.find] where = src diff --git a/instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/version.py b/instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/version.py index 86e1dbb17a..ebb75f6c11 100644 --- a/instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/version.py +++ b/instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.17.dev0" +__version__ = "0.18.dev0" diff --git a/instrumentation/opentelemetry-instrumentation-pyramid/tests/test_programmatic.py b/instrumentation/opentelemetry-instrumentation-pyramid/tests/test_programmatic.py index e5bbcb056b..2affc3f5d3 100644 --- a/instrumentation/opentelemetry-instrumentation-pyramid/tests/test_programmatic.py +++ b/instrumentation/opentelemetry-instrumentation-pyramid/tests/test_programmatic.py @@ -28,7 +28,6 @@ def expected_attributes(override_attributes): default_attributes = { - "component": "http", "http.method": "GET", "http.server_name": "localhost", "http.scheme": "http", diff --git a/instrumentation/opentelemetry-instrumentation-redis/setup.cfg b/instrumentation/opentelemetry-instrumentation-redis/setup.cfg index 5e3fc4a580..d6056d269f 100644 --- a/instrumentation/opentelemetry-instrumentation-redis/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-redis/setup.cfg @@ -19,7 +19,7 @@ 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/master/instrumentation/opentelemetry-instrumentation-redis +url = https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-redis platforms = any license = Apache-2.0 classifiers = @@ -39,15 +39,15 @@ package_dir= =src packages=find_namespace: install_requires = - opentelemetry-api == 0.17.dev0 - opentelemetry-instrumentation == 0.17.dev0 + opentelemetry-api == 0.18.dev0 + opentelemetry-instrumentation == 0.18.dev0 redis >= 2.6 wrapt >= 1.12.1 [options.extras_require] test = - opentelemetry-test == 0.17.dev0 - opentelemetry-sdk == 0.17.dev0 + opentelemetry-test == 0.18.dev0 + opentelemetry-sdk == 0.18.dev0 [options.packages.find] where = src diff --git a/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/version.py b/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/version.py index 86e1dbb17a..ebb75f6c11 100644 --- a/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/version.py +++ b/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.17.dev0" +__version__ = "0.18.dev0" diff --git a/instrumentation/opentelemetry-instrumentation-requests/setup.cfg b/instrumentation/opentelemetry-instrumentation-requests/setup.cfg index 2f5416d30b..8a421f6123 100644 --- a/instrumentation/opentelemetry-instrumentation-requests/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-requests/setup.cfg @@ -19,7 +19,7 @@ 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/master/instrumentation/opentelemetry-instrumentation-requests +url = https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-requests platforms = any license = Apache-2.0 classifiers = @@ -39,13 +39,13 @@ package_dir= =src packages=find_namespace: install_requires = - opentelemetry-api == 0.17.dev0 - opentelemetry-instrumentation == 0.17.dev0 + opentelemetry-api == 0.18.dev0 + opentelemetry-instrumentation == 0.18.dev0 requests ~= 2.0 [options.extras_require] test = - opentelemetry-test == 0.17.dev0 + opentelemetry-test == 0.18.dev0 httpretty ~= 1.0 [options.packages.find] diff --git a/instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/__init__.py b/instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/__init__.py index 13f6d8448a..3781545e8b 100644 --- a/instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/__init__.py @@ -119,7 +119,7 @@ def _instrumented_requests_call( return call_wrapped() # See - # https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/http.md#http-client + # https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md#http-client method = method.upper() span_name = "" if name_callback is not None: @@ -139,7 +139,6 @@ def _instrumented_requests_call( exception = None with recorder.record_client_duration(labels): if span.is_recording(): - span.set_attribute("component", "http") span.set_attribute("http.method", method) span.set_attribute("http.url", url) diff --git a/instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/version.py b/instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/version.py index 86e1dbb17a..ebb75f6c11 100644 --- a/instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/version.py +++ b/instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.17.dev0" +__version__ = "0.18.dev0" diff --git a/instrumentation/opentelemetry-instrumentation-requests/tests/test_requests_integration.py b/instrumentation/opentelemetry-instrumentation-requests/tests/test_requests_integration.py index 7749c1f8ab..b981655db0 100644 --- a/instrumentation/opentelemetry-instrumentation-requests/tests/test_requests_integration.py +++ b/instrumentation/opentelemetry-instrumentation-requests/tests/test_requests_integration.py @@ -79,7 +79,6 @@ def test_basic(self): self.assertEqual( span.attributes, { - "component": "http", "http.method": "GET", "http.url": self.URL, "http.status_code": 200, @@ -255,7 +254,6 @@ def span_callback(span, result: requests.Response): self.assertEqual( span.attributes, { - "component": "http", "http.method": "GET", "http.url": self.URL, "http.status_code": 200, @@ -287,8 +285,7 @@ def test_requests_exception_without_response(self, *_, **__): span = self.assert_span() self.assertEqual( - span.attributes, - {"component": "http", "http.method": "GET", "http.url": self.URL}, + span.attributes, {"http.method": "GET", "http.url": self.URL} ) self.assertEqual(span.status.status_code, StatusCode.ERROR) @@ -323,8 +320,7 @@ def test_requests_exception_without_proper_response_type(self, *_, **__): span = self.assert_span() self.assertEqual( - span.attributes, - {"component": "http", "http.method": "GET", "http.url": self.URL}, + span.attributes, {"http.method": "GET", "http.url": self.URL} ) self.assertEqual(span.status.status_code, StatusCode.ERROR) @@ -361,7 +357,6 @@ def test_requests_exception_with_response(self, *_, **__): self.assertEqual( span.attributes, { - "component": "http", "http.method": "GET", "http.url": self.URL, "http.status_code": 500, @@ -423,8 +418,7 @@ def test_invalid_url(self): self.assertEqual(span.name, "HTTP POST") self.assertEqual( - span.attributes, - {"component": "http", "http.method": "POST", "http.url": url}, + span.attributes, {"http.method": "POST", "http.url": url} ) self.assertEqual(span.status.status_code, StatusCode.ERROR) diff --git a/instrumentation/opentelemetry-instrumentation-sklearn/setup.cfg b/instrumentation/opentelemetry-instrumentation-sklearn/setup.cfg index 8610ae0d9f..c8b5801d51 100644 --- a/instrumentation/opentelemetry-instrumentation-sklearn/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-sklearn/setup.cfg @@ -19,7 +19,7 @@ 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/master/instrumentation/opentelemetry-instrumentation-sklearn +url = https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-sklearn platforms = any license = Apache-2.0 classifiers = @@ -39,13 +39,13 @@ package_dir= =src packages=find_namespace: install_requires = - opentelemetry-api == 0.17.dev0 - opentelemetry-instrumentation == 0.17.dev0 + opentelemetry-api == 0.18.dev0 + opentelemetry-instrumentation == 0.18.dev0 scikit-learn ~= 0.22.0 [options.extras_require] test = - opentelemetry-test == 0.17.dev0 + opentelemetry-test == 0.18.dev0 [options.packages.find] where = src diff --git a/instrumentation/opentelemetry-instrumentation-sklearn/src/opentelemetry/instrumentation/sklearn/version.py b/instrumentation/opentelemetry-instrumentation-sklearn/src/opentelemetry/instrumentation/sklearn/version.py index 1dfb1884f4..98df029ba4 100644 --- a/instrumentation/opentelemetry-instrumentation-sklearn/src/opentelemetry/instrumentation/sklearn/version.py +++ b/instrumentation/opentelemetry-instrumentation-sklearn/src/opentelemetry/instrumentation/sklearn/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.17.dev0" +__version__ = "0.18.dev0" diff --git a/instrumentation/opentelemetry-instrumentation-sqlalchemy/setup.cfg b/instrumentation/opentelemetry-instrumentation-sqlalchemy/setup.cfg index f58f345ec1..9aa09cfaca 100644 --- a/instrumentation/opentelemetry-instrumentation-sqlalchemy/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-sqlalchemy/setup.cfg @@ -19,7 +19,7 @@ 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/master/instrumentation/opentelemetry-instrumentation-sqlalchemy +url = https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-sqlalchemy platforms = any license = Apache-2.0 classifiers = @@ -39,14 +39,14 @@ package_dir= =src packages=find_namespace: install_requires = - opentelemetry-api == 0.17.dev0 - opentelemetry-instrumentation == 0.17.dev0 + opentelemetry-api == 0.18.dev0 + opentelemetry-instrumentation == 0.18.dev0 wrapt >= 1.11.2 sqlalchemy [options.extras_require] test = - opentelemetry-sdk == 0.17.dev0 + opentelemetry-sdk == 0.18.dev0 pytest [options.packages.find] diff --git a/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/engine.py b/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/engine.py index 86f52ad724..e32d41718f 100644 --- a/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/engine.py +++ b/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/engine.py @@ -12,18 +12,18 @@ # See the License for the specific language governing permissions and # limitations under the License. -from sqlalchemy.event import listen +from sqlalchemy.event import listen # pylint: disable=no-name-in-module from opentelemetry import trace from opentelemetry.instrumentation.sqlalchemy.version import __version__ from opentelemetry.trace.status import Status, StatusCode # Network attribute semantic convention here: -# https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/span-general.md#general-network-connection-attributes +# https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/span-general.md#general-network-connection-attributes _HOST = "net.peer.name" _PORT = "net.peer.port" # Database semantic conventions here: -# https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/database.md +# https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/database.md _STMT = "db.statement" _DB = "db.name" _USER = "db.user" @@ -72,22 +72,38 @@ def __init__(self, tracer, engine): listen(engine, "after_cursor_execute", self._after_cur_exec) listen(engine, "handle_error", self._handle_error) + def _operation_name(self, db_name, statement): + parts = [] + if isinstance(statement, str): + # otel spec recommends against parsing SQL queries. We are not trying to parse SQL + # but simply truncating the statement to the first word. This covers probably >95% + # use cases and uses the SQL statement in span name correctly as per the spec. + # For some very special cases it might not record the correct statement if the SQL + # dialect is too weird but in any case it shouldn't break anything. + parts.append(statement.split()[0]) + if db_name: + parts.append(db_name) + if not parts: + return self.vendor + return " ".join(parts) + # pylint: disable=unused-argument def _before_cur_exec(self, conn, cursor, statement, *args): + attrs, found = _get_attributes_from_url(conn.engine.url) + if not found: + attrs = _get_attributes_from_cursor(self.vendor, cursor, attrs) + + db_name = attrs.get(_DB, "") self.current_span = self.tracer.start_span( - statement, kind=trace.SpanKind.CLIENT + self._operation_name(db_name, statement), + kind=trace.SpanKind.CLIENT, ) with self.tracer.use_span(self.current_span, end_on_exit=False): if self.current_span.is_recording(): self.current_span.set_attribute(_STMT, statement) self.current_span.set_attribute("db.system", self.vendor) - - if not _set_attributes_from_url( - self.current_span, conn.engine.url - ): - _set_attributes_from_cursor( - self.current_span, self.vendor, cursor - ) + for key, value in attrs.items(): + self.current_span.set_attribute(key, value) # pylint: disable=unused-argument def _after_cur_exec(self, conn, cursor, statement, *args): @@ -108,25 +124,22 @@ def _handle_error(self, context): self.current_span.end() -def _set_attributes_from_url(span: trace.Span, url): +def _get_attributes_from_url(url): """Set connection tags from the url. return true if successful.""" - if span.is_recording(): - if url.host: - span.set_attribute(_HOST, url.host) - if url.port: - span.set_attribute(_PORT, url.port) - if url.database: - span.set_attribute(_DB, url.database) - if url.username: - span.set_attribute(_USER, url.username) - - return bool(url.host) - - -def _set_attributes_from_cursor(span: trace.Span, vendor, cursor): + attrs = {} + if url.host: + attrs[_HOST] = url.host + if url.port: + attrs[_PORT] = url.port + if url.database: + attrs[_DB] = url.database + if url.username: + attrs[_USER] = url.username + return attrs, bool(url.host) + + +def _get_attributes_from_cursor(vendor, cursor, attrs): """Attempt to set db connection attributes by introspecting the cursor.""" - if not span.is_recording(): - return if vendor == "postgresql": # pylint: disable=import-outside-toplevel from psycopg2.extensions import parse_dsn @@ -135,6 +148,7 @@ def _set_attributes_from_cursor(span: trace.Span, vendor, cursor): dsn = getattr(cursor.connection, "dsn", None) if dsn: data = parse_dsn(dsn) - span.set_attribute(_DB, data.get("dbname")) - span.set_attribute(_HOST, data.get("host")) - span.set_attribute(_PORT, int(data.get("port"))) + attrs[_DB] = data.get("dbname") + attrs[_HOST] = data.get("host") + attrs[_PORT] = int(data.get("port")) + return attrs diff --git a/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/version.py b/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/version.py index 86e1dbb17a..ebb75f6c11 100644 --- a/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/version.py +++ b/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.17.dev0" +__version__ = "0.18.dev0" diff --git a/instrumentation/opentelemetry-instrumentation-sqlalchemy/tests/test_sqlalchemy.py b/instrumentation/opentelemetry-instrumentation-sqlalchemy/tests/test_sqlalchemy.py index dfc6e429a7..673f401be5 100644 --- a/instrumentation/opentelemetry-instrumentation-sqlalchemy/tests/test_sqlalchemy.py +++ b/instrumentation/opentelemetry-instrumentation-sqlalchemy/tests/test_sqlalchemy.py @@ -35,7 +35,7 @@ def test_trace_integration(self): spans = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans), 1) - self.assertEqual(spans[0].name, "SELECT 1 + 1;") + self.assertEqual(spans[0].name, "SELECT :memory:") self.assertEqual(spans[0].kind, trace.SpanKind.CLIENT) def test_not_recording(self): @@ -68,5 +68,5 @@ def test_create_engine_wrapper(self): spans = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans), 1) - self.assertEqual(spans[0].name, "SELECT 1 + 1;") + self.assertEqual(spans[0].name, "SELECT :memory:") self.assertEqual(spans[0].kind, trace.SpanKind.CLIENT) diff --git a/instrumentation/opentelemetry-instrumentation-sqlite3/setup.cfg b/instrumentation/opentelemetry-instrumentation-sqlite3/setup.cfg index c705f63e94..97ae0f8ad2 100644 --- a/instrumentation/opentelemetry-instrumentation-sqlite3/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-sqlite3/setup.cfg @@ -19,7 +19,7 @@ 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/master/instrumentation/opentelemetry-instrumentation-sqlite3 +url = https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-sqlite3 platforms = any license = Apache-2.0 classifiers = @@ -39,14 +39,14 @@ package_dir= =src packages=find_namespace: install_requires = - opentelemetry-api == 0.17.dev0 - opentelemetry-instrumentation-dbapi == 0.17.dev0 - opentelemetry-instrumentation == 0.17.dev0 + opentelemetry-api == 0.18.dev0 + opentelemetry-instrumentation-dbapi == 0.18.dev0 + opentelemetry-instrumentation == 0.18.dev0 wrapt >= 1.0.0, < 2.0.0 [options.extras_require] test = - opentelemetry-test == 0.17.dev0 + opentelemetry-test == 0.18.dev0 [options.packages.find] where = src diff --git a/instrumentation/opentelemetry-instrumentation-sqlite3/src/opentelemetry/instrumentation/sqlite3/__init__.py b/instrumentation/opentelemetry-instrumentation-sqlite3/src/opentelemetry/instrumentation/sqlite3/__init__.py index bad033b292..7ba76968af 100644 --- a/instrumentation/opentelemetry-instrumentation-sqlite3/src/opentelemetry/instrumentation/sqlite3/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-sqlite3/src/opentelemetry/instrumentation/sqlite3/__init__.py @@ -51,8 +51,7 @@ class SQLite3Instrumentor(BaseInstrumentor): # No useful attributes of sqlite3 connection object _CONNECTION_ATTRIBUTES = {} - _DATABASE_COMPONENT = "sqlite" - _DATABASE_TYPE = "sql" + _DATABASE_SYSTEM = "sqlite" def _instrument(self, **kwargs): """Integrate with SQLite3 Python library. @@ -64,8 +63,7 @@ def _instrument(self, **kwargs): __name__, sqlite3, "connect", - self._DATABASE_COMPONENT, - self._DATABASE_TYPE, + self._DATABASE_SYSTEM, self._CONNECTION_ATTRIBUTES, version=__version__, tracer_provider=tracer_provider, @@ -90,8 +88,7 @@ def instrument_connection(self, connection): return dbapi.instrument_connection( tracer, connection, - self._DATABASE_COMPONENT, - self._DATABASE_TYPE, + self._DATABASE_SYSTEM, self._CONNECTION_ATTRIBUTES, ) diff --git a/instrumentation/opentelemetry-instrumentation-sqlite3/src/opentelemetry/instrumentation/sqlite3/version.py b/instrumentation/opentelemetry-instrumentation-sqlite3/src/opentelemetry/instrumentation/sqlite3/version.py index 86e1dbb17a..ebb75f6c11 100644 --- a/instrumentation/opentelemetry-instrumentation-sqlite3/src/opentelemetry/instrumentation/sqlite3/version.py +++ b/instrumentation/opentelemetry-instrumentation-sqlite3/src/opentelemetry/instrumentation/sqlite3/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.17.dev0" +__version__ = "0.18.dev0" diff --git a/instrumentation/opentelemetry-instrumentation-sqlite3/tests/test_sqlite3.py b/instrumentation/opentelemetry-instrumentation-sqlite3/tests/test_sqlite3.py index a4fc887061..6b8b0cb696 100644 --- a/instrumentation/opentelemetry-instrumentation-sqlite3/tests/test_sqlite3.py +++ b/instrumentation/opentelemetry-instrumentation-sqlite3/tests/test_sqlite3.py @@ -60,7 +60,7 @@ def test_execute(self): stmt = "CREATE TABLE IF NOT EXISTS test (id integer)" with self._tracer.start_as_current_span("rootSpan"): self._cursor.execute(stmt) - self.validate_spans(stmt) + self.validate_spans("CREATE") def test_executemany(self): """Should create a child span for executemany""" @@ -68,7 +68,7 @@ def test_executemany(self): with self._tracer.start_as_current_span("rootSpan"): data = [("1",), ("2",), ("3",)] self._cursor.executemany(stmt, data) - self.validate_spans(stmt) + self.validate_spans("INSERT") def test_callproc(self): """Should create a child span for callproc""" diff --git a/instrumentation/opentelemetry-instrumentation-starlette/setup.cfg b/instrumentation/opentelemetry-instrumentation-starlette/setup.cfg index ff329cb803..4b2123d9b7 100644 --- a/instrumentation/opentelemetry-instrumentation-starlette/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-starlette/setup.cfg @@ -19,7 +19,7 @@ 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/master/instrumentation/opentelemetry-instrumentation-starlette +url = https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-starlette platforms = any license = Apache-2.0 classifiers = @@ -38,8 +38,8 @@ package_dir= =src packages=find_namespace: install_requires = - opentelemetry-api == 0.17.dev0 - opentelemetry-instrumentation-asgi == 0.17.dev0 + opentelemetry-api == 0.18.dev0 + opentelemetry-instrumentation-asgi == 0.18.dev0 [options.entry_points] opentelemetry_instrumentor = @@ -47,7 +47,7 @@ opentelemetry_instrumentor = [options.extras_require] test = - opentelemetry-test == 0.17.dev0 + opentelemetry-test == 0.18.dev0 starlette ~= 0.13.0 requests ~= 2.23.0 # needed for testclient diff --git a/instrumentation/opentelemetry-instrumentation-starlette/src/opentelemetry/instrumentation/starlette/version.py b/instrumentation/opentelemetry-instrumentation-starlette/src/opentelemetry/instrumentation/starlette/version.py index 86e1dbb17a..ebb75f6c11 100644 --- a/instrumentation/opentelemetry-instrumentation-starlette/src/opentelemetry/instrumentation/starlette/version.py +++ b/instrumentation/opentelemetry-instrumentation-starlette/src/opentelemetry/instrumentation/starlette/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.17.dev0" +__version__ = "0.18.dev0" diff --git a/instrumentation/opentelemetry-instrumentation-system-metrics/setup.cfg b/instrumentation/opentelemetry-instrumentation-system-metrics/setup.cfg index 3376a89d47..f0c0407a33 100644 --- a/instrumentation/opentelemetry-instrumentation-system-metrics/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-system-metrics/setup.cfg @@ -19,7 +19,7 @@ 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/master/instrumentation/opentelemetry-instrumentation-system-metrics +url = https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-system-metrics platforms = any license = Apache-2.0 classifiers = @@ -39,13 +39,13 @@ package_dir= =src packages=find_namespace: install_requires = - opentelemetry-api == 0.17.dev0 - opentelemetry-sdk == 0.17.dev0 + opentelemetry-api == 0.18.dev0 + opentelemetry-sdk == 0.18.dev0 psutil ~= 5.7.0 [options.extras_require] test = - opentelemetry-test == 0.17.dev0 + opentelemetry-test == 0.18.dev0 [options.packages.find] where = src diff --git a/instrumentation/opentelemetry-instrumentation-system-metrics/src/opentelemetry/instrumentation/system_metrics/version.py b/instrumentation/opentelemetry-instrumentation-system-metrics/src/opentelemetry/instrumentation/system_metrics/version.py index 86e1dbb17a..ebb75f6c11 100644 --- a/instrumentation/opentelemetry-instrumentation-system-metrics/src/opentelemetry/instrumentation/system_metrics/version.py +++ b/instrumentation/opentelemetry-instrumentation-system-metrics/src/opentelemetry/instrumentation/system_metrics/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.17.dev0" +__version__ = "0.18.dev0" diff --git a/instrumentation/opentelemetry-instrumentation-tornado/setup.cfg b/instrumentation/opentelemetry-instrumentation-tornado/setup.cfg index 3a5390b2eb..035572e32f 100644 --- a/instrumentation/opentelemetry-instrumentation-tornado/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-tornado/setup.cfg @@ -19,7 +19,7 @@ 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/master/instrumentation/opentelemetry-instrumentation-tornado +url = https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-tornado platforms = any license = Apache-2.0 classifiers = @@ -39,13 +39,13 @@ package_dir= packages=find_namespace: install_requires = tornado >= 6.0 - opentelemetry-instrumentation == 0.17.dev0 - opentelemetry-api == 0.17.dev0 + opentelemetry-instrumentation == 0.18.dev0 + opentelemetry-api == 0.18.dev0 [options.extras_require] test = tornado >= 6.0 - opentelemetry-test == 0.17.dev0 + opentelemetry-test == 0.18.dev0 [options.packages.find] where = src diff --git a/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/__init__.py b/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/__init__.py index d825fbb71b..5806b3664c 100644 --- a/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/__init__.py @@ -174,7 +174,6 @@ def _log_exception(tracer, func, handler, args, kwargs): def _get_attributes_from_request(request): attrs = { - "component": "tornado", "http.method": request.method, "http.scheme": request.protocol, "http.host": request.host, diff --git a/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/client.py b/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/client.py index 5ec001bdab..810c6458e1 100644 --- a/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/client.py +++ b/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/client.py @@ -43,7 +43,6 @@ def fetch_async(tracer, func, _, args, kwargs): if span.is_recording(): attributes = { - "component": "tornado", "http.url": request.url, "http.method": request.method, } diff --git a/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/version.py b/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/version.py index 86e1dbb17a..ebb75f6c11 100644 --- a/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/version.py +++ b/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.17.dev0" +__version__ = "0.18.dev0" diff --git a/instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py b/instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py index 21002c83cd..3bdf007717 100644 --- a/instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py +++ b/instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py @@ -128,7 +128,6 @@ def _test_http_method_call(self, method): self.assert_span_has_attributes( server, { - "component": "tornado", "http.method": method, "http.scheme": "http", "http.host": "127.0.0.1:" + str(self.get_http_port()), @@ -146,7 +145,6 @@ def _test_http_method_call(self, method): self.assert_span_has_attributes( client, { - "component": "tornado", "http.url": self.get_url("/"), "http.method": method, "http.status_code": 201, @@ -205,7 +203,6 @@ def _test_async_handler(self, url, handler_name): self.assert_span_has_attributes( server, { - "component": "tornado", "http.method": "GET", "http.scheme": "http", "http.host": "127.0.0.1:" + str(self.get_http_port()), @@ -223,7 +220,6 @@ def _test_async_handler(self, url, handler_name): self.assert_span_has_attributes( client, { - "component": "tornado", "http.url": self.get_url(url), "http.method": "GET", "http.status_code": 201, @@ -243,7 +239,6 @@ def test_500(self): self.assert_span_has_attributes( server, { - "component": "tornado", "http.method": "GET", "http.scheme": "http", "http.host": "127.0.0.1:" + str(self.get_http_port()), @@ -258,7 +253,6 @@ def test_500(self): self.assert_span_has_attributes( client, { - "component": "tornado", "http.url": self.get_url("/error"), "http.method": "GET", "http.status_code": 500, @@ -278,7 +272,6 @@ def test_404(self): self.assert_span_has_attributes( server, { - "component": "tornado", "http.method": "GET", "http.scheme": "http", "http.host": "127.0.0.1:" + str(self.get_http_port()), @@ -294,7 +287,6 @@ def test_404(self): self.assert_span_has_attributes( client, { - "component": "tornado", "http.url": self.get_url("/missing-url"), "http.method": "GET", "http.status_code": 404, @@ -324,7 +316,6 @@ def test_dynamic_handler(self): self.assert_span_has_attributes( server, { - "component": "tornado", "http.method": "GET", "http.scheme": "http", "http.host": "127.0.0.1:" + str(self.get_http_port()), @@ -342,7 +333,6 @@ def test_dynamic_handler(self): self.assert_span_has_attributes( client, { - "component": "tornado", "http.url": self.get_url("/dyna"), "http.method": "GET", "http.status_code": 202, @@ -362,7 +352,6 @@ def test_excluded(path): self.assert_span_has_attributes( client, { - "component": "tornado", "http.url": self.get_url(path), "http.method": "GET", "http.status_code": 200, diff --git a/instrumentation/opentelemetry-instrumentation-urllib/setup.cfg b/instrumentation/opentelemetry-instrumentation-urllib/setup.cfg index ad12755454..02eeee485e 100644 --- a/instrumentation/opentelemetry-instrumentation-urllib/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-urllib/setup.cfg @@ -19,7 +19,7 @@ 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/master/instrumentation/opentelemetry-instrumentation-urllib +url = https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-urllib platforms = any license = Apache-2.0 classifiers = @@ -39,8 +39,8 @@ package_dir= =src packages=find_namespace: install_requires = - opentelemetry-api == 0.17.dev0 - opentelemetry-instrumentation == 0.17.dev0 + opentelemetry-api == 0.18.dev0 + opentelemetry-instrumentation == 0.18.dev0 [options.extras_require] test = diff --git a/instrumentation/opentelemetry-instrumentation-urllib/src/opentelemetry/instrumentation/urllib/__init__.py b/instrumentation/opentelemetry-instrumentation-urllib/src/opentelemetry/instrumentation/urllib/__init__.py index 3958a666ba..dddf2a00a0 100644 --- a/instrumentation/opentelemetry-instrumentation-urllib/src/opentelemetry/instrumentation/urllib/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-urllib/src/opentelemetry/instrumentation/urllib/__init__.py @@ -163,7 +163,6 @@ def _instrumented_open_call( exception = None with recorder.record_client_duration(labels): if span.is_recording(): - span.set_attribute("component", "http") span.set_attribute("http.method", method) span.set_attribute("http.url", url) diff --git a/instrumentation/opentelemetry-instrumentation-urllib/src/opentelemetry/instrumentation/urllib/version.py b/instrumentation/opentelemetry-instrumentation-urllib/src/opentelemetry/instrumentation/urllib/version.py index 86e1dbb17a..ebb75f6c11 100644 --- a/instrumentation/opentelemetry-instrumentation-urllib/src/opentelemetry/instrumentation/urllib/version.py +++ b/instrumentation/opentelemetry-instrumentation-urllib/src/opentelemetry/instrumentation/urllib/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.17.dev0" +__version__ = "0.18.dev0" diff --git a/instrumentation/opentelemetry-instrumentation-urllib/tests/test_urllib_integration.py b/instrumentation/opentelemetry-instrumentation-urllib/tests/test_urllib_integration.py index 28f84a62e1..d6af3acee8 100644 --- a/instrumentation/opentelemetry-instrumentation-urllib/tests/test_urllib_integration.py +++ b/instrumentation/opentelemetry-instrumentation-urllib/tests/test_urllib_integration.py @@ -104,7 +104,6 @@ def test_basic(self): self.assertEqual( span.attributes, { - "component": "http", "http.method": "GET", "http.url": self.URL, "http.status_code": 200, @@ -289,7 +288,6 @@ def span_callback(span, result: HTTPResponse): self.assertEqual( span.attributes, { - "component": "http", "http.method": "GET", "http.url": self.URL, "http.status_code": 200, @@ -320,7 +318,6 @@ def test_requests_exception_with_response(self, *_, **__): self.assertEqual( dict(span.attributes), { - "component": "http", "http.method": "GET", "http.url": "http://httpbin.org/status/500", "http.status_code": 500, diff --git a/instrumentation/opentelemetry-instrumentation-wsgi/setup.cfg b/instrumentation/opentelemetry-instrumentation-wsgi/setup.cfg index dafae56405..8085f59187 100644 --- a/instrumentation/opentelemetry-instrumentation-wsgi/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-wsgi/setup.cfg @@ -19,7 +19,7 @@ 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/master/instrumentation/opentelemetry-instrumentation-wsgi +url = https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-wsgi platforms = any license = Apache-2.0 classifiers = @@ -39,12 +39,12 @@ package_dir= =src packages=find_namespace: install_requires = - opentelemetry-api == 0.17.dev0 - opentelemetry-instrumentation == 0.17.dev0 + opentelemetry-api == 0.18.dev0 + opentelemetry-instrumentation == 0.18.dev0 [options.extras_require] test = - opentelemetry-test == 0.17.dev0 + opentelemetry-test == 0.18.dev0 [options.packages.find] where = src diff --git a/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py b/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py index dd83203fe1..c336a1320b 100644 --- a/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py @@ -104,7 +104,6 @@ def collect_request_attributes(environ): WSGI environ and returns a dictionary to be used as span creation attributes.""" result = { - "component": "http", "http.method": environ.get("REQUEST_METHOD"), "http.server_name": environ.get("SERVER_NAME"), "http.scheme": environ.get("wsgi.url_scheme"), diff --git a/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/version.py b/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/version.py index 86e1dbb17a..ebb75f6c11 100644 --- a/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/version.py +++ b/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.17.dev0" +__version__ = "0.18.dev0" diff --git a/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py b/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py index d563ee673d..d5168e3280 100644 --- a/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py +++ b/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py @@ -106,7 +106,6 @@ def validate_response( self.assertEqual(span_list[0].name, span_name) self.assertEqual(span_list[0].kind, trace_api.SpanKind.SERVER) expected_attributes = { - "component": "http", "http.server_name": "127.0.0.1", "http.scheme": "http", "net.host.port": 80, @@ -215,7 +214,6 @@ def test_request_attributes(self): self.assertDictEqual( attrs, { - "component": "http", "http.method": "GET", "http.host": "127.0.0.1", "http.url": "http://127.0.0.1/?foo=bar", diff --git a/reference/Dockerfile b/reference/Dockerfile new file mode 100644 index 0000000000..88fd3e547f --- /dev/null +++ b/reference/Dockerfile @@ -0,0 +1,5 @@ +FROM node:12 +RUN useradd -ms /bin/bash casper +RUN npm install ghost-cli lightstep-opentelemetry-launcher-node +USER casper + diff --git a/reference/docs/contributing.rst b/reference/docs/contributing.rst index d7e8af6121..761295acf5 100644 --- a/reference/docs/contributing.rst +++ b/reference/docs/contributing.rst @@ -8,15 +8,15 @@ wish to make via an `issue `_. Branches ======== -Developement happens in the `master` branch. When all the features for the next -milestone are merged, the next version is released and tagged on the `master` +Developement happens in the `main` branch. When all the features for the next +milestone are merged, the next version is released and tagged on the `main` branch as `vVERSION`. -Your pull request should targets the `master` branch. +Your pull request should targets the `main` branch. Once a new version is released, a `release/VERSION` branch might be created to support micro releases to `VERSION`. Patches should be cherry-picking from the -`master` branch where possible — or otherwise created from scratch. +`main` branch where possible — or otherwise created from scratch. Pull Request Process diff --git a/sdk-extension/opentelemetry-sdk-extension-aws/setup.cfg b/sdk-extension/opentelemetry-sdk-extension-aws/setup.cfg index bcbff56af9..e91464fd44 100644 --- a/sdk-extension/opentelemetry-sdk-extension-aws/setup.cfg +++ b/sdk-extension/opentelemetry-sdk-extension-aws/setup.cfg @@ -19,7 +19,7 @@ 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/master/sdk-extension/opentelemetry-sdk-extension-aws +url = https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/sdk-extension/opentelemetry-sdk-extension-aws platforms = any license = Apache-2.0 classifiers = @@ -39,7 +39,7 @@ package_dir= =src packages=find_namespace: install_requires = - opentelemetry-api == 0.17.dev0 + opentelemetry-api == 0.18.dev0 [options.entry_points] opentelemetry_propagator = @@ -49,7 +49,7 @@ opentelemetry_ids_generator = [options.extras_require] test = - opentelemetry-test == 0.17.dev0 + opentelemetry-test == 0.18.dev0 [options.packages.find] where = src diff --git a/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/trace/aws_xray_ids_generator.py b/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/trace/aws_xray_ids_generator.py index 6928e0b18d..bf908e03ff 100644 --- a/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/trace/aws_xray_ids_generator.py +++ b/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/trace/aws_xray_ids_generator.py @@ -12,6 +12,50 @@ # See the License for the specific language governing permissions and # limitations under the License. +""" +Installation +------------ + +:: + + pip install opentelemetry-sdk-extension-aws + +AWS X-Ray IDs Generator +----------------------- + +The **AWS X-Ray IDs Generator** provides a custom IDs Generator to make +traces generated using the OpenTelemetry SDKs `TracerProvider` compatible +with the AWS X-Ray backend service `trace ID format`_. + +Usage +----- + +Configure the OTel SDK TracerProvider with the provided custom IDs Generator to +make spans compatible with the AWS X-Ray backend tracing service. + +Install the OpenTelemetry SDK package. + +:: + + pip install opentelemetry-sdk + +Next, use the provided `AwsXRayIdsGenerator` to initialize the `TracerProvider`. + +.. code-block:: python + + import opentelemetry.trace as trace + from opentelemetry.sdk.extension.aws.trace import AwsXRayIdsGenerator + from opentelemetry.sdk.trace import TracerProvider + + trace.set_tracer_provider( + TracerProvider(ids_generator=AwsXRayIdsGenerator()) + ) + +API +--- +.. _trace ID format: https://docs.aws.amazon.com/xray/latest/devguide/xray-api-sendingdata.html#xray-api-traceids +""" + import random import time diff --git a/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/trace/propagation/aws_xray_format.py b/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/trace/propagation/aws_xray_format.py index 54b98e0ba5..63ccb00206 100644 --- a/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/trace/propagation/aws_xray_format.py +++ b/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/trace/propagation/aws_xray_format.py @@ -12,6 +12,42 @@ # See the License for the specific language governing permissions and # limitations under the License. +""" +AWS X-Ray Propagator +-------------------- + +The **AWS X-Ray Propagator** provides a propagator that when used, adds a `trace +header`_ to outgoing traces that is compatible with the AWS X-Ray backend service. +This allows the trace context to be propagated when a trace span multiple AWS +services. + +Usage +----- + +Use the provided AWS X-Ray Propagator to inject the necessary context into +traces sent to external systems. + +This can be done by either setting this environment variable: + +:: + + export OTEL_PROPAGATORS = aws_xray + + +Or by setting this propagator in your instrumented application: + +.. code-block:: python + + from opentelemetry import propagators + from opentelemetry.sdk.extension.aws.trace.propagation.aws_xray_format import AwsXRayFormat + + propagators.set_global_textmap(AwsXRayFormat()) + +API +--- +.. _trace header: https://docs.aws.amazon.com/xray/latest/devguide/xray-concepts.html#xray-concepts-tracingheader +""" + import logging import typing diff --git a/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/version.py b/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/version.py index 86e1dbb17a..ebb75f6c11 100644 --- a/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/version.py +++ b/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.17.dev0" +__version__ = "0.18.dev0" diff --git a/sdk-extension/opentelemetry-sdk-extension-aws/tests/trace/propagation/test_aws_xray_format.py b/sdk-extension/opentelemetry-sdk-extension-aws/tests/trace/propagation/test_aws_xray_format.py index 3d5fb36069..5130c9daed 100644 --- a/sdk-extension/opentelemetry-sdk-extension-aws/tests/trace/propagation/test_aws_xray_format.py +++ b/sdk-extension/opentelemetry-sdk-extension-aws/tests/trace/propagation/test_aws_xray_format.py @@ -139,7 +139,9 @@ def test_inject_into_context_with_non_default_state(self): AwsXRayPropagatorTest.XRAY_PROPAGATOR.inject( AwsXRayPropagatorTest.carrier_setter, carrier, - build_test_current_context(trace_state=TraceState({"foo": "bar"})), + build_test_current_context( + trace_state=TraceState([("foo", "bar")]) + ), ) # TODO: (NathanielRN) Assert trace state when the propagator supports it diff --git a/tests/opentelemetry-docker-tests/tests/mysql/test_mysql_functional.py b/tests/opentelemetry-docker-tests/tests/mysql/test_mysql_functional.py index ec6eed3132..df818ab137 100644 --- a/tests/opentelemetry-docker-tests/tests/mysql/test_mysql_functional.py +++ b/tests/opentelemetry-docker-tests/tests/mysql/test_mysql_functional.py @@ -81,7 +81,7 @@ def test_execute(self): stmt = "CREATE TABLE IF NOT EXISTS test (id INT)" with self._tracer.start_as_current_span("rootSpan"): self._cursor.execute(stmt) - self.validate_spans(stmt) + self.validate_spans("CREATE") def test_execute_with_connection_context_manager(self): """Should create a child span for execute with connection context""" @@ -90,7 +90,7 @@ def test_execute_with_connection_context_manager(self): with self._connection as conn: cursor = conn.cursor() cursor.execute(stmt) - self.validate_spans(stmt) + self.validate_spans("CREATE") def test_execute_with_cursor_context_manager(self): """Should create a child span for execute with cursor context""" @@ -98,7 +98,7 @@ def test_execute_with_cursor_context_manager(self): with self._tracer.start_as_current_span("rootSpan"): with self._connection.cursor() as cursor: cursor.execute(stmt) - self.validate_spans(stmt) + self.validate_spans("CREATE") def test_executemany(self): """Should create a child span for executemany""" @@ -106,7 +106,7 @@ def test_executemany(self): with self._tracer.start_as_current_span("rootSpan"): data = (("1",), ("2",), ("3",)) self._cursor.executemany(stmt, data) - self.validate_spans(stmt) + self.validate_spans("INSERT") def test_callproc(self): """Should create a child span for callproc""" diff --git a/tests/opentelemetry-docker-tests/tests/postgres/test_aiopg_functional.py b/tests/opentelemetry-docker-tests/tests/postgres/test_aiopg_functional.py index 030aecc66d..423151316a 100644 --- a/tests/opentelemetry-docker-tests/tests/postgres/test_aiopg_functional.py +++ b/tests/opentelemetry-docker-tests/tests/postgres/test_aiopg_functional.py @@ -89,7 +89,7 @@ def test_execute(self): stmt = "CREATE TABLE IF NOT EXISTS test (id integer)" with self._tracer.start_as_current_span("rootSpan"): async_call(self._cursor.execute(stmt)) - self.validate_spans(stmt) + self.validate_spans("CREATE") def test_executemany(self): """Should create a child span for executemany""" @@ -98,7 +98,7 @@ def test_executemany(self): with self._tracer.start_as_current_span("rootSpan"): data = (("1",), ("2",), ("3",)) async_call(self._cursor.executemany(stmt, data)) - self.validate_spans(stmt) + self.validate_spans("INSERT") def test_callproc(self): """Should create a child span for callproc""" @@ -167,7 +167,7 @@ def test_execute(self): stmt = "CREATE TABLE IF NOT EXISTS test (id integer)" with self._tracer.start_as_current_span("rootSpan"): async_call(self._cursor.execute(stmt)) - self.validate_spans(stmt) + self.validate_spans("CREATE") def test_executemany(self): """Should create a child span for executemany""" @@ -176,7 +176,7 @@ def test_executemany(self): with self._tracer.start_as_current_span("rootSpan"): data = (("1",), ("2",), ("3",)) async_call(self._cursor.executemany(stmt, data)) - self.validate_spans(stmt) + self.validate_spans("INSERT") def test_callproc(self): """Should create a child span for callproc""" diff --git a/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_functional.py b/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_functional.py index 76116dfd28..53fe3cacfb 100644 --- a/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_functional.py +++ b/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_functional.py @@ -15,6 +15,7 @@ import os import psycopg2 +from psycopg2 import sql from opentelemetry import trace as trace_api from opentelemetry.instrumentation.psycopg2 import Psycopg2Instrumentor @@ -81,7 +82,7 @@ def test_execute(self): stmt = "CREATE TABLE IF NOT EXISTS test (id integer)" with self._tracer.start_as_current_span("rootSpan"): self._cursor.execute(stmt) - self.validate_spans(stmt) + self.validate_spans("CREATE") def test_execute_with_connection_context_manager(self): """Should create a child span for execute with connection context""" @@ -90,7 +91,7 @@ def test_execute_with_connection_context_manager(self): with self._connection as conn: cursor = conn.cursor() cursor.execute(stmt) - self.validate_spans(stmt) + self.validate_spans("CREATE") def test_execute_with_cursor_context_manager(self): """Should create a child span for execute with cursor context""" @@ -98,7 +99,7 @@ def test_execute_with_cursor_context_manager(self): with self._tracer.start_as_current_span("rootSpan"): with self._connection.cursor() as cursor: cursor.execute(stmt) - self.validate_spans(stmt) + self.validate_spans("CREATE") self.assertTrue(cursor.closed) def test_executemany(self): @@ -107,7 +108,7 @@ def test_executemany(self): with self._tracer.start_as_current_span("rootSpan"): data = (("1",), ("2",), ("3",)) self._cursor.executemany(stmt, data) - self.validate_spans(stmt) + self.validate_spans("INSERT") def test_callproc(self): """Should create a child span for callproc""" @@ -116,3 +117,30 @@ def test_callproc(self): ): self._cursor.callproc("test", ()) self.validate_spans("test") + + def test_register_types(self): + psycopg2.extras.register_default_jsonb( + conn_or_curs=self._cursor, loads=lambda x: x + ) + + def test_composed_queries(self): + stmt = "CREATE TABLE IF NOT EXISTS users (id integer, name varchar)" + with self._tracer.start_as_current_span("rootSpan"): + self._cursor.execute(stmt) + self.validate_spans("CREATE") + + self._cursor.execute( + sql.SQL("SELECT FROM {table} where {field}='{value}'").format( + table=sql.Identifier("users"), + field=sql.Identifier("name"), + value=sql.Identifier("abc"), + ) + ) + + spans = self.memory_exporter.get_finished_spans() + span = spans[2] + self.assertEqual(span.name, "SELECT") + self.assertEqual( + span.attributes["db.statement"], + 'SELECT FROM "users" where "name"=\'"abc"\'', + ) diff --git a/tests/opentelemetry-docker-tests/tests/pymysql/test_pymysql_functional.py b/tests/opentelemetry-docker-tests/tests/pymysql/test_pymysql_functional.py index b8e4404805..278bfc4d42 100644 --- a/tests/opentelemetry-docker-tests/tests/pymysql/test_pymysql_functional.py +++ b/tests/opentelemetry-docker-tests/tests/pymysql/test_pymysql_functional.py @@ -78,7 +78,7 @@ def test_execute(self): stmt = "CREATE TABLE IF NOT EXISTS test (id INT)" with self._tracer.start_as_current_span("rootSpan"): self._cursor.execute(stmt) - self.validate_spans(stmt) + self.validate_spans("CREATE") def test_execute_with_cursor_context_manager(self): """Should create a child span for execute with cursor context""" @@ -86,7 +86,7 @@ def test_execute_with_cursor_context_manager(self): with self._tracer.start_as_current_span("rootSpan"): with self._connection.cursor() as cursor: cursor.execute(stmt) - self.validate_spans(stmt) + self.validate_spans("CREATE") def test_executemany(self): """Should create a child span for executemany""" @@ -94,7 +94,7 @@ def test_executemany(self): with self._tracer.start_as_current_span("rootSpan"): data = (("1",), ("2",), ("3",)) self._cursor.executemany(stmt, data) - self.validate_spans(stmt) + self.validate_spans("INSERT") def test_callproc(self): """Should create a child span for callproc""" diff --git a/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/mixins.py b/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/mixins.py index b2e9f24e3d..62e9b3622a 100644 --- a/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/mixins.py +++ b/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/mixins.py @@ -110,6 +110,8 @@ def tearDown(self): super().tearDown() def _check_span(self, span, name): + if self.SQL_DB: + name = "{0} {1}".format(name, self.SQL_DB) self.assertEqual(span.name, name) self.assertEqual(span.attributes.get(_DB), self.SQL_DB) self.assertIs(span.status.status_code, trace.status.StatusCode.UNSET) @@ -129,7 +131,7 @@ def test_orm_insert(self): stmt += "(?, ?)" else: stmt += "(%(id)s, %(name)s)" - self._check_span(span, stmt) + self._check_span(span, "INSERT") self.assertIn("INSERT INTO players", span.attributes.get(_STMT)) self.check_meta(span) @@ -146,7 +148,7 @@ def test_session_query(self): stmt += "?" else: stmt += "%(name_1)s" - self._check_span(span, stmt) + self._check_span(span, "SELECT") self.assertIn( "SELECT players.id AS players_id, players.name AS players_name \nFROM players \nWHERE players.name", span.attributes.get(_STMT), @@ -163,7 +165,7 @@ def test_engine_connect_execute(self): spans = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans), 1) span = spans[0] - self._check_span(span, stmt) + self._check_span(span, "SELECT") self.assertEqual(span.attributes.get(_STMT), "SELECT * FROM players") self.check_meta(span) @@ -188,4 +190,4 @@ def test_parent(self): self.assertEqual(parent_span.name, "sqlalch_op") self.assertEqual(parent_span.instrumentation_info.name, "sqlalch_svc") - self.assertEqual(child_span.name, stmt) + self.assertEqual(child_span.name, "SELECT " + self.SQL_DB) diff --git a/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_instrument.py b/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_instrument.py index 3da823d5ba..ac5b8f9389 100644 --- a/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_instrument.py +++ b/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_instrument.py @@ -56,7 +56,7 @@ def tearDown(self): def test_engine_traced(self): # ensures that the engine is traced - rows = self.conn.execute("SELECT 1").fetchall() + rows = self.conn.execute("SELECT").fetchall() self.assertEqual(len(rows), 1) traces = self.memory_exporter.get_finished_spans() @@ -64,6 +64,6 @@ def test_engine_traced(self): self.assertEqual(len(traces), 1) span = traces[0] # check subset of span fields - self.assertEqual(span.name, "SELECT 1") + self.assertEqual(span.name, "SELECT opentelemetry-tests") self.assertIs(span.status.status_code, trace.status.StatusCode.UNSET) self.assertGreater((span.end_time - span.start_time), 0) diff --git a/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_mysql.py b/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_mysql.py index e37fa4d51e..31942dd582 100644 --- a/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_mysql.py +++ b/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_mysql.py @@ -67,7 +67,7 @@ def test_engine_execute_errors(self): self.assertEqual(len(spans), 1) span = spans[0] # span fields - self.assertEqual(span.name, "SELECT * FROM a_wrong_table") + self.assertEqual(span.name, "SELECT opentelemetry-tests") self.assertEqual( span.attributes.get(_STMT), "SELECT * FROM a_wrong_table" ) diff --git a/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_postgres.py b/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_postgres.py index 2642d52a74..f9c38b1511 100644 --- a/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_postgres.py +++ b/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_postgres.py @@ -65,7 +65,7 @@ def test_engine_execute_errors(self): self.assertEqual(len(spans), 1) span = spans[0] # span fields - self.assertEqual(span.name, "SELECT * FROM a_wrong_table") + self.assertEqual(span.name, "SELECT opentelemetry-tests") self.assertEqual( span.attributes.get(_STMT), "SELECT * FROM a_wrong_table" ) diff --git a/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_sqlite.py b/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_sqlite.py index a3fae96bb8..2f64642486 100644 --- a/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_sqlite.py +++ b/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/test_sqlite.py @@ -43,7 +43,7 @@ def test_engine_execute_errors(self): self.assertEqual(len(spans), 1) span = spans[0] # span fields - self.assertEqual(span.name, stmt) + self.assertEqual(span.name, "SELECT :memory:") self.assertEqual( span.attributes.get(_STMT), "SELECT * FROM a_wrong_table" ) diff --git a/tox.ini b/tox.ini index e4958aa7f9..87462e4c87 100644 --- a/tox.ini +++ b/tox.ini @@ -140,6 +140,7 @@ envlist = lint docker-tests + docs [testenv] deps = @@ -281,6 +282,17 @@ commands = test: pytest {posargs} coverage: {toxinidir}/scripts/coverage.sh +[testenv:docs] +deps = + -c {toxinidir}/dev-requirements.txt + -r {toxinidir}/docs-requirements.txt + pytest + +changedir = docs + +commands = + sphinx-build -E -a -W -b html -T . _build/html + [testenv:lint] basepython: python3.8 recreate = False