1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-11-02 06:13:16 +03:00

Created a separate package for tracing-related stuff

Added mirroring of spans into Sentry
Tracer is a facade that redirects actions to tracing backends
This commit is contained in:
Alexander Presnyakov
2025-08-29 23:04:24 +00:00
committed by Leonid Fedorov
parent a0b4bcd1ce
commit 9b98c5c20a
22 changed files with 681 additions and 514 deletions

View File

@@ -0,0 +1,40 @@
"""Async sibling of TracedSession."""
from typing import Any
import aiohttp
from tracing.tracer import get_tracer
class TracedAsyncSession(aiohttp.ClientSession):
async def _request(
self, method: str, str_or_url: Any, *args: Any, **kwargs: Any
) -> aiohttp.ClientResponse:
tracer = get_tracer()
headers = kwargs.get("headers") or {}
if headers is None:
headers = {}
kwargs["headers"] = headers
url_text = str(str_or_url)
span_name = f"HTTP {method} {url_text}"
with tracer.start_as_current_span(span_name, kind="CLIENT") as span:
span.set_attribute("http.method", method)
span.set_attribute("http.url", url_text)
tracer.inject_outbound_headers(headers)
try:
response = await super()._request(method, str_or_url, *args, **kwargs)
except Exception as exc:
span.set_status("ERROR", str(exc))
raise
else:
span.set_attribute("http.status_code", response.status)
return response
def create_traced_async_session(**kwargs: Any) -> TracedAsyncSession:
return TracedAsyncSession(**kwargs)