Skip to content
Open
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
10 changes: 5 additions & 5 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,11 @@
scm_web = "https://github.com/" + REPO + "blob/" + branch

# Store variables in the epilogue so they are globally available.
rst_epilog = """
.. |SCM_WEB| replace:: {s}
.. |SCM_RAW_WEB| replace:: {sr}
.. |SCM_BRANCH| replace:: {b}
""".format(s=scm_web, sr=scm_raw_web, b=branch)
rst_epilog = f"""
.. |SCM_WEB| replace:: {scm_web}
.. |SCM_RAW_WEB| replace:: {scm_raw_web}
.. |SCM_BRANCH| replace:: {branch}
"""

# used to have links to repo files
extlinks = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def _get_resource_data(
resource_class(
**{
"resource": collector_resource,
"scope_{}".format(name): scope_data.values(),
f"scope_{name}": scope_data.values(),
}
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,7 @@
class InvalidCompressionValueException(Exception):
def __init__(self, environ_key: str, environ_value: str):
super().__init__(
'Invalid value "{}" for compression envvar {}'.format(
environ_value, environ_key
)
f'Invalid value "{environ_value}" for compression envvar {environ_key}'
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def __init__(
observed_timestamp: Optional[int] = None,
trace_id: Optional[int] = None,
span_id: Optional[int] = None,
trace_flags: Optional["TraceFlags"] = None,
trace_flags: Optional[TraceFlags] = None,
severity_text: Optional[str] = None,
severity_number: Optional[SeverityNumber] = None,
body: AnyValue = None,
Expand All @@ -104,7 +104,7 @@ def __init__(
context: Optional[Context] = None,
trace_id: Optional[int] = None,
span_id: Optional[int] = None,
trace_flags: Optional["TraceFlags"] = None,
trace_flags: Optional[TraceFlags] = None,
severity_text: Optional[str] = None,
severity_number: Optional[SeverityNumber] = None,
body: AnyValue = None,
Expand Down Expand Up @@ -430,7 +430,7 @@ def get_logger(
logger_provider: Optional[LoggerProvider] = None,
schema_url: Optional[str] = None,
attributes: Optional[_ExtendedAttributes] = None,
) -> "Logger":
) -> Logger:
"""Returns a `Logger` for use within a python process.

This function is a convenience wrapper for
Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-api/src/opentelemetry/context/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def create_key(keyname: str) -> str:
return keyname + "-" + str(uuid4())


def get_value(key: str, context: typing.Optional[Context] = None) -> "object":
def get_value(key: str, context: typing.Optional[Context] = None) -> object:
"""To access the local state of a concern, the RuntimeContext API
provides a function which takes a context and a key as input,
and returns a value.
Expand All @@ -98,7 +98,7 @@ def get_value(key: str, context: typing.Optional[Context] = None) -> "object":


def set_value(
key: str, value: "object", context: typing.Optional[Context] = None
key: str, value: object, context: typing.Optional[Context] = None
) -> Context:
"""To record the local state of a cross-cutting concern, the
RuntimeContext API provides a function which takes a context, a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,11 +539,11 @@ def _shutdown():

# pylint: disable=broad-exception-raised
raise Exception(
(

"MeterProvider.shutdown failed because the following "
"metric readers failed during shutdown:\n"
f"{metric_reader_error_string}"
)

)

def get_meter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def __init__(
preferred_temporality: dict[type, AggregationTemporality]
| None = None,
preferred_aggregation: dict[
type, "opentelemetry.sdk.metrics.view.Aggregation"
type, opentelemetry.sdk.metrics.view.Aggregation
]
| None = None,
) -> None:
Expand Down Expand Up @@ -150,7 +150,7 @@ def __init__(
preferred_temporality: dict[type, AggregationTemporality]
| None = None,
preferred_aggregation: dict[
type, "opentelemetry.sdk.metrics.view.Aggregation"
type, opentelemetry.sdk.metrics.view.Aggregation
]
| None = None,
):
Expand Down Expand Up @@ -217,16 +217,16 @@ def __init__(
preferred_temporality: dict[type, AggregationTemporality]
| None = None,
preferred_aggregation: dict[
type, "opentelemetry.sdk.metrics.view.Aggregation"
type, opentelemetry.sdk.metrics.view.Aggregation
]
| None = None,
) -> None:
self._collect: Callable[
[
"opentelemetry.sdk.metrics.export.MetricReader",
opentelemetry.sdk.metrics.export.MetricReader,
AggregationTemporality,
],
Iterable["opentelemetry.sdk.metrics.export.Metric"],
Iterable[opentelemetry.sdk.metrics.export.Metric],
] = None

self._instrument_class_temporality = {
Expand Down Expand Up @@ -350,10 +350,10 @@ def _set_collect_callback(
self,
func: Callable[
[
"opentelemetry.sdk.metrics.export.MetricReader",
opentelemetry.sdk.metrics.export.MetricReader,
AggregationTemporality,
],
Iterable["opentelemetry.sdk.metrics.export.Metric"],
Iterable[opentelemetry.sdk.metrics.export.Metric],
],
) -> None:
"""This function is internal to the SDK. It should not be called or overridden by users"""
Expand Down Expand Up @@ -397,7 +397,7 @@ def __init__(
preferred_temporality: dict[type, AggregationTemporality]
| None = None,
preferred_aggregation: dict[
type, "opentelemetry.sdk.metrics.view.Aggregation"
type, opentelemetry.sdk.metrics.view.Aggregation
]
| None = None,
) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __init__(
self,
name: str,
instrumentation_scope: InstrumentationScope,
measurement_consumer: "opentelemetry.sdk.metrics.MeasurementConsumer",
measurement_consumer: opentelemetry.sdk.metrics.MeasurementConsumer,
unit: str = "",
description: str = "",
):
Expand Down Expand Up @@ -84,7 +84,7 @@ def __init__(
self,
name: str,
instrumentation_scope: InstrumentationScope,
measurement_consumer: "opentelemetry.sdk.metrics.MeasurementConsumer",
measurement_consumer: opentelemetry.sdk.metrics.MeasurementConsumer,
callbacks: Iterable[CallbackT] | None = None,
unit: str = "",
description: str = "",
Expand Down Expand Up @@ -227,7 +227,7 @@ def __init__(
self,
name: str,
instrumentation_scope: InstrumentationScope,
measurement_consumer: "opentelemetry.sdk.metrics.MeasurementConsumer",
measurement_consumer: opentelemetry.sdk.metrics.MeasurementConsumer,
unit: str = "",
description: str = "",
explicit_bucket_boundaries_advisory: Sequence[float] | None = None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __init__(
self._sdk_config = sdk_config
# should never be mutated
self._reader_storages: Mapping[
"opentelemetry.sdk.metrics.MetricReader", MetricReaderStorage
opentelemetry.sdk.metrics.MetricReader, MetricReaderStorage
] = {
reader: MetricReaderStorage(
sdk_config,
Expand All @@ -74,7 +74,7 @@ def __init__(
for reader in sdk_config.metric_readers
}
self._async_instruments: List[
"opentelemetry.sdk.metrics._internal.instrument._Asynchronous"
opentelemetry.sdk.metrics._internal.instrument._Asynchronous
] = []

def consume_measurement(self, measurement: Measurement) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ class OtelTraceState:
rest: Sequence[str]

@staticmethod
def invalid() -> "OtelTraceState":
def invalid() -> OtelTraceState:
return OtelTraceState(INVALID_RANDOM_VALUE, INVALID_THRESHOLD, ())

@staticmethod
def parse(trace_state: TraceState | None) -> "OtelTraceState":
def parse(trace_state: TraceState | None) -> OtelTraceState:
if not trace_state:
return OtelTraceState.invalid()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class SpanExporter:

def export(
self, spans: typing.Sequence[ReadableSpan]
) -> "SpanExportResult": # pyright: ignore[reportReturnType]
) -> SpanExportResult: # pyright: ignore[reportReturnType]
"""Exports a batch of telemetry data.

Args:
Expand Down
8 changes: 4 additions & 4 deletions opentelemetry-sdk/tests/test_configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,14 @@ def get_description(self) -> str:

def should_sample(
self,
parent_context: Optional["Context"],
parent_context: Optional[Context],
trace_id: int,
name: str,
kind: SpanKind = None,
attributes: Attributes = None,
links: Sequence[Link] = None,
trace_state: TraceState = None,
) -> "SamplingResult":
) -> SamplingResult:
return SamplingResult(
Decision.RECORD_AND_SAMPLE,
None,
Expand All @@ -290,14 +290,14 @@ def get_description(self) -> str:

def should_sample(
self,
parent_context: "Context" | None,
parent_context: Context | None,
trace_id: int,
name: str,
kind: SpanKind | None = None,
attributes: Attributes = None,
links: Sequence[Link] | None = None,
trace_state: TraceState | None = None,
) -> "SamplingResult":
) -> SamplingResult:
return SamplingResult(
Decision.RECORD_AND_SAMPLE,
None,
Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ select = [
"PLE", # pylint error
"Q", # flake8-quotes
"G", # https://docs.astral.sh/ruff/rules/#flake8-logging-format-g
"UP011", # lru-cache-without-parameters
"UP015", # redundant-open-modes
"UP032", # f-string
"UP034", # extraneous-parentheses
"UP037", # quoted-annotation
]

ignore = [
Expand Down
2 changes: 1 addition & 1 deletion scripts/update_sha.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def update_sha(sha):
yaml = YAML()
yaml.preserve_quotes = True
for workflow_file in workflow_files:
with open(workflow_file, "r") as file:
with open(workflow_file) as file:
workflow = yaml.load(file)
workflow["env"]["CONTRIB_REPO_SHA"] = sha
with open(workflow_file, "w") as file:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def install_shim(
tracer_provider=tracer_provider,
)

@lru_cache()
@lru_cache
def cached_shim_tracer(span_context: SpanContext) -> ShimTracer:
return ShimTracer(
NoopTracer(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
_SHIM_KEY = create_key("scope_shim")


def create_tracer(otel_tracer_provider: TracerProvider) -> "TracerShim":
def create_tracer(otel_tracer_provider: TracerProvider) -> TracerShim:
"""Creates a :class:`TracerShim` object from the provided OpenTelemetry
:class:`opentelemetry.trace.TracerProvider`.

Expand Down Expand Up @@ -206,7 +206,7 @@ def unwrap(self):

return self._otel_span

def set_operation_name(self, operation_name: str) -> "SpanShim":
def set_operation_name(self, operation_name: str) -> SpanShim:
"""Updates the name of the wrapped OpenTelemetry span.

Args:
Expand Down Expand Up @@ -241,7 +241,7 @@ def finish(self, finish_time: float | None = None):
end_time = util.time_seconds_to_ns(finish_time)
self._otel_span.end(end_time=end_time)

def set_tag(self, key: str, value: ValueT) -> "SpanShim":
def set_tag(self, key: str, value: ValueT) -> SpanShim:
"""Sets an OpenTelemetry attribute on the wrapped OpenTelemetry span.

Args:
Expand All @@ -257,7 +257,7 @@ def set_tag(self, key: str, value: ValueT) -> "SpanShim":

def log_kv(
self, key_values: Attributes, timestamp: float | None = None
) -> "SpanShim":
) -> SpanShim:
"""Logs an event for the wrapped OpenTelemetry span.

Note:
Expand Down Expand Up @@ -356,7 +356,7 @@ class ScopeShim(Scope):
"""

def __init__(
self, manager: "ScopeManagerShim", span: SpanShim, span_cm=None
self, manager: ScopeManagerShim, span: SpanShim, span_cm=None
):
super().__init__(manager, span)
self._span_cm = span_cm
Expand All @@ -365,7 +365,7 @@ def __init__(
# TODO: Change type of `manager` argument to `opentracing.ScopeManager`? We
# need to get rid of `manager.tracer` for this.
@classmethod
def from_context_manager(cls, manager: "ScopeManagerShim", span_cm):
def from_context_manager(cls, manager: ScopeManagerShim, span_cm):
"""Constructs a :class:`ScopeShim` from an OpenTelemetry
`opentelemetry.trace.Span` context
manager.
Expand Down Expand Up @@ -452,14 +452,14 @@ class ScopeManagerShim(ScopeManager):
span state.
"""

def __init__(self, tracer: "TracerShim"):
def __init__(self, tracer: TracerShim):
# The only thing the ``__init__()``` method on the base class does is
# initialize `self._noop_span` and `self._noop_scope` with no-op
# objects. Therefore, it doesn't seem useful to call it.
# pylint: disable=super-init-not-called
self._tracer = tracer

def activate(self, span: SpanShim, finish_on_close: bool) -> "ScopeShim":
def activate(self, span: SpanShim, finish_on_close: bool) -> ScopeShim:
"""Activates a :class:`SpanShim` and returns a :class:`ScopeShim` which
represents the active span.

Expand All @@ -477,7 +477,7 @@ def activate(self, span: SpanShim, finish_on_close: bool) -> "ScopeShim":
return ScopeShim.from_context_manager(self, span_cm=span_cm)

@property
def active(self) -> "ScopeShim":
def active(self) -> ScopeShim:
"""Returns a :class:`ScopeShim` object representing the
currently-active span in the OpenTelemetry tracer.

Expand Down Expand Up @@ -505,7 +505,7 @@ def active(self) -> "ScopeShim":
return ScopeShim(self, span=wrapped_span)

@property
def tracer(self) -> "TracerShim":
def tracer(self) -> TracerShim:
"""Returns the :class:`TracerShim` reference used by this
:class:`ScopeManagerShim` for setting and getting the active span from
the OpenTelemetry tracer.
Expand Down Expand Up @@ -567,7 +567,7 @@ def start_active_span(
start_time: float | None = None,
ignore_active_span: bool = False,
finish_on_close: bool = True,
) -> "ScopeShim":
) -> ScopeShim:
"""Starts and activates a span. In terms of functionality, this method
behaves exactly like the same method on a "regular" OpenTracing tracer.
See :meth:`opentracing.Tracer.start_active_span` for more details.
Expand Down