Skip to content

fix(opentelemetry): update tests for otel sdk 1.40.0 compatibility#4662

Merged
provinzkraut merged 2 commits intolitestar-org:mainfrom
giorgiovilardo:support-opentelemetry-python-1-40
Apr 2, 2026
Merged

fix(opentelemetry): update tests for otel sdk 1.40.0 compatibility#4662
provinzkraut merged 2 commits intolitestar-org:mainfrom
giorgiovilardo:support-opentelemetry-python-1-40

Conversation

@giorgiovilardo
Copy link
Copy Markdown
Contributor

@giorgiovilardo giorgiovilardo commented Apr 2, 2026

Description

Referring to opentelemetry-python#5009, the issue is a bit nuanced: there is one change to make upstream - long story very short, there is an unsafe attribute access that is triggered by passing no boundaries to ExplicitBucketHistogramAggregation i.e. aggregation_last_value = {Counter: ExplicitBucketHistogramAggregation()} and then pass this as preferred_aggregation to the InMemoryMetricReader, in tests/unit/test_contrib/test_opentelemetry.py:33-35.

This will be fixed upstream but also made more robust on Litestar side with the proposed change:

aggregation_last_value = {Counter: ExplicitBucketHistogramAggregation(boundaries=[])}

By fixing this, we would expose a subsequent problem on test_open_telemetry_middleware_with_http_route, more specifically when navigating scope_metrics via index with scope_metrics = resource_metrics.scope_metrics[0]; this is due to 1.40.0 TracerProviders having a new TracerMetrics class that instruments them. This changes the ordering on the scope_metrics, making indexed access fail.

The other proposed change will just get the correct scope skipping the otel tagged one.

This will allow, once upstream is done, to unpin (or in general update) opentelemetry-sdk


📚 Documentation preview 📚: https://litestar-org.github.io/litestar-docs-preview/4662

@giorgiovilardo
Copy link
Copy Markdown
Contributor Author

@xrmx @provinzkraut

@giorgiovilardo giorgiovilardo force-pushed the support-opentelemetry-python-1-40 branch from cc022b7 to 3786661 Compare April 2, 2026 07:21
Copy link
Copy Markdown

@xrmx xrmx left a comment

Choose a reason for hiding this comment

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

I think you also need to remove the upper bound in pyproject.toml to see if it's working with 1.40.0.

@giorgiovilardo
Copy link
Copy Markdown
Contributor Author

giorgiovilardo commented Apr 2, 2026

hey @xrmx, yep already done that but not doing the unpin in this pr - leaving it to the more established contributors

relevant diffs / pip show

image

make test-all output

image

so yeah technically this is already able to receive otel 1.40.0 I guess, but still better to also fix upstream the unsafe access

@provinzkraut
Copy link
Copy Markdown
Member

Thanks for this @giorgiovilardo! I agree with @xrmx though, we should remove the version constraint in this same PR

@github-actions github-actions bot added the area/dependencies This PR involves changes to the dependencies label Apr 2, 2026
@giorgiovilardo giorgiovilardo force-pushed the support-opentelemetry-python-1-40 branch from 5082765 to 72ba042 Compare April 2, 2026 18:03
@giorgiovilardo
Copy link
Copy Markdown
Contributor Author

@provinzkraut done ;)

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.33%. Comparing base (ab72cc5) to head (6f585a1).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4662   +/-   ##
=======================================
  Coverage   67.33%   67.33%           
=======================================
  Files         292      292           
  Lines       14938    14938           
  Branches     1675     1675           
=======================================
  Hits        10058    10058           
  Misses       4743     4743           
  Partials      137      137           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@giorgiovilardo giorgiovilardo force-pushed the support-opentelemetry-python-1-40 branch from 72ba042 to c71f29f Compare April 2, 2026 18:08
@giorgiovilardo giorgiovilardo force-pushed the support-opentelemetry-python-1-40 branch from c71f29f to 6f585a1 Compare April 2, 2026 19:24
@provinzkraut provinzkraut enabled auto-merge (squash) April 2, 2026 19:51
@provinzkraut provinzkraut merged commit b65dc41 into litestar-org:main Apr 2, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/dependencies This PR involves changes to the dependencies pr/external size: small Triage Required 🏥 This requires triage type/bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants