Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d6ebdae
Upgrade ruff
DylanRussell Jul 29, 2026
3ec55c3
Change ruff stuff
DylanRussell Jul 29, 2026
1fb84c1
Merge branch 'main' into upgrade_ruff
DylanRussell Jul 29, 2026
4fa2538
Upgrade ruff part 2
DylanRussell Jul 30, 2026
e2dc5af
Merge branch 'main' into upgrade_ruff2
DylanRussell Jul 30, 2026
d708f8e
Fix failing CI
DylanRussell Jul 30, 2026
4eb5008
Force exclude
DylanRussell Jul 30, 2026
0d3635a
Fix failing CI
DylanRussell Jul 30, 2026
eceda61
Address comments
DylanRussell Aug 3, 2026
7eda824
Merge upstream/main into upgrade_ruff2
DylanRussell Aug 3, 2026
600e38f
Change ruff
DylanRussell Aug 3, 2026
103f427
Add changelog fragment for PR #5491
DylanRussell Aug 3, 2026
f899e95
Update lock file
DylanRussell Aug 3, 2026
bc05d86
Add line length 120
DylanRussell Aug 5, 2026
a579bd2
Revert "Add line length 120"
DylanRussell Aug 6, 2026
9e1f0ff
Merge branch 'main' into upgrade_ruff2
DylanRussell Aug 6, 2026
7dcfb88
Upgrade uv to 0.12.2
DylanRussell Aug 6, 2026
8edf531
Merge commit '0110bb1d273dbe848312d429326b844da9e86d93' into upgrade_…
DylanRussell Aug 17, 2026
ca5bd35
chore: merge Ruff 120 reformat and format branch
DylanRussell Aug 17, 2026
1960c97
Merge remote-tracking branch 'upstream/main' into upgrade_ruff2
DylanRussell Aug 17, 2026
bf53d3d
Merge branch 'main' into upgrade_ruff2
DylanRussell Aug 20, 2026
06437b4
Merge branch 'main' into upgrade_ruff2
DylanRussell Aug 21, 2026
44409c7
Merge remote-tracking branch 'upstream/main' into upgrade_ruff2
DylanRussell Aug 27, 2026
4e4a96f
Revert rule changes
DylanRussell Aug 27, 2026
2921d95
Put stuff in extend-select
DylanRussell Aug 27, 2026
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
1 change: 1 addition & 0 deletions .changelog/5491.changed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`opentelemetry-python`: enable Ruff default ruleset and fix auto-fixable lint issues
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repos:
args: ["--preview"]
- repo: https://github.com/astral-sh/uv-pre-commit
# uv version.
rev: 0.6.0
rev: 0.12.2
hooks:
- id: uv-lock
args: ["--index-url", "https://pypi.org/simple"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,7 @@ def _get_module_path(self, proto_file: str) -> str:
Python module path (dot-separated)
"""
transformed = self._transform_proto_path(proto_file)
if transformed.endswith(".py"):
transformed = transformed[:-3]
transformed = transformed.removesuffix(".py")
return transformed.replace("/", ".")

def _generate_file(self, file_desc: descriptor.FileDescriptorProto) -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import math
import typing

from typing_extensions import Self

T = typing.TypeVar("T")
M = typing.TypeVar("M", bound="JsonMessage")

Expand Down Expand Up @@ -39,7 +41,7 @@ def to_json(self) -> str:
return json.dumps(self.to_dict())

@classmethod
def from_json(cls: type[M], data: str | bytes) -> M:
def from_json(cls, data: str | bytes) -> Self:
"""
Deserialize from a JSON string or bytes.
"""
Expand Down Expand Up @@ -173,7 +175,7 @@ def decode_int64(value: int | str | None, field_name: str) -> int:
raise ValueError(f"Invalid int64 value for field '{field_name}': {value}") from None


def decode_float(value: float | int | str | None, field_name: str) -> float:
def decode_float(value: float | str | None, field_name: str) -> float:
"""
Parse float/double from number or string, handling special values.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def test_encode_float(value: float, expected: float | str) -> None:
(None, 0.0),
],
)
def test_decode_float(value: float | int | str | None, expected: float) -> None:
def test_decode_float(value: float | str | None, expected: float) -> None:
result = decode_float(value, "field")
if math.isnan(expected):
assert math.isnan(result)
Expand Down
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ asgiref==3.7.2
psutil==7.2.2
GitPython==3.1.58
pre-commit==3.7.0
ruff==0.16.0
ruff==0.16.1
7 changes: 3 additions & 4 deletions docs/examples/opencensus-exporter-tracer/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
span_processor = BatchSpanProcessor(exporter)

trace.get_tracer_provider().add_span_processor(span_processor)
with tracer.start_as_current_span("foo"):
with tracer.start_as_current_span("bar"):
with tracer.start_as_current_span("baz"):
print("Hello world from OpenTelemetry Python!")
with tracer.start_as_current_span("foo"), tracer.start_as_current_span("bar"):
with tracer.start_as_current_span("baz"):
print("Hello world from OpenTelemetry Python!")
7 changes: 3 additions & 4 deletions docs/getting_started/tracing_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

