@@ -69,8 +69,21 @@ def _get_path(request: Request) -> tuple[str, bool]:
6969
7070@dataclass
7171class TracingConfig (CommonTracingConfig ):
72+ """Configuration class for the OpenTelemetry middleware.
73+ Consult the OpenTelemetry ASGI documentation for more info about the configuration options.
74+ https://opentelemetry-python-contrib.readthedocs.io/en/latest/instrumentation/asgi/asgi.html
75+ """
76+
7277 exclude_urls_env_key : str = "STARLETTE"
78+ """Key to use when checking whether a list of excluded urls is passed via ENV.
79+ OpenTelemetry supports excluding urls by passing an env in the format '{exclude_urls_env_key}_EXCLUDED_URLS'.
80+ """
81+
7382 scope_span_details_extractor : Callable [[Any ], tuple [str , dict [str , Any ]]] = _get_default_span_details
83+ """
84+ Callback which should return a string and a tuple, representing the desired default span name and a dictionary
85+ with any additional span attributes to set.
86+ """
7487
7588
7689class TracingMiddleware :
@@ -162,6 +175,15 @@ async def get_metrics(request: Request) -> Response:
162175
163176
164177def setup_tracing (app : Starlette , config : TracingConfig ) -> None :
178+ """
179+ Set up tracing for a Starlette application.
180+ The function adds a TracingMiddleware to the Starlette application based on TracingConfig.
181+
182+ :param Starlette app: The FastAPI application instance.
183+ :param TracingConfig config: The Open Telemetry config.
184+ :returns: None
185+ """
186+
165187 app .add_middleware (TracingMiddleware , config = config )
166188
167189
@@ -173,6 +195,19 @@ def setup_metrics(
173195 include_trace_exemplar : bool ,
174196 include_metrics_endpoint : bool ,
175197) -> None :
198+ """
199+ Set up metrics for a Starlette application.
200+ This function adds a MetricsMiddleware to the Starlette application with the specified parameters.
201+ If include_metrics_endpoint is True, it also adds a route for "/metrics" that returns Prometheus default metrics.
202+
203+ :param Starlette app: The Starlette application instance.
204+ :param str app_name: The name of the Starlette application.
205+ :param str metrics_prefix: The prefix to use for the metrics (default is "starlette").
206+ :param bool include_trace_exemplar: Whether to include trace exemplars in the metrics.
207+ :param bool include_metrics_endpoint: Whether to include a /metrics endpoint.
208+ :returns: None
209+ """
210+
176211 app .add_middleware (
177212 MetricsMiddleware ,
178213 app_name = app_name ,
0 commit comments