mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2025-07-28 12:43:39 +08:00
Remove Configuration from instrumentations (#285)
This commit is contained in:
72
util/opentelemetry-util-http/README.rst
Normal file
72
util/opentelemetry-util-http/README.rst
Normal file
@ -0,0 +1,72 @@
|
||||
OpenTelemetry Util HTTP
|
||||
=======================
|
||||
|
||||
|pypi|
|
||||
|
||||
.. |pypi| image:: https://badge.fury.io/py/opentelemetry-util-http.svg
|
||||
:target: https://pypi.org/project/opentelemetry-util-http/
|
||||
|
||||
|
||||
This library provides ASGI, WSGI middleware and other HTTP-related
|
||||
functionality that is common to instrumented web frameworks (such as Django,
|
||||
Starlette, FastAPI, etc.) to track requests timing through OpenTelemetry.
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
::
|
||||
|
||||
pip install opentelemetry-util-http
|
||||
|
||||
|
||||
Usage (Quart)
|
||||
-------------
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from quart import Quart
|
||||
from opentelemetry.instrumentation.asgi import OpenTelemetryMiddleware
|
||||
|
||||
app = Quart(__name__)
|
||||
app.asgi_app = OpenTelemetryMiddleware(app.asgi_app)
|
||||
|
||||
@app.route("/")
|
||||
async def hello():
|
||||
return "Hello!"
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(debug=True)
|
||||
|
||||
|
||||
Usage (Django 3.0)
|
||||
------------------
|
||||
|
||||
Modify the application's ``asgi.py`` file as shown below.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
import os
|
||||
from django.core.asgi import get_asgi_application
|
||||
from opentelemetry.instrumentation.asgi import OpenTelemetryMiddleware
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'asgi_example.settings')
|
||||
|
||||
application = get_asgi_application()
|
||||
application = OpenTelemetryMiddleware(application)
|
||||
|
||||
|
||||
Usage (Raw ASGI)
|
||||
----------------
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from opentelemetry.instrumentation.asgi import OpenTelemetryMiddleware
|
||||
|
||||
app = ... # An ASGI application.
|
||||
app = OpenTelemetryMiddleware(app)
|
||||
|
||||
|
||||
References
|
||||
----------
|
||||
|
||||
* `OpenTelemetry Project <https://opentelemetry.io/>`_
|
51
util/opentelemetry-util-http/setup.cfg
Normal file
51
util/opentelemetry-util-http/setup.cfg
Normal file
@ -0,0 +1,51 @@
|
||||
# Copyright The OpenTelemetry Authors
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
[metadata]
|
||||
name = opentelemetry-util-http
|
||||
description = Web util for OpenTelemetry
|
||||
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/util/opentelemetry-util-http
|
||||
platforms = any
|
||||
license = Apache-2.0
|
||||
classifiers =
|
||||
Development Status :: 4 - Beta
|
||||
Intended Audience :: Developers
|
||||
License :: OSI Approved :: Apache Software License
|
||||
Programming Language :: Python
|
||||
Programming Language :: Python :: 3
|
||||
Programming Language :: Python :: 3.5
|
||||
Programming Language :: Python :: 3.6
|
||||
Programming Language :: Python :: 3.7
|
||||
Programming Language :: Python :: 3.8
|
||||
|
||||
[options]
|
||||
python_requires = >=3.5
|
||||
package_dir=
|
||||
=src
|
||||
packages=find_namespace:
|
||||
install_requires =
|
||||
opentelemetry-api == 0.18.dev0
|
||||
opentelemetry-instrumentation == 0.18.dev0
|
||||
asgiref ~= 3.0
|
||||
|
||||
[options.extras_require]
|
||||
test =
|
||||
opentelemetry-test == 0.18.dev0
|
||||
|
||||
[options.packages.find]
|
||||
where = src
|
26
util/opentelemetry-util-http/setup.py
Normal file
26
util/opentelemetry-util-http/setup.py
Normal file
@ -0,0 +1,26 @@
|
||||
# Copyright The OpenTelemetry Authors
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
import os
|
||||
|
||||
import setuptools
|
||||
|
||||
BASE_DIR = os.path.dirname(__file__)
|
||||
VERSION_FILENAME = os.path.join(
|
||||
BASE_DIR, "src", "opentelemetry", "util", "http", "version.py"
|
||||
)
|
||||
PACKAGE_INFO = {}
|
||||
with open(VERSION_FILENAME) as f:
|
||||
exec(f.read(), PACKAGE_INFO)
|
||||
|
||||
setuptools.setup(version=PACKAGE_INFO["__version__"])
|
@ -0,0 +1,59 @@
|
||||
# Copyright The OpenTelemetry Authors
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from os import environ
|
||||
from re import compile as re_compile
|
||||
from re import search
|
||||
|
||||
|
||||
class ExcludeList:
|
||||
"""Class to exclude certain paths (given as a list of regexes) from tracing requests"""
|
||||
|
||||
def __init__(self, excluded_urls):
|
||||
self._excluded_urls = excluded_urls
|
||||
if self._excluded_urls:
|
||||
self._regex = re_compile("|".join(excluded_urls))
|
||||
|
||||
def url_disabled(self, url: str) -> bool:
|
||||
return bool(self._excluded_urls and search(self._regex, url))
|
||||
|
||||
|
||||
_root = r"OTEL_PYTHON_{}"
|
||||
|
||||
|
||||
def get_traced_request_attrs(instrumentation):
|
||||
traced_request_attrs = environ.get(
|
||||
_root.format("{}_TRACED_REQUEST_ATTRS".format(instrumentation)), []
|
||||
)
|
||||
|
||||
if traced_request_attrs:
|
||||
traced_request_attrs = [
|
||||
traced_request_attr.strip()
|
||||
for traced_request_attr in traced_request_attrs.split(",")
|
||||
]
|
||||
|
||||
return traced_request_attrs
|
||||
|
||||
|
||||
def get_excluded_urls(instrumentation):
|
||||
excluded_urls = environ.get(
|
||||
_root.format("{}_EXCLUDED_URLS".format(instrumentation)), []
|
||||
)
|
||||
|
||||
if excluded_urls:
|
||||
excluded_urls = [
|
||||
excluded_url.strip() for excluded_url in excluded_urls.split(",")
|
||||
]
|
||||
|
||||
return ExcludeList(excluded_urls)
|
@ -0,0 +1,15 @@
|
||||
# Copyright The OpenTelemetry Authors
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
__version__ = "0.18.dev0"
|
0
util/opentelemetry-util-http/tests/__init__.py
Normal file
0
util/opentelemetry-util-http/tests/__init__.py
Normal file
Reference in New Issue
Block a user