summary refs log tree commit diff
path: root/synapse/http
diff options
context:
space:
mode:
Diffstat (limited to 'synapse/http')
-rw-r--r--synapse/http/client.py20
-rw-r--r--synapse/http/matrixfederationclient.py26
-rw-r--r--synapse/http/server.py24
-rw-r--r--synapse/http/site.py40
4 files changed, 64 insertions, 46 deletions
diff --git a/synapse/http/client.py b/synapse/http/client.py

index 084d0a5b84..89bd403312 100644 --- a/synapse/http/client.py +++ b/synapse/http/client.py
@@ -75,7 +75,13 @@ from synapse.http import QuieterFileBodyProducer, RequestTimedOutError, redact_u from synapse.http.proxyagent import ProxyAgent from synapse.http.types import QueryParams from synapse.logging.context import make_deferred_yieldable -from synapse.logging.opentracing import set_tag, start_active_span, tags +from synapse.logging.tracing import ( + SpanAttributes, + SpanKind, + StatusCode, + set_status, + start_active_span, +) from synapse.types import ISynapseReactor from synapse.util import json_decoder from synapse.util.async_helpers import timeout_deferred @@ -402,12 +408,11 @@ class SimpleHttpClient: with start_active_span( "outgoing-client-request", - tags={ - tags.SPAN_KIND: tags.SPAN_KIND_RPC_CLIENT, - tags.HTTP_METHOD: method, - tags.HTTP_URL: uri, + kind=SpanKind.CLIENT, + attributes={ + SpanAttributes.HTTP_METHOD: method, + SpanAttributes.HTTP_URL: uri, }, - finish_on_close=True, ): try: body_producer = None @@ -459,8 +464,7 @@ class SimpleHttpClient: type(e).__name__, e.args[0], ) - set_tag(tags.ERROR, True) - set_tag("error_reason", e.args[0]) + set_status(StatusCode.ERROR, e) raise async def post_urlencoded_get_json( diff --git a/synapse/http/matrixfederationclient.py b/synapse/http/matrixfederationclient.py
index 3c35b1d2c7..00704a6a7c 100644 --- a/synapse/http/matrixfederationclient.py +++ b/synapse/http/matrixfederationclient.py
@@ -72,9 +72,14 @@ from synapse.http.client import ( ) from synapse.http.federation.matrix_federation_agent import MatrixFederationAgent from synapse.http.types import QueryParams -from synapse.logging import opentracing +from synapse.logging import tracing from synapse.logging.context import make_deferred_yieldable, run_in_background -from synapse.logging.opentracing import set_tag, start_active_span, tags +from synapse.logging.tracing import ( + SpanAttributes, + SpanKind, + set_attribute, + start_active_span, +) from synapse.types import JsonDict from synapse.util import json_decoder from synapse.util.async_helpers import AwakenableSleeper, timeout_deferred @@ -517,18 +522,19 @@ class MatrixFederationHttpClient: scope = start_active_span( "outgoing-federation-request", - tags={ - tags.SPAN_KIND: tags.SPAN_KIND_RPC_CLIENT, - tags.PEER_ADDRESS: request.destination, - tags.HTTP_METHOD: request.method, - tags.HTTP_URL: request.path, + kind=SpanKind.CLIENT, + attributes={ + SpanAttributes.HTTP_HOST: request.destination, + SpanAttributes.HTTP_METHOD: request.method, + SpanAttributes.HTTP_URL: request.path, }, - finish_on_close=True, ) # Inject the span into the headers headers_dict: Dict[bytes, List[bytes]] = {} - opentracing.inject_header_dict(headers_dict, request.destination) + tracing.inject_active_tracing_context_into_header_dict( + headers_dict, request.destination + ) headers_dict[b"User-Agent"] = [self.version_string_bytes] @@ -614,7 +620,7 @@ class MatrixFederationHttpClient: request.method, response.code ).inc() - set_tag(tags.HTTP_STATUS_CODE, response.code) + set_attribute(SpanAttributes.HTTP_STATUS_CODE, response.code) response_phrase = response.phrase.decode("ascii", errors="replace") if 200 <= response.code < 300: diff --git a/synapse/http/server.py b/synapse/http/server.py
index 19f42159b8..6420c0837b 100644 --- a/synapse/http/server.py +++ b/synapse/http/server.py
@@ -61,13 +61,13 @@ from synapse.api.errors import ( from synapse.config.homeserver import HomeServerConfig from synapse.http.site import SynapseRequest from synapse.logging.context import defer_to_thread, preserve_fn, run_in_background -from synapse.logging.opentracing import active_span, start_active_span, trace_servlet +from synapse.logging.tracing import get_active_span, start_active_span, trace_servlet from synapse.util import json_encoder from synapse.util.caches import intern_dict from synapse.util.iterutils import chunk_seq if TYPE_CHECKING: - import opentracing + import opentelemetry from synapse.server import HomeServer @@ -329,7 +329,7 @@ class HttpServer(Protocol): subsequent arguments will be any matched groups from the regex. This should return either tuple of (code, response), or None. servlet_classname (str): The name of the handler to be used in prometheus - and opentracing logs. + and tracing logs. """ @@ -340,7 +340,7 @@ class _AsyncResource(resource.Resource, metaclass=abc.ABCMeta): requests by method, or override `_async_render` to handle all requests. Args: - extract_context: Whether to attempt to extract the opentracing + extract_context: Whether to attempt to extract the tracing context from the request the servlet is handling. """ @@ -510,7 +510,7 @@ class JsonResource(DirectServeJsonResource): callback: The handler for the request. Usually a Servlet servlet_classname: The name of the handler to be used in prometheus - and opentracing logs. + and tracing logs. """ method_bytes = method.encode("utf-8") @@ -878,19 +878,19 @@ async def _async_write_json_to_request_in_thread( expensive. """ - def encode(opentracing_span: "Optional[opentracing.Span]") -> bytes: + def encode(tracing_span: Optional["opentelemetry.trace.Span"]) -> bytes: # it might take a while for the threadpool to schedule us, so we write - # opentracing logs once we actually get scheduled, so that we can see how + # tracing logs once we actually get scheduled, so that we can see how # much that contributed. - if opentracing_span: - opentracing_span.log_kv({"event": "scheduled"}) + if tracing_span: + tracing_span.add_event("scheduled", attributes={"event": "scheduled"}) res = json_encoder(json_object) - if opentracing_span: - opentracing_span.log_kv({"event": "encoded"}) + if tracing_span: + tracing_span.add_event("scheduled", attributes={"event": "encoded"}) return res with start_active_span("encode_json_response"): - span = active_span() + span = get_active_span() json_str = await defer_to_thread(request.reactor, encode, span) _write_bytes_to_request(request, json_str) diff --git a/synapse/http/site.py b/synapse/http/site.py
index eeec74b78a..d82c046dd7 100644 --- a/synapse/http/site.py +++ b/synapse/http/site.py
@@ -37,7 +37,7 @@ from synapse.logging.context import ( from synapse.types import Requester if TYPE_CHECKING: - import opentracing + import opentelemetry logger = logging.getLogger(__name__) @@ -85,9 +85,9 @@ class SynapseRequest(Request): # server name, for client requests this is the Requester object. self._requester: Optional[Union[Requester, str]] = None - # An opentracing span for this request. Will be closed when the request is + # An tracing span for this request. Will be closed when the request is # completely processed. - self._opentracing_span: "Optional[opentracing.Span]" = None + self._tracing_span: Optional["opentelemetry.trace.Span"] = None # we can't yet create the logcontext, as we don't know the method. self.logcontext: Optional[LoggingContext] = None @@ -164,12 +164,12 @@ class SynapseRequest(Request): # If there's no authenticated entity, it was the requester. self.logcontext.request.authenticated_entity = authenticated_entity or requester - def set_opentracing_span(self, span: "opentracing.Span") -> None: - """attach an opentracing span to this request + def set_tracing_span(self, span: "opentelemetry.trace.Span") -> None: + """attach an tracing span to this request Doing so will cause the span to be closed when we finish processing the request """ - self._opentracing_span = span + self._tracing_span = span def get_request_id(self) -> str: return "%s-%i" % (self.get_method(), self.request_seq) @@ -309,8 +309,10 @@ class SynapseRequest(Request): self._processing_finished_time = time.time() self._is_processing = False - if self._opentracing_span: - self._opentracing_span.log_kv({"event": "finished processing"}) + if self._tracing_span: + self._tracing_span.add_event( + "finished processing", attributes={"event": "finished processing"} + ) # if we've already sent the response, log it now; otherwise, we wait for the # response to be sent. @@ -325,8 +327,10 @@ class SynapseRequest(Request): """ self.finish_time = time.time() Request.finish(self) - if self._opentracing_span: - self._opentracing_span.log_kv({"event": "response sent"}) + if self._tracing_span: + self._tracing_span.add_event( + "response sent", attributes={"event": "response sent"} + ) if not self._is_processing: assert self.logcontext is not None with PreserveLoggingContext(self.logcontext): @@ -361,9 +365,13 @@ class SynapseRequest(Request): with PreserveLoggingContext(self.logcontext): logger.info("Connection from client lost before response was sent") - if self._opentracing_span: - self._opentracing_span.log_kv( - {"event": "client connection lost", "reason": str(reason.value)} + if self._tracing_span: + self._tracing_span.add_event( + "client connection lost", + attributes={ + "event": "client connection lost", + "reason": str(reason.value), + }, ) if self._is_processing: @@ -471,9 +479,9 @@ class SynapseRequest(Request): usage.evt_db_fetch_count, ) - # complete the opentracing span, if any. - if self._opentracing_span: - self._opentracing_span.finish() + # complete the tracing span, if any. + if self._tracing_span: + self._tracing_span.end() try: self.request_metrics.stop(self.finish_time, self.code, self.sentLength)