Skip to content

Migrate typing for opentelemetry files #4510

New issue

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

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

Already on GitHub? # 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

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
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants