Skip to content

Commit

Permalink
Use ruff instead of black/isort for autoformatting
Browse files Browse the repository at this point in the history
  • Loading branch information
aabmass committed Mar 28, 2024
1 parent bb89e0a commit 91e8019
Show file tree
Hide file tree
Showing 123 changed files with 363 additions and 663 deletions.
19 changes: 0 additions & 19 deletions .isort.cfg

This file was deleted.

3 changes: 1 addition & 2 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
pylint==3.0.2
flake8==6.1.0
isort==5.12.0
black==22.3.0
httpretty==1.1.4
mypy==0.982
sphinx==7.1.2
Expand All @@ -19,3 +17,4 @@ asgiref==3.7.2
psutil==5.9.6
GitPython==3.1.41
flaky==3.7.0
ruff==0.3.4
4 changes: 1 addition & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,7 @@
.. |SCM_WEB| replace:: {s}
.. |SCM_RAW_WEB| replace:: {sr}
.. |SCM_BRANCH| replace:: {b}
""".format(
s=scm_web, sr=scm_raw_web, b=branch
)
""".format(s=scm_web, sr=scm_raw_web, b=branch)

# used to have links to repo files
extlinks = {
Expand Down
1 change: 0 additions & 1 deletion docs/examples/auto-instrumentation/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
assert len(argv) == 2

with tracer.start_as_current_span("client"):

with tracer.start_as_current_span("client-server"):
headers = {}
inject(headers)
Expand Down
1 change: 0 additions & 1 deletion docs/examples/django/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@


with tracer.start_as_current_span("client"):

with tracer.start_as_current_span("client-server"):
headers = {}
inject(headers)
Expand Down
1 change: 1 addition & 0 deletions docs/examples/django/instrumentation_example/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path("blog/", include("blog.urls"))
"""

from django.contrib import admin
from django.urls import include, path

Expand Down
1 change: 1 addition & 0 deletions docs/examples/django/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.

"""Django"s command-line utility for administrative tasks."""

import os
import sys

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@

class ErrorHandler0(ErrorHandler, ZeroDivisionError):
def _handle(self, error: Exception, *args, **kwargs):

logger.exception("ErrorHandler0 handling a ZeroDivisionError")
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
# pylint: disable=too-many-ancestors
class ErrorHandler1(ErrorHandler, IndexError, KeyError):
def _handle(self, error: Exception, *args, **kwargs):

if isinstance(error, IndexError):
logger.exception("ErrorHandler1 handling an IndexError")

Expand Down
1 change: 0 additions & 1 deletion docs/examples/opentracing/rediscache.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def __call__(self, func):
@wraps(func)
def inner(*args, **kwargs):
with self.tracer.start_active_span("Caching decorator") as scope1:

# Pickle the call args to get a canonical key. Don't do this in
# prod!
key = pickle.dumps((func.__qualname__, args, kwargs))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,24 +133,23 @@ def translate_to_collector(spans: Sequence[ReadableSpan]):
collector_span.parent_span_id = parent_id.to_bytes(8, "big")

if span.context.trace_state is not None:
for (key, value) in span.context.trace_state.items():
for key, value in span.context.trace_state.items():
collector_span.tracestate.entries.add(key=key, value=value)

if span.attributes:
for (key, value) in span.attributes.items():
for key, value in span.attributes.items():
utils.add_proto_attribute_value(
collector_span.attributes, key, value
)

if span.events:
for event in span.events:

collector_annotation = trace_pb2.Span.TimeEvent.Annotation(
description=trace_pb2.TruncatableString(value=event.name)
)

if event.attributes:
for (key, value) in event.attributes.items():
for key, value in event.attributes.items():
utils.add_proto_attribute_value(
collector_annotation.attributes, key, value
)
Expand Down Expand Up @@ -183,7 +182,7 @@ def translate_to_collector(spans: Sequence[ReadableSpan]):
)

