summary refs log tree commit diff
diff options
context:
space:
mode:
authorEric Eastwood <erice@element.io>2022-08-11 10:27:55 -0500
committerEric Eastwood <erice@element.io>2022-08-11 10:27:55 -0500
commit898ba0effe3d2563764c2a057df22f901f836d23 (patch)
tree524dd83ab043ce3b9ac813699727ab0ab69afd06
parentInstrument FederationStateIdsServlet (diff)
downloadsynapse-898ba0effe3d2563764c2a057df22f901f836d23.tar.xz
More tracing
-rw-r--r--synapse/federation/federation_server.py2
-rw-r--r--synapse/handlers/federation.py21
-rw-r--r--synapse/handlers/relations.py10
-rw-r--r--synapse/logging/tracing.py1
-rw-r--r--synapse/rest/client/room.py2
-rw-r--r--synapse/storage/databases/main/relations.py5
-rw-r--r--synapse/storage/util/partial_state_events_tracker.py6
-rw-r--r--synapse/util/ratelimitutils.py2
-rw-r--r--tests/logging/test_tracing.py2
9 files changed, 35 insertions, 16 deletions
diff --git a/synapse/federation/federation_server.py b/synapse/federation/federation_server.py
index 716cbc5cef..dd9aeba9c8 100644
--- a/synapse/federation/federation_server.py
+++ b/synapse/federation/federation_server.py
@@ -61,7 +61,7 @@ from synapse.logging.context import (
     nested_logging_context,
     run_in_background,
 )
