Skip to content

Commit

Permalink
Fix assorted CI issues
Browse files Browse the repository at this point in the history
This fixes assorted issues highlighted by CI, like unused imports,
import ordering, "malformed" docstrings, etc
  • Loading branch information
cookiefission committed Sep 2, 2022
1 parent ff4403c commit a955218
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def serve():
interceptors = [server_interceptor()])

Usage Aio Client
------------
----------------
.. code-block:: python

import logging
Expand Down Expand Up @@ -172,7 +172,7 @@ async def run():


Usage Aio Server
------------
----------------
.. code-block:: python

import logging
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,21 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from collections import OrderedDict
import functools
from collections import OrderedDict

import grpc
from grpc.aio import ClientCallDetails

from opentelemetry import context, trace
from opentelemetry.semconv.trace import SpanAttributes
from opentelemetry.propagate import inject
from opentelemetry.instrumentation.utils import _SUPPRESS_INSTRUMENTATION_KEY
from opentelemetry.instrumentation.grpc.version import __version__

from opentelemetry.trace.status import Status, StatusCode

from opentelemetry import context
from opentelemetry.instrumentation.grpc._client import (
OpenTelemetryClientInterceptor,
_carrier_setter,
)
from opentelemetry.instrumentation.utils import _SUPPRESS_INSTRUMENTATION_KEY
from opentelemetry.propagate import inject
from opentelemetry.semconv.trace import SpanAttributes
from opentelemetry.trace.status import Status, StatusCode


def _unary_done_callback(span, code, details):
Expand All @@ -55,7 +52,6 @@ def callback(call):
class _BaseAioClientInterceptor(OpenTelemetryClientInterceptor):
@staticmethod
def propagate_trace_in_details(client_call_details):
method = client_call_details.method.decode("utf-8")
metadata = client_call_details.metadata
if not metadata:
mutable_metadata = OrderedDict()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

from ._server import (
OpenTelemetryServerInterceptor,
_wrap_rpc_behavior,
_OpenTelemetryServicerContext,
_wrap_rpc_behavior,
)


