@@ -232,8 +232,30 @@ def instrument_app(
232
232
http_capture_headers_server_request : list [str ] | None = None ,
233
233
http_capture_headers_server_response : list [str ] | None = None ,
234
234
http_capture_headers_sanitize_fields : list [str ] | None = None ,
235
+ exclude_receive_span : bool = False ,
236
+ exclude_send_span : bool = False ,
235
237
):
236
- """Instrument an uninstrumented FastAPI application."""
238
+ """Instrument an uninstrumented FastAPI application.
239
+
240
+ Args:
241
+ app: The ASGI application callable to forward requests to.
242
+ server_request_hook: Optional callback which is called with the server span and ASGI
243
+ scope object for every incoming request.
244
+ client_request_hook: Optional callback which is called with the internal span, and ASGI
245
+ scope and event which are sent as dictionaries for when the method receive is called.
246
+ client_response_hook: Optional callback which is called with the internal span, and ASGI
247
+ scope and event which are sent as dictionaries for when the method send is called.
248
+ tracer_provider: The optional tracer provider to use. If omitted
249
+ the current globally configured one is used.
250
+ meter_provider: The optional meter provider to use. If omitted
251
+ the current globally configured one is used.
252
+ excluded_urls: Optional comma delimited string of regexes to match URLs that should not be traced.
253
+ http_capture_headers_server_request: Optional list of HTTP headers to capture from the request.
254
+ http_capture_headers_server_response: Optional list of HTTP headers to capture from the response.
255
+ http_capture_headers_sanitize_fields: Optional list of HTTP headers to sanitize.
256
+ exclude_receive_span: Optional flag to exclude the http receive span from the trace.
257
+ exclude_send_span: Optional flag to exclude the http send span from the trace.
258
+ """
237
259
if not hasattr (app , "_is_instrumented_by_opentelemetry" ):
238
260
app ._is_instrumented_by_opentelemetry = False
239
261
@@ -273,6 +295,8 @@ def instrument_app(
273
295
http_capture_headers_server_request = http_capture_headers_server_request ,
274
296
http_capture_headers_server_response = http_capture_headers_server_response ,
275
297
http_capture_headers_sanitize_fields = http_capture_headers_sanitize_fields ,
298
+ exclude_receive_span = exclude_receive_span ,
299
+ exclude_send_span = exclude_send_span ,
276
300
)
277
301
app ._is_instrumented_by_opentelemetry = True
278
302
if app not in _InstrumentedFastAPI ._instrumented_fastapi_apps :
@@ -373,6 +397,8 @@ def __init__(self, *args, **kwargs):
373
397
http_capture_headers_server_request = _InstrumentedFastAPI ._http_capture_headers_server_request ,
374
398
http_capture_headers_server_response = _InstrumentedFastAPI ._http_capture_headers_server_response ,
375
399
http_capture_headers_sanitize_fields = _InstrumentedFastAPI ._http_capture_headers_sanitize_fields ,
400
+ exclude_receive_span = False ,
401
+ exclude_send_span = False ,
376
402
)
377
403
self ._is_instrumented_by_opentelemetry = True
378
404
_InstrumentedFastAPI ._instrumented_fastapi_apps .add (self )
0 commit comments