@@ -46,7 +46,7 @@ def instrument_fastapi(
4646 # FastAPIInstrumentor expects a comma-separated string, not a list.
4747 excluded_urls = ',' .join (excluded_urls )
4848
49- if use_opentelemetry_instrumentation :
49+ if use_opentelemetry_instrumentation : # pragma: no branch
5050 FastAPIInstrumentor .instrument_app (app , excluded_urls = excluded_urls ) # type: ignore
5151
5252 registry = patch_fastapi ()
@@ -68,7 +68,7 @@ def uninstrument_context():
6868 yield
6969 finally :
7070 del registry [app ]
71- if use_opentelemetry_instrumentation :
71+ if use_opentelemetry_instrumentation : # pragma: no branch
7272 FastAPIInstrumentor .uninstrument_app (app )
7373
7474 return uninstrument_context ()
@@ -84,7 +84,7 @@ async def patched_solve_dependencies(*, request: Request | WebSocket, **kwargs:
8484 if instrumentation := registry .get (request .app ):
8585 return await instrumentation .solve_dependencies (request , result )
8686 else :
87- return result
87+ return result # pragma: no cover
8888
8989 # `solve_dependencies` is actually defined in `fastapi.dependencies.utils`,
9090 # but it's imported into `fastapi.routing`, which is where we need to patch it.
@@ -100,7 +100,7 @@ async def patched_run_endpoint_function(*, dependant: Any, values: dict[str, Any
100100 return await instrumentation .run_endpoint_function (
101101 original_run_endpoint_function , request , dependant , values , ** kwargs
102102 )
103- return await original_run_endpoint_function (dependant = dependant , values = values , ** kwargs )
103+ return await original_run_endpoint_function (dependant = dependant , values = values , ** kwargs ) # pragma: no cover
104104
105105 original_run_endpoint_function = fastapi .routing .run_endpoint_function
106106 fastapi .routing .run_endpoint_function = patched_run_endpoint_function
@@ -128,15 +128,15 @@ def __init__(
128128 if excluded_urls is None :
129129 self .excluded_urls_list = get_excluded_urls ('FASTAPI' )
130130 else :
131- self .excluded_urls_list = parse_excluded_urls (excluded_urls )
131+ self .excluded_urls_list = parse_excluded_urls (excluded_urls ) # pragma: no cover
132132
133133 async def solve_dependencies (
134134 self , request : Request | WebSocket , result : tuple [dict [str , Any ], list [Any ], Any , Any , Any ]
135135 ):
136136 try :
137137 url = get_host_port_url_tuple (request .scope )[2 ]
138138 if self .excluded_urls_list .url_disabled (url ):
139- return result
139+ return result # pragma: no cover
140140
141141 attributes : dict [str , Any ] | None = {
142142 # Shallow copy these so that the user can safely modify them, but we don't tell them that.
@@ -151,7 +151,7 @@ async def solve_dependencies(
151151 }
152152
153153 # Set the current app on `values` so that `patched_run_endpoint_function` can check it.
154- if isinstance (request , Request ):
154+ if isinstance (request , Request ): # pragma: no branch
155155 instrumented_values = _InstrumentedValues (result [0 ])
156156 instrumented_values .request = request
157157 result = (instrumented_values , * result [1 :])
@@ -169,7 +169,7 @@ async def solve_dependencies(
169169 # Usually this will all be inside a span added by FastAPIInstrumentor with more detailed attributes.
170170 # We only add these attributes after the request_attributes_mapper so that the user
171171 # doesn't rely on what we add here - they can use `request` instead.
172- if isinstance (request , Request ):
172+ if isinstance (request , Request ): # pragma: no branch
173173 attributes [SpanAttributes .HTTP_METHOD ] = request .method
174174 route : APIRoute | APIWebSocketRoute | None = request .scope .get ('route' )
175175 if route : # pragma: no branch
@@ -179,7 +179,7 @@ async def solve_dependencies(
179179 'fastapi.route.name' : route .name ,
180180 }
181181 )
182- if isinstance (route , APIRoute ):
182+ if isinstance (route , APIRoute ): # pragma: no branch
183183 attributes ['fastapi.route.operation_id' ] = route .operation_id
184184
185185 self .logfire_instance .log (level , 'FastAPI arguments' , attributes = attributes )
@@ -216,7 +216,7 @@ def _default_request_attributes_mapper(
216216 _request : Request | WebSocket ,
217217 attributes : dict [str , Any ],
218218):
219- return attributes
219+ return attributes # pragma: no cover
220220
221221
222222class _InstrumentedValues (dict ): # type: ignore
0 commit comments