-
Notifications
You must be signed in to change notification settings - Fork 626
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
Instrument SQLAlchemy engine connection phase #1133
Comments
I've created a PR adding this functionality - #1134 |
From your image it looks like there is a |
@shahargl so it creates a |
Do you use session factory? |
I use this example: https://github.com/ets-labs/python-dependency-injector/blob/master/examples/miniapps/fastapi-sqlalchemy/webapp/database.py class Database:
def __init__(self, db_url: str) -> None:
self._engine = create_engine(
db_url,
echo=get_config().QUERY_ECHO,
json_serializer=_custom_json_serializer,
pool_pre_ping=True,
pool_size=get_config().DB_POOL_SIZE,
)
self._session_factory = orm.scoped_session(
orm.sessionmaker(
autocommit=False,
autoflush=False,
bind=self._engine,
),
)
def create_database(self) -> None:
Base.metadata.create_all(self._engine)
@contextmanager
def session(self) -> Callable[..., AbstractContextManager[Session]]:
session: Session = self._session_factory()
try:
yield session
except Exception as e:
# logger.exception("Session rollback because of exception")
session.rollback()
raise e
finally:
session.close() and our dependency injector: from dependency_injector import containers, providers
class Container(containers.DeclarativeContainer):
wiring_config = containers.WiringConfiguration(packages=[
"api.routes",
"tasks.routes",
"common.observability"
])
config = providers.Configuration()
db = providers.Singleton(Database, db_url=get_config().DB_URL()) And then our Repository uses: event_repository = providers.Factory(EventRepository, session_factory=db.provided.session) |
** Is your feature request related to a problem? **
The SQLAlchemy instrumentation does not trace the actual connection to the database
Describe the solution you'd like
I want that
connect
function will also be tracedDescribe alternatives you've considered
Which alternative solutions or features have you considered?
Additional context
We are working with SQLAlchemy (snowflake db) and we implemented a solution where we can see the
connect
span also as attached in the screenshot (the span isdatabase-connect
)The text was updated successfully, but these errors were encountered: