8000 Migrate typing for opentelemetry files by sl0thentr0py · Pull Request #4510 · getsentry/sentry-python · GitHub
[go: up one dir, main page]

Skip to content

Migrate typing for opentelemetry files #4510

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 25, 2025
Merged

Conversation

sl0thentr0py
Copy link
Member
@sl0thentr0py sl0thentr0py commented Jun 24, 2025
  • remove casts
  • generalize is_valid_sample_rate to return the validated float
  • added a validate_scopes helper method to validate the scopes entry on the context and return the narrowed type
  • added a get_typed_attribute helper method to narrow the type on getting attributes from otel
  • fix a flaky test on gevent

@sl0thentr0py sl0thentr0py requested a review from a team as a code owner June 24, 2025 13:45
@sl0thentr0py sl0thentr0py force-pushed the neel/typing-2 branch 2 times, most recently from 4b736e1 to 80dd79f Compare June 24, 2025 14:14
Copy link
codecov bot commented Jun 24, 2025

Codecov Report

Attention: Patch coverage is 99.25373% with 1 line in your changes missing coverage. Please review.

Project coverage is 84.67%. Comparing base (f7db68d) to head (3f2b752).
Report is 1 commits behind head on neel/typing.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
sentry_sdk/opentelemetry/span_processor.py 96.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@               Coverage Diff               @@
##           neel/typing    #4510      +/-   ##
===============================================
- Coverage        84.68%   84.67%   -0.01%     
===============================================
  Files              144      144              
  Lines            14847    14854       +7     
  Branches          2370     2372       +2     
===============================================
+ Hits             12573    12578       +5     
- Misses            1544     1545       +1     
- Partials           730      731       +1     
Files with missing lines Coverage Δ
sentry_sdk/opentelemetry/contextvars_context.py 100.00% <100.00%> (ø)
sentry_sdk/opentelemetry/propagator.py 83.67% <100.00%> (ø)
sentry_sdk/opentelemetry/sampler.py 91.66% <100.00%> (ø)
sentry_sdk/opentelemetry/scope.py 95.87% <100.00%> (+0.17%) ⬆️
sentry_sdk/opentelemetry/tracing.py 90.32% <100.00%> (+0.32%) ⬆️
sentry_sdk/opentelemetry/utils.py 83.53% <100.00%> (ø)
sentry_sdk/profiler/transaction_profiler.py 85.98% <100.00%> (-0.60%) ⬇️
sentry_sdk/tracing_utils.py 84.35% <ø> (ø)
sentry_sdk/utils.py 89.48% <100.00%> (ø)
sentry_sdk/opentelemetry/span_processor.py 82.14% <96.00%> (ø)

if profiler_id is None:
return None

8000 return {"profiler_id": profiler_id}


def get_typed_attribute(
Copy link
Member Author

Choose a reason for hiding this comment

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

helper function to get an attribute with a certain typecheck

@@ -1561,10 +1561,11 @@ def parse_url(url: str, sanitize: bool = True) -> ParsedUrl:
)


def is_valid_sample_rate(rate: Any, source: str) -> bool:
def is_valid_sample_rate(rate: Any, source: str) -> Optional[float]:
Copy link
Member Author
@sl0thentr0py sl0thentr0py Jun 24, 2025

Choose a reason for hiding this comment

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

returns the validated float sample_rate to simplify all the float casts around

@sl0thentr0py sl0thentr0py merged commit 28fbd0a into neel/typing Jun 25, 2025
124 checks passed
@sl0thentr0py sl0thentr0py deleted the neel/typing-2 branch June 25, 2025 12:07
sl0thentr0py added a commit that referenced this pull request Jun 25, 2025
* remove casts
* generalize `is_valid_sample_rate` to return the validated float
* added a `validate_scopes` helper method to validate the scopes entry
on the context and return the narrowed type
* added a `get_typed_attribute` helper method to narrow the type on
getting attributes from otel
* fix a flaky test on gevent
sl0thentr0py added a commit that referenced this pull request Jun 25, 2025
* remove casts
* generalize `is_valid_sample_rate` to return the validated float
* added a `validate_scopes` helper method to validate the scopes entry
on the context and return the narrowed type
* added a `get_typed_attribute` helper method to narrow the type on
getting attributes from otel
* fix a flaky test on gevent
sl0thentr0py added a commit that referenced this pull request Jun 26, 2025
* remove casts
* generalize `is_valid_sample_rate` to return the validated float
* added a `validate_scopes` helper method to validate the scopes entry
on the context and return the narrowed type
* added a `get_typed_attribute` helper method to narrow the type on
getting attributes from otel
* fix a flaky test on gevent
@sl0thentr0py sl0thentr0py mentioned this pull request Jun 26, 2025
sl0thentr0py added a commit that referenced this pull request Jun 27, 2025
* remove casts
* generalize `is_valid_sample_rate` to return the validated float
* added a `validate_scopes` helper method to validate the scopes entry
on the context and return the narrowed type
* added a `get_typed_attribute` helper method to narrow the type on
getting attributes from otel
* fix a flaky test on gevent
sl0thentr0py added a commit that referenced this pull request Jun 30, 2025
extracted from
https://github.com/getsentry/sentry-python/pull/4487/files with lots of
manual fixes

* migrate old style `# type: bla` to inline types
* most importantly use
[`__future__.annotations`](https://peps.python.org/pep-0563/#enabling-the-future-behavior-in-python-3-7)
so that we can simply use forward annotations without wrapping them in
strings like we did before, this simplifies things substantially
* also guard only things that shouldn't be imported under
`TYPE_CHECKING`, in the future it seems we should avoid using
`TYPE_CHECKING` completely
* #4510
* #4522
* #4529
* #4530
* #4532
* #4533
* #4534

closes #2585
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0