Skip to content

Conversation

@dhruv-ahuja
Copy link
Contributor

This PR addresses the need to properly instrument async engines values, as mentioned in #1402's review comment.

@codecov
Copy link

codecov bot commented Sep 23, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@alexmojaki alexmojaki requested a review from Copilot September 23, 2025 23:27
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for instrumenting async SqlAlchemy engines by handling the engines parameter and automatically converting async engines to their sync equivalents for proper instrumentation.

  • Adds validation and conversion logic for the engines parameter in the instrumentation function
  • Updates test coverage to verify both single engine and multiple engines parameter usage
  • Introduces a test case to validate proper error handling for invalid engines parameter types

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
logfire/_internal/integrations/sqlalchemy.py Implements async engine conversion logic and engines parameter validation
tests/otel_integrations/test_sqlalchemy.py Adds comprehensive test coverage for engines parameter and parametrized existing tests

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

- move sync conversion to separate function
- remove extra parameter passed to async test
- remove unneeded test
engine = _convert_to_sync_engine(engine)

if engines is not None:
engines = [_convert_to_sync_engine(engine_entry) for engine_entry in engines] # type: ignore
Copy link
Contributor

Choose a reason for hiding this comment

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

i'm surprised there's a type error here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I also thought it would coerce the types internally, as the list[Engine] type is just a subset of Iterable[Engine | AsyncEngine | None]

@alexmojaki
Copy link
Contributor

Thanks!

@alexmojaki alexmojaki enabled auto-merge (squash) September 24, 2025 19:02
@alexmojaki alexmojaki merged commit 795064a into pydantic:main Sep 24, 2025
14 checks passed
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