Skip to content

chore: apply fixes for UP ruff rule#5133

Merged
lzchen merged 19 commits into
open-telemetry:mainfrom
emdneto:up-ruff-rule
May 7, 2026
Merged

chore: apply fixes for UP ruff rule#5133
lzchen merged 19 commits into
open-telemetry:mainfrom
emdneto:up-ruff-rule

Conversation

@emdneto

@emdneto emdneto commented Apr 21, 2026

Copy link
Copy Markdown
Member

Description


opentelemetry._logs._internal.LogRecord:1:more than one target located for cross-referencing 'Context': opentelemetry.context.Context, opentelemetry.context.context.Context

99% of the changes were made by ruff with ruff check --fix. The agent removed the unused imports and fixed minor issues.

Fixes #4227

This is important to make our codebase updated with the most recent supported syntax.

Assisted-by: Copilot

@emdneto
emdneto requested a review from a team as a code owner April 21, 2026 22:42
@DylanRussell

Copy link
Copy Markdown
Contributor

nice. couple failed CI checks but otherwise LGTM

@github-project-automation github-project-automation Bot moved this to Approved PRs in Python PR digest Apr 22, 2026
@emdneto emdneto moved this from Approved PRs to Ready for review in Python PR digest Apr 22, 2026

@emdneto emdneto left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for manual changes i've done in 6051e44 and 874317d to make CI pass

@emdneto emdneto added the Approve Public API check This label shows that the public symbols added or changed in a PR are strictly necessary label Apr 22, 2026

@MikeGoldsmith MikeGoldsmith left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Some linter checks failed that will need to be cleaned up.

Comment thread CHANGELOG.md Outdated
@MikeGoldsmith MikeGoldsmith moved this from Ready for review to Approved PRs in Python PR digest Apr 27, 2026
@DylanRussell

Copy link
Copy Markdown
Contributor

@emdneto

emdneto commented Apr 27, 2026

Copy link
Copy Markdown
Member Author

If you have time I think we could do the same thing in the contrib repo: https://github.com/open-telemetry/opentelemetry-python-contrib/blob/main/pyproject.toml#L162

That's the plan after getting this merged

@emdneto emdneto changed the title Apply fixes for UP ruff rule chore: apply fixes for UP ruff rule May 6, 2026
@xrmx xrmx moved this from Approved PRs to Ready for merge in Python PR digest May 7, 2026
@emdneto

emdneto commented May 7, 2026

Copy link
Copy Markdown
Member Author

Answering the question from today's SIG: is it safe for downstream typecheckers? E.g. Typing -> collections.abc

I wrote this PoC:

//lib_sdk.py

from collections.abc import Callable


def parse_value(v: str | int) -> str: return str(v)
def run_callback(cb: Callable[[str], int]) -> int: return cb("hi")

//downstream.py

from typing import Callable, Union

from lib_sdk import parse_value, run_callback

value: Union[str, int] = parse_value("abc")

def cb(s: str) -> int: return len(s)
old_cb: Callable[[str], int] = cb
run_callback(old_cb)

And later:

pyright --pythonversion 3.10 downstream.py
0 errors, 0 warnings, 0 informations

cc @xrmx

@lzchen
lzchen enabled auto-merge (squash) May 7, 2026 17:54
@lzchen
lzchen merged commit 57fe0c1 into open-telemetry:main May 7, 2026
465 checks passed
@github-project-automation github-project-automation Bot moved this from Ready for merge to Done in Python PR digest May 7, 2026
raajheshkannaa added a commit to raajheshkannaa/opentelemetry-python that referenced this pull request May 8, 2026
Submodule .rst files were removed in open-telemetry#5133. This was missed during the
prior merge.

Reviewed-by: Leighton Chen
raajheshkannaa added a commit to raajheshkannaa/opentelemetry-python that referenced this pull request May 17, 2026
Submodule .rst files were removed in open-telemetry#5133. This was missed during the
prior merge.

