Skip to content

Commit 95aa114

Browse files
committed
Merge remote-tracking branch 'origin/add-integration-for-aiohttp' into add-integration-for-aiohttp
2 parents 494c397 + 3e66a13 commit 95aa114

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

src/asgi_monitor/integrations/aiohttp.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,7 @@ class MetricsConfig(BaseMetricsConfig):
8888

8989
@dataclass(slots=True, frozen=True)
9090
class TracingConfig:
91-
"""
92-
Configuration class for the OpenTelemetry middleware.
93-
Consult the OpenTelemetry ASGI documentation for more info about the configuration options.
94-
https://opentelemetry-python-contrib.readthedocs.io/en/latest/instrumentation/asgi/asgi.html
95-
"""
91+
"""Configuration class for the OpenTelemetry middleware."""
9692

9793
scope_span_details_extractor: Callable[[Request], tuple[str, dict[str, Any]]] = _get_default_span_details
9894
"""
@@ -228,6 +224,15 @@ async def get_metrics(request: Request) -> Response:
228224

229225

230226
def setup_metrics(app: Application, config: MetricsConfig) -> None:
227+
"""
228+
Set up metrics for an Aiohttp application.
229+
This function adds a metrics_middleware to the Aiohttp application with the specified parameters.
230+
231+
:param Aiohttp app: The Aiohttp application instance.
232+
:param MetricsConfig config: Configuration for the metrics.
233+
:returns: None
234+
"""
235+
231236
metrics = build_metrics_manager(config)
232237
metrics.add_app_info()
233238

@@ -243,6 +248,15 @@ def setup_metrics(app: Application, config: MetricsConfig) -> None:
243248

244249

245250
def setup_tracing(app: Application, config: TracingConfig) -> None:
251+
"""
252+
Set up tracing for an Aiohttp application.
253+
The function adds a tracing_middleware to the Aiohttp application based on TracingConfig.
254+
255+
:param Aiohttp app: The Aiohttp application instance.
256+
:param TracingConfig config: The OpenTelemetry config.
257+
:return: None
258+
"""
259+
246260
app.middlewares.append(build_tracing_middleware(config))
247261

248262

src/asgi_monitor/logging/aiohttp/logger.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414

1515

1616
class TraceAccessLogger(AccessLogger):
17+
"""
18+
The heir of the default logging AccessLogger class,
19+
which implements the addition of trace meta information to the aiohttp request log.
20+
"""
21+
1722
def log(self, request: BaseRequest, response: StreamResponse, time: float) -> None:
1823
if not self.logger.isEnabledFor(logging.INFO):
1924
# Avoid formatting the log line if it will not be emitted.

0 commit comments

Comments
 (0)