Skip to content

Commit 5b6ea8e

Browse files
Merge branch 'optional-send-receive-spans-fastapi' into optional-send-receive-spans
2 parents 839dbf9 + 0741bc6 commit 5b6ea8e

File tree

1 file changed

+27
-1
lines changed
  • instrumentation/opentelemetry-instrumentation-fastapi/src/opentelemetry/instrumentation/fastapi

1 file changed

+27
-1
lines changed

instrumentation/opentelemetry-instrumentation-fastapi/src/opentelemetry/instrumentation/fastapi/__init__.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,30 @@ def instrument_app(
232232
http_capture_headers_server_request: list[str] | None = None,
233233
http_capture_headers_server_response: list[str] | None = None,
234234
http_capture_headers_sanitize_fields: list[str] | None = None,
235+
exclude_receive_span: bool = False,
236+
exclude_send_span: bool = False,
235237
):
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+
"""
237259
if not hasattr(app, "_is_instrumented_by_opentelemetry"):
238260
app._is_instrumented_by_opentelemetry = False
239261

@@ -273,6 +295,8 @@ def instrument_app(
273295
http_capture_headers_server_request=http_capture_headers_server_request,
274296
http_capture_headers_server_response=http_capture_headers_server_response,
275297
http_capture_headers_sanitize_fields=http_capture_headers_sanitize_fields,
298+
exclude_receive_span=exclude_receive_span,
299+
exclude_send_span=exclude_send_span,
276300
)
277301
app._is_instrumented_by_opentelemetry = True
278302
if app not in _InstrumentedFastAPI._instrumented_fastapi_apps:
@@ -373,6 +397,8 @@ def __init__(self, *args, **kwargs):
373397
http_capture_headers_server_request=_InstrumentedFastAPI._http_capture_headers_server_request,
374398
http_capture_headers_server_response=_InstrumentedFastAPI._http_capture_headers_server_response,
375399
http_capture_headers_sanitize_fields=_InstrumentedFastAPI._http_capture_headers_sanitize_fields,
400+
exclude_receive_span=False,
401+
exclude_send_span=False,
376402
)
377403
self._is_instrumented_by_opentelemetry = True
378404
_InstrumentedFastAPI._instrumented_fastapi_apps.add(self)

0 commit comments

Comments
 (0)