Expand All @@ -40,21 +40,21 @@ async def intercept_service(self, continuation, handler_call_details):
def telemetry_wrapper(behavior, request_streaming, response_streaming):
# handle streaming responses specially
if response_streaming:
return self._intercept_server_stream(
behavior,
handler_call_details,
)
else:
return self._intercept_server_unary(
return self._intercept_aio_server_stream(
behavior,
handler_call_details,
)

return self._intercept_aio_server_unary(
behavior,
handler_call_details,
)

next_handler = await continuation(handler_call_details)

return _wrap_rpc_behavior(next_handler, telemetry_wrapper)

def _intercept_server_unary(self, behavior, handler_call_details):
def _intercept_aio_server_unary(self, behavior, handler_call_details):
async def _unary_interceptor(request_or_iterator, context):
with self._set_remote_context(context):
with self._start_span(
Expand All @@ -80,7 +80,7 @@ async def _unary_interceptor(request_or_iterator, context):

return _unary_interceptor

def _intercept_server_stream(self, behavior, handler_call_details):
def _intercept_aio_server_stream(self, behavior, handler_call_details):
async def _stream_interceptor(request_or_iterator, context):
with self._set_remote_context(context):
with self._start_span(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,34 @@
# 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 pytest
from unittest import IsolatedAsyncioTestCase

import asyncio
import grpc
from grpc.aio import ClientCallDetails
import pytest

import opentelemetry.instrumentation.grpc
from opentelemetry import context, trace
from opentelemetry.instrumentation.grpc import (
aio_client_interceptors,
GrpcAioInstrumentorClient,
aio_client_interceptors,
)
from opentelemetry.instrumentation.grpc._aio_client import (
UnaryUnaryAioClientInterceptor,
)
from opentelemetry.semconv.trace import SpanAttributes
from opentelemetry.instrumentation.utils import _SUPPRESS_INSTRUMENTATION_KEY
from opentelemetry.propagate import get_global_textmap, set_global_textmap
from opentelemetry.semconv.trace import SpanAttributes

from opentelemetry.test.mock_textmap import MockTextMapPropagator
from opentelemetry.test.test_base import TestBase

from tests.protobuf import ( # pylint: disable=no-name-in-module
test_server_pb2_grpc,
test_server_pb2,
)
from .protobuf.test_server_pb2 import Request

from ._aio_client import (
simple_method,
server_streaming_method,
client_streaming_method,
bidirectional_streaming_method,
client_streaming_method,
server_streaming_method,
simple_method,
)
from ._server import create_test_server

from opentelemetry.instrumentation.grpc._aio_client import (
UnaryUnaryAioClientInterceptor,
)
from .protobuf import test_server_pb2_grpc # pylint: disable=no-name-in-module


class RecordingInterceptor(grpc.aio.UnaryUnaryClientInterceptor):
Expand Down Expand Up @@ -280,6 +270,7 @@ async def test_error_stream_stream(self):
trace.StatusCode.ERROR,
)

# pylint:disable=no-self-use
async def test_client_interceptor_trace_context_propagation(self):
"""ensure that client interceptor correctly inject trace context into all outgoing requests."""

Expand Down Expand Up @@ -347,7 +338,7 @@ async def test_stream_unary_with_suppress_key(self):
finally:
context.detach(token)

async def test_stream_unary_with_suppress_key(self):
async def test_stream_stream_with_suppress_key(self):
token = context.attach(
context.set_value(_SUPPRESS_INSTRUMENTATION_KEY, True)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,32 @@
# 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.

# pylint:disable=unused-argument
# pylint:disable=no-self-use
import pytest
import asyncio
from unittest import IsolatedAsyncioTestCase

import asyncio
import grpc
import grpc.aio
from concurrent.futures.thread import ThreadPoolExecutor
import pytest

from time import sleep
from opentelemetry.test.test_base import TestBase
from opentelemetry import trace
import opentelemetry.instrumentation.grpc
from opentelemetry.semconv.trace import SpanAttributes
from opentelemetry import trace
from opentelemetry.instrumentation.grpc import (
GrpcAioInstrumentorServer,
aio_server_interceptor,
)
from opentelemetry.sdk import trace as trace_sdk
from opentelemetry.semconv.trace import SpanAttributes
from opentelemetry.test.test_base import TestBase
from opentelemetry.trace import StatusCode

from .protobuf.test_server_pb2 import Request, Response
from .protobuf.test_server_pb2_grpc import (
GRPCTestServerServicer,
add_GRPCTestServerServicer_to_server,
)
from opentelemetry.instrumentation.grpc import (
GrpcAioInstrumentorServer,
aio_server_interceptor,
)

# pylint:disable=unused-argument
# pylint:disable=no-self-use


class Servicer(GRPCTestServerServicer):
Expand Down Expand Up @@ -351,6 +349,7 @@ async def test_span_lifetime(self):
class SpanLifetimeServicer(GRPCTestServerServicer):
# pylint:disable=C0103
async def SimpleMethod(self, request, context):
# pylint:disable=attribute-defined-outside-init
self.span = trace.get_current_span()

return Response(
Expand Down Expand Up @@ -394,7 +393,9 @@ async def sequential_requests(channel):
spans_list = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans_list), 2)

span1, span2 = spans_list
span1 = spans_list[0]
span2 = spans_list[1]

# Spans should belong to separate traces
self.assertNotEqual(span1.context.span_id, span2.context.span_id)
self.assertNotEqual(span1.context.trace_id, span2.context.trace_id)
Expand Down Expand Up @@ -453,7 +454,9 @@ async def concurrent_requests(channel):
spans_list = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans_list), 2)

span1, span2 = spans_list
span1 = spans_list[0]
span2 = spans_list[1]

# Spans should belong to separate traces
self.assertNotEqual(span1.context.span_id, span2.context.span_id)
self.assertNotEqual(span1.context.trace_id, span2.context.trace_id)
Expand Down Expand Up @@ -501,9 +504,6 @@ async def request(channel):
await run_with_test_server(request, servicer=AbortServicer())

spans_list = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans_list), 1)
child_span = spans_list[0]

self.assertEqual(len(spans_list), 1)
span = spans_list[0]

Expand Down

0 comments on commit a955218

Please sign in to comment.