tracer = trace.get_tracer(__name__)

with tracer.start_as_current_span("foo"):
with tracer.start_as_current_span("bar"):
with tracer.start_as_current_span("baz"):
print("Hello world from OpenTelemetry Python!")
with tracer.start_as_current_span("foo"), tracer.start_as_current_span("bar"):
with tracer.start_as_current_span("baz"):
print("Hello world from OpenTelemetry Python!")
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,13 @@ def test_export(self):
# pylint: disable=unsubscriptable-object
export_arg = mock_export.call_args[0]
service_request = next(export_arg[0])
output_spans = getattr(service_request, "spans")
output_node = getattr(service_request, "node")
output_spans = service_request.spans
output_node = service_request.node
self.assertEqual(len(output_spans), 1)
self.assertIsNotNone(getattr(output_node, "library_info"))
self.assertIsNotNone(getattr(output_node, "service_info"))
output_identifier = getattr(output_node, "identifier")
self.assertEqual(getattr(output_identifier, "host_name"), "testHostName")
self.assertIsNotNone(output_node.library_info)
self.assertIsNotNone(output_node.service_info)
output_identifier = output_node.identifier
self.assertEqual(output_identifier.host_name, "testHostName")

def test_export_service_name(self):
trace_api.set_tracer_provider(TracerProvider(resource=Resource.create({SERVICE_NAME: "testServiceName"})))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,14 @@ def test_temporality_lowmemory_env(self):
self.assertEqual(result[instrument_class], expected)

