fix missing dep in docs build (#557)

This commit is contained in:
alrex
2021-06-30 12:49:45 -07:00
committed by GitHub
parent de93b2ad28
commit 5b43a5993d
14 changed files with 221 additions and 203 deletions

View File

@ -8,6 +8,7 @@ sphinx-autodoc-typehints
-e "git+https://github.com/open-telemetry/opentelemetry-python.git#egg=opentelemetry-semantic-conventions&subdirectory=opentelemetry-semantic-conventions"
-e "git+https://github.com/open-telemetry/opentelemetry-python-contrib.git#egg=opentelemetry-instrumentation&subdirectory=opentelemetry-instrumentation"
-e "git+https://github.com/open-telemetry/opentelemetry-python.git#egg=opentelemetry-sdk&subdirectory=opentelemetry-sdk"
-e "git+https://github.com/open-telemetry/opentelemetry-python-contrib.git#egg=opentelemetry-util-http&subdirectory=util/opentelemetry-util-http"
# Required by opentelemetry-instrumentation
fastapi>=0.65.2

View File

@ -1,7 +1,10 @@
import typing
import wrapt
from aiopg.utils import _ContextManager, _PoolAcquireContextManager
from aiopg.utils import ( # pylint: disable=no-name-in-module
_ContextManager,
_PoolAcquireContextManager,
)
from opentelemetry.instrumentation.dbapi import (
CursorTracer,
@ -61,7 +64,9 @@ def get_traced_connection_proxy(
def cursor(self, *args, **kwargs):
coro = self._cursor(*args, **kwargs)
return _ContextManager(coro)
return _ContextManager( # pylint: disable=no-value-for-parameter
coro
)
async def _cursor(self, *args, **kwargs):
# pylint: disable=protected-access

View File

@ -34,7 +34,10 @@ import typing
import aiopg
import wrapt
from aiopg.utils import _ContextManager, _PoolContextManager
from aiopg.utils import ( # pylint: disable=no-name-in-module
_ContextManager,
_PoolContextManager,
)
from opentelemetry.instrumentation.aiopg.aiopg_integration import (
AiopgIntegration,
@ -108,7 +111,7 @@ def wrap_connect(
version=version,
tracer_provider=tracer_provider,
)
return _ContextManager(
return _ContextManager( # pylint: disable=no-value-for-parameter
db_integration.wrapped_connection(wrapped, args, kwargs)
)

View File

@ -17,7 +17,10 @@ from unittest import mock
from unittest.mock import MagicMock
import aiopg
from aiopg.utils import _ContextManager, _PoolAcquireContextManager
from aiopg.utils import ( # pylint: disable=no-name-in-module
_ContextManager,
_PoolAcquireContextManager,
)
import opentelemetry.instrumentation.aiopg
from opentelemetry import trace as trace_api
@ -525,7 +528,7 @@ class MockConnection:
# pylint: disable=no-self-use
def cursor(self):
coro = self._cursor()
return _ContextManager(coro)
return _ContextManager(coro) # pylint: disable=no-value-for-parameter
async def _cursor(self):
return MockCursor()

View File

@ -14,7 +14,7 @@
import sys
import unittest
import unittest.mock as mock
from unittest import mock
import opentelemetry.instrumentation.asgi as otel_asgi
from opentelemetry import trace as trace_api

View File

@ -79,6 +79,7 @@ class TestServer(test_server_pb2_grpc.GRPCTestServerServicer):
def create_test_server(port):
# pylint: disable=consider-using-with
server = grpc.server(futures.ThreadPoolExecutor(max_workers=1))
test_server_pb2_grpc.add_GRPCTestServerServicer_to_server(

View File

@ -82,50 +82,50 @@ class TestOpenTelemetryServerInterceptor(TestBase):
grpc_server_instrumentor = GrpcInstrumentorServer()
grpc_server_instrumentor.instrument()
server = grpc.server(
futures.ThreadPoolExecutor(max_workers=1),
options=(("grpc.so_reuseport", 0),),
)
with futures.ThreadPoolExecutor(max_workers=1) as executor:
server = grpc.server(
executor, options=(("grpc.so_reuseport", 0),),
)
server.add_generic_rpc_handlers((UnaryUnaryRpcHandler(handler),))
server.add_generic_rpc_handlers((UnaryUnaryRpcHandler(handler),))
port = server.add_insecure_port("[::]:0")
channel = grpc.insecure_channel("localhost:{:d}".format(port))
port = server.add_insecure_port("[::]:0")
channel = grpc.insecure_channel("localhost:{:d}".format(port))
rpc_call = "TestServicer/handler"
try:
server.start()
channel.unary_unary(rpc_call)(b"test")
finally:
server.stop(None)
rpc_call = "TestServicer/handler"
try:
server.start()
channel.unary_unary(rpc_call)(b"test")
finally:
server.stop(None)
spans_list = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans_list), 1)
span = spans_list[0]
self.assertEqual(span.name, rpc_call)
self.assertIs(span.kind, trace.SpanKind.SERVER)
spans_list = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans_list), 1)
span = spans_list[0]
self.assertEqual(span.name, rpc_call)
self.assertIs(span.kind, trace.SpanKind.SERVER)
# Check version and name in span's instrumentation info
self.check_span_instrumentation_info(
span, opentelemetry.instrumentation.grpc
)
# Check version and name in span's instrumentation info
self.check_span_instrumentation_info(
span, opentelemetry.instrumentation.grpc
)
# Check attributes
self.assert_span_has_attributes(
span,
{
SpanAttributes.NET_PEER_IP: "[::1]",
SpanAttributes.NET_PEER_NAME: "localhost",
SpanAttributes.RPC_METHOD: "handler",
SpanAttributes.RPC_SERVICE: "TestServicer",
SpanAttributes.RPC_SYSTEM: "grpc",
SpanAttributes.RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[
0
],
},
)
# Check attributes
self.assert_span_has_attributes(
span,
{
SpanAttributes.NET_PEER_IP: "[::1]",
SpanAttributes.NET_PEER_NAME: "localhost",
SpanAttributes.RPC_METHOD: "handler",
SpanAttributes.RPC_SERVICE: "TestServicer",
SpanAttributes.RPC_SYSTEM: "grpc",
SpanAttributes.RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[
0
],
},
)
grpc_server_instrumentor.uninstrument()
grpc_server_instrumentor.uninstrument()
def test_uninstrument(self):
def handler(request, context):
@ -134,22 +134,22 @@ class TestOpenTelemetryServerInterceptor(TestBase):
grpc_server_instrumentor = GrpcInstrumentorServer()
grpc_server_instrumentor.instrument()
grpc_server_instrumentor.uninstrument()
server = grpc.server(
futures.ThreadPoolExecutor(max_workers=1),
options=(("grpc.so_reuseport", 0),),
)
with futures.ThreadPoolExecutor(max_workers=1) as executor:
server = grpc.server(
executor, options=(("grpc.so_reuseport", 0),),
)
server.add_generic_rpc_handlers((UnaryUnaryRpcHandler(handler),))
server.add_generic_rpc_handlers((UnaryUnaryRpcHandler(handler),))
port = server.add_insecure_port("[::]:0")
channel = grpc.insecure_channel("localhost:{:d}".format(port))
port = server.add_insecure_port("[::]:0")
channel = grpc.insecure_channel("localhost:{:d}".format(port))
rpc_call = "TestServicer/test"
try:
server.start()
channel.unary_unary(rpc_call)(b"test")
finally:
server.stop(None)
rpc_call = "TestServicer/test"
try:
server.start()
channel.unary_unary(rpc_call)(b"test")
finally:
server.stop(None)
spans_list = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans_list), 0)
@ -160,23 +160,24 @@ class TestOpenTelemetryServerInterceptor(TestBase):
# Intercept gRPC calls...
interceptor = server_interceptor()
server = grpc.server(
futures.ThreadPoolExecutor(max_workers=1),
options=(("grpc.so_reuseport", 0),),
interceptors=[interceptor],
)
add_GRPCTestServerServicer_to_server(Servicer(), server)
port = server.add_insecure_port("[::]:0")
channel = grpc.insecure_channel("localhost:{:d}".format(port))
with futures.ThreadPoolExecutor(max_workers=1) as executor:
server = grpc.server(
executor,
options=(("grpc.so_reuseport", 0),),
interceptors=[interceptor],
)
add_GRPCTestServerServicer_to_server(Servicer(), server)
port = server.add_insecure_port("[::]:0")
channel = grpc.insecure_channel("localhost:{:d}".format(port))
rpc_call = "/GRPCTestServer/SimpleMethod"
request = Request(client_id=1, request_data="test")
msg = request.SerializeToString()
try:
server.start()
channel.unary_unary(rpc_call)(msg)
finally:
server.stop(None)
rpc_call = "/GRPCTestServer/SimpleMethod"
request = Request(client_id=1, request_data="test")
msg = request.SerializeToString()
try:
server.start()
channel.unary_unary(rpc_call)(msg)
finally:
server.stop(None)
spans_list = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans_list), 1)
@ -227,24 +228,25 @@ class TestOpenTelemetryServerInterceptor(TestBase):
interceptor = server_interceptor()
# setup the server
server = grpc.server(
futures.ThreadPoolExecutor(max_workers=1),
options=(("grpc.so_reuseport", 0),),
interceptors=[interceptor],
)
add_GRPCTestServerServicer_to_server(TwoSpanServicer(), server)
port = server.add_insecure_port("[::]:0")
channel = grpc.insecure_channel("localhost:{:d}".format(port))
with futures.ThreadPoolExecutor(max_workers=1) as executor:
server = grpc.server(
executor,
options=(("grpc.so_reuseport", 0),),
interceptors=[interceptor],
)
add_GRPCTestServerServicer_to_server(TwoSpanServicer(), server)
port = server.add_insecure_port("[::]:0")
channel = grpc.insecure_channel("localhost:{:d}".format(port))
# setup the RPC
rpc_call = "/GRPCTestServer/SimpleMethod"
request = Request(client_id=1, request_data="test")
msg = request.SerializeToString()
try:
server.start()
channel.unary_unary(rpc_call)(msg)
finally:
server.stop(None)
# setup the RPC
rpc_call = "/GRPCTestServer/SimpleMethod"
request = Request(client_id=1, request_data="test")
msg = request.SerializeToString()
try:
server.start()
channel.unary_unary(rpc_call)(msg)
finally:
server.stop(None)
spans_list = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans_list), 2)
@ -287,25 +289,25 @@ class TestOpenTelemetryServerInterceptor(TestBase):
# Intercept gRPC calls...
interceptor = server_interceptor()
# setup the server
server = grpc.server(
futures.ThreadPoolExecutor(max_workers=1),
options=(("grpc.so_reuseport", 0),),
interceptors=[interceptor],
)
add_GRPCTestServerServicer_to_server(Servicer(), server)
port = server.add_insecure_port("[::]:0")
channel = grpc.insecure_channel("localhost:{:d}".format(port))
with futures.ThreadPoolExecutor(max_workers=1) as executor:
server = grpc.server(
executor,
options=(("grpc.so_reuseport", 0),),
interceptors=[interceptor],
)
add_GRPCTestServerServicer_to_server(Servicer(), server)
port = server.add_insecure_port("[::]:0")
channel = grpc.insecure_channel("localhost:{:d}".format(port))
# setup the RPC
rpc_call = "/GRPCTestServer/ServerStreamingMethod"
request = Request(client_id=1, request_data="test")
msg = request.SerializeToString()
try:
server.start()
list(channel.unary_stream(rpc_call)(msg))
finally:
server.stop(None)
# setup the RPC
rpc_call = "/GRPCTestServer/ServerStreamingMethod"
request = Request(client_id=1, request_data="test")
msg = request.SerializeToString()
try:
server.start()
list(channel.unary_stream(rpc_call)(msg))
finally:
server.stop(None)
spans_list = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans_list), 1)
@ -355,25 +357,25 @@ class TestOpenTelemetryServerInterceptor(TestBase):
# Intercept gRPC calls...
interceptor = server_interceptor()
# setup the server
server = grpc.server(
futures.ThreadPoolExecutor(max_workers=1),
options=(("grpc.so_reuseport", 0),),
interceptors=[interceptor],
)
add_GRPCTestServerServicer_to_server(TwoSpanServicer(), server)
port = server.add_insecure_port("[::]:0")
channel = grpc.insecure_channel("localhost:{:d}".format(port))
with futures.ThreadPoolExecutor(max_workers=1) as executor:
server = grpc.server(
executor,
options=(("grpc.so_reuseport", 0),),
interceptors=[interceptor],
)
add_GRPCTestServerServicer_to_server(TwoSpanServicer(), server)
port = server.add_insecure_port("[::]:0")
channel = grpc.insecure_channel("localhost:{:d}".format(port))
# setup the RPC
rpc_call = "/GRPCTestServer/ServerStreamingMethod"
request = Request(client_id=1, request_data="test")
msg = request.SerializeToString()
try:
server.start()
list(channel.unary_stream(rpc_call)(msg))
finally:
server.stop(None)
# setup the RPC
rpc_call = "/GRPCTestServer/ServerStreamingMethod"
request = Request(client_id=1, request_data="test")
msg = request.SerializeToString()
try:
server.start()
list(channel.unary_stream(rpc_call)(msg))
finally:
server.stop(None)
spans_list = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans_list), 2)
@ -422,22 +424,23 @@ class TestOpenTelemetryServerInterceptor(TestBase):
active_span_in_handler = trace.get_current_span()
return b""
server = grpc.server(
futures.ThreadPoolExecutor(max_workers=1),
options=(("grpc.so_reuseport", 0),),
interceptors=[interceptor],
)
server.add_generic_rpc_handlers((UnaryUnaryRpcHandler(handler),))
with futures.ThreadPoolExecutor(max_workers=1) as executor:
server = grpc.server(
executor,
options=(("grpc.so_reuseport", 0),),
interceptors=[interceptor],
)
server.add_generic_rpc_handlers((UnaryUnaryRpcHandler(handler),))
port = server.add_insecure_port("[::]:0")
channel = grpc.insecure_channel("localhost:{:d}".format(port))
port = server.add_insecure_port("[::]:0")
channel = grpc.insecure_channel("localhost:{:d}".format(port))
active_span_before_call = trace.get_current_span()
try:
server.start()
channel.unary_unary("TestServicer/handler")(b"")
finally:
server.stop(None)
active_span_before_call = trace.get_current_span()
try:
server.start()
channel.unary_unary("TestServicer/handler")(b"")
finally:
server.stop(None)
active_span_after_call = trace.get_current_span()
self.assertEqual(active_span_before_call, trace.INVALID_SPAN)
@ -457,22 +460,23 @@ class TestOpenTelemetryServerInterceptor(TestBase):
active_spans_in_handler.append(trace.get_current_span())
return b""
server = grpc.server(
futures.ThreadPoolExecutor(max_workers=1),
options=(("grpc.so_reuseport", 0),),
interceptors=[interceptor],
)
server.add_generic_rpc_handlers((UnaryUnaryRpcHandler(handler),))
with futures.ThreadPoolExecutor(max_workers=1) as executor:
server = grpc.server(
executor,
options=(("grpc.so_reuseport", 0),),
interceptors=[interceptor],
)
server.add_generic_rpc_handlers((UnaryUnaryRpcHandler(handler),))
port = server.add_insecure_port("[::]:0")
channel = grpc.insecure_channel("localhost:{:d}".format(port))
port = server.add_insecure_port("[::]:0")
channel = grpc.insecure_channel("localhost:{:d}".format(port))
try:
server.start()
channel.unary_unary("TestServicer/handler")(b"")
channel.unary_unary("TestServicer/handler")(b"")
finally:
server.stop(None)
try:
server.start()
channel.unary_unary("TestServicer/handler")(b"")
channel.unary_unary("TestServicer/handler")(b"")
finally:
server.stop(None)
self.assertEqual(len(active_spans_in_handler), 2)
# pylint:disable=unbalanced-tuple-unpacking
@ -520,30 +524,31 @@ class TestOpenTelemetryServerInterceptor(TestBase):
active_spans_in_handler.append(trace.get_current_span())
return b""
server = grpc.server(
futures.ThreadPoolExecutor(max_workers=2),
options=(("grpc.so_reuseport", 0),),
interceptors=[interceptor],
)
server.add_generic_rpc_handlers((UnaryUnaryRpcHandler(handler),))
with futures.ThreadPoolExecutor(max_workers=2) as executor:
server = grpc.server(
executor,
options=(("grpc.so_reuseport", 0),),
interceptors=[interceptor],
)
server.add_generic_rpc_handlers((UnaryUnaryRpcHandler(handler),))
port = server.add_insecure_port("[::]:0")
channel = grpc.insecure_channel("localhost:{:d}".format(port))
port = server.add_insecure_port("[::]:0")
channel = grpc.insecure_channel("localhost:{:d}".format(port))
try:
server.start()
# Interleave calls so spans are active on each thread at the same
# time
with futures.ThreadPoolExecutor(max_workers=2) as tpe:
f1 = tpe.submit(
channel.unary_unary("TestServicer/handler"), b""
)
f2 = tpe.submit(
channel.unary_unary("TestServicer/handler"), b""
)
futures.wait((f1, f2))
finally:
server.stop(None)
try:
server.start()
# Interleave calls so spans are active on each thread at the same
# time
with futures.ThreadPoolExecutor(max_workers=2) as tpe:
f1 = tpe.submit(
channel.unary_unary("TestServicer/handler"), b""
)
f2 = tpe.submit(
channel.unary_unary("TestServicer/handler"), b""
)
futures.wait((f1, f2))
finally:
server.stop(None)
self.assertEqual(len(active_spans_in_handler), 2)
# pylint:disable=unbalanced-tuple-unpacking
@ -584,24 +589,25 @@ class TestOpenTelemetryServerInterceptor(TestBase):
def handler(request, context):
context.abort(grpc.StatusCode.FAILED_PRECONDITION, failure_message)
server = grpc.server(
futures.ThreadPoolExecutor(max_workers=1),
options=(("grpc.so_reuseport", 0),),
interceptors=[interceptor],
)
with futures.ThreadPoolExecutor(max_workers=1) as executor:
server = grpc.server(
executor,
options=(("grpc.so_reuseport", 0),),
interceptors=[interceptor],
)
server.add_generic_rpc_handlers((UnaryUnaryRpcHandler(handler),))
server.add_generic_rpc_handlers((UnaryUnaryRpcHandler(handler),))
port = server.add_insecure_port("[::]:0")
channel = grpc.insecure_channel("localhost:{:d}".format(port))
port = server.add_insecure_port("[::]:0")
channel = grpc.insecure_channel("localhost:{:d}".format(port))
rpc_call = "TestServicer/handler"
rpc_call = "TestServicer/handler"
server.start()
# unfortunately, these are just bare exceptions in grpc...
with self.assertRaises(Exception):
channel.unary_unary(rpc_call)(b"")
server.stop(None)
server.start()
# unfortunately, these are just bare exceptions in grpc...
with self.assertRaises(Exception):
channel.unary_unary(rpc_call)(b"")
server.stop(None)
spans_list = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans_list), 1)