if link.attributes:
for (key, value) in link.attributes.items():
for key, value in link.attributes.items():
utils.add_proto_attribute_value(
collector_span_link.attributes, key, value
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,31 @@
from itertools import count
from typing import (
Any,
Mapping,
Optional,
List,
Callable,
TypeVar,
Dict,
Iterator,
List,
Mapping,
Optional,
TypeVar,
)

from opentelemetry.sdk.util.instrumentation import InstrumentationScope
from opentelemetry.proto.common.v1.common_pb2 import AnyValue as PB2AnyValue
from opentelemetry.proto.common.v1.common_pb2 import (
InstrumentationScope as PB2InstrumentationScope,
ArrayValue as PB2ArrayValue,
)
from opentelemetry.proto.resource.v1.resource_pb2 import (
Resource as PB2Resource,
from opentelemetry.proto.common.v1.common_pb2 import (
InstrumentationScope as PB2InstrumentationScope,
)
from opentelemetry.proto.common.v1.common_pb2 import AnyValue as PB2AnyValue
from opentelemetry.proto.common.v1.common_pb2 import KeyValue as PB2KeyValue
from opentelemetry.proto.common.v1.common_pb2 import (
KeyValueList as PB2KeyValueList,
)
from opentelemetry.proto.common.v1.common_pb2 import (
ArrayValue as PB2ArrayValue,
from opentelemetry.proto.resource.v1.resource_pb2 import (
Resource as PB2Resource,
)
from opentelemetry.sdk.trace import Resource
from opentelemetry.sdk.util.instrumentation import InstrumentationScope
from opentelemetry.util.types import Attributes

_logger = logging.getLogger(__name__)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,24 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from collections import defaultdict
from typing import Sequence, List
from typing import List, Sequence

from opentelemetry.exporter.otlp.proto.common._internal import (
_encode_attributes,
_encode_instrumentation_scope,
_encode_resource,
_encode_span_id,
_encode_trace_id,
_encode_value,
_encode_attributes,
)
from opentelemetry.proto.collector.logs.v1.logs_service_pb2 import (
ExportLogsServiceRequest,
)
from opentelemetry.proto.logs.v1.logs_pb2 import LogRecord as PB2LogRecord
from opentelemetry.proto.logs.v1.logs_pb2 import (
ScopeLogs,
ResourceLogs,
ScopeLogs,
)
from opentelemetry.proto.logs.v1.logs_pb2 import LogRecord as PB2LogRecord

from opentelemetry.sdk._logs import LogData


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

from opentelemetry.sdk.metrics.export import (
MetricExporter,
from opentelemetry.exporter.otlp.proto.common._internal import (
_encode_attributes,
)
from opentelemetry.proto.collector.metrics.v1.metrics_service_pb2 import (
ExportMetricsServiceRequest,
)
from opentelemetry.proto.common.v1.common_pb2 import InstrumentationScope
from opentelemetry.proto.metrics.v1 import metrics_pb2 as pb2
from opentelemetry.proto.resource.v1.resource_pb2 import (
Resource as PB2Resource,
)
from opentelemetry.sdk.environment_variables import (
OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION,
OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE,
)
from opentelemetry.sdk.metrics.view import Aggregation
from os import environ
from opentelemetry.sdk.metrics import (
Counter,
Histogram,
Expand All @@ -26,37 +38,23 @@
ObservableUpDownCounter,
UpDownCounter,
)
from opentelemetry.exporter.otlp.proto.common._internal import (
_encode_attributes,
)
from opentelemetry.sdk.environment_variables import (
OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE,
)
from opentelemetry.sdk.metrics.export import (
AggregationTemporality,
)
from opentelemetry.proto.collector.metrics.v1.metrics_service_pb2 import (
ExportMetricsServiceRequest,
)
from opentelemetry.proto.common.v1.common_pb2 import InstrumentationScope
from opentelemetry.proto.metrics.v1 import metrics_pb2 as pb2
from opentelemetry.sdk.metrics.export import (
MetricsData,
Gauge,
Histogram as HistogramType,
MetricExporter,
MetricsData,
Sum,
ExponentialHistogram as ExponentialHistogramType,
)
from typing import Dict
from opentelemetry.proto.resource.v1.resource_pb2 import (
Resource as PB2Resource,
from opentelemetry.sdk.metrics.export import (
ExponentialHistogram as ExponentialHistogramType,
)
from opentelemetry.sdk.environment_variables import (
OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION,
from opentelemetry.sdk.metrics.export import (
Histogram as HistogramType,
)
from opentelemetry.sdk.metrics.view import (
ExponentialBucketHistogramAggregation,
Aggregation,
ExplicitBucketHistogramAggregation,
ExponentialBucketHistogramAggregation,
)

_logger = logging.getLogger(__name__)
Expand All @@ -68,7 +66,6 @@ def _common_configuration(
preferred_temporality: Dict[type, AggregationTemporality] = None,
preferred_aggregation: Dict[type, Aggregation] = None,
) -> None:

MetricExporter.__init__(
self,
preferred_temporality=self._get_temporality(preferred_temporality),
Expand All @@ -78,7 +75,6 @@ def _common_configuration(
def _get_temporality(
self, preferred_temporality: Dict[type, AggregationTemporality]
) -> Dict[type, AggregationTemporality]:

otel_exporter_otlp_metrics_temporality_preference = (
environ.get(
OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE,
Expand Down Expand Up @@ -135,7 +131,6 @@ def _get_aggregation(
self,
preferred_aggregation: Dict[type, Aggregation],
) -> Dict[type, Aggregation]:

otel_exporter_otlp_metrics_default_histogram_aggregation = environ.get(
OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION,
"explicit_bucket_histogram",
Expand All @@ -144,17 +139,14 @@ def _get_aggregation(
if otel_exporter_otlp_metrics_default_histogram_aggregation == (
"base2_exponential_bucket_histogram"
):

instrument_class_aggregation = {
Histogram: ExponentialBucketHistogramAggregation(),
}

else:

if otel_exporter_otlp_metrics_default_histogram_aggregation != (
"explicit_bucket_histogram"
):

_logger.warning(
(
"Invalid value for %s: %s, using explicit bucket "
Expand All @@ -177,7 +169,6 @@ def encode_metrics(data: MetricsData) -> ExportMetricsServiceRequest:
resource_metrics_dict = {}

for resource_metrics in data.resource_metrics:

resource = resource_metrics.resource

# It is safe to assume that each entry in data.resource_metrics is
Expand All @@ -187,7 +178,6 @@ def encode_metrics(data: MetricsData) -> ExportMetricsServiceRequest:
resource_metrics_dict[resource] = scope_metrics_dict

for scope_metrics in resource_metrics.scope_metrics:

instrumentation_scope = scope_metrics.scope

# The SDK groups metrics in instrumentation scopes already so
Expand Down Expand Up @@ -271,7 +261,6 @@ def encode_metrics(data: MetricsData) -> ExportMetricsServiceRequest:

elif isinstance(metric.data, ExponentialHistogramType):
for data_point in metric.data.data_points:

if data_point.positive.bucket_counts:
positive = pb2.ExponentialHistogramDataPoint.Buckets(
offset=data_point.positive.offset,
Expand Down Expand Up @@ -306,9 +295,7 @@ def encode_metrics(data: MetricsData) -> ExportMetricsServiceRequest:
max=data_point.max,
min=data_point.min,
)
pb2_metric.exponential_histogram.aggregation_temporality = (
metric.data.aggregation_temporality
)
pb2_metric.exponential_histogram.aggregation_temporality = metric.data.aggregation_temporality
pb2_metric.exponential_histogram.data_points.append(pt)

else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,26 @@
from typing import List, Optional, Sequence

from opentelemetry.exporter.otlp.proto.common._internal import (
_encode_trace_id,
_encode_span_id,
_encode_instrumentation_scope,
_encode_attributes,
_encode_instrumentation_scope,
_encode_resource,
_encode_span_id,
_encode_trace_id,
)
from opentelemetry.proto.collector.trace.v1.trace_service_pb2 import (
ExportTraceServiceRequest as PB2ExportTraceServiceRequest,
)
from opentelemetry.proto.trace.v1.trace_pb2 import (
ScopeSpans as PB2ScopeSpans,
ResourceSpans as PB2ResourceSpans,
)
from opentelemetry.proto.trace.v1.trace_pb2 import (
ResourceSpans as PB2ResourceSpans,
ScopeSpans as PB2ScopeSpans,
)
from opentelemetry.proto.trace.v1.trace_pb2 import Span as PB2SPan
from opentelemetry.proto.trace.v1.trace_pb2 import Status as PB2Status
from opentelemetry.sdk.trace import Event, ReadableSpan
from opentelemetry.trace import Link
from opentelemetry.trace import SpanKind
from opentelemetry.trace.span import SpanContext, TraceState, Status
from opentelemetry.trace import Link, SpanKind
from opentelemetry.trace.span import SpanContext, Status, TraceState

# pylint: disable=E1101
_SPAN_KIND_MAP = {
Expand Down

0 comments on commit 91e8019

Please sign in to comment.