Skip to content

Commit

Permalink
[DO NOT MERGE] Add some more Sentry trace points
Browse files Browse the repository at this point in the history
  • Loading branch information
rra committed Nov 21, 2024
1 parent dc63403 commit 7a47c0c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
2 changes: 2 additions & 0 deletions src/gafaelfawr/dependencies/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Annotated
from urllib.parse import urlencode, urlparse

import sentry_sdk
from fastapi import Depends, Header, HTTPException, status

from ..auth import (
Expand Down Expand Up @@ -236,6 +237,7 @@ class AuthenticateRead(Authenticate):
Should be used as a FastAPI dependency.
"""

@sentry_sdk.trace
async def __call__(
self,
*,
Expand Down
34 changes: 18 additions & 16 deletions src/gafaelfawr/dependencies/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
including from dependencies.
"""

from collections.abc import AsyncIterator
from dataclasses import dataclass
from typing import Annotated, Any
from typing import Any

from fastapi import Depends, HTTPException, Request
import sentry_sdk
from fastapi import HTTPException, Request
from safir.dependencies.db_session import db_session_dependency
from safir.dependencies.logger import logger_dependency
from safir.metrics import EventManager
Expand Down Expand Up @@ -99,11 +101,7 @@ async def __call__(
self,
*,
request: Request,
session: Annotated[
async_scoped_session, Depends(db_session_dependency)
],
logger: Annotated[BoundLogger, Depends(logger_dependency)],
) -> RequestContext:
) -> AsyncIterator[RequestContext]:
"""Create a per-request context and return it."""
if not self._config or not self._process_context or not self._events:
raise RuntimeError("ContextDependency not initialized")
Expand All @@ -117,15 +115,19 @@ async def __call__(
"type": "missing_client_ip",
},
)
return RequestContext(
request=request,
ip_address=ip_address,
config=self._config,
logger=logger,
events=self._events,
session=session,
factory=Factory(self._process_context, session, logger),
)
with sentry_sdk.start_span(name="logger"):
logger = await logger_dependency(request)
with sentry_sdk.start_span(name="context"):
async for session in db_session_dependency():
yield RequestContext(
request=request,
ip_address=ip_address,
config=self._config,
logger=logger,
events=self._events,
session=session,
factory=Factory(self._process_context, session, logger),
)

@property
def process_context(self) -> ProcessContext:
Expand Down

0 comments on commit 7a47c0c

Please sign in to comment.