diff --git a/.changelog/4939.added b/.changelog/4939.added new file mode 100644 index 0000000000..ddf66bd1fb --- /dev/null +++ b/.changelog/4939.added @@ -0,0 +1 @@ +`opentelemetry-instrumentation-fastapi`: document environment variables, trace propagation, websocket support, logging integration, and add PyPI link diff --git a/instrumentation/opentelemetry-instrumentation-fastapi/src/opentelemetry/instrumentation/fastapi/__init__.py b/instrumentation/opentelemetry-instrumentation-fastapi/src/opentelemetry/instrumentation/fastapi/__init__.py index 2513f5eb86..90649ac19e 100644 --- a/instrumentation/opentelemetry-instrumentation-fastapi/src/opentelemetry/instrumentation/fastapi/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-fastapi/src/opentelemetry/instrumentation/fastapi/__init__.py @@ -2,6 +2,12 @@ # SPDX-License-Identifier: Apache-2.0 """ +This library provides automatic and manual instrumentation of FastAPI web frameworks, +instrumenting http requests served by applications utilizing the framework. + +The package is available on PyPI as `opentelemetry-instrumentation-fastapi +`_. + Usage ----- @@ -175,6 +181,41 @@ def client_response_hook(span: Span, scope: Scope, message: Message): Note: The environment variable names used to capture HTTP headers are still experimental, and thus are subject to change. +Exporter and general SDK configuration +*************************************** +This page only documents environment variables specific to FastAPI instrumentation. +General OpenTelemetry SDK configuration, such as ``OTEL_SERVICE_NAME``, ``OTEL_EXPORTER_OTLP_ENDPOINT``, +and ``OTEL_EXPORTER_OTLP_PROTOCOL``, is not specific to FastAPI and is documented separately in the +`OpenTelemetry Python SDK environment variables `_ +and the `general SDK configuration spec `_. +These variables are read by the SDK and exporter packages once they are installed and configured, and do not +require any FastAPI-specific setup. + +Trace context propagation +************************** +Incoming trace context is extracted automatically. This instrumentation is built on top of the ASGI +:class:`opentelemetry.instrumentation.asgi.OpenTelemetryMiddleware`, which reads the configured +propagators (``tracecontext`` and ``baggage`` by default) from incoming request headers and continues +the trace without any manual code. To use a different propagator (for example AWS X-Ray or B3), set +the ``OTEL_PROPAGATORS`` environment variable; see the +`propagators API docs `_ for details. + +WebSocket support +******************* +WebSocket connections are instrumented as well as HTTP requests, since the underlying ASGI middleware +handles both the ``http`` and ``websocket`` ASGI scope types. No additional configuration is required to +trace WebSocket connections beyond the standard ``FastAPIInstrumentor.instrument_app(app)`` call. + +Logs +****** +Logs are not captured automatically by this instrumentation. To correlate Python log records with the +current trace and export them as OpenTelemetry log records/events, install and configure +``opentelemetry-instrumentation-logging`` separately, and set ``OTEL_PYTHON_LOG_CORRELATION=true`` +(or pass ``set_logging_format=True`` to ``LoggingInstrumentor().instrument()``) to inject trace context +into log records. See the +`logging instrumentation docs `_ +for the full configuration options. + API --- """