Reviewed-by: Leighton Chen
herin049 pushed a commit to herin049/opentelemetry-python that referenced this pull request May 20, 2026
…ry#5017)

* docs: add missing modules to sphinx documentation build

Add RST files and toctree entries for modules that were not included
in the sphinx doc build:

API:
- opentelemetry._events (Events API)
- opentelemetry.attributes (Attributes utilities)
- opentelemetry.trace.propagation (Trace context propagation)

SDK:
- opentelemetry.sdk._events (Events SDK implementation)
- opentelemetry.sdk._logs.export (Log export processors and exporters)

Closes open-telemetry#2573

Signed-off-by: Raajhesh Kannaa Chidambaram <[email protected]>

* fix: add Event class to nitpick_ignore for sphinx docs build

Signed-off-by: Raajhesh Kannaa Chidambaram <[email protected]>

* fix: add changelog entry and nitpick_ignore for get_finished_logs

Add CHANGELOG entry for the docs PR and suppress the Sphinx
cross-reference warning for get_finished_logs (referenced as :func:
in a docstring we did not modify).

* fix: add Token class to nitpick_ignore for sphinx docs build

* address review: remove events API, fix get_finished_logs xref, move changelog

- Remove docs/api/_events.rst and docs/sdk/_events.rst (events API is
  deprecated per MikeGoldsmith, avoid exposing it in docs).
- Remove _events entries from api/index.rst and sdk/index.rst toctrees.
- Drop Event class nitpick_ignore entry (no longer needed).
- Fix docstring cross-reference on InMemoryLogRecordExporter from :func:
  to :meth: since get_finished_logs is a method, and drop its
  nitpick_ignore entry.
- Move changelog entry from 1.41.0/0.62b0 to Unreleased.

* docs: remove trace.propagation.rst per maintainer review

Submodule .rst files were removed in open-telemetry#5133. This was missed during the
prior merge.

Reviewed-by: Leighton Chen

* docs: re-export AnyValue from attributes module for sphinx forward-ref resolution

sphinx_autodoc_typehints calls get_type_hints on BoundedAttributes,
which uses _ExtendedAttributes (Mapping[str, 'AnyValue']) from util.types.
The forward ref to 'AnyValue' resolves in BoundedAttributes' __globals__
(the attributes module), not in util.types where it is defined.
Re-export AnyValue into the attributes module namespace so the
forward ref resolves and the docs build succeeds.

Signed-off-by: Raajhesh Kannaa Chidambaram <[email protected]>

* docs: use explicit re-export for AnyValue (fix ruff)

Signed-off-by: Raajhesh Kannaa Chidambaram <[email protected]>

* docs: use __all__ for AnyValue re-export to satisfy both pylint and ruff

* docs: inject AnyValue into attributes namespace via conf.py instead of re-exporting

Signed-off-by: Raajhesh Kannaa Chidambaram <[email protected]>

* docs: migrate changelog entry to towncrier fragment

Address @emdneto's feedback: replace direct CHANGELOG.md edit with a
.changelog/5017.fixed fragment per the new towncrier workflow added in

* docs: drop dead trace toctree (no trace.{status,span,propagation}.rst exist)

The Submodules toctree referenced files that were never added in this PR and trace.propagation.rst was removed earlier per review. Sphinx -W treats the missing toctree target as a warning-as-error, breaking the docs build.

Signed-off-by: Raajhesh Kannaa Chidambaram <[email protected]>

---------

Signed-off-by: Raajhesh Kannaa Chidambaram <[email protected]>
Co-authored-by: Raajhesh Kannaa Chidambaram <[email protected]>
Co-authored-by: Leighton Chen <[email protected]>
Co-authored-by: Emídio Neto <[email protected]>
liustve added a commit to aws-observability/aws-otel-python-instrumentation that referenced this pull request Jun 17, 2026
Automated update of OpenTelemetry dependencies.