-from synapse.logging.tracing import log_kv, start_active_span_from_edu, trace, tag_args
+from synapse.logging.tracing import log_kv, start_active_span_from_edu, tag_args, trace
 from synapse.metrics.background_process_metrics import wrap_as_background_process
 from synapse.replication.http.federation import (
     ReplicationFederationSendEduRestServlet,
diff --git a/synapse/handlers/federation.py b/synapse/handlers/federation.py
index 45d56402ec..54c23c1eb2 100644
--- a/synapse/handlers/federation.py
+++ b/synapse/handlers/federation.py
@@ -59,7 +59,13 @@ from synapse.events.validator import EventValidator
 from synapse.federation.federation_client import InvalidResponseError
 from synapse.http.servlet import assert_params_in_dict
 from synapse.logging.context import nested_logging_context
-from synapse.logging.tracing import SynapseTags, set_attribute, trace, tag_args
+from synapse.logging.tracing import (
+    SynapseTags,
+    set_attribute,
+    start_active_span,
+    tag_args,
+    trace,
+)
 from synapse.metrics.background_process_metrics import run_as_background_process
 from synapse.module_api import NOT_SPAM
 from synapse.replication.http.federation import (
@@ -380,13 +386,16 @@ class FederationHandler:
         # First we try hosts that are already in the room
         # TODO: HEURISTIC ALERT.
 
-        curr_state = await self._storage_controllers.state.get_current_state(room_id)
+        with start_active_span("getting likely_domains"):
+            curr_state = await self._storage_controllers.state.get_current_state(
+                room_id
+            )
 
-        curr_domains = get_domains_from_state(curr_state)
+            curr_domains = get_domains_from_state(curr_state)
 
-        likely_domains = [
-            domain for domain, depth in curr_domains if domain != self.server_name
-        ]
+            likely_domains = [
+                domain for domain, depth in curr_domains if domain != self.server_name
+            ]
 
         async def try_backfill(domains: List[str]) -> bool:
             # TODO: Should we try multiple of these at a time?
diff --git a/synapse/handlers/relations.py b/synapse/handlers/relations.py
index 41c64d62c8..70497353a3 100644
--- a/synapse/handlers/relations.py
+++ b/synapse/handlers/relations.py
@@ -19,7 +19,7 @@ import attr
 from synapse.api.constants import RelationTypes
 from synapse.api.errors import SynapseError
 from synapse.events import EventBase, relation_from_event
-from synapse.logging.tracing import trace
+from synapse.logging.tracing import SynapseTags, set_attribute, trace
 from synapse.storage.databases.main.relations import _RelatedEvent
 from synapse.types import JsonDict, Requester, StreamToken, UserID
 from synapse.visibility import filter_events_for_client
@@ -166,6 +166,7 @@ class RelationsHandler:
 
         return return_value
 
+    @trace
     async def get_relations_for_event(
         self,
         event_id: str,
@@ -200,6 +201,7 @@ class RelationsHandler:
 
         return related_events, next_token
 
+    @trace
     async def get_annotations_for_event(
         self,
         event_id: str,
@@ -245,6 +247,7 @@ class RelationsHandler:
 
         return filtered_results
 
+    @trace
     async def _get_threads_for_events(
         self,
         events_by_id: Dict[str, EventBase],
@@ -406,6 +409,11 @@ class RelationsHandler:
             # The event should get bundled aggregations.
             events_by_id[event.event_id] = event
 
+        set_attribute(
+            SynapseTags.FUNC_ARG_PREFIX + f"event_ids ({len(events_by_id)})",
+            str(events_by_id.keys()),
+        )
+
         # event ID -> bundled aggregation in non-serialized form.
         results: Dict[str, BundledAggregations] = {}
 
diff --git a/synapse/logging/tracing.py b/synapse/logging/tracing.py
index e629548a04..86ff8fc637 100644
--- a/synapse/logging/tracing.py
+++ b/synapse/logging/tracing.py
@@ -912,7 +912,6 @@ def trace(func: Callable[P, R]) -> Callable[P, R]:
     Sets the operation name to that of the function's name.
     See the module's doc string for usage examples.
     """
-
     return trace_with_opname(func.__name__)(func)
 
 
diff --git a/synapse/rest/client/room.py b/synapse/rest/client/room.py
index 94fc6bba84..3880846e9a 100644
--- a/synapse/rest/client/room.py
+++ b/synapse/rest/client/room.py
@@ -563,7 +563,6 @@ class RoomMessageListRestServlet(RestServlet):
     async def on_GET(
         self, request: SynapseRequest, room_id: str
     ) -> Tuple[int, JsonDict]:
-        logger.info("RoomMessageListRestServlet afwefaewfewfew")
         requester = await self.auth.get_user_by_req(request, allow_guest=True)
         pagination_config = await PaginationConfig.from_request(
             self.store, request, default_limit=10
@@ -593,7 +592,6 @@ class RoomMessageListRestServlet(RestServlet):
             as_client_event=as_client_event,
             event_filter=event_filter,
         )
-        logger.info("RoomMessageListRestServlet afwefaewfewfew got msgs")
 
         return 200, msgs
 
diff --git a/synapse/storage/databases/main/relations.py b/synapse/storage/databases/main/relations.py
index 7bd27790eb..255854cd66 100644
--- a/synapse/storage/databases/main/relations.py
+++ b/synapse/storage/databases/main/relations.py
@@ -30,6 +30,7 @@ import attr
 
 from synapse.api.constants import RelationTypes
 from synapse.events import EventBase
+from synapse.logging.tracing import trace
 from synapse.storage._base import SQLBaseStore
 from synapse.storage.database import LoggingTransaction, make_in_list_sql_clause
 from synapse.storage.databases.main.stream import generate_pagination_where_clause
@@ -349,6 +350,10 @@ class RelationsWorkerStore(SQLBaseStore):
     def get_applicable_edit(self, event_id: str) -> Optional[EventBase]:
         raise NotImplementedError()
 
+    # TODO: What's the proper way to fix this so we can stack @trace on top of
+    # @cachedList
+    #
+    # @trace
     @cachedList(cached_method_name="get_applicable_edit", list_name="event_ids")
     async def get_applicable_edits(
         self, event_ids: Collection[str]
diff --git a/synapse/storage/util/partial_state_events_tracker.py b/synapse/storage/util/partial_state_events_tracker.py
index 55a275392c..07af89ee31 100644
--- a/synapse/storage/util/partial_state_events_tracker.py
+++ b/synapse/storage/util/partial_state_events_tracker.py
@@ -20,7 +20,7 @@ from twisted.internet import defer
 from twisted.internet.defer import Deferred
 
 from synapse.logging.context import PreserveLoggingContext, make_deferred_yieldable
-from synapse.logging.tracing import trace
+from synapse.logging.tracing import trace_with_opname
 from synapse.storage.databases.main.events_worker import EventsWorkerStore
 from synapse.storage.databases.main.room import RoomWorkerStore
 from synapse.util import unwrapFirstError
@@ -59,7 +59,7 @@ class PartialStateEventsTracker:
             for o in observers:
                 o.callback(None)
 
-    @trace
+    @trace_with_opname("PartialStateEventsTracker.await_full_state")
     async def await_full_state(self, event_ids: Collection[str]) -> None:
         """Wait for all the given events to have full state.
 
@@ -153,7 +153,7 @@ class PartialCurrentStateTracker:
             for o in observers:
                 o.callback(None)
 
-    @trace
+    @trace_with_opname("PartialCurrentStateTracker.await_full_state")
     async def await_full_state(self, room_id: str) -> None:
         # We add the deferred immediately so that the DB call to check for
         # partial state doesn't race when we unpartial the room.
diff --git a/synapse/util/ratelimitutils.py b/synapse/util/ratelimitutils.py
index b04e440f58..2c0c6d53de 100644
--- a/synapse/util/ratelimitutils.py
+++ b/synapse/util/ratelimitutils.py
@@ -21,13 +21,13 @@ from typing import Any, DefaultDict, Iterator, List, Set
 from twisted.internet import defer
 
 from synapse.api.errors import LimitExceededError
-from synapse.logging.tracing import start_active_span
 from synapse.config.ratelimiting import FederationRatelimitSettings
 from synapse.logging.context import (
     PreserveLoggingContext,
     make_deferred_yieldable,
     run_in_background,
 )
+from synapse.logging.tracing import start_active_span
 from synapse.util import Clock
 
 if typing.TYPE_CHECKING:
diff --git a/tests/logging/test_tracing.py b/tests/logging/test_tracing.py
index cb0ebb0844..337796bccf 100644
--- a/tests/logging/test_tracing.py
+++ b/tests/logging/test_tracing.py
@@ -16,7 +16,7 @@ from twisted.internet import defer
 from twisted.test.proto_helpers import MemoryReactorClock
 
 from synapse.logging.context import make_deferred_yieldable, run_in_background
-from synapse.logging.tracing import start_active_span, trace_with_opname, tag_args
+from synapse.logging.tracing import start_active_span, tag_args, trace_with_opname
 from synapse.util import Clock
 
 from tests.unittest import TestCase