Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
max-line-length = 79
ignore = W503,E203
7 changes: 5 additions & 2 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[settings]
force_single_line=True
from_first=True
multi_line_output=3
include_trailing_comma=True
force_grid_wrap=0
use_parentheses=True
line_length=79
3 changes: 2 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ disable=missing-docstring,
too-few-public-methods, # Might be good to re-enable this later.
too-many-instance-attributes,
too-many-arguments,
ungrouped-imports # Leave this up to isort
ungrouped-imports, # Leave this up to isort
bad-continuation # Leave this up to black

# 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
Expand Down
37 changes: 19 additions & 18 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,65 +12,66 @@

import os
import sys
sys.path.insert(0, os.path.abspath('../opentelemetry-api/src/'))

sys.path.insert(0, os.path.abspath("../opentelemetry-api/src/"))


# -- Project information -----------------------------------------------------

project = 'OpenTelemetry'
copyright = '2019, OpenTelemetry Authors'
author = 'OpenTelemetry Authors'
project = "OpenTelemetry"
copyright = "2019, OpenTelemetry Authors"
author = "OpenTelemetry Authors"


# -- General configuration ---------------------------------------------------

# Easy automatic cross-references for `code in backticks`
default_role = 'any'
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',
"sphinx.ext.autodoc",
# Support for google-style docstrings
'sphinx.ext.napoleon',
"sphinx.ext.napoleon",
# Infer types from hints instead of docstrings
'sphinx_autodoc_typehints',
"sphinx_autodoc_typehints",
# Add links to source from generated docs
'sphinx.ext.viewcode',
"sphinx.ext.viewcode",
# Link to other sphinx docs
'sphinx.ext.intersphinx',
"sphinx.ext.intersphinx",
]