View File

@ -22,11 +22,10 @@ Usage
.. code-block:: python
import requests
import opentelemetry.instrumentation.requests
from opentelemetry.instrumentation.requests import RequestsInstrumentor
# You can optionally pass a custom TracerProvider to
# RequestsInstrumentor.instrument()
opentelemetry.instrumentation.requests.RequestsInstrumentor().instrument()
RequestsInstrumentor.instrument()
response = requests.get(url="https://www.example.org/")
API

View File

@ -42,6 +42,7 @@ from .tornado_test_app import (
class TornadoTest(AsyncHTTPTestCase, TestBase):
# pylint:disable=no-self-use
def get_app(self):
tracer = trace.get_tracer(__name__)
app = make_app(tracer)

View File

@ -14,8 +14,8 @@
import sys
import unittest
import unittest.mock as mock
import wsgiref.util as wsgiref_util
from unittest import mock
from urllib.parse import urlsplit
import opentelemetry.instrumentation.wsgi as otel_wsgi

View File

@ -26,7 +26,7 @@ https://w3c.github.io/trace-context/#trace-context-http-response-headers-format
import typing
from abc import ABC, abstractmethod
import opentelemetry.trace as trace
from opentelemetry import trace
from opentelemetry.context.context import Context
from opentelemetry.propagators import textmap
from opentelemetry.trace import format_span_id, format_trace_id

View File

@ -631,9 +631,9 @@ def update_dependencies(targets, version, packages):
if str(pkg) == "all":
continue
print(pkg)
package_name = str(pkg).split("/")[-1]
package_name = str(pkg).split("/", maxsplit=1)[-1]
# Windows uses backslashes
package_name = str(pkg).split("\\")[-1]
package_name = str(pkg).split("\\", maxsplit=1)[-1]
print(package_name)
update_files(

View File

@ -35,11 +35,10 @@ _prefix = "opentelemetry-instrumentation-"
def main():
root_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
setuppy_tmpl = Template(
open(
os.path.join(root_path, _template_dir, _template_name), "r"
).read()
)
with open(
os.path.join(root_path, _template_dir, _template_name), "r"
) as template:
setuppy_tmpl = Template(template.read())
base_instrumentation_path = os.path.join(root_path, "instrumentation")
for instrumentation in os.listdir(base_instrumentation_path):

View File

@ -51,7 +51,7 @@ API
import logging
import typing
import opentelemetry.trace as trace
from opentelemetry import trace
from opentelemetry.context import Context
from opentelemetry.propagators.textmap import (
CarrierT,