def test_temporality_invalid_env_logs_warning(self):
with patch.dict(
"os.environ",
{OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE: "INVALID"},
with (
patch.dict(
"os.environ",
{OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE: "INVALID"},
),
self.assertLogs(_AGGREGATION_LOGGER_NAME, level="WARNING"),
):
with self.assertLogs(_AGGREGATION_LOGGER_NAME, level="WARNING"):
result = _get_temporality(None)
result = _get_temporality(None)
self.assertEqual(
result[Counter],
AggregationTemporality.CUMULATIVE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,6 @@ def _exporting(self) -> str:
Returns a string that describes the overall exporter, to be used in
warning messages.
"""
pass

def _set_meter_provider(self, meter_provider: MeterProvider) -> None:
self._metrics = create_exporter_metrics(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from opentelemetry.exporter.otlp.proto.common.trace_encoder import (
encode_spans,
)
from opentelemetry.exporter.otlp.proto.grpc.exporter import ( # noqa: F401
from opentelemetry.exporter.otlp.proto.grpc.exporter import (
_RETRYABLE_ERROR_CODES,
InvalidCompressionValueException,
OTLPExporterMixin,
Expand Down Expand Up @@ -174,11 +174,9 @@ def setUp(self):
self.span = _Span(
"a",
context=Mock(
**{
"trace_state": {"a": "b", "c": "d"},
"span_id": 10217189687419569865,
"trace_id": 67545097771067222548457157018666467027,
}
trace_state={"a": "b", "c": "d"},
span_id=10217189687419569865,
trace_id=67545097771067222548457157018666467027,
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,25 +73,21 @@ def setUp(self):
self.tracer = tracer_provider.get_tracer(__name__)

event_mock = Mock(
**{
"timestamp": 1591240820506462784,
"attributes": BoundedAttributes(attributes={"a": 1, "b": False}),
}
timestamp=1591240820506462784,
attributes=BoundedAttributes(attributes={"a": 1, "b": False}),
)

type(event_mock).name = PropertyMock(return_value="a")
type(event_mock).dropped_attributes = PropertyMock(return_value=0)
self.span = _Span(
"a",
context=Mock(
**{
"trace_state": {"a": "b", "c": "d"},
"span_id": 10217189687419569865,
"trace_id": 67545097771067222548457157018666467027,
}
trace_state={"a": "b", "c": "d"},
span_id=10217189687419569865,
trace_id=67545097771067222548457157018666467027,
),
resource=SDKResource({"a": 1, "b": False}),
parent=Mock(**{"span_id": 12345}),
parent=Mock(span_id=12345),
attributes=BoundedAttributes(attributes={"a": 1, "b": True}),
events=[event_mock],
links=[
Expand All @@ -111,28 +107,24 @@ def setUp(self):
self.span2 = _Span(
"b",
context=Mock(
**{
"trace_state": {"a": "b", "c": "d"},
"span_id": 10217189687419569865,
"trace_id": 67545097771067222548457157018666467027,
}
trace_state={"a": "b", "c": "d"},
span_id=10217189687419569865,
trace_id=67545097771067222548457157018666467027,
),
resource=SDKResource({"a": 2, "b": False}),
parent=Mock(**{"span_id": 12345}),
parent=Mock(span_id=12345),
instrumentation_scope=InstrumentationScope(name="name", version="version"),
)

self.span3 = _Span(
"c",
context=Mock(
**{
"trace_state": {"a": "b", "c": "d"},
"span_id": 10217189687419569865,
"trace_id": 67545097771067222548457157018666467027,
}
trace_state={"a": "b", "c": "d"},
span_id=10217189687419569865,
trace_id=67545097771067222548457157018666467027,
),
resource=SDKResource({"a": 1, "b": False}),
parent=Mock(**{"span_id": 12345}),
parent=Mock(span_id=12345),
instrumentation_scope=InstrumentationScope(name="name2", version="version2"),
)

Expand Down Expand Up @@ -669,13 +661,11 @@ def _create_span_with_status(status: SDKStatus):
span = _Span(
"a",
context=Mock(
**{
"trace_state": {"a": "b", "c": "d"},
"span_id": 10217189687419569865,
"trace_id": 67545097771067222548457157018666467027,
}
trace_state={"a": "b", "c": "d"},
span_id=10217189687419569865,
trace_id=67545097771067222548457157018666467027,
),
parent=Mock(**{"span_id": 12345}),
parent=Mock(span_id=12345),
instrumentation_scope=InstrumentationScope(name="name", version="version"),
)
span.set_status(status)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
_resolve_timeout,
)
from opentelemetry.metrics import MeterProvider
from opentelemetry.proto.collector.metrics.v1.metrics_service_pb2 import ( # noqa: F401
from opentelemetry.proto.collector.metrics.v1.metrics_service_pb2 import (
ExportMetricsServiceRequest,
)
from opentelemetry.proto.common.v1.common_pb2 import ( # noqa: F401
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ def _collect_data_points(
return label_keys, label_rows, values

# pylint: disable=no-self-use
def _check_value(self, value: int | float | str | Sequence) -> str:
def _check_value(self, value: float | str | Sequence) -> str:
"""Check the label value and return is appropriate representation"""
if not isinstance(value, str):
return dumps(value, default=str)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ def get_data_for_max_tag_length_test(
span.set_attribute("tuple4", (2,) * 10)
span.set_attribute("tuple5", (True,) * 25)
span.set_attribute("tuple6", (True,) * 10)
span.set_attribute("range1", range(0, 25))
span.set_attribute("range2", range(0, 10))
span.set_attribute("range1", range(25))
span.set_attribute("range2", range(10))
span.set_attribute("empty_list", [])
span.set_attribute("none_list", ["hello", None, "world"])
span.end(end_time=end_time)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ def get_data_for_max_tag_length_test(
span.set_attribute("tuple4", (2,) * 10)
span.set_attribute("tuple5", (True,) * 25)
span.set_attribute("tuple6", (True,) * 10)
span.set_attribute("range1", range(0, 25))
span.set_attribute("range2", range(0, 10))
span.set_attribute("range1", range(25))
span.set_attribute("range2", range(10))
span.set_attribute("empty_list", [])
span.set_attribute("none_list", ["hello", None, "world"])
span.end(end_time=end_time)
Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-api/src/opentelemetry/_logs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
from opentelemetry._logs.severity import SeverityNumber

__all__ = [
"LogRecord",
"Logger",
"LoggerProvider",
"LogRecord",
"NoOpLogger",
"NoOpLoggerProvider",
"SeverityNumber",
"get_logger",
"get_logger_provider",
"set_logger_provider",
"SeverityNumber",
]
2 changes: 1 addition & 1 deletion opentelemetry-api/src/opentelemetry/context/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from uuid import uuid4

# pylint: disable=wrong-import-position
from opentelemetry.context.context import Context, _RuntimeContext # noqa
from opentelemetry.context.context import Context, _RuntimeContext
from opentelemetry.context.contextvars_context import ContextVarsRuntimeContext
from opentelemetry.environment_variables import OTEL_PYTHON_CONTEXT

Expand Down
34 changes: 17 additions & 17 deletions opentelemetry-api/src/opentelemetry/metrics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,31 +91,31 @@
obj.__module__ = __name__

__all__ = [
"Asynchronous",
"CallbackOptions",
"MeterProvider",
"NoOpMeterProvider",
"Meter",
"CallbackT",
"Counter",
"_Gauge",
"_NoOpGauge",
"NoOpCounter",
"UpDownCounter",
"NoOpUpDownCounter",
"Histogram",
"Instrument",
"Meter",
"MeterProvider",
"NoOpCounter",
"NoOpHistogram",
"ObservableCounter",
"NoOpMeter",
"NoOpMeterProvider",
"NoOpObservableCounter",
"ObservableUpDownCounter",
"Instrument",
"Synchronous",
"Asynchronous",
"NoOpObservableGauge",
"ObservableGauge",
"NoOpObservableUpDownCounter",
"NoOpUpDownCounter",
"ObservableCounter",
"ObservableGauge",
"ObservableUpDownCounter",
"Observation",
"Synchronous",
"UpDownCounter",
"_Gauge",
"_NoOpGauge",
"get_meter",
"get_meter_provider",
"set_meter_provider",
"Observation",
"CallbackT",
"NoOpMeter",
]
Loading
Loading