File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55
66import strawberry
77from fastapi import Depends
8+ from strawberry .extensions .tracing import OpenTelemetryExtension
89from strawberry .fastapi import GraphQLRouter
910from strawberry .types import Info
1011from datajunction_server .api .graphql .queries .catalogs import list_catalogs
@@ -128,6 +129,11 @@ class Query:
128129 )
129130
130131
131- schema = strawberry .Schema (query = Query )
132+ schema = strawberry .Schema (
133+ query = Query ,
134+ extensions = [
135+ OpenTelemetryExtension ,
136+ ],
137+ )
132138
133139graphql_app = GraphQLRouter (schema , context_getter = get_context )
Original file line number Diff line number Diff line change 22Main DJ server app.
33"""
44
5+ from contextlib import asynccontextmanager
56import logging
67from datajunction_server .api import setup_logging # noqa
78
5455
5556dependencies = [Depends (default_attribute_types ), Depends (default_catalog )]
5657
58+
59+ @asynccontextmanager
60+ async def lifespan (app : FastAPI ):
61+ """
62+ Lifespan context for initializing and tearing down app-wide resources, like the FastAPI cache
63+ """
64+ FastAPICache .init (InMemoryBackend (), prefix = "inmemory-cache" ) # pragma: no cover
65+
66+ yield
67+
68+
5769app = FastAPI (
5870 title = settings .name ,
5971 description = settings .description ,
6375 "url" : "https://mit-license.org/" ,
6476 },
6577 dependencies = dependencies ,
78+ lifespan = lifespan ,
6679)
6780
6881app .add_middleware (
98111app .include_router (notifications .router )
99112
100113
101- @app .on_event ("startup" )
102- async def startup ():
103- """
104- Initialize FastAPI cache when the server starts up
105- """
106- FastAPICache .init (InMemoryBackend (), prefix = "inmemory-cache" ) # pragma: no cover
107-
108-
109114@app .exception_handler (DJException )
110115async def dj_exception_handler (
111116 request : Request ,
You can’t perform that action at this time.
0 commit comments