**Build Status:** ❌
[failure](https://github.com/aws-observability/aws-otel-python-instrumentation/actions/runs/27184408784)

**Updated versions:**
- [OpenTelemetry
Python](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.42.1):
1.42.1
- [OpenTelemetry
Contrib](https://github.com/open-telemetry/opentelemetry-python-contrib/releases/tag/v0.63b1):
0.63b1
-
[opentelemetry-sdk-extension-aws](https://pypi.org/project/opentelemetry-sdk-extension-aws/2.1.0/):
2.1.0
-
[opentelemetry-propagator-aws-xray](https://pypi.org/project/opentelemetry-propagator-aws-xray/1.0.2/):
1.0.2

**Upstream releases with breaking changes:**
Note: the mechanism to detect upstream breaking changes is not perfect.
Be sure to check all new releases and understand if any additional
changes need to be addressed.


**opentelemetry-python-contrib:**
- [Version
1.41.0/0.62b0](https://github.com/open-telemetry/opentelemetry-python-contrib/releases/tag/v0.62b0)

*Description of changes:*

- Drops the `opentelemetry-instrumentation-boto` runtime dependency
(legacy boto2 instrumentation), removed entirely upstream in:
open-telemetry/opentelemetry-python-contrib#4303

- Drops Python 3.9 support to match upstream's new minimum (Python
≥3.10): open-telemetry/opentelemetry-python#5076
(core) and
open-telemetry/opentelemetry-python-contrib#4412
(contrib)

- Switches `from importlib_metadata import version` to stdlib `from
importlib.metadata import version` after upstream dropped the
third-party `importlib-metadata` package from `opentelemetry-api`:
open-telemetry/opentelemetry-python#3234

- Refactors the botocore patches (`_botocore_patches.py`) to use the new
`ExtensionRegistry` API. Upstream split `_KNOWN_EXTENSIONS` into
`_BOTOCORE_EXTENSIONS` + `_AIOBOTOCORE_EXTENSIONS`, removed
`_find_extension`, and moved `_safe_invoke` to
`opentelemetry.instrumentation.botocore.utils` as part of adding
aiobotocore instrumentation:
open-telemetry/opentelemetry-python-contrib#4049

- Removes the Starlette ASGI `suppress_http_instrumentation` patch
(which the existing ADOT TODO already flagged) since the ASGI middleware
now natively honors `suppress_http_instrumentation` upstream:
open-telemetry/opentelemetry-python-contrib#4375

- Adapts the configurator tests to upstream's renamed
`BaggageSpanProcessor._baggage_key_predicate` → `_predicates` (now a
list of callables, after the constructor was reworked to accept either a
single predicate or a sequence):
open-telemetry/opentelemetry-python-contrib#4371

- Adapts `test_otlp_attribute_vs_body_types` to upstream's
`_VALID_ANY_VALUE_TYPES` switching `typing.Mapping`/`typing.Sequence` to
`collections.abc.Mapping`/`collections.abc.Sequence`:
open-telemetry/opentelemetry-python#5133

- Bumps the mysqlclient contract-test pin from `2.2.4` to `2.2.8` and
updates the matching `db.name` assertion. The 0.62b0 dbapi
semantic-convention migration
(open-telemetry/opentelemetry-python-contrib#4109)
added an empty-string filter inside `_set_db_name`, which exposed a
latent gap: mysqlclient < 2.2.7 didn't expose a Python-level `conn.db`
attribute (added upstream in
PyMySQL/mysqlclient#752, shipped in mysqlclient
2.2.7), so OTel's dbapi instrumentation defaulted `database` to `""` and
the empty value used to land on the span unconditionally. After 0.62b0
the empty value is dropped, so the assertion `db.name == ""` now fails
with "key not found". Bumping mysqlclient lets `conn.db` flow through as
the actual database name (`testdb`) so the assertion becomes meaningful.


By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.

---------

Co-authored-by: github-actions <[email protected]>
Co-authored-by: Steve Liu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Approve Public API check This label shows that the public symbols added or changed in a PR are strictly necessary

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Add more rules to ruff linter

5 participants