Skip to content

Commit

Permalink
Upgrade black (#802)
Browse files Browse the repository at this point in the history
  • Loading branch information
owais authored Nov 10, 2021
1 parent f4d09f9 commit 3137c1f
Show file tree
Hide file tree
Showing 70 changed files with 352 additions and 147 deletions.
1 change: 0 additions & 1 deletion .python-version

This file was deleted.

2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pylint<2.10
flake8~=3.7
isort~=5.6
black>=19.3b0,==19.*
black>=21.10b0
httpretty~=1.0
mypy==0.790
sphinx
Expand Down
14 changes: 12 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,22 @@ def getlistcfg(strval):
if "class_references" in mcfg:
class_references = getlistcfg(mcfg["class_references"])
for class_reference in class_references:
nitpick_ignore.append(("py:class", class_reference,))
nitpick_ignore.append(
(
"py:class",
class_reference,
)
)

if "anys" in mcfg:
anys = getlistcfg(mcfg["anys"])
for _any in anys:
nitpick_ignore.append(("any", _any,))
nitpick_ignore.append(
(
"any",
_any,
)
)

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ def inject(
return
sampled = (trace.TraceFlags.SAMPLED & span.context.trace_flags) != 0
setter.set(
carrier, self.TRACE_ID_KEY, format_trace_id(span.context.trace_id),
carrier,
self.TRACE_ID_KEY,
format_trace_id(span.context.trace_id),
)
setter.set(
carrier, self.PARENT_ID_KEY, format_span_id(span.context.span_id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ def test_constructor_explicit(self):
"""Test the constructor passing all the options."""
agent_url = "http://localhost:8126"
exporter = datadog.DatadogSpanExporter(
agent_url=agent_url, service="explicit",
agent_url=agent_url,
service="explicit",
)

self.assertEqual(exporter.agent_url, agent_url)
Expand Down Expand Up @@ -472,7 +473,8 @@ def test_span_processor_dropped_spans(self):
tracer_provider.shutdown()

@mark.skipif(
sys.platform == "win32", reason="unreliable test on windows",
sys.platform == "win32",
reason="unreliable test on windows",
)
def test_span_processor_scheduled_delay(self):
"""Test that spans are exported each schedule_delay_millis"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ class RichConsoleSpanExporter(SpanExporter):
"""

def __init__(
self, service_name: Optional[str] = None,
self,
service_name: Optional[str] = None,
):
self.service_name = service_name
self.console = Console()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ async def on_request_start(
request_span_name = f"HTTP {http_method}"

trace_config_ctx.span = trace_config_ctx.tracer.start_span(
request_span_name, kind=SpanKind.CLIENT,
request_span_name,
kind=SpanKind.CLIENT,
)

if callable(request_hook):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ def test_status_codes(self):
(HTTPStatus.OK, StatusCode.UNSET),
(HTTPStatus.TEMPORARY_REDIRECT, StatusCode.UNSET),
(HTTPStatus.SERVICE_UNAVAILABLE, StatusCode.ERROR),
(HTTPStatus.GATEWAY_TIMEOUT, StatusCode.ERROR,),
(
HTTPStatus.GATEWAY_TIMEOUT,
StatusCode.ERROR,
),
):
with self.subTest(status_code=status_code):
host, port = self._http_request(
Expand Down Expand Up @@ -178,7 +181,8 @@ def response_hook(

host, port = self._http_request(
trace_config=aiohttp_client.create_trace_config(
request_hook=request_hook, response_hook=response_hook,
request_hook=request_hook,
response_hook=response_hook,
),
method=method,
url=path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def _instrument(self, **kwargs):

# pylint:disable=no-self-use
def _uninstrument(self, **kwargs):
""""Disable aiopg instrumentation"""
""" "Disable aiopg instrumentation"""
wrappers.unwrap_connect()
wrappers.unwrap_create_pool()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@ async def __call__(self, scope, receive, send):

try:
with self.tracer.start_as_current_span(
span_name, kind=trace.SpanKind.SERVER,
span_name,
kind=trace.SpanKind.SERVER,
) as span:
if span.is_recording():
attributes = collect_request_attributes(scope)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,15 @@ def _determine_parent_context(
) -> Context:
"""Determine the parent context for the current Lambda invocation.
See more:
https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/instrumentation/aws-lambda.md#determining-the-parent-of-a-span
See more:
https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/instrumentation/aws-lambda.md#determining-the-parent-of-a-span
Args:
lambda_event: user-defined, so it could be anything, but this
method counts it being a map with a 'headers' key
Returns:
A Context with configuration found in the carrier.
"""
Args:
lambda_event: user-defined, so it could be anything, but this
method counts it being a map with a 'headers' key
Returns:
A Context with configuration found in the carrier.
"""
parent_context = None

xray_env_var = os.environ.get(_X_AMZN_TRACE_ID)
Expand Down Expand Up @@ -194,7 +194,9 @@ def _instrumented_lambda_handler_call(
tracer = get_tracer(__name__, __version__, tracer_provider)

with tracer.start_as_current_span(
name=orig_handler_name, context=parent_context, kind=span_kind,
name=orig_handler_name,
context=parent_context,
kind=span_kind,
) as span:
if span.is_recording():
lambda_context = args[1]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ class TestAwsLambdaInstrumentor(TestBase):
def setUp(self):
super().setUp()
self.common_env_patch = mock.patch.dict(
"os.environ", {_HANDLER: "mocks.lambda_function.handler"},
"os.environ",
{_HANDLER: "mocks.lambda_function.handler"},
)
self.common_env_patch.start()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ def _common_request( # pylint: disable=too-many-locals
endpoint_name = getattr(instance, "host").split(".")[0]

with self._tracer.start_as_current_span(
f"{endpoint_name}.command", kind=SpanKind.CONSUMER,
f"{endpoint_name}.command",
kind=SpanKind.CONSUMER,
) as span:
span.set_attribute("endpoint", endpoint_name)
if args:
Expand All @@ -135,7 +136,11 @@ def _common_request( # pylint: disable=too-many-locals

if span.is_recording():
add_span_arg_tags(
span, endpoint_name, args, args_name, traced_args,
span,
endpoint_name,
args,
args_name,
traced_args,
)

# Obtaining region name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ def assert_only_span(self):
return spans[0]

def assert_span(
self, service: str, operation: str, request_id=None, attributes=None,
self,
service: str,
operation: str,
request_id=None,
attributes=None,
):
span = self.assert_only_span()
expected = self._default_span_attributes(service, operation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ def _instrument(self, **kwargs):

tracer_provider = kwargs.get("tracer_provider")
tracer = get_tracer(
__name__, __version__, tracer_provider=tracer_provider,
__name__,
__version__,
tracer_provider=tracer_provider,
)

_DjangoMiddleware._tracer = tracer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,19 +356,23 @@ async def test_trace_parent(self):
traceparent_value = f"00-{trace_id}-{span_id}-01"

Client().get(
"/span_name/1234/", traceparent=traceparent_value,
"/span_name/1234/",
traceparent=traceparent_value,
)
span = self.memory_exporter.get_finished_spans()[0]

self.assertEqual(
trace_id, format_trace_id(span.get_span_context().trace_id),
trace_id,
format_trace_id(span.get_span_context().trace_id),
)
self.assertIsNotNone(span.parent)
self.assertEqual(
trace_id, format_trace_id(span.parent.trace_id),
trace_id,
format_trace_id(span.parent.trace_id),
)
self.assertEqual(
span_id, format_span_id(span.parent.span_id),
span_id,
format_span_id(span.parent.span_id),
)
self.memory_exporter.clear()

Expand All @@ -382,7 +386,8 @@ def test_trace_response_headers(self):

response = Client().get("/span_name/1234/")
self.assertTraceResponseHeaderMatchesSpan(
response, self.memory_exporter.get_finished_spans()[0],
response,
self.memory_exporter.get_finished_spans()[0],
)
self.memory_exporter.clear()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,19 +330,23 @@ async def test_trace_parent(self):
traceparent_value = f"00-{trace_id}-{span_id}-01"

await self.async_client.get(
"/span_name/1234/", traceparent=traceparent_value,
"/span_name/1234/",
traceparent=traceparent_value,
)
span = self.memory_exporter.get_finished_spans()[0]

self.assertEqual(
trace_id, format_trace_id(span.get_span_context().trace_id),
trace_id,
format_trace_id(span.get_span_context().trace_id),
)
self.assertIsNotNone(span.parent)
self.assertEqual(
trace_id, format_trace_id(span.parent.trace_id),
trace_id,
format_trace_id(span.parent.trace_id),
)
self.assertEqual(
span_id, format_span_id(span.parent.span_id),
span_id,
format_span_id(span.parent.span_id),
)
self.memory_exporter.clear()

Expand All @@ -359,7 +363,8 @@ async def test_trace_response_headers(self):

self.assertTrue(response.has_header("traceresponse"))
self.assertEqual(
response["Access-Control-Expose-Headers"], "traceresponse",
response["Access-Control-Expose-Headers"],
"traceresponse",
)
self.assertEqual(
response["traceresponse"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ class ElasticsearchInstrumentor(BaseInstrumentor):
def __init__(self, span_name_prefix=None):
if not span_name_prefix:
span_name_prefix = environ.get(
"OTEL_PYTHON_ELASTICSEARCH_NAME_PREFIX", "Elasticsearch",
"OTEL_PYTHON_ELASTICSEARCH_NAME_PREFIX",
"Elasticsearch",
)
self._span_name_prefix = span_name_prefix.strip()
super().__init__()
Expand Down Expand Up @@ -187,7 +188,8 @@ def wrapper(wrapped, _, args, kwargs):
body = kwargs.get("body", None)

with tracer.start_as_current_span(
op_name, kind=SpanKind.CLIENT,
op_name,
kind=SpanKind.CLIENT,
) as span:

if callable(request_hook):
Expand Down Expand Up @@ -215,7 +217,8 @@ def wrapper(wrapped, _, args, kwargs):
for member in _ATTRIBUTES_FROM_RESULT:
if member in rv:
span.set_attribute(
f"elasticsearch.{member}", str(rv[member]),
f"elasticsearch.{member}",
str(rv[member]),
)

if callable(response_hook):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ def _start_response(status, response_headers, *args, **kwargs):
return super().__call__(env, _start_response)
except Exception as exc:
activation.__exit__(
type(exc), exc, getattr(exc, "__traceback__", None),
type(exc),
exc,
getattr(exc, "__traceback__", None),
)
context.detach(token)
raise
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ def _test_method(self, method):
self.assertEqual(span.name, f"HelloWorldResource.on_{method.lower()}")
self.assertEqual(span.status.status_code, StatusCode.UNSET)
self.assertEqual(
span.status.description, None,
span.status.description,
None,
)
self.assertSpanHasAttributes(
span,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ def _create_app_explicit_excluded_urls(self):
to_exclude = "/user/123,/foobar"
self._instrumentor.uninstrument() # Disable previous instrumentation (setUp)
self._instrumentor.instrument(
tracer_provider=tracer_provider, excluded_urls=to_exclude,
tracer_provider=tracer_provider,
excluded_urls=to_exclude,
)
return self._create_fastapi_app()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,9 @@ def instrument_app(
tracer = trace.get_tracer(__name__, __version__, tracer_provider)

_before_request = _wrapped_before_request(
request_hook, tracer, excluded_urls=excluded_urls,
request_hook,
tracer,
excluded_urls=excluded_urls,
)
app._before_request = _before_request
app.before_request(_before_request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ def test_trace_response(self):
self.assertEqual(len(span_list), 1)

self.assertTraceResponseHeaderMatchesSpan(
response.headers, span_list[0],
response.headers,
span_list[0],
)

set_global_response_propagator(orig)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ def instrumentation_dependencies(self) -> Collection[str]:
def _instrument(self, **kwargs):
for ctype in self._which_channel(kwargs):
_wrap(
"grpc", ctype, self.wrapper_fn,
"grpc",
ctype,
self.wrapper_fn,
)

def _uninstrument(self, **kwargs):
Expand All @@ -217,7 +219,8 @@ def wrapper_fn(self, original_func, instance, args, kwargs):
channel = original_func(*args, **kwargs)
tracer_provider = kwargs.get("tracer_provider")
return intercept_channel(
channel, client_interceptor(tracer_provider=tracer_provider),
channel,
client_interceptor(tracer_provider=tracer_provider),
)


Expand Down
Loading

0 comments on commit 3137c1f

Please sign in to comment.