You've already forked mariadb-columnstore-engine
							
							
				mirror of
				https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
				synced 2025-11-03 17:13:17 +03:00 
			
		
		
		
	Tracing requests Custom log factory adds all trace values as one log record parameter (it will be empty if trace values are empty, like in MainThread where there are no incoming requests)
		
			
				
	
	
		
			44 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			44 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
"""Async sibling of TracedSession"""
 | 
						|
 | 
						|
from typing import Any
 | 
						|
 | 
						|
import aiohttp
 | 
						|
 | 
						|
from cmapi_server.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)
 | 
						|
            try:
 | 
						|
                tracer.inject_traceparent(headers)
 | 
						|
            except Exception:
 | 
						|
                pass
 | 
						|
            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)
 | 
						|
 | 
						|
 |