intersphinx_mapping = {'python': ('https://docs.python.org/3/', None)}
intersphinx_mapping = {"python": ("https://docs.python.org/3/", 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
nitpick_ignore = []

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
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']
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

autodoc_default_options = {
'members': True,
'undoc-members': True,
'show-inheritance': True,
'member-order': 'bysource'
"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'
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,
Expand Down
7 changes: 1 addition & 6 deletions ext/opentelemetry-ext-wsgi/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@

BASE_DIR = os.path.dirname(__file__)
VERSION_FILENAME = os.path.join(
BASE_DIR,
"src",
"opentelemetry",
"ext",
"wsgi",
"version.py",
BASE_DIR, "src", "opentelemetry", "ext", "wsgi", "version.py"
)
PACKAGE_INFO = {}
with open(VERSION_FILENAME) as f:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@ class OpenTelemetryMiddleware:
wsgi: The WSGI application callable.
"""

def __init__(
self,
wsgi,
propagators=None,
):
def __init__(self, wsgi, propagators=None):
self.wsgi = wsgi

# TODO: implement context propagation
Expand All @@ -54,9 +50,9 @@ def _add_request_attributes(span, environ):
span.set_attribute("http.host", host)

url = (
environ.get("REQUEST_URI") or
environ.get("RAW_URI") or
wsgiref_util.request_uri(environ, include_query=False)
environ.get("REQUEST_URI")
or environ.get("RAW_URI")
or wsgiref_util.request_uri(environ, include_query=False)
)
span.set_attribute("http.url", url)

Expand Down Expand Up @@ -101,5 +97,5 @@ def __call__(self, environ, start_response):
for yielded in iterable:
yield yielded
finally:
if hasattr(iterable, 'close'):
if hasattr(iterable, "close"):
iterable.close()
25 changes: 9 additions & 16 deletions ext/opentelemetry-ext-wsgi/tests/test_wsgi_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def iter_wsgi(environ, start_response):
assert isinstance(environ, dict)
start_response("200 OK", [("Content-Type", "text/plain")])
return response

return iter_wsgi


Expand All @@ -66,10 +67,9 @@ class TestWsgiApplication(unittest.TestCase):
def setUp(self):
tracer = trace_api.tracer()
self.span_context_manager = mock.MagicMock()
self.span_context_manager.__enter__.return_value = \
mock.create_autospec(
trace_api.Span, spec_set=True
)
self.span_context_manager.__enter__.return_value = mock.create_autospec(
trace_api.Span, spec_set=True
)
self.patcher = mock.patch.object(
tracer,
"start_span",
Expand Down Expand Up @@ -112,10 +112,7 @@ def validate_response(self, response, error=None):
break

self.assertEqual(self.status, "200 OK")
self.assertEqual(
self.response_headers,
[("Content-Type", "text/plain")]
)
self.assertEqual(self.response_headers, [("Content-Type", "text/plain")])
if error:
self.assertIs(self.exc_info[0], error)
self.assertIsInstance(self.exc_info[1], error)
Expand Down Expand Up @@ -157,8 +154,7 @@ def setUp(self):

def test_request_attributes(self):
OpenTelemetryMiddleware._add_request_attributes( # noqa pylint: disable=protected-access
self.span,
self.environ,
self.span, self.environ
)
expected = (
mock.call("component", "http"),
Expand All @@ -171,7 +167,7 @@ def test_request_attributes(self):

def test_response_attributes(self):
OpenTelemetryMiddleware._add_response_attributes( # noqa pylint: disable=protected-access
self.span, "404 Not Found",
self.span, "404 Not Found"
)
expected = (
mock.call("http.status_code", 404),
Expand All @@ -182,13 +178,10 @@ def test_response_attributes(self):

def test_response_attributes_invalid_status_code(self):
OpenTelemetryMiddleware._add_response_attributes( # noqa pylint: disable=protected-access
self.span, "Invalid Status Code",
self.span, "Invalid Status Code"
)
self.assertEqual(self.span.set_attribute.call_count, 1)
self.span.set_attribute.assert_called_with(
"http.status_text",
"Status Code",
)
self.span.set_attribute.assert_called_with("http.status_text", "Status Code")


if __name__ == "__main__":
Expand Down
13 changes: 6 additions & 7 deletions opentelemetry-api/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,14 @@
description="OpenTelemetry Python API",
include_package_data=True,
long_description=open("README.rst").read(),
install_requires=[
"typing; python_version<'3.5'",
],
install_requires=["typing; python_version<'3.5'"],
extras_require={},
license="Apache-2.0",
package_dir={"": "src"},
packages=setuptools.find_namespace_packages(where="src",
include="opentelemetry.*"),
url=("https://github.com/open-telemetry/opentelemetry-python"
"/tree/master/opentelemetry-api"),
packages=setuptools.find_namespace_packages(where="src", include="opentelemetry.*"),
url=(
"https://github.com/open-telemetry/opentelemetry-python"
"/tree/master/opentelemetry-api"
),
zip_safe=False,
)
4 changes: 3 additions & 1 deletion opentelemetry-api/src/opentelemetry/context/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,16 @@ async def main():

from .base_context import BaseRuntimeContext

__all__ = ['Context']
__all__ = ["Context"]


Context: typing.Optional[BaseRuntimeContext]

try:
from .async_context import AsyncRuntimeContext

Context = AsyncRuntimeContext() # pylint:disable=invalid-name
except ImportError:
from .thread_local_context import ThreadLocalRuntimeContext

Context = ThreadLocalRuntimeContext() # pylint:disable=invalid-name
10 changes: 5 additions & 5 deletions opentelemetry-api/src/opentelemetry/context/async_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,31 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from contextvars import ContextVar
import typing
from contextvars import ContextVar

from . import base_context


class AsyncRuntimeContext(base_context.BaseRuntimeContext):
class Slot(base_context.BaseRuntimeContext.Slot):
def __init__(self, name: str, default: 'object'):
def __init__(self, name: str, default: "object"):
# pylint: disable=super-init-not-called
self.name = name
self.contextvar: 'ContextVar[object]' = ContextVar(name)
self.contextvar: "ContextVar[object]" = ContextVar(name)
self.default: typing.Callable[..., object]
self.default = base_context.wrap_callable(default)

def clear(self) -> None:
self.contextvar.set(self.default())

def get(self) -> 'object':
def get(self) -> "object":
try:
return self.contextvar.get()
except LookupError:
value = self.default()
self.set(value)
return value

def set(self, value: 'object') -> None:
def set(self, value: "object") -> None:
self.contextvar.set(value)
Loading